-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Day 1: Added solution for Part 2. Refactored functions and re-organiz…
…ed the code.
- Loading branch information
1 parent
923e2d1
commit 77b2702
Showing
5 changed files
with
142 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using AdventOfCode2019 | ||
|
||
# Modules input provided here: https://adventofcode.com/2019/day/1/input | ||
mass_input = [85824, | ||
112173, | ||
142065, | ||
55390, | ||
111295, | ||
148584, | ||
123987, | ||
66433, | ||
95844, | ||
122580, | ||
146901, | ||
107700, | ||
63930, | ||
100389, | ||
139126, | ||
122243, | ||
65950, | ||
87443, | ||
137945, | ||
147755, | ||
86370, | ||
66749, | ||
133758, | ||
68317, | ||
147417, | ||
97202, | ||
75113, | ||
105996, | ||
103130, | ||
113328, | ||
128427, | ||
108580, | ||
131832, | ||
147958, | ||
137067, | ||
117676, | ||
61678, | ||
127254, | ||
51090, | ||
69924, | ||
58966, | ||
127437, | ||
144987, | ||
80181, | ||
85474, | ||
100216, | ||
119810, | ||
129946, | ||
84880, | ||
61614, | ||
107350, | ||
77076, | ||
93028, | ||
140464, | ||
86826, | ||
67901, | ||
118846, | ||
118658, | ||
63646, | ||
63328, | ||
106271, | ||
87376, | ||
90156, | ||
143507, | ||
139729, | ||
140393, | ||
70324, | ||
77304, | ||
81383, | ||
127336, | ||
144535, | ||
93496, | ||
145119, | ||
73128, | ||
103189, | ||
69519, | ||
95701, | ||
112919, | ||
104766, | ||
124188, | ||
69855, | ||
99495, | ||
147075, | ||
115498, | ||
115468, | ||
68706, | ||
51445, | ||
69871, | ||
134449, | ||
130838, | ||
105809, | ||
110721, | ||
50893, | ||
126521, | ||
81542, | ||
81384, | ||
148523, | ||
105748, | ||
93331, | ||
129279] | ||
|
||
# Part 1: Fuel requirement not taking into account the mass of fuel (d'oh!) | ||
naive_fuel_requirement = sum(naive_fuel.(mass_input)) | ||
|
||
# Part 2: Fuel requirement taking into account mass of fuel | ||
actual_fuel_requirement = sum(actual_fuel.(mass_input)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
module AdventOfCode2019 | ||
|
||
include("RocketEquation.jl") | ||
# Day 1 | ||
include("FuelEquations.jl") | ||
export naive_fuel | ||
export actual_fuel | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Day 1: The Tyranny of the Rocket Equation - https://adventofcode.com/2019/day/1 | ||
|
||
function naive_fuel(mass) | ||
needed_fuel = max((mass ÷ 3) - 2, 0) | ||
return needed_fuel | ||
end | ||
|
||
function actual_fuel(mass) | ||
meta_fuel = fuel(mass) | ||
store = meta_fuel | ||
while meta_fuel > 0 | ||
meta_fuel = fuel(meta_fuel) | ||
store += meta_fuel | ||
end | ||
return store | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
using AdventOfCode2019 | ||
using Test | ||
|
||
@testset "AdventOfCode2019.jl" begin | ||
# Day 1, part 1 examples | ||
@test fuel(12) == 2 | ||
@test fuel(14) == 2 | ||
@test fuel(1969) == 654 | ||
@test fuel(100756) == 33583 | ||
@testset "AoC 2019 - Day01" begin | ||
# Day 1, Part 1 examples | ||
@test naive_fuel(2) == 0 | ||
@test naive_fuel(8) == 0 | ||
@test naive_fuel(9) == 1 | ||
@test naive_fuel(12) == 2 | ||
@test naive_fuel(14) == 2 | ||
@test naive_fuel(1969) == 654 | ||
@test naive_fuel(100756) == 33583 | ||
# Day 1, Part 2 examples | ||
@test actual_fuel(14) == 2 | ||
@test actual_fuel(1969) == 966 | ||
@test actual_fuel(100756) == 50346 | ||
end |