summaryrefslogtreecommitdiffstats
path: root/2019/day1/rec_fuel.py
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:40:39 +0300
committerYigit Sever2021-12-13 10:40:39 +0300
commitbf16b19b1f6deffd1983efca059db576f3b60ee5 (patch)
tree1262f68d8eb2c326684d395aebcd5a1cc0b0f748 /2019/day1/rec_fuel.py
parent74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff)
downloadaoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip
2019, tracking
Diffstat (limited to '2019/day1/rec_fuel.py')
-rw-r--r--2019/day1/rec_fuel.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/2019/day1/rec_fuel.py b/2019/day1/rec_fuel.py
new file mode 100644
index 0000000..d837202
--- /dev/null
+++ b/2019/day1/rec_fuel.py
@@ -0,0 +1,23 @@
1import sys
2
3
4def recfuel(mass):
5 """Calculate the fuel required for the module
6 use the new weight of the fuel recursively
7 r(M) = r(M / 3 - 2)
8 """
9 M = mass // 3 - 2
10
11 if M < 0:
12 return 0
13 else:
14 return M + recfuel(M)
15
16
17total = 0
18
19for mass in sys.stdin:
20 ret = recfuel(int(mass))
21 total += ret
22
23print(total)