-
Notifications
You must be signed in to change notification settings - Fork 7
/
13.jl
30 lines (29 loc) · 937 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
function main()
coords = Set()
first_fold = true
for line in readlines()
if ',' in line
x, y = split(line, ',') .|> x -> parse(Int, x)
push!(coords, (y, x))
elseif '=' in line
fold_is_x = occursin("x=", line)
fold_val = parse(Int, split(line, '=')[2])
new_coords = Set()
for (y, x) in coords
fold_x = fold_is_x ? min(0, fold_val - x) * 2 : 0
fold_y = fold_is_x ? 0 : min(0, fold_val - y) * 2
push!(new_coords, (y + fold_y, x + fold_x))
end
coords = new_coords
first_fold && length(coords) |> println
first_fold = false
end
end
y_max, x_max = maximum(coords) .+ 1
field = [collect(" " ^ x_max) for _ in 1:y_max]
for (y, x) in coords
field[y + 1][x + 1] = '#'
end
field .|> join .|> println
end
main()