-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay02.java
More file actions
62 lines (57 loc) · 1.33 KB
/
Day02.java
File metadata and controls
62 lines (57 loc) · 1.33 KB
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
import java.util.List;
class Day02{
public static int p1(List<String> input){
int totalScore=0;
for(String round: input){
totalScore+=ScoreRound(Decode1(round));
}
return totalScore;
}
public static int p2(List<String> input){
int totalScore=0;
for(String round: input){
totalScore+=ScoreRound(Decode2(round));
}
return totalScore;
}
public static String Decode1(String round)
{
return round
.replace('X','R')
.replace('Y','P')
.replace('Z','S')
.replace('A','R')
.replace('B','P')
.replace('C','S');
}
public static String Decode2(String round)
{
switch (round) {
case "A X": return "R S";
case "A Y": return "R R";
case "A Z": return "R P";
case "B X": return "P R";
case "B Y": return "P P";
case "B Z": return "P S";
case "C X": return "S P";
case "C Y": return "S S";
case "C Z": return "S R";
}
return "";
}
public static int ScoreRound(String round)
{
switch (round) {
case "R R": return 1+3;
case "R P": return 2+6;
case "R S": return 3+0;
case "P R": return 1+0;
case "P P": return 2+3;
case "P S": return 3+6;
case "S R": return 1+6;
case "S P": return 2+0;
case "S S": return 3+3;
}
return 0;
}
}