Advent of Ada Submissions

[JeremyGrosser][4][Ada][advent/day4_2.adb at 3886b077597131c55f15bd23bf3f5dc14faeb4c8 · JeremyGrosser/advent · GitHub]

[Zertovitch][4][Ada]hac/aoc_2022_04.adb at 74dd26dbb513dec406561fa5e8cc439f6abe802c · zertovitch/hac · GitHub

[rocher][4][Ada] Part one here:

pragma Ada_2022;

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Day04_P1 is

    type Section_Range is record
        Start_Section : Natural := 0;
        End_Section   : Natural := 0;
    end record;

    function Contains (A, B : Section_Range) return Boolean is
       (A.Start_Section >= B.Start_Section
        and then A.End_Section <= B.End_Section);
    -- returns True when A contains B: B ⊆ A

    First, Second : Section_Range;
    Separator     : Character;
    Σ_Contained   : Natural := 0;
    Input         : File_Type;

begin
    Open (Input, In_File, "input.txt");

    loop
        Get (Input, First.Start_Section);
        Get (Input, Separator); -- skip '-'
        Get (Input, First.End_Section);

        Get (Input, Separator); -- skip ','

        Get (Input, Second.Start_Section);
        Get (Input, Separator); -- skip '-'
        Get (Input, Second.End_Section);

        if Contains (First, Second) or else Contains (Second, First) then
            Σ_Contained := @ + 1;
        end if;

        exit when End_Of_File (Input);
    end loop;

    Close (Input);
    Put_Line ("Answer:" & Σ_Contained'Image);
end Day04_P1;

and part 2:

pragma Ada_2022;

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Day04_P2 is

    type Section_Range is record
        Start_Section : Natural := 0;
        End_Section   : Natural := 0;
    end record;

    function Disjoint (A, B : Section_Range) return Boolean is
       (A.End_Section < B.Start_Section
        or else B.End_Section < A.Start_Section);
    -- returns True when sections are like --AA-BB- or --BB-AA--
    -- that is: A ∩ B = ∅

    First, Second : Section_Range;
    Separator     : Character;
    Σ_Overlap     : Natural := 0;
    Input         : File_Type;

begin
    Open (Input, In_File, "input.txt");

    loop
        Get (Input, First.Start_Section);
        Get (Input, Separator); -- skip '-'
        Get (Input, First.End_Section);

        Get (Input, Separator); -- skip ','

        Get (Input, Second.Start_Section);
        Get (Input, Separator); -- skip '-'
        Get (Input, Second.End_Section);

        if not Disjoint (First, Second) then
            Σ_Overlap := @ + 1;
        end if;

        exit when End_Of_File (Input);
    end loop;

    Close (Input);
    Put_Line ("Answer:" & Σ_Overlap'Image);
end Day04_P2;
1 Like

[cantanima][4][SPARK]Solved this one in Ada, then “converted” to SPARK

[rvlad13][1][Ada] GitHub - rvl13/Advent_of_code_2022_Ada
[rvlad13][2][Ada] same repo
[rvlad13][3][Ada] same repo
[rvlad13][4][Ada] same repo

Since I am new user, it doesn’t allow me to post more than 2 links, So not able to put link to all the solutions. Anyways, all the solutions are located in same repo.
I have also started making use of HAC Ada Compiler today (day 4) onwards.

2 Likes

[fsherratt][3][SPARK]GitHub - fsherratt/Advent_Of_Code_2022
[fsherratt][4][SPARK]GitHub - fsherratt/Advent_Of_Code_2022

[ebriot][3][Ada] advent_of_code/2022/day3 at master · briot/advent_of_code · GitHub

[Neoxas][4][SPARK]GitHub - Neoxas/aoc_2022_ada: AOC 2022 solutions written in SPARK ADA!

[zetah11][3][SPARK][aoc2022/day3.adb at 28767c99bd1352326b4048b952192ad7949fdbf5 · zetah11/aoc2022 · GitHub]
[zetah11][4][SPARK][aoc2022/day4.adb at 28767c99bd1352326b4048b952192ad7949fdbf5 · zetah11/aoc2022 · GitHub]

How do we indicate a second program for the second part of a day?

[Jeff Carter][2][Ada]AoA_22/day02_1.adb at ff37060da99b1537c35ff8ad71542abf1e6b30ea · jrcarter/AoA_22 · GitHub

[RREE][4][Ada] AoC/2022/04 at main · RREE/AoC · GitHub

[rommudoh][4][Ada] aoc2022-Ada/day04.adb at main - aoc2022-Ada - Codeberg.org

[anuj-seth][2][Ada]Day 2

[AJ-Ianozi][4][Ada]adventofcode/day4.adb at bee3c2dc4fd0bf7e6c1d8916f529dc30cf5beee1 · AJ-Ianozi/adventofcode · GitHub

[William-Franck][4][Ada] Release Day-04 · captain-haddock17/Advent_of_Code_2022 · GitHub

[smionean][4][Ada]AdventOfCode/day04.adb at b2477ddbdea82d78c266b44a511228dcf7206d70 · smionean/AdventOfCode · GitHub

Zertovitch][5][Ada]hac/aoc_2022_05.adb at 74328263349cefe3f90ed29f87128b459dd0a59b · zertovitch/hac · GitHub

Caution: code is unedited in this commit!

[JeremyGrosser][5][Ada][advent/day5_2.adb at a1277cbb9fc5601d91da59877bb4663c979c79af · JeremyGrosser/advent · GitHub]

[cantanima][5][Ada]Day 5: Supply Stacks