summaryrefslogtreecommitdiffstats
path: root/2019/day1
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
parent74b27ccca31bb757c737dd7fdc02f513f57561b2 (diff)
downloadaoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.gz
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.tar.bz2
aoc-bf16b19b1f6deffd1983efca059db576f3b60ee5.zip
2019, tracking
Diffstat (limited to '2019/day1')
-rw-r--r--2019/day1/README.md5
-rw-r--r--2019/day1/part1.in100
-rw-r--r--2019/day1/part2.in100
-rw-r--r--2019/day1/rec_fuel.py23
4 files changed, 228 insertions, 0 deletions
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 @@
1I realized part 1 can be solved with a perl one liner;
2
3```bash
4perl -ne '$c += int ($_ / 3) - 2;END {print $c}' < part1.in
5```
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 @@
193912
2138996
3112824
4110011
5139024
6132292
774029
881664
9138077
10109614
11121056
12136338
13132771
1486611
15131526
16123101
1761315
1893900
1962070
2097957
2167168
22119464
23119066
24111076
2556856
26144203
27109400
28120187
2957915
30143353
3171308
3267695
33141275
34106552
35136209
3686990
3798969
3857207
3999103
4071940
4163145
4291765
43121095
44139700
45128851
4677138
4766712
4891318
4996924
50132235
5199897
5267479
5387996
54121100
5555411
5661715
57130658
58121030
59141445
6083939
6190402
62121107
6359618
64120112
6558140
66103514
6790538
6855552
69142739
7061770
71147374
7280038
73128830
7493328
7552369
7671801
77144536
78147140
79118213
80128056
8192155
82114384
8389234
84124451
8594214
8679174
87108427
88111041
8996715
90128414
9162521
9293897
93107428
9490637
95126176
9678676
9769504
9893663
9980869
100124230
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 @@
193912
2138996
3112824
4110011
5139024
6132292
774029
881664
9138077
10109614
11121056
12136338
13132771
1486611
15131526
16123101
1761315
1893900
1962070
2097957
2167168
22119464
23119066
24111076
2556856
26144203
27109400
28120187
2957915
30143353
3171308
3267695
33141275
34106552
35136209
3686990
3798969
3857207
3999103
4071940
4163145
4291765
43121095
44139700
45128851
4677138
4766712
4891318
4996924
50132235
5199897
5267479
5387996
54121100
5555411
5661715
57130658
58121030
59141445
6083939
6190402
62121107
6359618
64120112
6558140
66103514
6790538
6855552
69142739
7061770
71147374
7280038
73128830
7493328
7552369
7671801
77144536
78147140
79118213
80128056
8192155
82114384
8389234
84124451
8594214
8679174
87108427
88111041
8996715
90128414
9162521
9293897
93107428
9490637
95126176
9678676
9769504
9893663
9980869
100124230
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)