day 2 task 1

This commit is contained in:
matthias@arch 2022-12-03 02:53:53 +01:00
parent 032f129cb2
commit cf920586b9
6 changed files with 9830 additions and 0 deletions

BIN
2/day2 Executable file

Binary file not shown.

4791
2/diff Normal file

File diff suppressed because it is too large Load Diff

35
2/main.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
constexpr char ROCK = 1;
constexpr char PAPER = 2;
constexpr char SCISSORS = 3;
inline int get_result(const char& myChoice, const char& opponentChoice) {
if (myChoice == SCISSORS and opponentChoice == ROCK) { return 0; }
else if (myChoice == ROCK and opponentChoice == SCISSORS) { return 6; }
else if (myChoice == opponentChoice) { return 3; }
else if (myChoice > opponentChoice) { return 6; }
return 0;
}
int main() {
int score = 0;
auto is = std::ifstream("scores.txt");
std::string line;
if (is.is_open()) {
for (std::string line; std::getline(is, line); ) {
char other = line.at(0) + 1 - 'A'; // convert to 1,2,3;
char mine = line.at(2) + 1 - 'X'; // convert to 1,2,3
score += mine + get_result(mine, other);
}
}
else {
std::cerr << "Could not open file scores.txt" << std::endl;
return 1;
}
std::cout << "My score is " << score << std::endl;
return 0;
}

2501
2/out Normal file

File diff suppressed because it is too large Load Diff

2500
2/scores.txt Normal file

File diff suppressed because it is too large Load Diff

3
2/scores.txt__ Normal file
View File

@ -0,0 +1,3 @@
A Y
B X
C Z