Initial commit

This commit is contained in:
fiveop committed 2021-12-22 11:33:30 +01:00
commit cd6cc0be1e
73 files changed
+10338

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
using Pkg
Pkg.add("Match")
using Match
include("utils.jl")
function solution2_1()
input_lines = non_empty_lines("2.data")
function parse_line(line)
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
end
map(fline->split(line, " "), input_lines)
x = 0
y = 0
for line in input_lines
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
@match command begin
"forward" => begin x += parsed_amount end
"up" => begin y -= parsed_amount end
"down" => begin y += parsed_amount end
end
end
(x, y, x*y)
end
function solution2_2()
input_lines = non_empty_lines("2.data")
aim = 0
x = 0
y = 0
for line in input_lines
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
@match command begin
"forward" => begin x += parsed_amount; y += parsed_amount * aim end
"up" => begin aim -= parsed_amount end
"down" => begin aim += parsed_amount end
end
end
(x, y, x*y)
end
(solution2_1(), solution2_2())