In diesem Thread könnt ihr eure Lösungen posten, oder euch über das Puzzle austauschen.
Mit dem Code 1131555-15717edc könnt ihr außerdem unserem privaten Leaderboard beitreten.
Quellcode bitte in dieser Syntax posten („python“ durch die verwendete Sprache ersetzen):
#!/usr/bin/env python3
def main():
answers = parse_input("06-input.txt")
count_union = count_unified(answers)
print(f"The count of unified group answers with yes is {count_union}.")
count_intersect = count_same(answers)
print(f"The count of unified group answers with yes is {count_intersect}.")
def count_same(answers: tuple[tuple[str]]):
sum = 0
for group in answers:
sum += len(intersection_group_answers(group))
return sum
def intersection_group_answers(group_answers: tuple[str]):
intersection = set("abcdefghijklmnopqrstuvwxyz")
for person in group_answers:
intersection.intersection_update(person)
return intersection
def count_unified(answers: tuple[tuple[str]]):
sum = 0
for group in answers:
sum += len(unify_group_answers(group))
return sum
def unify_group_answers(group_answers: tuple[str]):
unified = set()
for person in group_answers:
unified.update(person)
return unified
def parse_input(filename: str) -> tuple[tuple[str]]:
answers = []
with open(filename, "r") as file:
groups = file.read().split("\n\n")
for group in groups:
answers.append(group.splitlines())
return tuple(answers)
if __name__ == "__main__":
main()