Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Collections;
  9.  
  10. namespace PuzzleKornShell
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         //String abc = "qwertyuiopasdfghjklzxcvbnm";
  15.         String abc   = "abcdefghijklmnopqrstuvwxyz";
  16.         Random r = new Random();
  17.        
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.         }
  26.  
  27.         public string rAlph()
  28.         {
  29.             String alph = "";
  30.             while (alph.Length < abc.Length)
  31.             {
  32.                 int x = r.Next(0, abc.Length);
  33.                 while (alph.Contains(Convert.ToString(abc[x]))) x = r.Next(0, abc.Length);
  34.                 alph += abc[x];
  35.             }
  36.             return alph;
  37.         }
  38.  
  39.         private void button1_Click(object sender, EventArgs e)
  40.         {
  41.             button1.Enabled = false;
  42.             int max = 0;
  43.             String ut = "";
  44.             listBox1.Items.Clear();
  45.             for (int k = 0; k < 1000; k++)
  46.             {
  47.                 String s = "";
  48.                 String alph = rAlph();
  49.                 String x = textBox1.Text;
  50.                 int kos = 1;
  51.                 while (kos < 1000000)
  52.                 {
  53.                     for (int i = 0; i < x.Length; i++)
  54.                     {
  55.                         int c = x[i] - 97;
  56.                         if (c >= 0 && c < 28)
  57.                         {
  58.                             s += alph[c];
  59.                         }
  60.                         else
  61.                         {
  62.                             s += x[i];
  63.                         }
  64.                     }
  65.                     x = s;
  66.                     if (textBox1.Text.Equals(s)) break;
  67.                     s = "";
  68.                     kos++;
  69.                 }
  70.                 if (kos > max)
  71.                 {
  72.                     max = kos;
  73.                     ut = alph;
  74.                 }
  75.                 //listBox1.Items.Add(alph + ": " + Convert.ToString(kos));
  76.             }
  77.             listBox1.Items.Add("MAX: " + ut + ": " + Convert.ToString(max));
  78.             button1.Enabled = true;
  79.             skriv(ut);
  80.         }
  81.  
  82.         private void skriv(String EkkeltAlfabet)
  83.         {
  84.             String s = "";
  85.             String alph = EkkeltAlfabet;
  86.             String x = textBox1.Text;
  87.             int kos = 1;
  88.             while (kos < 1000000)
  89.             {
  90.                 for (int i = 0; i < x.Length; i++)
  91.                 {
  92.                     int c = x[i] - 97;
  93.                     if (c >= 0 && c < 28)
  94.                     {
  95.                         listBox1.Items.Add("** Replaced " + x[i] + " with " + alph[c]);
  96.                         s += alph[c];
  97.                     }
  98.                     else
  99.                     {
  100.                         s += x[i];
  101.                     }
  102.                 }
  103.                 x = s;
  104.                 listBox1.Items.Add(Convert.ToString(kos) + ": " + x);
  105.                 if (textBox1.Text.Equals(s)) break;
  106.                 s = "";
  107.                 kos++;
  108.             }
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement