-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.py
31 lines (24 loc) · 829 Bytes
/
day1.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
expenseReport = open('day1-input.txt', 'r')
expenses = list(map(lambda x: int(x), expenseReport.readlines()))
expensesLookup = set(expenses)
targetSum = 2020
def findTwoSum():
for expense in expenses:
target = 2020 - expense
if target in expensesLookup:
return [target, expense]
return 'Found nothing'
print(findTwoSum())
def findThreeSum():
allSums = {}
for i in range(len(expenses)):
k = i + 1
while k < len(expenses):
total = expenses[i] + expenses[k]
allSums[2020 - total] = [expenses[i], expenses[k]]
k += 1
for expense in expenses:
if expense in allSums:
return allSums[expense] + [expense] + [allSums[expense][0] * allSums[expense][1] * expense]
return 'Found nothing'
print(findThreeSum())