day 10 p1, day 9 not done lol

This commit is contained in:
grant 2022-12-11 18:58:08 -06:00
parent f035d91781
commit 770f72f433
3 changed files with 122 additions and 9 deletions

45
2022/day-10.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main(int argc, char* argv[]){
std::cout<<"paste input followed by a ;\n";
std::vector<int> inp;
std::string line;
std::vector<int> instructions;
int reg = 1;
int cyc = 0;
while(getline(std::cin, line)){
if(line==";")
break;
if(line.find("noop") != std::string::npos){
instructions.push_back(0);
} else {
line.erase(0,5);
instructions.push_back(0);
instructions.push_back(stoi(line));
}
}
int signal = 0;
int crt_r = 0;
int reg_2 = 0;
std::vector<std::string> crt = {"........................................","........................................","........................................","........................................","........................................","........................................"};
for(int i : instructions){
//std::cout<<i<<std::endl;
cyc++;
if(cyc==20||cyc==60||cyc==100||cyc==140||cyc==180||cyc==220){
signal+=reg*cyc;
//std::cout<<signal<<std::endl;
}
if(cyc%40==0)
crt_r++;
else{
}
reg+=i;
}
std::cout<<"part 1 :"<<signal<<std::endl<<crt[0];
return 0;
}

View File

@ -4,29 +4,94 @@
#include <algorithm>
struct move{
char move;
int distance;
};
struct grid{
std::vector<std::vector<char>> grid;
std::vector<std::vector<char>> t_visited;
std::vector<std::vector<int>> t_visited;
int x;
int y;
int old_x;
int old_y;
int old_t_x;
int old_t_y;
int t_x;
int t_y;
};
// grid will just update the head to the x and y pos
grid update(grid g){
//extend if necessary
grid temp = g;
if(g.y<g.old_y){
std::vector<char> t;
for(int i = 0;i!=temp.grid[0].size();i++)
t.push_back('.');
g.grid.push_back(t);
}
if(g.y>=g.grid.size()){
std::vector<char> t;
for(int i = 0;i!=temp.grid[0].size();i++)
t.push_back('.');
g.grid.push_back(t);
}
if(g.x<g.old_x){
for(int i = 0;i!=temp.grid.size();i++){
g.grid[i].push_back('.');
}
}
if(g.x>=g.grid[0].size()){
for(int i = 0;i!=temp.grid.size();i++){
g.grid[i].insert(g.grid[i].begin(),1,'.');
}
}
g.grid[g.grid.size()-g.old_y-1][g.old_x]='.';
//handle tail movement first
if(g.x>g.old_x){
//moving right
}
//move head accordingly
//g.grid[g.grid.size()-g.old_y-1][g.old_x]='.';
g.grid[g.grid.size()-1-g.y][g.x]='H';
g.old_x=g.x;
g.old_y=g.y;
return g;
}
void list(grid g){
for(std::vector<char> c : g.grid){
for(char cc : c)
std::cout<<cc;
std::cout<<std::endl;
}
}
int main(int argc, char* argv[]){
std::cout<<"paste input followed by a ;\n";
grid grid = {{{'H'}},{{'X'}},0,0}; // B means both are in the same spot
grid grid = {{{'H'}},{{0,0}},0,0,0,0,0,0,0,0}; // B means both are in the same spot
std::string line;
std::vector<move> moves;
std::vector<char> moves;
while(getline(std::cin, line)){
if(line==";")
break;
moves.push_back({line[0],line[2]-'0'});
for(int i = 0;i!=line[2]-'0';i++)
moves.push_back(line[0]);
}
for(move i : moves){
for(int i = 0; i!=moves.size();i++){
if(moves[i]=='U')
grid.y+=1;
if(moves[i]=='D')
grid.y-=1;
if(moves[i]=='R')
grid.x+=1;
if(moves[i]=='L')
grid.x-=1;
std::cout<<moves[i]<<" "<<grid.x<<grid.y<<std::endl;
grid = update(grid);
list(grid);
std::cout<<std::endl<<std::endl;
}
std::cout<<std::endl;
//std::cout<<grid.grid.size();
return 0;
}

View File

@ -29,6 +29,9 @@ y22-d7:
#2022 day 8 ~ both parts
y22-d8:
g++ -o ./2022/day-8 ./2022/day-8.cpp && ./2022/day-8
#2022 day 7 ~ both parts
#2022 day 9 ~ (not done lol) both parts
y22-d9:
g++ -o ./2022/day-9 ./2022/day-9.cpp && ./2022/day-9
g++ -o ./2022/day-9 ./2022/day-9.cpp && ./2022/day-9
#2022 day 10 ~ both parts
y22-d10:
g++ -o ./2022/day-10 ./2022/day-10.cpp && ./2022/day-10