summaryrefslogtreecommitdiffstats
path: root/day6/__init__.py
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2021-12-02 17:39:03 +0100
commit4dec21f362c03136e9811a4f4c162fcd8c50544e (patch)
treecd90c52c7c936fdbe5fc7f22f3f5bf3240faf9a8 /day6/__init__.py
parent37aa8eec0498d7e8491084711132f16db9129a39 (diff)
download2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.gz
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.tar.bz2
2021-4dec21f362c03136e9811a4f4c162fcd8c50544e.zip
Added day 10
Diffstat (limited to 'day6/__init__.py')
-rw-r--r--day6/__init__.py47
1 files changed, 0 insertions, 47 deletions
diff --git a/day6/__init__.py b/day6/__init__.py
deleted file mode 100644
index f9d4f87..0000000
--- a/day6/__init__.py
+++ /dev/null
@@ -1,47 +0,0 @@
1from typing import Iterator, Any, Generator, List
2
3from aoc import BaseAssignment
4
5
6class Assignment(BaseAssignment):
7 def read_input(self, example = False) -> Generator:
8 group = []
9 for line in super().read_input(example):
10 if len(line) == 0:
11 yield group
12 group = []
13 continue
14
15 group.append(line)
16
17 yield group
18
19
20class AssignmentOne(Assignment):
21 def run(self, input: Iterator) -> Any:
22 return sum([
23 len(set(''.join(group)))
24 for group in input
25 ])
26
27
28class AssignmentTwo(Assignment):
29 def everyone_same_answer_count(self, group: List):
30 answer_count = {}
31 for person in group:
32 for answer in person:
33 answer_count[answer] = answer_count[answer] + 1 \
34 if answer in answer_count \
35 else 1
36 return sum([
37 1
38 for value in answer_count.values()
39 if value == len(group)
40 ])
41
42
43 def run(self, input: Iterator) -> Any:
44 return sum([
45 self.everyone_same_answer_count(group)
46 for group in input
47 ])