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.

55 lines
1.4 KiB

  1. import time
  2. def split_into_list(file_path):
  3. f = open(file_path, "r")
  4. list_of_lists = []
  5. for line in f:
  6. stripped_line = line.strip()
  7. stripped_line = int(float(stripped_line))
  8. #line_list = stripped_line.split()
  9. list_of_lists.append(stripped_line)
  10. f.close()
  11. return(list_of_lists)
  12. def add_to_each(list_of_terms, num):
  13. j = 0
  14. for i in list_of_terms:
  15. print(i)
  16. try:
  17. k = j+1
  18. #print(k)
  19. l = list_of_terms[k]
  20. #print(l)
  21. j=j+1
  22. total = 0
  23. total += list_of_terms[num]+l
  24. print(list_of_terms[num])
  25. print(l)
  26. print(total)
  27. if (total) == 2020:
  28. print("equal")
  29. newlist = []
  30. newlist.append(list_of_terms[num])
  31. newlist.append(l)
  32. return newlist
  33. else:
  34. print("not equal")
  35. except IndexError:
  36. print("done")
  37. def iterate_list(list_of_terms):
  38. for i in range(len(list_of_terms)):
  39. newlist = add_to_each(list_of_terms, i)
  40. print(newlist)
  41. if newlist != None:
  42. return newlist
  43. else:
  44. continue
  45. list_of_terms = split_into_list("day1input.txt")
  46. answer_nums = iterate_list(list_of_terms)
  47. print(answer_nums)
  48. final_answer = (answer_nums[0]*answer_nums[1])
  49. print(final_answer)