[cantanima][1][Ada]Calorie Counting
[smionean][1][Ada]https://github.com/smionean/AdventOfCode/tree/master/2022/day01
[analogrelay][1][Ada] aoc2022/day_01.adb at 1870db114d7e9555364e8d4a1445cc295552e627 Β· analogrelay/aoc2022 Β· GitHub
[JeremyGrosser][2][Ada][advent/day2_2.adb at 3fdc3b70869b12840f96afe5a2c9ecb7c66de300 Β· JeremyGrosser/advent Β· GitHub]
[Zertovitch][2][Ada]hac/aoc_2022_02.adb at 93ad0ab88a063470721cbe5b02b5630fdf91ca88 Β· zertovitch/hac Β· GitHub
[cantanima][2][Ada][AoC2022/Day2 at master Β· johnperry-math/AoC2022 Β· GitHub]
[ebriot][1][Ada] advent_of_code/2022/day1 at master Β· briot/advent_of_code Β· GitHub
[ebriot][2][Ada] advent_of_code/2022/day2 at master Β· briot/advent_of_code Β· GitHub
[rommudoh][1][Ada] aoc2022-Ada/day01.adb at main - aoc2022-Ada - Codeberg.org
[rommudoh][2][Ada] aoc2022-Ada/day02.adb at main - aoc2022-Ada - Codeberg.org
[rocher][2][Ada] Lβets play Rock, Paper Scissors β¦ literally!
Part one here:
pragma Ada_2022;
with Ada.Text_IO; use Ada.Text_IO;
procedure Day02_P1 is
Type Rock_Paper_Scissors is ('πͺ¨', 'π§»', 'β');
for Rock_Paper_Scissors use ('πͺ¨' => 1, 'π§»' => 2, 'β' => 3);
Type Result is ('π', 'π€', 'π');
for Result use ('π' => 0, 'π€' => 3, 'π' => 6);
Result_Table : array (Rock_Paper_Scissors, Rock_Paper_Scissors) of Result :=
('πͺ¨' => (
'πͺ¨' => 'π€',
'π§»' => 'π',
'β' => 'π'),
'π§»' => (
'πͺ¨' => 'π',
'π§»' => 'π€',
'β' => 'π'),
'β' => (
'πͺ¨' => 'π',
'π§»' => 'π',
'β' => 'π€'));
-- Result table for players given as (Opponent, Player);
function Round (Opponent, Player: Rock_Paper_Scissors) return Natural is
Score : Natural := 0;
begin
Score := Result'Enum_Rep (Result_Table (Opponent, Player));
Score := @ + Rock_Paper_Scissors'Enum_Rep (Player);
return Score;
end;
Subtype Opponent_Char is Character range 'A' .. 'C';
Opponent_Strategy : array (Opponent_Char) of Rock_Paper_Scissors :=
('A' => 'πͺ¨', 'B' => 'π§»', 'C' => 'β');
Subtype Player_Char is Character range 'X' .. 'Z';
Player_Strategy : array (Player_Char) of Rock_Paper_Scissors :=
('X' => 'πͺ¨', 'Y' => 'π§»', 'Z' => 'β');
Opponent : Character;
Player : Character;
Score : Natural := 0;
Space : Character;
Input : File_Type;
begin
Open (Input, In_File, "input.txt");
loop
Get (Input, Opponent);
Get (Input, Space);
Get (Input, Player);
Score := @ + Round (Opponent_Strategy (Opponent), Player_Strategy (PLayer));
exit when End_Of_File (Input);
end loop;
Close (Input);
Put_Line ("Answer:" & Score'Image);
end Day02_P1;
My day 1 is in a message above. Itβs pretty fun getting used to SPARK this way!
[zetah11][2][SPARK][aoc2022/day2.adb at 3d253bff347ad66db3c17ae1b48191dfc9de2ffa Β· zetah11/aoc2022 Β· GitHub]
[jklmnn][2][SPARK]aoc/day_2022_2.adb at 8d67cb10e4528210a9219d7f20b7689c33308938 Β· jklmnn/aoc Β· GitHub
[William-Franck][2][Ada]Release Day-02 Β· captain-haddock17/Advent_of_Code_2022 Β· GitHub
[rocher][2][Ada] And here part 2:
pragma Ada_2022;
with Ada.Text_IO; use Ada.Text_IO;
procedure Day02_P2 is
Type Rock_Paper_Scissors is ('πͺ¨', 'π§»', 'β');
for Rock_Paper_Scissors use ('πͺ¨' => 1, 'π§»' => 2, 'β' => 3);
Type Result is ('π', 'π€', 'π');
for Result use ('π' => 0, 'π€' => 3, 'π' => 6);
Result_Table : array (Rock_Paper_Scissors, Rock_Paper_Scissors) of Result :=
('πͺ¨' => (
'πͺ¨' => 'π€',
'π§»' => 'π',
'β' => 'π'),
'π§»' => (
'πͺ¨' => 'π',
'π§»' => 'π€',
'β' => 'π'),
'β' => (
'πͺ¨' => 'π',
'π§»' => 'π',
'β' => 'π€'));
-- Result table for players given as (Opponent, Player);
function Round (Opponent, Player: Rock_Paper_Scissors) return Natural is
Score : Natural := 0;
begin
Score := Result'Enum_Rep (Result_Table (Opponent, Player));
Score := @ + Rock_Paper_Scissors'Enum_Rep (Player);
return Score;
end;
Subtype Opponent_Char is Character range 'A' .. 'C';
Opponent_Strategy : array (Opponent_Char) of Rock_Paper_Scissors :=
('A' => 'πͺ¨', 'B' => 'π§»', 'C' => 'β');
Subtype Player_Char is Character range 'X' .. 'Z';
Player_Strategy : array (Player_Char) of Result :=
('X' => 'π', 'Y' => 'π€', 'Z' => 'π');
function Choose_Shape (Opponent: Rock_Paper_Scissors; R : Result)
return Rock_Paper_Scissors
is
Player : Rock_Paper_Scissors;
begin
for P in Rock_Paper_Scissors'Range loop
if Result_Table (Opponent, P) = R then
Player := P;
end if;
end loop;
return Player;
end;
Opponent : Character;
Player : Character;
Score : Natural := 0;
Space : Character;
Input : File_Type;
begin
Open (Input, In_File, "__Current_Path__" & "input.txt");
loop
Get (Input, Opponent);
Get (Input, Space);
Get (Input, Player);
Score := @ + Round (Opponent_Strategy (Opponent),
Choose_Shape (Opponent_Strategy (Opponent),
Player_Strategy (PLayer)));
exit when End_Of_File (Input);
end loop;
Close (Input);
Put_Line ("Answer:" & Score'Image);
end Day02_P2;
[smionean][2][Ada]day02.adb
[max][2][SPARK] source/day_02.adb
[max][3][SPARK] source/day_03.adb
[max][4][SPARK] source/day_04.adb
[max][5][Ada] source/day_05.adb
[max][6][SPARK] source/day_06.adb
[max][7][SPARK] source/day_07.adb
[max][8][Ada] source/day_08.adb
[max][9][SPARK] source/day_09.adb
[max][10][SPARK] source/day_10.adb
[max][11][Ada] source/day_11.adb
[max][12][Ada] source/day_12.adb
[max][13][Ada] source/day_13.adb
[max][14][Ada] source/day_14.adb
[max][15][Ada] source/day_15.adb
[max][16][Ada] source/day_16.adb
[max][17][Ada] source/day_17.adb
[max][18][Ada] source/day_18.adb
[max][19][Ada] source/day_19.adb
[max][20][Ada] source/day_20.adb
[max][21][Ada] source/day_21.adb
[max][22][Ada] source/day_22.adb
[max][23][Ada] source/day_23.adb
[max][24][Ada] source/day_24.adb
[max][25][Ada] source/day_25.adb
[yannickmoy][1][SPARK] advent_of_code_2022/spark/day1 at main Β· yannickmoy/advent_of_code_2022 Β· GitHub
[Neoxas][1][SPARK] GitHub - Neoxas/aoc_2022_ada: AOC 2022 solutions written in SPARK ADA!
[Neoxas][2][SPARK] GitHub - Neoxas/aoc_2022_ada: AOC 2022 solutions written in SPARK ADA!
Haha! Nice use of Unicode!
Group.Append (Calories'Value (Line (Line'First .. Last)));
How did you make gnatprove
eat this without Fabianβs powerful technique? The Line
could contain any garbage and 'Value
will raise exception, no?
Kind reminder: Join us in the AOC leaderboard!
Please feel free to add yourself to the AOC leaderboard shared in this post.
Visit Leaderboard - Advent of Code 2022 and use the code 1708445-6a8f7730
to join.