Skip to content

Commit 637c1b9

Browse files
committed
add day 08: Space Image Format
1 parent 1bf53c9 commit 637c1b9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

08_space_image_format.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
verbose = ARGV.delete('-v')
2+
3+
width = 25
4+
layer = width * 6
5+
6+
input = ARGF.read.chomp
7+
8+
layers = input.each_char.each_slice(layer).to_a
9+
10+
min_layer = layers.min_by { |x| x.count(?0) }
11+
p min_layer.tally if verbose
12+
puts min_layer.count(?1) * min_layer.count(?2)
13+
14+
pixels = layers.transpose.map { |pixel| pixel.find { |layer| layer != ?2 } }
15+
disp = {?1 => ?#, ?0 => ' '}.freeze
16+
pixels.each_slice(width) { |row| puts row.map { |pixel| disp.fetch(pixel) }.join }

0 commit comments

Comments
 (0)