advent-of-code/2020/ruby/day_02.rb

6 lines
258 B

day1 = proc {|min,max,char,pass| (min..max).cover?(pass.count(char)) }
day2 = proc {|p1,p2,char,pass| [pass[p1-1], pass[p2-1]].count(char) == 1 }
puts ARGF.read.scan(/^(\d+)-(\d+)\s*(\w):\s*(\w+)$/)
.map {|a,b,c,d| [a.to_i, b.to_i, c, d] }
.count(&day2)