Moving too the laptop

This commit is contained in:
Ben
2019-12-01 18:26:51 +00:00
parent cb9257e51e
commit c3cddf3606
8 changed files with 204 additions and 0 deletions

5
2019/1stDay/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"files.associations": {
"cmath": "cpp"
}
}

BIN
2019/1stDay/challenge1 Normal file

Binary file not shown.

View File

@@ -0,0 +1,32 @@
#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
int main(int argc, char** argv)
{
std::ifstream infile( argv[1] );
int accumilator = 0;
// for ( std::string line; !infile.eof(); std::getline( infile, line ) )
// {
// if ( line.length() == 0 ) continue;
// accumilator += (std::stoi( line ) / 3) - 2;
// }
std::string line;
while (!infile.eof())
{
std::getline(infile, line);
if ( line.length() == 0 ) continue;
accumilator += (std::stoi( line ) / 3) - 2;
}
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
}

View File

@@ -0,0 +1,20 @@
--- Day 1: The Tyranny of the Rocket Equation ---
Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him measurements from fifty stars.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
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?

BIN
2019/1stDay/challenge2 Normal file

Binary file not shown.

View File

@@ -0,0 +1,36 @@
#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
int fuelForMass ( int mass, int accumilator = 0 )
{
int res = (mass / 3) - 2;
if ( res > 0 )
return fuelForMass( res, accumilator + res );
return res;
};
int main(int argc, char** argv)
{
std::ifstream infile( argv[1] );
int accumilator = 0;
std::string line;
while (!infile.eof())
{
std::getline(infile, line);
if ( line.length() == 0 ) continue;
accumilator += fuelForMass( std::stoi( line ) );
}
std::cout << "Sum of the fuel requrements : " << accumilator << std::endl;
}

View File

@@ -0,0 +1,11 @@
--- Part Two ---
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.)

100
2019/1stDay/input.txt Normal file
View File

@@ -0,0 +1,100 @@
54755
96495
111504
53923
118158
118082
137413
135315
87248
127646
79201
52399
77966
129568
63880
128973
55491
111226
126447
87017
112469
83975
51280
60239
120524
57122
136517
117378
93629
55125
68990
70336
115119
68264
148122
70075
106770
54976
123852
61813
113373
53924
59660
67111
52825
81568
110842
134870
135529
78689
129451
96041
91627
70863
100098
121908
96623
143752
149936
116283
149488
126158
106499
124927
109574
70711
139078
67212
124251
123803
73569
145668
96045
59748
123238
68005
121412
97236
104800
86786
141680
123807
82310
76593
146092
82637
92339
93821
56247
58328
90159
105700
57317
69011
125544
102372
63797
92127
111207
77596