Advertisement
pmcgee

Delphi - call next_permutation

Sep 7th, 2020 (edited)
1,046
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.68 KB | None | 0 0
  1. program Project_d_permut;
  2. {$APPTYPE CONSOLE}
  3.  
  4. uses
  5.   System.SysUtils,
  6.   System.Diagnostics,
  7.   Next_perm_string in 'Next_perm_string.pas';
  8.  
  9. var
  10.     s          : AnsiString;
  11.     i, len     : integer;
  12.     StopWatch  : TStopwatch;
  13.  
  14. begin
  15.     s    := 'abcdef';  //ghijkl';
  16.     len  := length(s)+1;
  17.     i    := 0;
  18.  
  19.     StopWatch := StopWatch.StartNew;
  20.  
  21.     repeat  begin
  22.         if (i<6)  then writeln( s );           //comment out for performance
  23.         inc(i);
  24.     end
  25.     until not  D_next_permutation(s, 1, len ) ;
  26.  
  27.     StopWatch.Stop;
  28.     writeln;
  29.     writeln( 'Delphi  ', i );
  30.     writeln( 'Seconds: ',  StopWatch.elapsedMilliSeconds/1000:2:3 );
  31.  
  32.     readln;
  33. end.
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement