-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.py
55 lines (49 loc) · 1.45 KB
/
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
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
import time
def split_into_list(file_path):
f = open(file_path, "r")
list_of_lists = []
for line in f:
stripped_line = line.strip()
stripped_line = int(float(stripped_line))
#line_list = stripped_line.split()
list_of_lists.append(stripped_line)
f.close()
return(list_of_lists)
def add_to_each(list_of_terms, num):
j = 0
for i in list_of_terms:
print(i)
try:
k = j+1
#print(k)
l = list_of_terms[k]
#print(l)
j=j+1
total = 0
total += list_of_terms[num]+l
print(list_of_terms[num])
print(l)
print(total)
if (total) == 2020:
print("equal")
newlist = []
newlist.append(list_of_terms[num])
newlist.append(l)
return newlist
else:
print("not equal")
except IndexError:
print("done")
def iterate_list(list_of_terms):
for i in range(len(list_of_terms)):
newlist = add_to_each(list_of_terms, i)
print(newlist)
if newlist != None:
return newlist
else:
continue
list_of_terms = split_into_list("day1input.txt")
answer_nums = iterate_list(list_of_terms)
print(answer_nums)
final_answer = (answer_nums[0]*answer_nums[1])
print(final_answer)