/
main.jl
43 lines (37 loc) · 977 Bytes
/
main.jl
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
lines = readlines("input.txt")
function solution_part_1(lines)
depth = 0
horizontal = 0
for line in lines
action, value = split(line, " ")
value = parse(Int16, value)
if action == "up"
depth -= value
elseif action == "down"
depth += value
elseif action == "forward"
horizontal += value
end
end
return horizontal * depth
end
function solution_part_2(lines)
depth = 0
horizontal = 0
aim = 0
for line in lines
action, value = split(line, " ")
value = parse(Int16, value)
if action == "up"
aim -= value
elseif action == "down"
aim += value
elseif action == "forward"
horizontal += value
depth += aim * value
end
end
return horizontal * depth
end
println("Solution part 1: ", solution_part_1(lines))
println("Solution part 2: ", solution_part_2(lines))