Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6b674e5

Browse files
authored
Add 2019 Day 1 Solution (#11)
1 parent 9ab842d commit 6b674e5

File tree

2 files changed

+229
-0
lines changed

2 files changed

+229
-0
lines changed

2019/01/input.txt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
112908
2+
61769
3+
65967
4+
51494
5+
99689
6+
114098
7+
135346
8+
59561
9+
147324
10+
50465
11+
117491
12+
77845
13+
91959
14+
59847
15+
84013
16+
85763
17+
62121
18+
58965
19+
89809
20+
97870
21+
77696
22+
70218
23+
118404
24+
83505
25+
141729
26+
61534
27+
101073
28+
131358
29+
76104
30+
120836
31+
109789
32+
96510
33+
65406
34+
117906
35+
74921
36+
95412
37+
99875
38+
134298
39+
105235
40+
82802
41+
103392
42+
81906
43+
133786
44+
140681
45+
109004
46+
148434
47+
92333
48+
83848
49+
98297
50+
95728
51+
138202
52+
79312
53+
55633
54+
138461
55+
50293
56+
141922
57+
140303
58+
66542
59+
50054
60+
99076
61+
143201
62+
66702
63+
133583
64+
70308
65+
146824
66+
95606
67+
63054
68+
129272
69+
133051
70+
58626
71+
119896
72+
66265
73+
99925
74+
131752
75+
74669
76+
148387
77+
132124
78+
107188
79+
55535
80+
145004
81+
78122
82+
50885
83+
70325
84+
100859
85+
86484
86+
88795
87+
148164
88+
64473
89+
143089
90+
121023
91+
52904
92+
120927
93+
87164
94+
133709
95+
89427
96+
105350
97+
106378
98+
98492
99+
78394
100+
145200

2019/01/solution.ipynb

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"# Advent of Code 2019 - Day 1\n",
7+
"\n",
8+
"## Part 1"
9+
],
10+
"metadata": {}
11+
},
12+
{
13+
"cell_type": "code",
14+
"source": [
15+
"total_fuel = 0\n",
16+
"with open('input.txt', 'r') as f:\n",
17+
" for mass in [int(i) for i in f]:\n",
18+
" module_fuel = int(mass / 3) - 2\n",
19+
" total_fuel = total_fuel + module_fuel\n",
20+
" \n",
21+
"print(f'Part 1 fuel needed: {total_fuel}')"
22+
],
23+
"outputs": [
24+
{
25+
"output_type": "stream",
26+
"name": "stdout",
27+
"text": [
28+
"Part 1 fuel needed: 3275518\n"
29+
]
30+
}
31+
],
32+
"execution_count": 1,
33+
"metadata": {
34+
"collapsed": false,
35+
"outputHidden": false,
36+
"inputHidden": false
37+
}
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"source": [
42+
"## Part 2"
43+
],
44+
"metadata": {}
45+
},
46+
{
47+
"cell_type": "code",
48+
"source": [
49+
"def get_fuel_reqs(mass):\n",
50+
" fuel = int(mass / 3) - 2\n",
51+
" \n",
52+
" if fuel <= 0:\n",
53+
" return 0\n",
54+
" else:\n",
55+
" return fuel + get_fuel_reqs(fuel)\n",
56+
" \n",
57+
"print(f'Test data: {get_fuel_reqs(1969)}')"
58+
],
59+
"outputs": [
60+
{
61+
"output_type": "stream",
62+
"name": "stdout",
63+
"text": [
64+
"Test data: 966\n"
65+
]
66+
}
67+
],
68+
"execution_count": 2,
69+
"metadata": {
70+
"collapsed": false,
71+
"outputHidden": false,
72+
"inputHidden": false
73+
}
74+
},
75+
{
76+
"cell_type": "code",
77+
"source": [
78+
"total_fuel = 0\n",
79+
"with open('input.txt', 'r') as f:\n",
80+
" for mass in [int(i) for i in f]:\n",
81+
" total_fuel = total_fuel + get_fuel_reqs(mass)\n",
82+
" \n",
83+
"print(f'Part 2 fuel needed: {total_fuel}')"
84+
],
85+
"outputs": [
86+
{
87+
"output_type": "stream",
88+
"name": "stdout",
89+
"text": [
90+
"Part 2 fuel needed: 4910404\n"
91+
]
92+
}
93+
],
94+
"execution_count": 3,
95+
"metadata": {
96+
"collapsed": false,
97+
"outputHidden": false,
98+
"inputHidden": false
99+
}
100+
}
101+
],
102+
"metadata": {
103+
"kernel_info": {
104+
"name": "advent-of-code"
105+
},
106+
"language_info": {
107+
"name": "python",
108+
"version": "3.8.0",
109+
"mimetype": "text/x-python",
110+
"codemirror_mode": {
111+
"name": "ipython",
112+
"version": 3
113+
},
114+
"pygments_lexer": "ipython3",
115+
"nbconvert_exporter": "python",
116+
"file_extension": ".py"
117+
},
118+
"kernelspec": {
119+
"name": "advent-of-code",
120+
"language": "python",
121+
"display_name": "advent-of-code"
122+
},
123+
"nteract": {
124+
"version": "0.15.0"
125+
}
126+
},
127+
"nbformat": 4,
128+
"nbformat_minor": 4
129+
}

0 commit comments

Comments
 (0)