Estoy intentando hacer años anteriores
This commit is contained in:
100
2019/day_1/input
Normal file
100
2019/day_1/input
Normal file
@@ -0,0 +1,100 @@
|
||||
102480
|
||||
121446
|
||||
118935
|
||||
54155
|
||||
102510
|
||||
142419
|
||||
73274
|
||||
57571
|
||||
123916
|
||||
99176
|
||||
143124
|
||||
141318
|
||||
72224
|
||||
145479
|
||||
97027
|
||||
126427
|
||||
94990
|
||||
100521
|
||||
105589
|
||||
123009
|
||||
77143
|
||||
142861
|
||||
92366
|
||||
66478
|
||||
102195
|
||||
128373
|
||||
128447
|
||||
120178
|
||||
99122
|
||||
98671
|
||||
89541
|
||||
125720
|
||||
107984
|
||||
126544
|
||||
145231
|
||||
110241
|
||||
123926
|
||||
72793
|
||||
76705
|
||||
128338
|
||||
74262
|
||||
68845
|
||||
65297
|
||||
112536
|
||||
59892
|
||||
57115
|
||||
73230
|
||||
80569
|
||||
146118
|
||||
108843
|
||||
59221
|
||||
140492
|
||||
122616
|
||||
140652
|
||||
64404
|
||||
99782
|
||||
104375
|
||||
86926
|
||||
143145
|
||||
114969
|
||||
108948
|
||||
77236
|
||||
143655
|
||||
71406
|
||||
97588
|
||||
64892
|
||||
105345
|
||||
104393
|
||||
93442
|
||||
54525
|
||||
94116
|
||||
123606
|
||||
106813
|
||||
59904
|
||||
149253
|
||||
81620
|
||||
80892
|
||||
66309
|
||||
142604
|
||||
97984
|
||||
79743
|
||||
79448
|
||||
123756
|
||||
64927
|
||||
139703
|
||||
71448
|
||||
135964
|
||||
86083
|
||||
94767
|
||||
116856
|
||||
73786
|
||||
141083
|
||||
122581
|
||||
82239
|
||||
122282
|
||||
96092
|
||||
80029
|
||||
52957
|
||||
72062
|
||||
52124
|
||||
40
2019/day_1/tyranny.cc
Normal file
40
2019/day_1/tyranny.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
std::vector<int> read_input_file() {
|
||||
std::ifstream file("input");
|
||||
std::vector<int> data;
|
||||
std::string line;
|
||||
|
||||
while(std::getline(file, line))
|
||||
data.push_back(std::stoi(line));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int calculate_fuel(int mass) {
|
||||
return (mass / 3) - 2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto data = read_input_file();
|
||||
|
||||
int result_a = 0;
|
||||
int result_b = 0;
|
||||
|
||||
for(auto &input : data) {
|
||||
int fuel = calculate_fuel(input);
|
||||
result_a += fuel;
|
||||
|
||||
while(fuel > 0){
|
||||
result_b += fuel;
|
||||
fuel = calculate_fuel(fuel);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << result_a << ", " << result_b << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
2
2019/day_2/input
Normal file
2
2019/day_2/input
Normal file
@@ -0,0 +1,2 @@
|
||||
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,2,19,13,23,1,23,10,27,1,13,27,31,2,31,10,35,1,35,9,39,1,39,13,43,1,13,43,47,1,47,13,51,1,13,51,55,1,5,55,59,2,10,59,63,1,9,63,67,1,6,67,71,2,71,13,75,2,75,13,79,1,79,9,83,2,83,10,87,1,9,87,91,1,6,91,95,1,95,10,99,1,99,13,103,1,13,103,107,2,13,107,111,1,111,9,115,2,115,10,119,1,119,5,123,1,123,2,127,1,127,5,0,99,2,14,0,0
|
||||
|
||||
50
2019/day_2/intcode.hh
Normal file
50
2019/day_2/intcode.hh
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef INTCODE_H
|
||||
#define INTCODE_H
|
||||
|
||||
#include<vector>
|
||||
#include<iostream>
|
||||
|
||||
class IntCode {
|
||||
std::vector<int> memory;
|
||||
bool halt = false;
|
||||
int ip = 0; //instruction pointer
|
||||
|
||||
void op_add() {
|
||||
int param_1 = memory[memory[ip+1]];
|
||||
int param_2 = memory[memory[ip+2]];
|
||||
|
||||
memory[memory[ip+3]] = param_1 + param_2;
|
||||
ip += 4;
|
||||
}
|
||||
|
||||
void op_mult() {
|
||||
int param_1 = memory[memory[ip+1]];
|
||||
int param_2 = memory[memory[ip+2]];
|
||||
|
||||
memory[memory[ip+3]] = param_1 * param_2;
|
||||
ip += 4;
|
||||
}
|
||||
|
||||
void run() {
|
||||
while(!halt){
|
||||
switch(memory[ip]) {
|
||||
case 1: op_add(); break;
|
||||
case 2: op_mult(); break;
|
||||
case 99: halt = true; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
IntCode(std::vector<int> memory) {
|
||||
this->memory = memory;
|
||||
run();
|
||||
}
|
||||
|
||||
|
||||
int get(int address) {
|
||||
return memory[address];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
47
2019/day_2/program_alarm.cc
Normal file
47
2019/day_2/program_alarm.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "intcode.hh"
|
||||
|
||||
std::vector<int> read_input_file() {
|
||||
std::ifstream file("input");
|
||||
std::vector<int> data;
|
||||
std::string line;
|
||||
|
||||
while(std::getline(file, line, ','))
|
||||
data.push_back(std::stoi(line));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void solve_a(std::vector<int> memory) {
|
||||
memory[1] = 12;
|
||||
memory[2] = 2;
|
||||
|
||||
auto vm = IntCode(memory);
|
||||
std::cout << vm.get(0) << std::endl;
|
||||
}
|
||||
|
||||
void solve_b(std::vector<int> memory) {
|
||||
for(int x = 0; x < 99; x++){
|
||||
for(int y = 0; y < 99; y++){
|
||||
memory[1] = x;
|
||||
memory[2] = y;
|
||||
|
||||
auto vm = IntCode(memory);
|
||||
if(vm.get(0) == 19690720)
|
||||
std::cout << x << ", " << y << " = " << (100 * x) + y << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto memory = read_input_file();
|
||||
|
||||
solve_a(memory);
|
||||
solve_b(memory);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user