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
|
//Class constructor
|
||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
std::vector<int> elfs;
|
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() override final {
|
Output part1() override final { return Output(); }
|
||||||
orderCalories(elfs);
|
Output part2() override final { return Output(); }
|
||||||
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());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -50,10 +50,9 @@ void runSolutions() {
|
|||||||
|
|
||||||
//Free memory for heap allocated solution
|
//Free memory for heap allocated solution
|
||||||
delete solution;
|
delete solution;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
runSolutions<int>();
|
runSolutions<int>();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user