Autor Beitrag
tartare
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Sa 03.02.07 14:14 
Hallo,

Ich programmiere gerade ein Programm, welches Kreuzungsschemen für Vererbung berechnen soll.
Jedenfalls habe ich dafür ein array[2][merkmalsanzahl bis zu 9] meiner selbsterstellten Klasse "Wert".
Nun will ich alle Möglichkeiten in ein anderes array[anzahl aller möglichkeiten = 2^merkmalsanzahl][merkmalsanzahl] eintragen. (das hochzeichen funktioniert nicht sondern Math.Pow(basis, exponent)

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Beispiel:  merkmalsazahl = 4 
           0 1 2 3
         0 A B C D
         1 E F G H 
           
         möglichkeiten = 2^4 = 16
           
           0 1 2 3 
         0 A B C D <- ein buchstabe ist ein "Wert"
         1 A F C D
         2 A B G D
         3 A B C H
         .
        14 E B C H
        15 E F G D


Also entweder ein element aus dem 1. oder dem 2. array der selben position muss in das neue array.

ich habe nur leider keine ahnung wie ich das in einer schleifer oder anderweitig umsetzen kann. Vielleicht hat ja jemand eine Idee.
Danke im Vorraus

mfg tartare

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 03.02.07 14:23 
Rekrusion bietet sioch hier an.
Das Schema ist auch einem Kilometerstandsanzeiger ähnlich, der hat aber je Stelle 10 Möglichkeiten, du nur zwei.
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 03.02.07 14:25 
wie wärs so...

ausblenden Delphi-Quelltext
1:
2:
3:
for i := low(a) to high(a) do
 for j := low(b) to high(b) do
  c[i,j] = a[i]*b[j];
tartare Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Sa 03.02.07 21:35 
Gibt es noch ein anderes Beispiel zur Rekursion, weil dieses versteh ich nicht.

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.
tartare Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Do 08.02.07 16:50 
Ok ich hab das Problem jetzt so gelöst:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
           
          Maxanzahl = Convert.ToInt32(Math.Pow(2, merkmalsanzahl));
          for (int j = 0; j < merkmalsanzahl; j++)   
              for (int i = 0; i < 2; i++)
              {
                  for (int k = i * (Maxanzahl / Convert.ToInt32(Math.Pow(2, j + 1))); k < Maxanzahl; k++)
                  {                  
                      gv.FMoeglichkeit[k][j] = Frau.wert[i][j];
                      gv.MMoeglichkeit[k][j] = Mann.wert[i][j];
                      o ++;
                      if (o == Maxanzahl / Convert.ToInt32(Math.Pow(2, j + 1)))
                      {
                          k += Maxanzahl / Convert.ToInt32(Math.Pow(2, j + 1));
                          o = 0;
                      }
                  }
              }

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.