Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections;
- namespace PuzzleKornShell
- {
- public partial class Form1 : Form
- {
- //String abc = "qwertyuiopasdfghjklzxcvbnm";
- String abc = "abcdefghijklmnopqrstuvwxyz";
- Random r = new Random();
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- public string rAlph()
- {
- String alph = "";
- while (alph.Length < abc.Length)
- {
- int x = r.Next(0, abc.Length);
- while (alph.Contains(Convert.ToString(abc[x]))) x = r.Next(0, abc.Length);
- alph += abc[x];
- }
- return alph;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- button1.Enabled = false;
- int max = 0;
- String ut = "";
- listBox1.Items.Clear();
- for (int k = 0; k < 1000; k++)
- {
- String s = "";
- String alph = rAlph();
- String x = textBox1.Text;
- int kos = 1;
- while (kos < 1000000)
- {
- for (int i = 0; i < x.Length; i++)
- {
- int c = x[i] - 97;
- if (c >= 0 && c < 28)
- {
- s += alph[c];
- }
- else
- {
- s += x[i];
- }
- }
- x = s;
- if (textBox1.Text.Equals(s)) break;
- s = "";
- kos++;
- }
- if (kos > max)
- {
- max = kos;
- ut = alph;
- }
- //listBox1.Items.Add(alph + ": " + Convert.ToString(kos));
- }
- listBox1.Items.Add("MAX: " + ut + ": " + Convert.ToString(max));
- button1.Enabled = true;
- skriv(ut);
- }
- private void skriv(String EkkeltAlfabet)
- {
- String s = "";
- String alph = EkkeltAlfabet;
- String x = textBox1.Text;
- int kos = 1;
- while (kos < 1000000)
- {
- for (int i = 0; i < x.Length; i++)
- {
- int c = x[i] - 97;
- if (c >= 0 && c < 28)
- {
- listBox1.Items.Add("** Replaced " + x[i] + " with " + alph[c]);
- s += alph[c];
- }
- else
- {
- s += x[i];
- }
- }
- x = s;
- listBox1.Items.Add(Convert.ToString(kos) + ": " + x);
- if (textBox1.Text.Equals(s)) break;
- s = "";
- kos++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement