Skip to content

Instantly share code, notes, and snippets.

@azharkhan
Last active December 11, 2019 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azharkhan/55bfb95a4de57b782469fd72fbc79212 to your computer and use it in GitHub Desktop.
Save azharkhan/55bfb95a4de57b782469fd72fbc79212 to your computer and use it in GitHub Desktop.
Advent of Code 2019 - 1
with open("fuel.txt", "r") as f:
lines = [int(line) for line in f.readlines()]
def add(x, y): return x + y
def calc(x):
if (x // 3 - 2 <= 0):
return 0
else:
return x // 3 - 2 + calc(x // 3 - 2)
fuel = reduce(add, map(calc, lines))
print(fuel)
71343
60747
122054
67364
53017
81716
55910
120565
59809
148941
124539
108258
77377
97572
56164
57858
97899
53786
129974
88645
89330
136628
139228
128560
88358
85431
68350
61458
61833
104279
127850
111139
94752
95037
141723
96355
89433
78355
108635
59567
55589
141992
104238
68291
147546
73476
70991
62313
58672
121783
63158
112817
117776
134302
107446
124540
84279
51193
78829
142544
102528
131341
121502
78165
127783
81012
106876
90403
62091
58090
74824
109657
55042
108119
56850
69635
107792
131462
106842
83864
127170
88563
138150
117904
75996
78850
76719
133639
55213
111209
126243
123495
89420
54618
110194
79674
109834
77521
110024
115217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment