Working out solutions for Advent of Code
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.

01b.py 545B

12345678910111213141516171819202122232425
  1. def main():
  2. #lines = [12, 14, 1969, 100756]
  3. with open("01ain.txt", "r") as file:
  4. lines = file.readlines()
  5. masses = [int(x) for x in lines]
  6. fuels = [getFuel(x) for x in masses]
  7. newfuels = []
  8. for fuel in fuels:
  9. of = fuel
  10. f = fuel
  11. while f > 0:
  12. f = getFuel(f)
  13. of += f
  14. newfuels.append(of)
  15. #print(newfuels)
  16. print(sum(newfuels))
  17. def getFuel(f):
  18. fuel = (f//3) - 2
  19. if fuel > 0:
  20. return fuel
  21. return 0
  22. if __name__ == "__main__":
  23. main()