summaryrefslogtreecommitdiff
path: root/day6/main.py
diff options
context:
space:
mode:
authorCody Hiar <cody@hiar.ca>2021-02-05 09:29:54 -0700
committerCody Hiar <cody@hiar.ca>2021-02-05 09:29:54 -0700
commitb4a3bd52e5e610f431d9aa49e3ac0af918e1e344 (patch)
tree0b0a1794a93d7f9cfa5bfa9088eb75da750d7c94 /day6/main.py
parent34f71edd66e22b7d1e1b262d92d80e1bf335aa57 (diff)
Adding day 5 and 6
Diffstat (limited to 'day6/main.py')
-rw-r--r--day6/main.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/day6/main.py b/day6/main.py
new file mode 100644
index 0000000..7bad5d2
--- /dev/null
+++ b/day6/main.py
@@ -0,0 +1,24 @@
+"""Day 6."""
+from collections import Counter
+
+
+def score_part1(group):
+ """Determine score for group in part 1."""
+ return len(set(group.replace("\n", "")))
+
+
+def score_part2(group):
+ """Determine score for group in part 2."""
+ group_size = group.count("\n") + 1
+ counter = Counter(group.replace("\n", ""))
+ return sum(1 for _, occurences in counter.items() if occurences == group_size)
+
+
+with open("input") as f:
+ groups = f.read().rstrip().split("\n\n")
+
+# Part 1
+print(sum(map(score_part1, groups)))
+
+# Part 2
+print(sum(map(score_part2, groups)))