-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay02.java
73 lines (68 loc) · 2.01 KB
/
Day02.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
//part 1
package org.thehuglio;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
public class Main {
public static void main(String[] args) {
File file = new File("data.txt");
Reader reader = new Reader(file);
System.out.println(reader.data);
int totalpoints = 0;
for (String s : reader.data) {
String[] a = s.split(" ");
totalpoints += score(a[0],a[1]);
}
System.out.println(totalpoints);
}
private static int score(String as, String bs) {
int ai = tonumber(as);
int bi = tonumber(bs);
if (ai == bi) { return bi + 3; }
else if (ai + 1 == bi || ai - 2 == bi) { return bi + 6;}
else {return bi;}
}
private static int tonumber(String s) {
if (s.equals("A") || s.equals("X")) { return 1;}
else if (s.equals("B") || s.equals("Y")) { return 2;}
else {return 3;}
}
}
//part 2
package org.thehuglio;
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("data.txt");
Reader reader = new Reader(file);
System.out.println(reader.data);
int totalpoints = 0;
for (String s : reader.data) {
String[] a = s.split(" ");
totalpoints += score(a[0],a[1]);
}
System.out.println(totalpoints);
}
private static int score(String as, String bs) {
int score;
if (bs.equals("Z")) {
score = tonumber(as) + 1;
if (score == 4) { score = 1;}
return score + 6;
}
else if (bs.equals("Y")) {
score = tonumber(as);
return score + 3;
} else {
score = tonumber(as) - 1;
if (score == 0) { score = 3;}
return score;
}
}
private static int tonumber(String s) {
if (s.equals("A")) { return 1;}
else if (s.equals("B")) { return 2;}
else {return 3;}
}
}