From 90d1031207b5a9b3343cc2d8bea86be70ee77605 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 6 Dec 2020 21:44:06 -0700 Subject: [PATCH] Add code for 2020 day 6. --- day_6/info.md | 1 + day_6/part_1.py | 16 ++++++++++++++++ day_6/part_2.py | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 day_6/info.md create mode 100644 day_6/part_1.py create mode 100644 day_6/part_2.py diff --git a/day_6/info.md b/day_6/info.md new file mode 100644 index 0000000..414ac23 --- /dev/null +++ b/day_6/info.md @@ -0,0 +1 @@ +https://adventofcode.com/2020/day/6 \ No newline at end of file diff --git a/day_6/part_1.py b/day_6/part_1.py new file mode 100644 index 0000000..2524fd4 --- /dev/null +++ b/day_6/part_1.py @@ -0,0 +1,16 @@ +with open("data") as f: + plane = f.read() + + +plane = plane.split("\n\n") + +count = 0 +for group in plane: + group_answers = [] + for person in group.split("\n"): + for q in person: + if q not in group_answers: + group_answers.append(q) + count += len(group_answers) + +print(count) \ No newline at end of file diff --git a/day_6/part_2.py b/day_6/part_2.py new file mode 100644 index 0000000..2635197 --- /dev/null +++ b/day_6/part_2.py @@ -0,0 +1,19 @@ +with open("data") as f: + plane = f.read() + + +plane = plane.split("\n\n") + +count = 0 +for group in plane: + group_size = len(group.split("\n")) + group_answers = {} + for person in group.split("\n"): + for q in person: + if q not in group_answers: + group_answers[q] = 1 + else: + group_answers[q] += 1 + count += len([1 for v in group_answers.values() if v == group_size]) + +print(count) \ No newline at end of file