Completed Day1
This commit is contained in:
parent
e18371fcca
commit
43a925864a
@ -152,7 +152,6 @@
|
|||||||
<ClCompile Include="src\days\day23.cpp" />
|
<ClCompile Include="src\days\day23.cpp" />
|
||||||
<ClCompile Include="src\days\day24.cpp" />
|
<ClCompile Include="src\days\day24.cpp" />
|
||||||
<ClCompile Include="src\days\day25.cpp" />
|
<ClCompile Include="src\days\day25.cpp" />
|
||||||
<ClCompile Include="src\days\Source.cpp" />
|
|
||||||
<ClCompile Include="src\main.cpp" />
|
<ClCompile Include="src\main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
<ClCompile Include="src\main.cpp">
|
<ClCompile Include="src\main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\days\Source.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="src\days\day01.cpp">
|
<ClCompile Include="src\days\day01.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -18,8 +18,8 @@ struct SDay {
|
|||||||
SDay(std::string name);
|
SDay(std::string name);
|
||||||
~SDay();
|
~SDay();
|
||||||
|
|
||||||
virtual Output part1() const = 0;
|
virtual Output part1() = 0;
|
||||||
virtual Output part2() const = 0;
|
virtual Output part2() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Output>
|
template <typename Output>
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
#include "../aoc2022.h"
|
|
||||||
|
|
||||||
template <typename Output>
|
|
||||||
struct SDay0 : public SDay<Output> {
|
|
||||||
//Class constructor
|
|
||||||
using SDay<Output>::SDay;
|
|
||||||
|
|
||||||
//Solutions to both days
|
|
||||||
Output part1() const override final { return Output(); }
|
|
||||||
Output part2() const override final { return Output(); }
|
|
||||||
};
|
|
@ -5,25 +5,38 @@ 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() const override final {
|
Output part1() override final {
|
||||||
|
orderCalories(elfs);
|
||||||
std::string line{""};
|
return elfs[elfs.size()-1];
|
||||||
int currentElf{0}, maxElf{0};
|
}
|
||||||
|
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))
|
while (std::getline(this->input, line))
|
||||||
{
|
{
|
||||||
if (line == "")
|
if (line == "")
|
||||||
{//Break to a new elf
|
{//Break to a new elf
|
||||||
if (currentElf > maxElf)
|
elfs.push_back(currentElf);
|
||||||
maxElf = currentElf;
|
|
||||||
currentElf = 0;
|
currentElf = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Add the new line to the current elf
|
//Add the new line to the current elf
|
||||||
currentElf += std::stoi(line);
|
currentElf += std::stoi(line);
|
||||||
}
|
}
|
||||||
return maxElf;
|
//Push the final elf
|
||||||
|
elfs.push_back(currentElf);
|
||||||
|
return std::sort(elfs.begin(), elfs.end());
|
||||||
}
|
}
|
||||||
Output part2() const override final { return Output(); }
|
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay02 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay03 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay04 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay05 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay06 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay07 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay08 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay09 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay10 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay11 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay12 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay13 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay14 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay15 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay16 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay17 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay18 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay19 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay20 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay21 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay22 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay23 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay24 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,6 @@ struct SDay25 : public SDay<Output> {
|
|||||||
using SDay<Output>::SDay;
|
using SDay<Output>::SDay;
|
||||||
|
|
||||||
//Solutions to both days
|
//Solutions to both days
|
||||||
Output part1() const override final { return Output(); }
|
Output part1() override final { return Output(); }
|
||||||
Output part2() const override final { return Output(); }
|
Output part2() override final { return Output(); }
|
||||||
};
|
};
|
||||||
|
@ -27,7 +27,7 @@ void runSolutions() {
|
|||||||
new SDay22<Output>("day22"),
|
new SDay22<Output>("day22"),
|
||||||
new SDay23<Output>("day23"),
|
new SDay23<Output>("day23"),
|
||||||
new SDay24<Output>("day24"),
|
new SDay24<Output>("day24"),
|
||||||
new SDay25<Output>("day25"),
|
new SDay25<Output>("day25")
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& solution : solutions)
|
for (auto& solution : solutions)
|
||||||
|
Loading…
Reference in New Issue
Block a user