From d8651623f86e1f28e4a8c945802a1a05e887bdcf Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 1 Dec 2018 21:11:14 -0800 Subject: [PATCH] [2018][ruby][2.x] --- 2018/ruby/day_02.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 2018/ruby/day_02.rb diff --git a/2018/ruby/day_02.rb b/2018/ruby/day_02.rb new file mode 100644 index 0000000..df0945a --- /dev/null +++ b/2018/ruby/day_02.rb @@ -0,0 +1,11 @@ +a = ARGF.read.lines.map(&:chomp).map(&:chars) +# two = a.count {|i| i.any? {|x| i.count(x) == 2} } +# three = a.count {|i| i.any? {|x| i.count(x) == 3} } +# puts two * three +x,y = a.flat_map {|i| + a.select {|j| + i.zip(j).select {|a,b| a != b }.count == 1 + } +}.map(&:join) + +p x.chars.zip(y.chars).select {|a,b| a == b }.map(&:first).join