Skip to content

Commit 4407ddb

Browse files
committed
Day 1 2020
1 parent c30efd7 commit 4407ddb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
day_23.rb
22
day_23_input.txt
3+
*.txt

Diff for: 2020/1.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from functools import reduce
2+
3+
f = open("day1input.txt", "r")
4+
items = list(map(int, f.read().rstrip().split("\n")))
5+
6+
# Part 1
7+
def find_result(items):
8+
result1 = None
9+
result2 = None
10+
for i in range(len(items) - 1):
11+
for j in range(i + 1, len(items)):
12+
if items[i] + items[j] == 2020:
13+
result1, result2 = items[i], items[j]
14+
return [result1, result2]
15+
16+
print(reduce((lambda x, y: x * y), find_result(items)))
17+
18+
# Part 2
19+
def find_triple_result(items):
20+
result1 = None
21+
result2 = None
22+
result3 = None
23+
for i in range(len(items) - 2):
24+
for j in range(i + 1, len(items) - 1):
25+
for k in range(j + 1, len(items)):
26+
if items[i] + items[j] + items[k] == 2020:
27+
result1, result2, result3 = items[i], items[j], items[k]
28+
return [result1, result2, result3]
29+
30+
print(reduce((lambda x, y: x * y), find_triple_result(items)))

0 commit comments

Comments
 (0)