-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProblem2.js
More file actions
42 lines (38 loc) · 1.08 KB
/
Problem2.js
File metadata and controls
42 lines (38 loc) · 1.08 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
let a = document.getElementsByTagName("pre")[0].innerHTML;
// Part 1
a.trim()
.split("\n")
.map(x => x.split(" "))
.map(a => {
let score = a[1] == "X" ? 1 : a[1] == "Y" ? 2 : 3;
if(
(a[0] == "A" && a[1] == "X") ||
(a[0] == "B" && a[1] == "Y") ||
(a[0] == "C" && a[1] == "Z"))
{score+=3;}
else if(
(a[0] == "A" && a[1] == "Y") ||
(a[0] == "B" && a[1] == "Z") ||
(a[0] == "C" && a[1] == "X"))
{score+=6;}
return score;
})
.reduce((acc , x) => acc+x , 0);
// Part 2
a.trim()
.split("\n")
.map(x => x.split(" "))
.map(a => {
let score = a[1] == "X" ? 0 : a[1] == "Y" ? 3 : 6;
if(a[1] == "X"){
score = score + (a[0] == "A" ? 3 : a[0] == "B" ? 1 : 2);
}
if(a[1] == "Y"){
score = score + (a[0] == "A" ? 1 : a[0] == "B" ? 2 : 3);
}
if(a[1] == "Z"){
score = score + (a[0] == "A" ? 2 : a[0] == "B" ? 3 : 1);
}
return score;
})
.reduce((acc , x) => acc+x , 0);