-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday13.jl
37 lines (33 loc) · 974 Bytes
/
day13.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
lines = readlines("data/day13.txt")
dots = map(filter(l -> ',' ∈ l, lines)) do l
return parse.(Int, split(l, ','))
end
folds = map(filter(l -> '=' ∈ l, lines)) do l
dir, loc = match(r"fold along (.)=(.*)", l).captures
return (dir, parse(Int, loc))
end
for (i, (dir, loc)) ∈ enumerate(folds)
global dots = map(dots) do (x, y)
if dir == "x" && x > loc
x = 2*loc - x
elseif dir == "y" && y > loc
y = 2*loc - y
end
return (x, y)
end
if i == 1
# Part 1 - How many dots are visible after completing just the first fold instruction on your transparent paper?
println("part1 = ", length(Set(dots)))
end
end
mx = maximum(((x, y),) -> x, dots)
my = maximum(((x, y),) -> y, dots)
output = fill(' ', my+1, mx+1)
for (x, y) ∈ dots
output[y+1, x+1] = '■'
end
# Part 2 - What code do you use to activate the infrared thermal imaging camera system?
println("part2:")
for row ∈ eachrow(output)
println(join(row, ""))
end