From cbae7f56fa71a044b470e77b689cb8a0c0a46733 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sun, 6 Dec 2020 12:16:58 +0000 Subject: [PATCH] Add a python version --- day6/get_yes_counts.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 day6/get_yes_counts.py diff --git a/day6/get_yes_counts.py b/day6/get_yes_counts.py new file mode 100644 index 0000000..6c2967c --- /dev/null +++ b/day6/get_yes_counts.py @@ -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)) -- 2.39.5