From 54171d76f4041ee04eace5632051a0d6a7c77ee0 Mon Sep 17 00:00:00 2001 From: Nathan van Ofwegen Date: Mon, 7 Dec 2020 19:23:10 +0100 Subject: [PATCH] day6 --- day6/day6.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/day6/day6.py b/day6/day6.py index e69de29..be84548 100644 --- a/day6/day6.py +++ b/day6/day6.py @@ -0,0 +1,58 @@ +def part1(): + file = open("input.txt") + + questions = [] + sum = 0 + + for line in file: + + if line == "\n": + sum += len(set(questions)) + questions = [] + + else: + chars = list(line.strip()) + for char in chars: + questions.append(char) + + sum += len(set(questions)) + + print("Part 1: %d" % sum) + + +def part2(): + file = open("input.txt") + + questions = {} + participants = 0 + + sum = 0 + + for line in file: + + if line == "\n": + for question in questions: + if questions[question] == participants: + sum += 1 + questions = {} + participants = 0 + + else: + chars = list(line.strip()) + participants += 1 + for char in chars: + if char in questions: + questions[char] += 1 + else: + questions[char] = 1 + + for question in questions: + if questions[question] == participants: + sum += 1 + + print("Part 2: %d" % sum) + + +if __name__ == "__main__": + part1() + part2()