-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDayTwo.cpp
58 lines (49 loc) · 1.97 KB
/
DayTwo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by Aidan Nagorcka-Smith on 30/12/2022.
//
#include "DayTwo.h"
#include <iostream>
#include "DayTwoParser.h"
#include "RockPaperScissors.h"
namespace AdventOfCode::DayTwo {
int pointValueForSelection(const RockPaperScissors::Selection &selection) {
switch (selection) {
case RockPaperScissors::Selection::kRock:
return 1;
case RockPaperScissors::Selection::kPaper:
return 2;
case RockPaperScissors::Selection::kScissors:
return 3;
}
}
int playerTwoPointValueForResult(const RockPaperScissors::Result &result) {
switch (result) {
case RockPaperScissors::Result::kPlayerTwoWin:
return 6;
case RockPaperScissors::Result::kDraw:
return 3;
case RockPaperScissors::Result::kPlayerOneWin:
return 0;
}
}
int playerTwoScoreForRound(const RockPaperScissors::Round &round) {
int scoreFromSelection = pointValueForSelection(round.playerTwoSelection());
int scoreFromResult = playerTwoPointValueForResult(RockPaperScissors::resultFromRound(round));
return scoreFromResult + scoreFromSelection;
}
int puzzleSolution(const Input &input) {
int totalScore = 0;
for (const auto &round : input) {
totalScore += playerTwoScoreForRound(round);
}
return totalScore;
}
void run() {
Input puzzleOneInput = Parser::parseFilePuzzleOne(Parser::kDayTwoInputFilePath);
std::cout << "Day 2 - Puzzle 1" << std::endl
<< "My score in the Rock, Paper, Scissors tournament: " << puzzleSolution(puzzleOneInput) << std::endl;
Input puzzleTwoInput = Parser::parseFilePuzzleTwo(Parser::kDayTwoInputFilePath);
std::cout << "Day 2 - Puzzle 2" << std::endl
<< "My score in the Rock, Paper, Scissors tournament: " << puzzleSolution(puzzleTwoInput) << std::endl;
}
}