From 5beb8a1276589d973041d7460d43e5a4ea48ef17 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 7 Dec 2019 21:21:07 -0800 Subject: [PATCH] [2019][ruby][8.x] --- 2019/ruby/day_08.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2019/ruby/day_08.rb diff --git a/2019/ruby/day_08.rb b/2019/ruby/day_08.rb new file mode 100644 index 0000000..2e59ee6 --- /dev/null +++ b/2019/ruby/day_08.rb @@ -0,0 +1,17 @@ +image = ARGF.read.scan(/\d/).map(&:to_i) + +w = 25 +h = 6 + +# l = image.each_slice(w*h).min_by {|l| l.count(0) } +# p l.count(1) * l.count(2) + +layers = image.each_slice(w*h) +puts layers + .inject {|n,l| n.zip(l) } + .map(&:flatten) + .map {|layers| layers.drop_while {|p| p == 2 }.first } + .map {|p| p.zero? ? "█" : " " } + .each_slice(w) + .map(&:join) + .join("\n")