[smionean][10][Ada]AdventOfCode/day10.adb at 8ecfdd14250ec52d5fccbca7314fdf4c73d5a5ff · smionean/AdventOfCode · GitHub
[Jeff Carter][10][Ada]AoA_22/day10_1.adb at cbc0bed18db2079fca26e64a2641e10d062f456d · jrcarter/AoA_22 · GitHub
[JeremyGrosser][11][Ada][advent/day11_2.adb at ec4d24ac38532c214c9ea67cfd6569fc825da90f · JeremyGrosser/advent · GitHub]
[rommudoh][12][Ada] aoc2022-Ada/day12.adb at main - aoc2022-Ada - Codeberg.org
[cantanima][12][Ada]Hill Climbing Algorithm
[rocher][11][Ada] Solution to monkeys playing with Items. Simple parser for input file included.
pragma Ada_2022;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Containers.Doubly_Linked_Lists; use Ada.Containers;
with Ada.Containers.Functional_Vectors;
with Ada.Numerics.Big_Numbers.Big_Integers;
use Ada.Numerics.Big_Numbers.Big_Integers;
procedure Day11_P2 is
package Items_Package is new Doubly_Linked_Lists (Natural);
use Items_Package;
type Operand_Type is record
Use_Old : Boolean;
Number : Natural;
end record;
type Operation_Type is record
Kind : Character; -- '*' or '+'
Operand_2 : Operand_Type;
end record;
type Monkey_Type is record
Index : Natural;
Items : Items_Package.List := Empty_List;
Operation : Operation_Type;
Test_Div : Natural;
If_True : Natural;
If_False : Natural;
Min_True : Natural := Natural'Last;
Min_False : Natural := Natural'Last;
Inspected : Natural := 0;
end record;
type Monkey_Acc is access all Monkey_Type;
package Monkey_Package is new Functional_Vectors
(Index_Type => Natural, Element_Type => Monkey_Acc);
use Monkey_Package;
Troop : Monkey_Package.Sequence;
Input : File_Type;
LCM : Natural := 0;
function Inspect (Monkey : Monkey_Acc; Item : Natural) return Natural is
Operand_2 : Natural;
Big_Result : Big_Natural;
Result : Natural;
begin
if Monkey.Operation.Operand_2.Use_Old then
Operand_2 := Item;
else
Operand_2 := Monkey.Operation.Operand_2.Number;
end if;
case Monkey.Operation.Kind is
when '+' =>
Big_Result :=
To_Big_Integer (Item) + To_Big_Integer (Operand_2);
when '*' =>
Big_Result :=
To_Big_Integer (Item) * To_Big_Integer (Operand_2);
when others =>
null;
end case;
Result := To_Integer (Big_Result mod To_Big_Integer (LCM));
return Result;
end Inspect;
begin
Open (Input, In_File, "input.txt");
loop
declare
Monkey : Monkey_Acc := null;
Line : String (1 .. 32);
Number : Natural;
Is_Eof : Boolean;
begin
Get (Input, Line (1 .. 6)); -- "Monkey"
Get (Input, Line (7 .. 8)); -- " <Character>"
Number := Natural'Value (Line (7 .. 8)); -- assume Number <= 9
Get (Input, Line (1)); -- ':'
Monkey := new Monkey_Type;
Monkey.Index := Number;
Troop := Add (Troop, Number, Monkey);
Get (Input, Line (1 .. 18)); -- " Starting items: "
Get (Input, Number); -- Natural
loop
Monkey.Items.Append (Number);
Look_Ahead (Input, Line (1), Is_Eof);
exit when Line (1) /= ',';
Get (Input, Line (1)); -- ','
Get (Input, Number); -- Natural
end loop;
Get (Input, Line (1 .. 23)); -- " Operation: new = old ""
Get (Input, Monkey.Operation.Kind); -- <operation>, '*' or '+'
Get (Input, Line (1)); -- ' '
Look_Ahead (Input, Line (1), Is_Eof);
if Line (1) = 'o' then
Monkey.Operation.Operand_2.Use_Old := True;
Get (Input, Line (1 .. 3)); -- 'old'
else
Monkey.Operation.Operand_2.Use_Old := False;
Get (Input, Number);
Monkey.Operation.Operand_2.Number := Number;
end if;
Get (Input, Line (1 .. 21)); -- " Test: divisible by "
Get (Input, Monkey.Test_Div); -- Natural
if LCM = 0 then
LCM := Monkey.Test_Div;
else
LCM := LCM * Monkey.Test_Div;
end if;
Get (Input, Line (1 .. 29)); -- " If true ... monkey "
Get (Input, Monkey.If_True); -- Natural;
Get (Input, Line (1 .. 30)); -- " If false ... monkey "
Get (Input, Monkey.If_False); -- Natural;
exit when End_Of_File (Input);
end;
end loop;
Close (Input);
for I in 1 .. 10_000 loop
for Monkey of Troop loop
for Item of Monkey.Items loop
declare
Worry_Level : Natural;
Receiver : Monkey_Acc;
begin
-- new item inspected
Monkey.Inspected := @ + 1;
-- new Worry_Level according to Monkey rules
Worry_Level := Inspect (Monkey, Item);
-- in part 1, Monkey gets bored with item
-- Worry_Level := @ / 3;
-- Monkey throws the item
if Worry_Level mod Monkey.Test_Div = 0 then
Receiver := Get (Troop, Monkey.If_True);
else
Receiver := Get (Troop, Monkey.If_False);
end if;
Append (Receiver.Items, Worry_Level);
end;
end loop;
-- Monkey has thrown all items
Monkey.Items := Empty_List;
end loop;
end loop;
declare
Max1, Max2 : Natural := 0;
begin
for Monkey of Troop loop
if Monkey.Inspected > Max1 then
Max2 := Max1;
Max1 := Monkey.Inspected;
else
Max2 := Natural'Max (@, Monkey.Inspected);
end if;
end loop;
Put_Line
("Answer:" &
Big_Natural'Image (To_Big_Integer (Max1) * To_Big_Integer (Max2)));
end;
end Day11_P2;
[Zertovitch][12][Ada]hac/aoc_2022_12.adb at 173d00de738e45be41e5ae4405b0c7adedd3f677 · zertovitch/hac · GitHub
[Jeff Carter][11][Ada]AoA_22/day11_1.adb at d66bff8f1c628f2fc4f91323956c3f0f066a7c42 · jrcarter/AoA_22 · GitHub
[cantanima][13][Ada]Distress signal
Update on the total on puzzle solved so far:
- Solved with Ada: 135 ($1350)
- Solved with SPARK: 45 ($900)
- Total: 180 ($2250)
[rommudoh][13][Ada] aoc2022-Ada/day13.adb at main - aoc2022-Ada - Codeberg.org
[anuj-seth][5][Ada]Day 5
[anuj-seth][6][Ada]Day 6
[Zertovitch][13][Ada]hac/aoc_2022_13.adb at 8fcc06a8d918d365d32ecf23e4e5668f076ddc64 · zertovitch/hac · GitHub
[wutka][13][SPARK] advent-of-code-2022-spark/day13.adb at 3675f0cc244e6dfdf88cdc6292543d6ed9bffbe5 · wutka/advent-of-code-2022-spark · GitHub
[wutka][14][SPARK] advent-of-code-2022-spark/day14.adb at 5cbef4dca43dbb21c2b9da7dde4d8cfaef706726 · wutka/advent-of-code-2022-spark · GitHub
[wutka][15][SPARK] advent-of-code-2022-spark/day15.adb at c6ec0bbaa61b179b748279911fef209e26f62881 · wutka/advent-of-code-2022-spark · GitHub
[rommudoh][14][Ada] aoc2022-Ada/day14.adb at main - aoc2022-Ada - Codeberg.org
[cantanima][14][Ada]Regolith Reservoir
Decide to sleep last night for a change, so it’s a little later than usual.
[Zertovitch][14][Ada]hac/aoc_2022_14.adb at 534f31e5fd1a2f5901592942867df509982dc93b · zertovitch/hac · GitHub
Similar thing here: the puzzle pops up at 6am, and if I am not done till ~7h30, my work on AoC is frozen for some 12 hours…
[cantanima][15][Ada]Beacon Exclusion Zone
[rommudoh][15][Ada] aoc2022-Ada/day15.adb at main - aoc2022-Ada - Codeberg.org