summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-06 06:14:11 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-06 06:14:11 +0100
commitedfb0961feede558e6a86e531b0c6412ea8baef4 (patch)
treed6a24fc2cc30b71ab249f7d2628045df8b998ca9
parent481ea0df1c89833af35156c1c30c29fb8d882f76 (diff)
downloadaoc-edfb0961feede558e6a86e531b0c6412ea8baef4.tar.gz
day 06
-rw-r--r--20/py/d06.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/20/py/d06.py b/20/py/d06.py
new file mode 100644
index 0000000..8604b00
--- /dev/null
+++ b/20/py/d06.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+import sys
+
+
+def pt1(_in):
+ res = 0
+ questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
+ for line in _in:
+ if line == "\n":
+ res += 26 - len(questions)
+ questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
+ continue
+ for ans in line:
+ if ans in questions:
+ questions.remove(ans)
+ res += 26 - len(questions)
+ return res
+
+
+def pt2(_in):
+ res = 0
+ questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
+ for line in _in:
+ person = set()
+ if line == "\n":
+ res += len(questions)
+ questions = {s for s in "abcdefghijklmnopqrstuvwxyz"}
+ continue
+ for ans in line:
+ person.add(ans)
+ for q in questions.copy():
+ if q not in person:
+ questions.remove(q)
+ res += len(questions)
+ return res
+
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1:
+ input = open(sys.argv[1], "r").readlines()
+ else:
+ input = open("../input/06", "r").readlines()
+ print(pt1(input))
+ print(pt2(input))