blob: d8372029dfb5ae0e42a8580d959d4649ca4c335a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import sys
def recfuel(mass):
"""Calculate the fuel required for the module
use the new weight of the fuel recursively
r(M) = r(M / 3 - 2)
"""
M = mass // 3 - 2
if M < 0:
return 0
else:
return M + recfuel(M)
total = 0
for mass in sys.stdin:
ret = recfuel(int(mass))
total += ret
print(total)
|