Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
51
Task/Hailstone-sequence/Delphi/hailstone-sequence-2.pas
Normal file
51
Task/Hailstone-sequence/Delphi/hailstone-sequence-2.pas
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
program ShowHailstoneSequence;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
System.SysUtils,
|
||||
System.Types,
|
||||
System.Threading,
|
||||
System.SyncObjs,
|
||||
Boost.Algorithm,
|
||||
Boost.Int,
|
||||
System.Diagnostics;
|
||||
|
||||
var
|
||||
lList: TIntegerDynArray;
|
||||
lMaxSequence, lMaxLength, i: Integer;
|
||||
StopWatch: TStopwatch;
|
||||
|
||||
begin
|
||||
lList := Hailstone(27);
|
||||
Writeln(Format('27: %d elements', [lList.Count]));
|
||||
Writeln(lList.toString(4), #10);
|
||||
|
||||
lMaxSequence := 0;
|
||||
lMaxLength := 0;
|
||||
|
||||
StopWatch := TStopwatch.Create;
|
||||
StopWatch.Start;
|
||||
|
||||
TParallel.for (1, 1, 100000,
|
||||
procedure(idx: Integer)
|
||||
var
|
||||
lList: TIntegerDynArray;
|
||||
begin
|
||||
lList := Hailstone(idx);
|
||||
if lList.Count > lMaxLength then
|
||||
begin
|
||||
TInterlocked.Exchange(lMaxSequence, idx);
|
||||
TInterlocked.Exchange(lMaxLength, lList.Count);
|
||||
end;
|
||||
end);
|
||||
|
||||
StopWatch.Stop;
|
||||
|
||||
Write(Format('Longest sequence under 100,000: %d with %d elements', [lMaxSequence,
|
||||
lMaxLength]));
|
||||
|
||||
Writeln(Format(' in %d ms', [StopWatch.ElapsedMilliseconds]));
|
||||
|
||||
Readln;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue