Added day 1 solution.

This commit is contained in:
Brandon Scott 2019-12-14 01:53:54 -06:00
parent 9076063ef3
commit bace232896
2 changed files with 136 additions and 0 deletions

100
input/day1.txt Normal file
View File

@ -0,0 +1,100 @@
136583
77036
109200
142168
74357
146941
129306
98180
105195
129127
135956
116070
89198
51306
144552
109900
56658
52478
115147
63882
70342
98678
107384
135359
87237
84469
106477
104645
77066
74143
76537
140547
68128
116624
148407
78276
117623
96019
75825
75010
98644
119641
139736
104452
72599
63017
59648
126163
69629
79080
92195
58221
134276
80301
89870
146799
145702
138367
131977
56781
85326
138115
70241
60454
76934
119321
93493
123047
149941
141729
70141
134525
93312
92043
79582
115959
51058
94686
70749
99408
118560
95821
58995
94906
98421
118673
83575
83434
63884
70575
134177
116233
113954
52829
123860
128020
126718
144463
140192
143461

36
src/day1.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
int main()
{
std::string line;
std::ifstream input_file("../input/day1.txt");
auto part1_sum = 0;
auto part2_sum = 0;
if (input_file.is_open())
{
while (getline(input_file, line))
{
auto val = std::stoi(line);
auto calculated_value = std::floor(val / 3) - 2;
part1_sum += calculated_value;
while (calculated_value > 0)
{
part2_sum += calculated_value;
calculated_value = std::floor(calculated_value / 3) - 2;
}
}
input_file.close();
}
std::cout << "Part 1 Sum: " << part1_sum << std::endl;
std::cout << "Part 2 Sum: " << part2_sum << std::endl;
return 0;
}