Updated repository and removed day01 to make it clean
This commit is contained in:
parent
43a925864a
commit
28c7d44666
2250
input/day01
2250
input/day01
File diff suppressed because it is too large
Load Diff
@ -5,38 +5,7 @@ struct SDay01 : public SDay<Output> {
|
||||
//Class constructor
|
||||
using SDay<Output>::SDay;
|
||||
|
||||
std::vector<int> elfs;
|
||||
|
||||
//Solutions to both days
|
||||
Output part1() override final {
|
||||
orderCalories(elfs);
|
||||
return elfs[elfs.size()-1];
|
||||
}
|
||||
Output part2() override final {
|
||||
//If elfs has been populated (by part 1)
|
||||
if (elfs.size() > 0)
|
||||
return (elfs[elfs.size() - 1] + elfs[elfs.size() - 2] + elfs[elfs.size() - 3]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void orderCalories(std::vector<int> &elfs) {
|
||||
this->input.seekg(0);
|
||||
std::string line{ "" };
|
||||
int currentElf{ 0 };
|
||||
|
||||
while (std::getline(this->input, line))
|
||||
{
|
||||
if (line == "")
|
||||
{//Break to a new elf
|
||||
elfs.push_back(currentElf);
|
||||
currentElf = 0;
|
||||
continue;
|
||||
}
|
||||
//Add the new line to the current elf
|
||||
currentElf += std::stoi(line);
|
||||
}
|
||||
//Push the final elf
|
||||
elfs.push_back(currentElf);
|
||||
return std::sort(elfs.begin(), elfs.end());
|
||||
}
|
||||
Output part1() override final { return Output(); }
|
||||
Output part2() override final { return Output(); }
|
||||
};
|
||||
|
@ -50,7 +50,6 @@ void runSolutions() {
|
||||
|
||||
//Free memory for heap allocated solution
|
||||
delete solution;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user