Ravi Shah
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
56 additions and
0 deletions
-
day1.py
|
|
|
@ -0,0 +1,56 @@ |
|
|
|
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") |
|
|
|
print("yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet") |
|
|
|
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) |