[py] Port 2017_04

This commit is contained in:
Joscha 2022-12-06 19:39:49 +01:00
parent d3d8a493f1
commit 0bf180482b
3 changed files with 37 additions and 37 deletions

35
py/aoc/y2017/d04.py Normal file
View file

@ -0,0 +1,35 @@
import collections
# PART 1
def load_phrases(inputstr):
phrases = []
for line in inputstr.splitlines():
phrase = line.split(" ")
phrases.append(phrase)
return phrases
def is_valid(phrase):
return len(phrase) == len(set(phrase))
def count(what, when):
return len(list(filter(when, what)))
# PART 2
def is_valid_2(phrase):
phrase = ["".join(sorted(word)) for word in phrase]
return len(phrase) == len(set(phrase))
def solve(inputstr):
phrases = load_phrases(inputstr)
correct = count(phrases, is_valid)
print(f"Part 1: {correct}")
correct_2 = count(phrases, is_valid_2)
print(f"Part 2: {correct_2}")