-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.py
57 lines (40 loc) · 1.3 KB
/
day6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import pytest
@pytest.mark.parametrize("group, total", [
(["abc"], 3),
(["a", "b", "c"], 3),
(["ab", "ac"], 3),
(["a", "a", "a", "a"], 1)])
def test_calculate_group_total(group, total):
assert calculate_group_total(group) == total
def calculate_group_total(group):
group_string = ""
for person in group:
group_string += person
group_total = len(set(group_string))
return group_total
def calculate_group_total_part2(group):
group_set = set("abcdefghijklmnopqrstuvwxyz")
for person in group:
person_set = set(person)
group_set = group_set & person_set
return len(group_set)
input_list = []
with open('day6.txt', 'r') as f:
strings = f.read().splitlines()
group = []
for item in strings:
if item:
group.append(item)
else:
if group:
input_list.append(group)
group = []
running_total = 0
for group in input_list:
running_total += calculate_group_total(group)
print("Part 1: {}".format(running_total))
running_total = 0
for group in input_list:
running_total += calculate_group_total_part2(group)
print("Part 2: {}".format(running_total))