From a3d275c27d75dcb7f8b14239dff8d682f7504664 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 3 Dec 2019 21:20:50 -0800 Subject: [PATCH] [2019][ruby][4.x] --- 2019/ruby/day_04.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 2019/ruby/day_04.rb diff --git a/2019/ruby/day_04.rb b/2019/ruby/day_04.rb new file mode 100644 index 0000000..42efdf6 --- /dev/null +++ b/2019/ruby/day_04.rb @@ -0,0 +1,5 @@ +puts (236491..713787).map(&:to_s).count {|password| + matching_digits = password.scan(/(.)\1/) + + !matching_digits.empty? && matching_digits.flatten.any? {|d| !password.include?(d * 3) } && password.chars.each_cons(2).all? {|a,b| a <= b } +}