From 7005eb7ff4a9a5de68d54db326dfc41d8c1b3f83 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Fri, 2 Dec 2022 07:01:11 +0000 Subject: [PATCH] Add 2022 Day 2. --- 2022/puzzle-02-01.cc | 30 ++++++++++++++++++++++++++++++ 2022/puzzle-02-02.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 2022/puzzle-02-01.cc create mode 100644 2022/puzzle-02-02.cc diff --git a/2022/puzzle-02-01.cc b/2022/puzzle-02-01.cc new file mode 100644 index 0000000..46b9ce8 --- /dev/null +++ b/2022/puzzle-02-01.cc @@ -0,0 +1,30 @@ +// +// Created by Matthew Gretton-Dann on 02/12/2022. +// + +#include +#include +#include +#include + +using Int = std::int64_t; + +auto main() -> int +{ + // A = Rock, B = Paper, C = Scissors + // X = Rock, B = Paper, C = Scisscors + std::map scores = { + {"A X", 1 + 3}, {"A Y", 2 + 6}, {"A Z", 3 + 0}, {"B X", 1 + 0}, {"B Y", 2 + 3}, + {"B Z", 3 + 6}, {"C X", 1 + 6}, {"C Y", 2 + 0}, {"C Z", 3 + 3}, + }; + + Int score{0}; + std::string line; + while (std::getline(std::cin, line)) { + auto it{scores.find(line)}; + assert(it != scores.end()); + score += it->second; + } + std::cout << "Score: " << score << '\n'; + return EXIT_SUCCESS; +} diff --git a/2022/puzzle-02-02.cc b/2022/puzzle-02-02.cc new file mode 100644 index 0000000..05578d6 --- /dev/null +++ b/2022/puzzle-02-02.cc @@ -0,0 +1,30 @@ +// +// Created by Matthew Gretton-Dann on 02/12/2022. +// + +#include +#include +#include +#include + +using Int = std::int64_t; + +auto main() -> int +{ + // A = Rock, B = Paper, C = Scissors + // X = Lose, B = Draw, C = Win + std::map scores = { + {"A X", 3 + 0}, {"A Y", 1 + 3}, {"A Z", 2 + 6}, {"B X", 1 + 0}, {"B Y", 2 + 3}, + {"B Z", 3 + 6}, {"C X", 2 + 0}, {"C Y", 3 + 3}, {"C Z", 1 + 6}, + }; + + Int score{0}; + std::string line; + while (std::getline(std::cin, line)) { + auto it{scores.find(line)}; + assert(it != scores.end()); + score += it->second; + } + std::cout << "Score: " << score << '\n'; + return EXIT_SUCCESS; +}