aoc_2a.py 714 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Oct 15 20:54:13 2021
  4. @author: Jonatan
  5. """
  6. def parse_line(line):
  7. ret = {}
  8. cnt = {}
  9. for c in line:
  10. if c in cnt:
  11. cnt[c] += 1
  12. else:
  13. cnt[c] = 1
  14. for dupes in cnt:
  15. if cnt[dupes] == 2:
  16. ret[2] = 1
  17. elif cnt[dupes] == 3:
  18. ret[3] = 1
  19. return ret
  20. def main():
  21. two = 0
  22. three = 0
  23. with open("input.txt") as file:
  24. for line in file:
  25. res = parse_line(line.rstrip())
  26. if 2 in res:
  27. two += 1
  28. if 3 in res:
  29. three += 1
  30. print(two*three)
  31. if __name__ == "__main__":
  32. main()