-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoC2.java
82 lines (70 loc) · 3.16 KB
/
AoC2.java
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
74
75
76
77
78
79
80
81
82
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
public class AoC2 {
public static void main(String[] args) {
String fileName = "AoC2";
try {
String[] rows = Arrays.stream(Files.readString(Paths.get(fileName))
.split("\n"))
.toArray(String[]::new);
String[] enemyMoves = Arrays.stream(rows)
.map(s -> s.split(" ")[0])
.toArray(String[]::new);
String[] myMoves = Arrays.stream(rows)
.map(s -> s.split(" ")[1])
.toArray(String[]::new);
long points = 0;
for (int i = 0; i < rows.length; i++) {
switch (enemyMoves[i]) {
}
if (enemyMoves[i].equals("A") && myMoves[i].equals("X")) {
points += 1 + 3;
} else if (enemyMoves[i].equals("A") && myMoves[i].equals("Y")) {
points += 2 + 6;
} else if (enemyMoves[i].equals("A") && myMoves[i].equals("Z")) {
points += 3;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("X")) {
points += 1;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("Y")) {
points += 2 + 3;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("Z")) {
points += 3 + 6;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("X")) {
points += 1 + 6;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("Y")) {
points += 2;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("Z")) {
points += 3 + 3;
}
}
System.out.println(points);
points = 0;
for (int i = 0; i < rows.length; i++) {
if (enemyMoves[i].equals("A") && myMoves[i].equals("X")) {
points += 3;
} else if (enemyMoves[i].equals("A") && myMoves[i].equals("Y")) {
points += 1 + 3;
} else if (enemyMoves[i].equals("A") && myMoves[i].equals("Z")) {
points += 2 + 6;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("X")) {
points += 1;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("Y")) {
points += 2 + 3;
} else if (enemyMoves[i].equals("B") && myMoves[i].equals("Z")) {
points += 3 + 6;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("X")) {
points += 2;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("Y")) {
points += 3 + 3;
} else if (enemyMoves[i].equals("C") && myMoves[i].equals("Z")) {
points += 1 + 6;
}
}
System.out.println(points);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}