Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Zahlen-Kombinationen (https://www.delphipraxis.net/55220-zahlen-kombinationen.html)

bioser 18. Okt 2005 20:05

Re: Zahlen-Kombinationen
 
Zitat:

Zitat von freak4fun
Wie kommst du auf ' 2 0 1 3'? :gruebel:

Mit BioserPermutation ('0123', 3); komme ich auf 3012.

MfG
freak

Ja, genau.

bioser 18. Okt 2005 20:14

Re: Zahlen-Kombinationen
 
Zitat:

Zitat von alzaimar
Oh, ist doch aber nicht schwer:

Delphi-Quellcode:
Procedure BiosenPermutator (aList, aOutput : TList; aCount : Integer);
Begin
  aOutput[0] := aList [aCount];
  For i := 0 to High (aList) do
    if i<aCount then
      aOutput[i+1] := aList[i]
    else if i>aCount Then
      aOutput[i] := aList[i];
End;
Ungestet, aber sollte klappen.

Ja, das sieht doch sehr gut aus. Danke. Das high brauche ich nicht, dafür setze ich alist.count-1 ein. Vorher sollte man noch die Ausgabeliste mit Create erzeugen. Die Ausgabeliste benötigt aber noch Speicherplatz, oder ? So funktioniert es nämlich nicht.

alzaimar 19. Okt 2005 15:33

Re: Zahlen-Kombinationen
 
Der Aufrufer von BioserPermutation ist für die Speicherverwaltung zuständig. Weiterhin kannst/solltest Du die Datentypen sowie die High-funktion ggf an deinen Datentyp anpassen.
Wenn Deine Liste z.B. Als Array [0..3] Of Integer deklariert ist, dann wäre es ja schön blod, die zuerst in eine TList zu kopieren, dann zu BioserPermutieren, um sie abschließend wieder von der TList in das Array of Integer zurück zukopieren. Insofern verwendest Du meinen Code natürlich nur als Anhaltspunt.

Eichhoernchen 21. Okt 2005 15:56

Re: Zahlen-Kombinationen
 
Wir haben damit jetzt gerade in der Schule begonnen,
vielleicht hilft dir das:

Delphi-Quellcode:
const n = 5;

var
  Form1: TForm1;
  zahl_gesetzt : array[1..n] of Boolean;
  zahlen : array[1..n] of Integer;
  count : integer;

implementation

{$R *.dfm}

procedure init;
var i : integer;
Begin
for i := 1 to n do
 zahl_gesetzt[i] := false;
 count := 0;
end;

procedure Ausgabe(zahl : integer);
Begin
 Form1.StringGrid1.Cells[0, count] := IntToStr(zahl);
 inc(count);
 Form1.Stringgrid1.RowCount := count;
 Form1.StringGrid1.Update;
 Form1.StringGrid1.Refresh;
end;

procedure permut(i : integer);
var j, k ,zahl : integer;
Begin
 for j := 1 to n do
  if not zahl_gesetzt[j]
    then Begin
          zahlen[i] := j;
          zahl_gesetzt[j] := true;
          if i < n
            then permut(i+1)
            else Begin
                  zahl := 0;
                  for k := n downto 1 do
                    zahl := zahl + (zahlen[k] * round(power(10, n-k)));
                  Ausgabe(zahl);
                 end;
          zahl_gesetzt[j] := false;
         end;
end;



procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Init;
permut(1);
end;

Hoffe es hilft!


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:43 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz