My friends keep bugging me to play Halo today. Which, to be fair, I'm excited to play, especially with the game finally releasing in a few days. I'm REALLY excited for the launch party, it will be my first since entering the gaming industry! But I'm still getting this in between matches while I have a few moments.
for (int i = 0; i < NUM_DAYS; i++) {
// 1) Age fish, keeping track of new fish
int newFish = 0;
for (int j = 0; j < feesh.size(); j++) {
if (feesh[j] == 0) {
feesh[j] = 6;
newFish++;
} else {
feesh[j]--;
}
}
// 2) Add new fish to the end
while (newFish-- > 0) feesh.push_back(8);
}
Pretty easy. I managed to do it throughout the course of two matches.
Ahahaha, okay, this is great. The problem is exactly the same, but more days. Meaning it was a brute force bait of a problem. I tried running it for fifteen minutes and it didn't finish. I'm going to need to be more clever about this. Maybe just a few buckets for the different ages?
Yeah. That ended up silly. It ended up in the quintillions of fish. But with my new bucket solution it worked!
for (int i = 0; i < NUM_DAYS; i++) {
// 1) Mark fish ready for birth
unsigned long long newFish = feesh[0];
feesh[7] += feesh[0];
// 2) Age all existing fish
for (int j = 1; j < 9; j++) {
feesh[j-1] = feesh[j];
}
// 3) Add in newly birthed fish
feesh[8] = newFish;
}