M .gitignore => .gitignore +1 -0
@@ 1,2 1,3 @@
*.o
*.in
+__pycache__/
A day03/day03b.py => day03/day03b.py +29 -0
@@ 0,0 1,29 @@
+#! /usr/bin/env python3
+# vim:fenc=utf-8
+#
+# Copyright © 2022 Adrian Perez de Castro <aperez@igalia.com>
+#
+# Distributed under terms of the MIT license.
+
+from common import item_priority
+import sys
+
+def common_group_item(a, b, c):
+ common = frozenset(a) & frozenset(b) & frozenset(c)
+ assert len(common) == 1
+ for item in common:
+ return item
+
+def line_groups(lines):
+ lines = iter(lines)
+ while True:
+ try:
+ yield (next(lines).strip(),
+ next(lines).strip(),
+ next(lines).strip())
+ except StopIteration:
+ return
+
+print(sum((item_priority(item)
+ for item in (common_group_item(a, b, c)
+ for a, b, c in line_groups(sys.stdin.readlines())))))