new structure

This commit is contained in:
Akumatic
2019-12-02 21:39:49 +01:00
parent 17217d3d2c
commit e79d6aa6a6
9 changed files with 132 additions and 10 deletions

36
2019/01/README.md Normal file
View File

@ -0,0 +1,36 @@
# 2019 Day 1: The Tyranny of the Rocket Equation
#### [Direct Link](https://adventofcode.com/2019/day/1)
## Part 1
The Elves quickly load you into a spacecraft and prepare to launch.
At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet.
Fuel required to launch a given **module** is based on its **mass**. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
For example:
- For a mass of `12`, divide by 3 and round down to get `4`, then subtract 2 to get 2.
- For a mass of `14`, dividing by 3 and rounding down still yields `4`, so the fuel required is also `2`.
- For a mass of `1969`, the fuel required is `654`.
- For a mass of `100756`, the fuel required is `33583`.
The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
**What is the sum of the fuel requirements** for all of the modules on your spacecraft?
## Part 2
During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.
Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2. However, that fuel **also** requires fuel, and **that** fuel requires fuel, and so on. Any mass that would require **negative fuel** should instead be treated as if it requires **zero fuel**; the remaining mass, if any, is instead handled by **wishing really hard**, which has no mass and is outside the scope of this calculation.
So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:
- A module of mass `14` requires `2` fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is `0`, which would call for a negative fuel), so the total fuel required is still just `2`.
- At first, a module of mass `1969` requires `654` fuel. Then, this fuel requires `216` more fuel (`654 / 3 - 2`). `216` then requires `70` more fuel, which requires `21` fuel, which requires `5` fuel, which requires no further fuel. So, the total fuel required for a module of mass `1969` is `654 + 216 + 70 + 21 + 5 = 966`.
- The fuel required by a module of mass `100756` and its fuel is: `33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346`.
**What is the sum of the fuel requirements** for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)

21
2019/01/code.py Normal file
View File

@ -0,0 +1,21 @@
""" https://adventofcode.com/2019/day/1 """
def readFile():
with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f:
return [int(line[:-1]) for line in f.readlines()]
def part1(vals : list):
return sum([val // 3 - 2 for val in vals])
def part2(vals : list):
fuel = [val // 3 - 2 for val in vals]
for f in fuel:
temp = f // 3 - 2
if temp > 0:
fuel.append(temp)
return sum(fuel)
if __name__ == "__main__":
vals = readFile()
print(f"Part 1: {part1(vals)}")
print(f"Part 2: {part2(vals)}")

100
2019/01/input.txt Normal file
View File

@ -0,0 +1,100 @@
142536
103450
101545
133505
112476
62461
108718
93376
149609
147657
120888
85008
82501
122988
109493
91656
70001
130308
140298
104623
103542
129220
67381
143889
105384
139467
129004
89271
123863
108567
95453
109698
139953
107458
69734
106036
126036
84832
68715
51484
92833
50734
58267
109650
137004
77709
95073
84817
55711
95408
148990
51697
129180
56196
72692
77049
124294
85102
124400
75981
135842
119561
79871
98771
134213
141322
131828
65692
113994
104632
129273
118023
54700
148185
61618
132304
88308
121386
119548
115527
76627
63168
137582
113598
100899
100167
134345
90716
55476
113403
52745
78755
73421
93337
71171
122979
134298
123117
111244
122177

2
2019/01/solution.txt Normal file
View File

@ -0,0 +1,2 @@
Part 1: 3432671
Part 2: 5146132