Added older advents
This commit is contained in:
parent
8db2505049
commit
9cf858b860
78 changed files with 13807 additions and 0 deletions
56
advent_of_code_2015/day6/main1.cc
Normal file
56
advent_of_code_2015/day6/main1.cc
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "main.ih"
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<Instruction> instructions;
|
||||
|
||||
while(!cin.eof())
|
||||
{
|
||||
Instruction instr;
|
||||
cin >> instr;
|
||||
|
||||
instructions.push_back(instr);
|
||||
cout << "Instruction set " << instr.action << "\n";
|
||||
cout << " from: [" << instr.from.x << ", " << instr.from.y << "]\n";
|
||||
cout << " througn: [" << instr.through.x << ", " << instr.through.y << "]\n";
|
||||
}
|
||||
|
||||
vector<vector<bool>> lights;
|
||||
lights.resize(1000, vector<bool>(1000, false));
|
||||
|
||||
for (Instruction const &instr : instructions)
|
||||
{
|
||||
for (size_t idx = instr.from.x; idx <= instr.through.x; ++idx)
|
||||
{
|
||||
for (size_t idy = instr.from.y; idy <= instr.through.y; ++idy)
|
||||
{
|
||||
switch(instr.action)
|
||||
{
|
||||
case TURN_OFF:
|
||||
lights[idx][idy] = false;
|
||||
break;
|
||||
|
||||
case TURN_ON:
|
||||
lights[idx][idy] = true;
|
||||
break;
|
||||
|
||||
case TOGGLE:
|
||||
lights[idx][idy] = !lights[idx][idy];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t lights_on = 0;
|
||||
for (size_t idx = 0; idx != lights.size(); ++idx)
|
||||
{
|
||||
for (size_t idy = 0; idy != lights[idx].size(); ++idy)
|
||||
{
|
||||
if (lights[idx][idy])
|
||||
++lights_on;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "There are " << lights_on << " lights turned on!\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue