0

I am working on a small program that will take 3 digit number and shuffle it to all the possible outcomes. This is the code I have, and of course it works, but it seems very inefficient, and was wondering what other way can I do? As in instead of using different textbox can I use one, and shuffle the number placements?

namespace possibleoutcomes
{
    public partial class Form1 : Form
    {

        private void button1_Click(object sender, EventArgs e)
        {

            listBox1.Items.Add(textBox1.Text + textBox2.Text + textBox3.Text);
            listBox1.Items.Add(textBox1.Text + textBox3.Text + textBox2.Text);
            listBox1.Items.Add(textBox2.Text + textBox3.Text + textBox1.Text);
            listBox1.Items.Add(textBox2.Text + textBox1.Text + textBox3.Text);
            listBox1.Items.Add(textBox3.Text + textBox2.Text + textBox1.Text);
            listBox1.Items.Add(textBox3.Text + textBox1.Text + textBox2.Text);

        }


    }
}
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
andyADD
  • 610
  • 1
  • 6
  • 20
  • This is the same as this problem http://stackoverflow.com/questions/756055/listing-all-permutations-of-a-string-integer – Alfredo Alvarez Aug 26 '14 at 21:18
  • 1
    FYI, that's not a shuffle, you are listing *permutations*. – Blorgbeard Aug 26 '14 at 21:18
  • `-1`I Don't see any Shuffling going on here – MethodMan Aug 26 '14 at 21:19
  • 1
    Working code belongs on CodeReview SE – BradleyDotNET Aug 26 '14 at 21:19
  • FYI don't post duplicate questions to your code.. if you are unsure of how to do something try thinking about what it is you want to do then at least experiment with it.. for example look up how to use COntrols class in a ForEach loop or how to create a List or a HashSet or HashTable but don't give up just because you refuse to open / expand your mind.. – MethodMan Aug 26 '14 at 21:23
  • Oh wow so I have been looking in the wrong direction. Ok thanks I will look at the link alfredo alvarez linked, and look up permutaltions as what blorgbeard said. @DJKRAZE I was using a list earlier, and array, but it ended up doing 5436 and it output single number onto new line. – andyADD Aug 26 '14 at 21:24
  • Do you call it "working code" if it has known deficiencies? – Nerf Herder Aug 26 '14 at 21:35
  • @NerfHerder it gets the job done, just sloppy. – andyADD Aug 26 '14 at 22:57

0 Answers0