advent/2017/day04.py

34 lines
574 B
Python
Raw Permalink Normal View History

2017-12-14 00:48:23 +00:00
from itertools import combinations
from collections import Counter
with open('data04.txt') as f:
phrases = [r.strip() for r in f.readlines()]
def test_words(phrase):
words = phrase.split()
unique = set(words)
return len(unique) == len(words)
def test_anagrams(phrase):
words = phrase.split()
for a, b in combinations(words, 2):
if Counter(a) == Counter(b):
return False
return True
total = 0
'''
# part 1
for phrase in phrases:
if test_words(phrase):
total += 1
'''
# part 2
for phrase in phrases:
if test_anagrams(phrase):
total += 1
print(total)