Working out solutions for Advent of Code
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223
  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 = [(x//3) - 2 for x in masses]
  7. newfuels = []
  8. for fuel in fuels:
  9. of = fuel
  10. f = fuel
  11. while f > 0:
  12. af = (f//3) - 2
  13. if af > 0:
  14. of += af
  15. f = af
  16. else:
  17. f = 0
  18. newfuels.append(of)
  19. #print(newfuels)
  20. print(sum(newfuels))
  21. if __name__ == "__main__":
  22. main()