Advent of code 2015 solutions https://adventofcode.com/2015/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5.py 736B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/python
  2. import re
  3. def is_nice_1(word):
  4. has_vowels = len(re.sub('[^aeiou]+', '', word)) >= 3
  5. has_doubles = re.search('(.)\\1', word) is not None
  6. has_bad_letters = re.search('ab|cd|pq|xy', word) is not None
  7. return has_vowels and has_doubles and not has_bad_letters
  8. def is_nice_2(word):
  9. has_repeated_pair = re.search('(..).*?\\1', word) is not None
  10. has_repeated_letter = re.search('(.).\\1', word) is not None
  11. return has_repeated_pair and has_repeated_letter
  12. with open('5.txt', 'r') as file:
  13. input = file.read()
  14. nice_1 = 0
  15. nice_2 = 0
  16. for string in input.splitlines():
  17. if is_nice_1(string):
  18. nice_1 += 1
  19. if is_nice_2(string):
  20. nice_2 += 1
  21. print(nice_1)
  22. print(nice_2)