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.

56 lines
1.5 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. print("yeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet")
  30. newlist = []
  31. newlist.append(list_of_terms[num])
  32. newlist.append(l)
  33. return newlist
  34. else:
  35. print("not equal")
  36. except IndexError:
  37. print("done")
  38. def iterate_list(list_of_terms):
  39. for i in range(len(list_of_terms)):
  40. newlist = add_to_each(list_of_terms, i)
  41. print(newlist)
  42. if newlist != None:
  43. return newlist
  44. else:
  45. continue
  46. list_of_terms = split_into_list("day1input.txt")
  47. answer_nums = iterate_list(list_of_terms)
  48. print(answer_nums)
  49. final_answer = (answer_nums[0]*answer_nums[1])
  50. print(final_answer)