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/README.md | 5 +++ 2019/day1/part1.in | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2019/day1/part2.in | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2019/day1/rec_fuel.py | 23 ++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 2019/day1/README.md create mode 100644 2019/day1/part1.in create mode 100644 2019/day1/part2.in create mode 100644 2019/day1/rec_fuel.py (limited to '2019/day1') diff --git a/2019/day1/README.md b/2019/day1/README.md new file mode 100644 index 0000000..af0b60e --- /dev/null +++ b/2019/day1/README.md @@ -0,0 +1,5 @@ +I realized part 1 can be solved with a perl one liner; + +```bash +perl -ne '$c += int ($_ / 3) - 2;END {print $c}' < part1.in +``` diff --git a/2019/day1/part1.in b/2019/day1/part1.in new file mode 100644 index 0000000..63d0a1a --- /dev/null +++ b/2019/day1/part1.in @@ -0,0 +1,100 @@ +93912 +138996 +112824 +110011 +139024 +132292 +74029 +81664 +138077 +109614 +121056 +136338 +132771 +86611 +131526 +123101 +61315 +93900 +62070 +97957 +67168 +119464 +119066 +111076 +56856 +144203 +109400 +120187 +57915 +143353 +71308 +67695 +141275 +106552 +136209 +86990 +98969 +57207 +99103 +71940 +63145 +91765 +121095 +139700 +128851 +77138 +66712 +91318 +96924 +132235 +99897 +67479 +87996 +121100 +55411 +61715 +130658 +121030 +141445 +83939 +90402 +121107 +59618 +120112 +58140 +103514 +90538 +55552 +142739 +61770 +147374 +80038 +128830 +93328 +52369 +71801 +144536 +147140 +118213 +128056 +92155 +114384 +89234 +124451 +94214 +79174 +108427 +111041 +96715 +128414 +62521 +93897 +107428 +90637 +126176 +78676 +69504 +93663 +80869 +124230 diff --git a/2019/day1/part2.in b/2019/day1/part2.in new file mode 100644 index 0000000..63d0a1a --- /dev/null +++ b/2019/day1/part2.in @@ -0,0 +1,100 @@ +93912 +138996 +112824 +110011 +139024 +132292 +74029 +81664 +138077 +109614 +121056 +136338 +132771 +86611 +131526 +123101 +61315 +93900 +62070 +97957 +67168 +119464 +119066 +111076 +56856 +144203 +109400 +120187 +57915 +143353 +71308 +67695 +141275 +106552 +136209 +86990 +98969 +57207 +99103 +71940 +63145 +91765 +121095 +139700 +128851 +77138 +66712 +91318 +96924 +132235 +99897 +67479 +87996 +121100 +55411 +61715 +130658 +121030 +141445 +83939 +90402 +121107 +59618 +120112 +58140 +103514 +90538 +55552 +142739 +61770 +147374 +80038 +128830 +93328 +52369 +71801 +144536 +147140 +118213 +128056 +92155 +114384 +89234 +124451 +94214 +79174 +108427 +111041 +96715 +128414 +62521 +93897 +107428 +90637 +126176 +78676 +69504 +93663 +80869 +124230 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