-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday11.jl
36 lines (31 loc) · 868 Bytes
/
day11.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
module Day11
using AdventOfCode2017
function day11(input::String = readInput(joinpath(@__DIR__, "..", "data", "day11.txt")))
instructions = split(rstrip(input), ",")
coords = [0, 0, 0]
part2 = 0
for instruction in instructions
move!(coords, instruction)
tmp = maximum(abs.(coords))
if tmp > part2
part2 = tmp
end
end
return [maximum(abs.(coords)), part2]
end
function move!(coords::Vector{Int}, direction::AbstractString)
if direction == "n"
coords .+= [0, -1, 1]
elseif direction == "s"
coords .+= [0, 1, -1]
elseif direction == "se"
coords .+= [1, 0, -1]
elseif direction == "nw"
coords .+= [-1, 0, 1]
elseif direction == "sw"
coords .+= [-1, 1, 0]
elseif direction == "ne"
coords .+= [1, -1, 0]
end
end
end # module