-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday_2.cpp
73 lines (55 loc) · 1.81 KB
/
day_2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "day"
//---------------------------------------------------------------------------//
namespace aoc::YEAR::DAY {
//---------------------------------------------------------------------------//
// Test data
std::string testinput =
R"(A Y
B X
C Z)";
//---------------------------------------------------------------------------//
inline std::istream& test_input() {
static std::stringstream ss;
return ss = std::stringstream ( testinput );;
}
//---------------------------------------------------------------------------//
void Task_1 ( std::istream& puzzle_input ) {
auto ans = 0ull;
std::string line;
//aoc::test_enable();
std::istream& file = is_test_enabled() ? test_input() : puzzle_input;
auto score = [] ( auto a, auto b ) {
return ( ( 4 + b - a ) % 3 ) * 3 + b + 1;
};
while ( getline ( file, line ) ) {
char a = line[0] - 'A', b = line[2] - 'X';
ans += score ( a, b );
}
/*
0 - rock
1 - paper
2 - scissor
(4 + 2 - 0) % 3 = 0 lost
(4 + 0 - 0) % 3 = 1 remis
(4 + 1 - 0) % 3 = 2 win
*/
OUT ( ans );
}
//---------------------------------------------------------------------------//
void Task_2 ( std::istream& puzzle_input ) {
auto ans = 0ull;
//aoc::test_enable();
std::istream& file = aoc::is_test_enabled() ? test_input() : puzzle_input;
auto score = [] ( auto a, auto b ) {
return ( ( 4 + b - a ) % 3 ) * 3 + b + 1;
};
std::string line;
while ( getline ( file, line ) ) {
char a = line[0] - 'A', b = line[2] - 'X';
ans += score ( a, ( 2 + a + b ) % 3 );
}
OUT ( ans );
}
//---------------------------------------------------------------------------//
}
//---------------------------------------------------------------------------//