-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path5.jl
More file actions
25 lines (23 loc) · 709 Bytes
/
5.jl
File metadata and controls
25 lines (23 loc) · 709 Bytes
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
function solve(lines, allow_diagonals)
map = zeros(Int, (1001, 1001))
for line in lines
from, to = split(line, " -> ")
toCoords(x) = (a -> parse(Int, a)).(split(x, ","))
from = toCoords(from) .+ 1 # Shift all by one, so that Julia indices would work
to = toCoords(to) .+ 1
if any(from .== to) || allow_diagonals
while from != to
map[from[2], from[1]] += 1
from += (to .> from) - (to .< from)
end
map[from[2], from[1]] += 1
end
end
return sum(map .>= 2)
end
function main()
lines = readlines()
println(solve(lines, false))
println(solve(lines, true))
end
main()