Added another small performance improvement for day 14
This commit is contained in:
parent
29663ad82e
commit
95de6f1f7b
|
@ -204,27 +204,34 @@ end;
|
||||||
procedure TPlatform.Tilt(constref AIntervals: TCubeRockIntervalsList; constref ASource, ATarget:
|
procedure TPlatform.Tilt(constref AIntervals: TCubeRockIntervalsList; constref ASource, ATarget:
|
||||||
TIntegersList; const AUp: Boolean);
|
TIntegersList; const AUp: Boolean);
|
||||||
var
|
var
|
||||||
i, rock, nextFree, step: Integer;
|
i, j, rock, nextFree, direction: Integer;
|
||||||
interval: TCubeRockInterval;
|
|
||||||
begin
|
begin
|
||||||
if AUp then
|
if AUp then
|
||||||
step := 1
|
direction := 1
|
||||||
else
|
else
|
||||||
step := -1;
|
direction := -1;
|
||||||
for i := 0 to AIntervals.Count - 1 do
|
for i := 0 to AIntervals.Count - 1 do
|
||||||
begin
|
begin
|
||||||
for interval in AIntervals[i] do
|
j := 0;
|
||||||
|
if AUp then
|
||||||
|
nextFree := AIntervals[i][j].Start
|
||||||
|
else
|
||||||
|
nextFree := AIntervals[i][j].Stop;
|
||||||
|
for rock in ASource[i] do
|
||||||
begin
|
begin
|
||||||
if AUp then
|
// Goes to next interval if rock is not in current interval.
|
||||||
nextFree := interval.Start
|
while AIntervals[i][j].Stop < rock do
|
||||||
else
|
begin
|
||||||
nextFree := interval.Stop;
|
Inc(j);
|
||||||
for rock in ASource[i] do
|
if AUp then
|
||||||
if (interval.Start <= rock) and (rock <= interval.Stop) then
|
nextFree := AIntervals[i][j].Start
|
||||||
begin
|
else
|
||||||
ATarget[nextFree].Add(i);
|
nextFree := AIntervals[i][j].Stop;
|
||||||
Inc(nextFree, step);
|
end;
|
||||||
end;
|
|
||||||
|
// rock must now be in current interval.
|
||||||
|
ATarget[nextFree].Add(i);
|
||||||
|
Inc(nextFree, direction);
|
||||||
end;
|
end;
|
||||||
ASource[i].Clear;
|
ASource[i].Clear;
|
||||||
end;
|
end;
|
||||||
|
|
Loading…
Reference in New Issue