From: Brett Parker Date: Sun, 6 Dec 2020 12:16:58 +0000 (+0000) Subject: Add a python version X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2020.git/commitdiff_plain/cbae7f56fa71a044b470e77b689cb8a0c0a46733?ds=inline;hp=f77fa4ec82ab82ff7937fc664752bce80144a8f1 Add a python version --- 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))