Lanternfish hits hard though...
This commit is contained in:
parent
cbc075544c
commit
15d2a47735
5 changed files with 138 additions and 0 deletions
1
day6/data/testInput.txt
Normal file
1
day6/data/testInput.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3,4,3,1,2
|
BIN
day6/day6Part1
Executable file
BIN
day6/day6Part1
Executable file
Binary file not shown.
68
day6/day6Part1.cpp
Normal file
68
day6/day6Part1.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
string rawInput;
|
||||||
|
vector<int> fishCount = {};
|
||||||
|
vector<int> nextFishCount;
|
||||||
|
int dayCount = 0;
|
||||||
|
ifstream readFile ("data/input.txt", ios::in);
|
||||||
|
|
||||||
|
//Read file into arrays
|
||||||
|
while(getline(readFile, rawInput))
|
||||||
|
{
|
||||||
|
for(int i=0;i<rawInput.size();i++)
|
||||||
|
{
|
||||||
|
switch(rawInput[i])
|
||||||
|
{
|
||||||
|
case '1':
|
||||||
|
fishCount.push_back(1);
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
fishCount.push_back(2);
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
fishCount.push_back(3);
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
fishCount.push_back(4);
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
fishCount.push_back(5);
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
fishCount.push_back(6);
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
fishCount.push_back(7);
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
fishCount.push_back(8);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFishCount = fishCount;
|
||||||
|
for(dayCount;dayCount<80;dayCount++)
|
||||||
|
{
|
||||||
|
for(int i=0;i<fishCount.size();i++)
|
||||||
|
{
|
||||||
|
if(fishCount[i] == 0)
|
||||||
|
{
|
||||||
|
nextFishCount[i] = 6;
|
||||||
|
nextFishCount.push_back(8);
|
||||||
|
}
|
||||||
|
else nextFishCount[i]--;
|
||||||
|
}
|
||||||
|
fishCount = nextFishCount;
|
||||||
|
}
|
||||||
|
cout << "Fish Count: " << fishCount.size() << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
day6/day6Part2
Executable file
BIN
day6/day6Part2
Executable file
Binary file not shown.
69
day6/day6Part2.cpp
Normal file
69
day6/day6Part2.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <cmath>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
string rawInput;
|
||||||
|
vector<short int> fishCount = {};
|
||||||
|
vector<short int> nextFishCount;
|
||||||
|
short int dayCount = 0;
|
||||||
|
ifstream readFile ("data/input.txt", ios::in);
|
||||||
|
|
||||||
|
//Read file into arrays
|
||||||
|
while(getline(readFile, rawInput))
|
||||||
|
{
|
||||||
|
for(int i=0;i<rawInput.size();i++)
|
||||||
|
{
|
||||||
|
switch(rawInput[i])
|
||||||
|
{
|
||||||
|
case '1':
|
||||||
|
fishCount.push_back(1);
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
fishCount.push_back(2);
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
fishCount.push_back(3);
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
fishCount.push_back(4);
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
fishCount.push_back(5);
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
fishCount.push_back(6);
|
||||||
|
break;
|
||||||
|
case '7':
|
||||||
|
fishCount.push_back(7);
|
||||||
|
break;
|
||||||
|
case '8':
|
||||||
|
fishCount.push_back(8);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nextFishCount = fishCount;
|
||||||
|
for(dayCount;dayCount<256;dayCount++)
|
||||||
|
{
|
||||||
|
for(int i=0;i<fishCount.size();i++)
|
||||||
|
{
|
||||||
|
if(fishCount[i] == 0)
|
||||||
|
{
|
||||||
|
nextFishCount[i] = 6;
|
||||||
|
nextFishCount.push_back(8);
|
||||||
|
}
|
||||||
|
else nextFishCount[i]--;
|
||||||
|
}
|
||||||
|
cout << "New Day! Processing day " << dayCount << "..." << endl;
|
||||||
|
fishCount = nextFishCount;
|
||||||
|
}
|
||||||
|
cout << "Fish Count: " << fishCount.size() << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue