Encoder: Offtopic: Stochastik-Aufgabe

Beitrag lesen

Eine Brute-force-Attacke auf das Problem‽

Ja, ich wollte wissen was wirklich rauskommt. Weil mir gings so dass ich die erste Überlegung rein vom Durchlesen als sinnvoll eingeschätzt hab. Die zweite sagte dann nee, das geht anders. Erschien mir aber auch irgendwo schlüssig. Und meine Überlegung war dann eine dritte Lösung, drum wollt ich wissen was da wirklich rauskommt. Wie man das erklärt ist ja dann ne andere Sache.

Magst du deinen Algorithmus mal zeigen?

Gern, der läuft sogar nur wenige Sekunden.

const int elements = 12;
      int ges = 0;
      int wanted = 0;

for (int a = 0; a < elements; a++)
        for (int b = 0; b < elements; b++)
          for (int c = 0; c < elements; c++)
            for (int d = 0; d < elements; d++)
              for (int e = 0; e < elements; e++)
                for (int f = 0; f < elements; f++)
                  for (int g = 0; g < elements; g++)
                    for (int h = 0; h < elements; h++)
                    {
                      int count = 0;
                      if (a == b) count++;
                      if (a == c) count++;
                      if (a == d) count++;
                      if (a == e) count++;
                      if (a == f) count++;
                      if (a == g) count++;
                      if (a == h) count++;

if (b == c) count++;
                      if (b == d) count++;
                      if (b == e) count++;
                      if (b == f) count++;
                      if (b == g) count++;
                      if (b == h) count++;

if (c == d) count++;
                      if (c == e) count++;
                      if (c == f) count++;
                      if (c == g) count++;
                      if (c == h) count++;

if (d == e) count++;
                      if (d == f) count++;
                      if (d == g) count++;
                      if (d == h) count++;

if (e == f) count++;
                      if (e == g) count++;
                      if (e == h) count++;

if (f == g) count++;
                      if (f == h) count++;

if (g == h) count++;

if (count == 2)
                        wanted++;

ges++;
                    }

Console.WriteLine(ges);
      Console.WriteLine(wanted);