-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathd8.jl
35 lines (31 loc) · 861 Bytes
/
d8.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
digits = [parse(Int64, x) for x in readline("input.txt")]
width = 25
height = 6
size = width * height
layers = [digits[start:start + size - 1] for start in 1:size:length(digits)]
# p1
layer = layers[argmin([sum(layer .== 0) for layer in layers])]
println(sum(layer .== 1) * sum(layer .== 2))
# p2
function print_image(image::Array{Int,2})
for row in eachrow(image)
for pixel in row
if pixel == 0
print(" ")
elseif pixel == 1
print("#")
end
end
print("\n")
end
end
image = fill(2, height, width)
for layer in reverse(layers)
layer2d = reshape(layer, width, height)' # row-major reshaping trick
for coord in CartesianIndices(layer2d)
if layer2d[coord] != 2
image[coord] = layer2d[coord]
end
end
end
print_image(image)