From 80d66a0f76a949d67e4f89ac3ebe4a877c90a095 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Sun, 13 Dec 2020 20:34:46 +0100 Subject: Added day6 --- day6/__init__.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 day6/__init__.py (limited to 'day6/__init__.py') diff --git a/day6/__init__.py b/day6/__init__.py new file mode 100644 index 0000000..f9d4f87 --- /dev/null +++ b/day6/__init__.py @@ -0,0 +1,47 @@ +from typing import Iterator, Any, Generator, List + +from aoc import BaseAssignment + + +class Assignment(BaseAssignment): + def read_input(self, example = False) -> Generator: + group = [] + for line in super().read_input(example): + if len(line) == 0: + yield group + group = [] + continue + + group.append(line) + + yield group + + +class AssignmentOne(Assignment): + def run(self, input: Iterator) -> Any: + return sum([ + len(set(''.join(group))) + for group in input + ]) + + +class AssignmentTwo(Assignment): + def everyone_same_answer_count(self, group: List): + answer_count = {} + for person in group: + for answer in person: + answer_count[answer] = answer_count[answer] + 1 \ + if answer in answer_count \ + else 1 + return sum([ + 1 + for value in answer_count.values() + if value == len(group) + ]) + + + def run(self, input: Iterator) -> Any: + return sum([ + self.everyone_same_answer_count(group) + for group in input + ]) -- cgit v1.2.3