Skip to content

Commit

Permalink
Day 24 (Second part) [IMPROVED]
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleErwin committed Dec 24, 2018
1 parent 9451134 commit 86b19a0
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions 2018/src/day24_2.adb
Original file line number Diff line number Diff line change
Expand Up @@ -519,33 +519,38 @@ procedure Day24_2 is
end Determine_Remaining_Units;

Answer : Integer;
Finished : Boolean := False;
Finished : Boolean;
Tick : Integer;
Winner : Side;
Maximum_Iterations : Integer := 100_000;

Immune_System_Army : Army;
Infection_Army : Army;
begin
Boost_Loop:
for Boost in 0 .. Max_Boost loop
Put_Line("Trying boost of " & Integer'Image(Boost));
if Boost = 58 then
Put_Line("Skipping boost 58, because it will never end.");
else
Finished := False;
Load_File (Immune_System_Army => Immune_System_Army,
Infection_Army => Infection_Army,
Boost => Boost);

while not Finished loop
Finished := Fight(Immune_Army => Immune_System_Army,
Infection_Army => Infection_Army);
end loop;
Finished := False;
Tick := 0;
Load_File (Immune_System_Army => Immune_System_Army,
Infection_Army => Infection_Army,
Boost => Boost);

while not Finished loop
Finished := Fight(Immune_Army => Immune_System_Army,
Infection_Army => Infection_Army);
Tick := Tick + 1;
if Tick > Maximum_Iterations then
Finished := True;
end if;
end loop;

if Tick < Maximum_Iterations then
Answer := Determine_Remaining_Units(Immune_Army => Immune_System_Army,
Infection_Army => Infection_Army,
Winning_Side => Winner);
exit Boost_Loop when Winner = Immune;
end if;
exit Boost_Loop when Winner = Immune;
end loop Boost_Loop;

Put_Line("Answer:" & Integer'Image(Answer));
Expand Down

0 comments on commit 86b19a0

Please sign in to comment.