We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1bf53c9 commit 637c1b9Copy full SHA for 637c1b9
08_space_image_format.rb
@@ -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