From bf16b19b1f6deffd1983efca059db576f3b60ee5 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 13 Dec 2021 10:40:39 +0300 Subject: 2019, tracking --- 2019/day1/rec_fuel.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 2019/day1/rec_fuel.py (limited to '2019/day1/rec_fuel.py') 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 @@ +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) -- cgit v1.2.3-70-g09d2