Updated main and aoc2022 ready for tomorrow :)
This commit is contained in:
parent
11cf615f43
commit
880f9f2a75
2
.gitignore
vendored
2
.gitignore
vendored
@ -447,4 +447,4 @@ FodyWeavers.xsd
|
||||
*.app
|
||||
|
||||
#Advent of Code Solutions
|
||||
.[Oo]utput
|
||||
./[Oo]utput
|
@ -157,6 +157,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\aoc2022.h" />
|
||||
<ClInclude Include="src\days\days.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".gitignore" />
|
||||
|
@ -101,6 +101,9 @@
|
||||
<ClInclude Include="src\aoc2022.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\days\days.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".gitignore" />
|
||||
|
@ -1,5 +1,13 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
template <typename Output>
|
||||
struct SDay {
|
||||
@ -7,7 +15,7 @@ struct SDay {
|
||||
std::ifstream input;
|
||||
|
||||
//Constructor and Destructor
|
||||
SDay(std::string);
|
||||
SDay(std::string name);
|
||||
~SDay();
|
||||
|
||||
virtual Output part1() const = 0;
|
||||
|
26
src/days/days.h
Normal file
26
src/days/days.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "day01.cpp"
|
||||
#include "day02.cpp"
|
||||
#include "day03.cpp"
|
||||
#include "day04.cpp"
|
||||
#include "day05.cpp"
|
||||
#include "day06.cpp"
|
||||
#include "day07.cpp"
|
||||
#include "day08.cpp"
|
||||
#include "day09.cpp"
|
||||
#include "day10.cpp"
|
||||
#include "day11.cpp"
|
||||
#include "day12.cpp"
|
||||
#include "day13.cpp"
|
||||
#include "day14.cpp"
|
||||
#include "day15.cpp"
|
||||
#include "day16.cpp"
|
||||
#include "day17.cpp"
|
||||
#include "day18.cpp"
|
||||
#include "day19.cpp"
|
||||
#include "day20.cpp"
|
||||
#include "day21.cpp"
|
||||
#include "day22.cpp"
|
||||
#include "day23.cpp"
|
||||
#include "day24.cpp"
|
||||
#include "day25.cpp"
|
78
src/main.cpp
78
src/main.cpp
@ -1,31 +1,59 @@
|
||||
#include "aoc2022.h"
|
||||
#include <string>
|
||||
#include "days/Source.cpp"
|
||||
#include "days/days.h"
|
||||
|
||||
template <typename Output>
|
||||
void runSolutions() {
|
||||
//Heap allocate all solutions
|
||||
std::vector<SDay<Output>*> solutions = {
|
||||
new SDay01<Output>("day01"),
|
||||
new SDay02<Output>("day02"),
|
||||
new SDay03<Output>("day03"),
|
||||
new SDay04<Output>("day04"),
|
||||
new SDay05<Output>("day05"),
|
||||
new SDay06<Output>("day06"),
|
||||
new SDay07<Output>("day07"),
|
||||
new SDay08<Output>("day08"),
|
||||
new SDay09<Output>("day09"),
|
||||
new SDay11<Output>("day11"),
|
||||
new SDay12<Output>("day12"),
|
||||
new SDay13<Output>("day13"),
|
||||
new SDay14<Output>("day14"),
|
||||
new SDay15<Output>("day15"),
|
||||
new SDay16<Output>("day16"),
|
||||
new SDay17<Output>("day17"),
|
||||
new SDay18<Output>("day18"),
|
||||
new SDay19<Output>("day19"),
|
||||
new SDay20<Output>("day20"),
|
||||
new SDay21<Output>("day21"),
|
||||
new SDay22<Output>("day22"),
|
||||
new SDay23<Output>("day23"),
|
||||
new SDay24<Output>("day24"),
|
||||
new SDay25<Output>("day25"),
|
||||
};
|
||||
|
||||
for (auto& solution : solutions)
|
||||
{//Run each day in turn, recording execution times for each part
|
||||
std::cout << " Name Part 1 Part 2 Elapsed\n";
|
||||
std::cout << "=================================================================\n";
|
||||
std::cout << " " << solution->name;
|
||||
|
||||
//Run solutions and keep timer on each
|
||||
std::ofstream output("output/" + solution->name);
|
||||
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
output << solution->part1() << std::endl;
|
||||
std::chrono::duration<double> part1Time = std::chrono::steady_clock::now() - start;
|
||||
output << solution->part2();
|
||||
std::chrono::duration<double> part2Time = std::chrono::steady_clock::now() - start - part1Time;
|
||||
std::chrono::duration<double> elapsedTime = std::chrono::steady_clock::now() - start;
|
||||
|
||||
std::cout << " " << 1e3 * part1Time.count() << "ms " << 1e3 * part2Time.count() << "ms " << 1e3 * elapsedTime.count() << "ms\n" << std::endl;
|
||||
|
||||
//Free memory for heap allocated solution
|
||||
delete solution;
|
||||
|
||||
void createDays() {
|
||||
std::string fileName;
|
||||
std::string line;
|
||||
std::ofstream file;
|
||||
for (int i = 1; i <= 25; i++)
|
||||
{
|
||||
std::ifstream source{ "src/days/Source.cpp" };
|
||||
if (i < 10)
|
||||
{
|
||||
file.open("src/days/day0" + std::to_string(i) + ".cpp");
|
||||
}
|
||||
else
|
||||
{
|
||||
file.open("src/days/day" + std::to_string(i) + ".cpp");
|
||||
}
|
||||
while (std::getline(source, line))
|
||||
{
|
||||
file << line << "\n";
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
//SDay01<int> day1("day01");
|
||||
createDays();
|
||||
runSolutions<int>();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user