1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# class String
#   BAD = %w[ ab cd pq xy ]

#   def nice?
#     # It contains at least three vowels (aeiou only), like aei, xazegov, or aeiouaeiouaeiou.
#     self.count("aeiou") > 2 &&
#       # It contains at least one letter that appears twice in a row, like xx, abcdde (dd), or aabbccdd (aa, bb, cc, or dd).
#       self =~ /(.)\1/ &&
#       # It does not contain the strings ab, cd, pq, or xy, even if they are part of one of the other requirements.
#       BAD.none? {|bad| self.include?(bad) }
#   end
# end

# require "minitest"
# class TestNice < Minitest::Test
#   def test_nice?
#     assert "ugknbfddgicrmopn".nice?
#     assert "aaa".nice?
#     refute "jchzalrnumimnmhp".nice?
#     refute "haegwjzuvuyypxyu".nice?
#     refute "dvszwmarrgswjxmb".nice?
#   end
# end

class String
  def nice?
    self =~ /(..).*\1/ && self =~ /(.).\1/
  end
end

puts DATA.read.each_line.count(&:nice?)
__END__