Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Suche Algo. für 123-->132-->213-->... (https://www.delphipraxis.net/81649-suche-algo-fuer-123-132-213-a.html)

Christian18 30. Nov 2006 19:48


Suche Algo. für 123-->132-->213-->...
 
Hallo,

ich soll in Delphi ein Programm schreiben, womit ich folgendes machen kann!

123
132
213
231
312
321

Ich weiß jetzt nicht, ob das wirklich alle varianten sind. Die Anzahl soll variabel sein. aber max 12

mit 12 würde es so aussehen

1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 12 11
...

Wie kann ich das in ein Delphi Programm verfassen???

MFG Christian18

DGL-luke 30. Nov 2006 19:50

Re: Suche Algo. für 123-->132-->213-->...
 
Du suchst nach [dp]Permutation*[/dp]en.

mkinzler 30. Nov 2006 20:04

Re: Suche Algo. für 123-->132-->213-->...
 
Du mußt die zahl in die Ziffern erlegen (DIV/MOD) und dann systematisch neu zusammensetzen.

omata 1. Dez 2006 23:51

Re: Suche Algo. für 123-->132-->213-->...
 
Hallo Christian18,

hier mal ein Beispiel für eine Textbildschirmanwendung...

Delphi-Quellcode:
procedure permute(fest, variable:string);
var i:byte;
begin
  if length(variable) = 0 then
    writeln(fest)
  else begin
    for i:=1 to length(variable) do begin
      permute(
        fest + copy(variable, i, 1),
        copy(variable, 1, i-1) + copy(variable, i+1, length(variable))
      );
    end;
  end;
end;
Aufruf...
Delphi-Quellcode:
permute('', '123');
Gruss
Thorsten


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:40 Uhr.

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