Advent 2022 day2 & day3

This commit is contained in:
Jos van Goor 2022-12-03 10:48:26 +01:00
parent 68a75987e2
commit 104f034568
6 changed files with 2923 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,47 @@
#include <fmt/format.h>
#include <array>
#include <fstream>
void run_game(const std::array<std::array<int, 3>, 3>& scoring)
{
int score = 0;
std::fstream in{"input.txt"};
char elf{};
char you{};
while (true)
{
in >> elf >> you;
if (in.eof())
break;
score += scoring[elf - 'A'][you - 'X'];
}
fmt::print("Result: {}\n", score);
}
int main()
{
std::array<std::array<int, 3>, 3> scoring_part1
{{
//X Y Z
{{4, 8, 3}}, // A (rock)
{{1, 5, 9}}, // B (paper)
{{7, 2, 6}} // C (scissors)
}};
std::array<std::array<int, 3>, 3> scoring_part2
{{
//X Y Z
{{3, 4, 8}}, // A (rock)
{{1, 5, 9}}, // B (paper)
{{2, 6, 7}} // C (scissors)
}};
run_game(scoring_part1);
run_game(scoring_part2);
}