-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.jl
31 lines (28 loc) · 845 Bytes
/
13.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
open("13.txt") do f
P = split.(split(read(f, String), "\n\n"), "\n")
function mirror(b, smudge)
C = size(b, 2)
for c ∈ 1:C-1
left = b[:, c:-1:max(1, 2*c-C+1)]
right = b[:, c+1:min(end, 2c)]
if smudge
sum(left.≠right)==1 && return c
else
left==right && return c
end
end
return 0
end
p1, p2 = 0, 0
B::Array{BitArray} = []
for p ∈ P
b = BitArray(undef, length(p), length(p[1]))
for (r, l) ∈ enumerate(p), (c, ch) ∈ enumerate(l)
b[r,c] = ch=='#'
end
p1 += mirror(b, false) + 100*mirror(rotl90(b), false)
p2 += mirror(b, true) + 100*mirror(rotl90(b), true)
end
println("Part 1: ", p1)
println("Part 2: ", p2)
end