My solutions for Advent of Code 2020
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
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)
|