AoC2015/day05/solution.rb

23 lines
608 B
Ruby

#!/bin/env ruby
strings = File.readlines('./input').map(&:strip)
bad_pairs = Regexp.new(/ab|cd|pq|xy/).freeze
double_letters = Regexp.new(/([a-z])\1/).freeze
three_vowels = Regexp.new(/[aeiou]/).freeze
letter_pairs = Regexp.new(/([a-z]{2}).*\1/).freeze
alternate = Regexp.new(/([a-z]).\1/).freeze
part1 = strings.reject do |string|
bad_pairs.match?(string) == true or double_letters.match?(string) == false or string.scan(three_vowels).count < 3
end
puts part1.count
part2 = strings.reject do |string|
letter_pairs.match?(string) == false or alternate.match?(string) == false
end
puts part2.count