diff --git a/2022/day-10.cpp b/2022/day-10.cpp new file mode 100644 index 0000000..fdd6519 --- /dev/null +++ b/2022/day-10.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +int main(int argc, char* argv[]){ + std::cout<<"paste input followed by a ;\n"; + std::vector inp; + std::string line; + std::vector 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 crt = {"........................................","........................................","........................................","........................................","........................................","........................................"}; + for(int i : instructions){ + //std::cout< struct move{ char move; - int distance; }; struct grid{ std::vector> grid; - std::vector> t_visited; + std::vector> 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 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 t; + for(int i = 0;i!=temp.grid[0].size();i++) + t.push_back('.'); + g.grid.push_back(t); + } + 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 c : g.grid){ + for(char cc : c) + std::cout< moves; + std::vector 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<