]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/commitdiff
Add a python version
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 6 Dec 2020 12:16:58 +0000 (12:16 +0000)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 6 Dec 2020 12:16:58 +0000 (12:16 +0000)
day6/get_yes_counts.py [new file with mode: 0644]

diff --git a/day6/get_yes_counts.py b/day6/get_yes_counts.py
new file mode 100644 (file)
index 0000000..6c2967c
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+group_questions=[]
+questions=dict()
+people_count=0
+
+for line in open("input.txt", "r"):
+    line=line.rstrip()
+    if (line == ""):
+        all_yes="".join(questions.keys())
+        everyone_yes="".join([a for a in questions.keys() if questions[a] == people_count])
+        group_questions.append((all_yes, everyone_yes))
+        questions=dict()
+        people_count=0
+        continue
+    people_count+=1
+    for char in line:
+        if char in questions:
+            questions[char]+=1
+        else:
+            questions[char]=1
+
+if (len(questions.keys()) > 0):
+    all_yes="".join(questions.keys())
+    everyone_yes="".join([a for a in questions.keys() if questions[a] == people_count])
+    group_questions.append((all_yes, everyone_yes))
+
+sum_of_groups=0
+sum_of_everyone=0
+for group in group_questions:
+    sum_of_groups+=len(group[0])
+    sum_of_everyone+=len(group[1])
+
+
+print("Sum of groups: {}".format(sum_of_groups))
+print("Sum of groups (everyone said yes): {}".format(sum_of_everyone))