Advertisement
Musical_Muze

Advent of Code 2019, Day 1 Part 2

Dec 2nd, 2019
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. import math
  2.  
  3. inputFile = open("modules.txt", "r")
  4. outputFile = open("answer.txt", "w")
  5.  
  6. sum = 0
  7.  
  8. for i in inputFile:
  9.     mass = int(i)
  10.     fuel = (math.trunc(mass/3))-2
  11.     fuelTotal = fuel
  12.     while (fuel > 0):
  13.         fuel = (math.trunc(fuel/3))-2
  14.         if (fuel > 0):
  15.             fuelTotal = fuelTotal + fuel
  16.     sum = sum + fuelTotal
  17.  
  18. outputFile.write(str(sum))
  19.  
  20. inputFile.close()
  21. outputFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement