-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.adb
57 lines (37 loc) · 1.17 KB
/
day1.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
with Ada.Text_IO;
procedure Day1
with SPARK_Mode => On
is
function Mass_To_Fuel (Mass : Natural) return Natural is
((Mass / 3) -2);
procedure Fuel_Calculation (Fuel : in out Natural)
is
Min_Fuel : constant Natural := 6;
Fuel_Remaining : Natural := Fuel;
begin
while Fuel_Remaining > Min_Fuel loop
Fuel_Remaining := Mass_To_Fuel(Fuel_Remaining);
Fuel := Fuel + Fuel_Remaining;
end loop;
end Fuel_Calculation;
Input_Mass : Natural;
Fuel : Natural;
Accumulator_1 : Natural := 0;
Accumulator_2 : Natural := 0;
begin
loop
declare
Line : constant String := Ada.Text_IO.Get_Line;
begin
Input_Mass := Natural'Value(Line);
Fuel := Mass_To_Fuel(Input_Mass);
Accumulator_1 := Accumulator_1 + Fuel;
-- Next, deal with the fuel the fuel needs (and etc.)
Fuel_Calculation(Fuel);
Accumulator_2 := Accumulator_2 + Fuel;
exit when Ada.Text_IO.End_Of_File;
end;
end loop;
Ada.Text_IO.Put_Line("Total Part 1: " & Accumulator_1'Image);
Ada.Text_IO.Put_Line("Total Part 2: " & Accumulator_2'Image);
end Day1;