Advent of Code 2020: Python Solution (25 Part Series)
1 Advent of Code 2020: Python Solution Day 1
2 Advent of Code 2020: Python Solution Day 2
… 21 more parts…
3 Advent of Code 2020: Python Solution Day 3
4 Advent of Code 2020: Python Solution Day 4
5 Advent of Code 2020: Python Solution Day 5
6 Advent of Code 2020: Python Solution Day 6
7 Advent of Code 2020: Python Solution Day 7
8 Advent of Code 2020: Python Solution Day 8
9 Advent of Code 2020: Python Solution Day 9
10 Advent of Code 2020: Python Solution Day 10
11 Advent of Code 2020: Python Solution Day 11
12 Advent of Code 2020: Python Solution Day 12
13 Advent of Code 2020: Python Solution Day 13
14 Advent of Code 2020: Python Solution Day 14
15 Advent of Code 2020: Python Solution Day 15
16 Advent of Code 2020: Python Solution Day 16
17 Advent of Code 2020: Python Solution Day 17
18 Advent of Code 2020: Python Solution Day 18
19 Advent of Code 2020: Python Solution Day 19
20 Advent of Code 2020: Python Solution Day 20
21 Advent of Code 2020: Python Solution Day 21
22 Advent of Code 2020: Python Solution Day 22
23 Advent of Code 2020: Python Solution Day 23
24 Advent of Code 2020: Python Solution Day 24
25 Advent of Code 2020: Python Solution Day 25
I am trying this only after few hour of the challenge unlocked. And first part was easy to solve. But for second part, I had to take help from reddit thread, specially here.
From few challenges, I first started with the toy example given there and if all the cases matches on this example input then feed my input to this algorithm and done. Here, day6_test.txt
is a example input present on the challenge link. And day6.txt
is my input. A repo with output is present at GitHub.
with open("day6_test.txt", "r") as fp:
lines=fp.readlines()
with open("day6.txt", "r") as fp:
lines=fp.readlines()
groups = []
group = []
for question in lines:
if question!="\n":
group.append(question.split("\n")[0])
else:
groups.append(group)
group=[]
groups.append(group)
# solution to challenge 1 solution_1 = []
for group in groups:
#print(f"Group: ", group) unique_ques = []
for ques in group:
unique_ques.extend([uq for uq in ques])
#print(f"Unique questions: {set(unique_ques)}") solution_1.extend(list(set(unique_ques)))
print(f"Solution 1: {len(solution_1)}")
# solution to challenge 2 from collections import Counter
total = 0
for group in groups:
#print(f"\nGroup: {group}") group_size = len(group)
#print(f"Length of group: {group_size}")
# make single list of enitire group and count occurence counts = Counter("".join(group))
#print(counts)
counts = Counter(list(counts.values()))[group_size]
total+=counts
print(f"Solution 2:", total)
Enter fullscreen mode Exit fullscreen mode
I write blogs about Computer Vision projects on my GitHub page q-viper.github.io and if you got some time please share yours too.
Advent of Code 2020: Python Solution (25 Part Series)
1 Advent of Code 2020: Python Solution Day 1
2 Advent of Code 2020: Python Solution Day 2
… 21 more parts…
3 Advent of Code 2020: Python Solution Day 3
4 Advent of Code 2020: Python Solution Day 4
5 Advent of Code 2020: Python Solution Day 5
6 Advent of Code 2020: Python Solution Day 6
7 Advent of Code 2020: Python Solution Day 7
8 Advent of Code 2020: Python Solution Day 8
9 Advent of Code 2020: Python Solution Day 9
10 Advent of Code 2020: Python Solution Day 10
11 Advent of Code 2020: Python Solution Day 11
12 Advent of Code 2020: Python Solution Day 12
13 Advent of Code 2020: Python Solution Day 13
14 Advent of Code 2020: Python Solution Day 14
15 Advent of Code 2020: Python Solution Day 15
16 Advent of Code 2020: Python Solution Day 16
17 Advent of Code 2020: Python Solution Day 17
18 Advent of Code 2020: Python Solution Day 18
19 Advent of Code 2020: Python Solution Day 19
20 Advent of Code 2020: Python Solution Day 20
21 Advent of Code 2020: Python Solution Day 21
22 Advent of Code 2020: Python Solution Day 22
23 Advent of Code 2020: Python Solution Day 23
24 Advent of Code 2020: Python Solution Day 24
25 Advent of Code 2020: Python Solution Day 25
暂无评论内容