-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
77 lines (66 loc) · 1.19 KB
/
index.ts
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
import run from 'aocrunner'
const parseInput = (rawInput: string): Round[] =>
rawInput
.trim()
.split('\n')
.map((v) => v.split(' ') as Round)
type Round = ['A' | 'B' | 'C', 'X' | 'Y' | 'Z']
const part1 = (rawInput: string) => {
const input = parseInput(rawInput)
const myMoves = {
X: { value: 1, A: 3, B: 0, C: 6 },
Y: { value: 2, A: 6, B: 3, C: 0 },
Z: { value: 3, A: 0, B: 6, C: 3 },
}
let score = 0
for (const round of input) {
score += myMoves[round[1]].value + myMoves[round[1]][round[0]]
}
return score.toString()
}
const part2 = (rawInput: string) => {
const input = parseInput(rawInput)
const theirMoves = {
A: { X: 3, Y: 1, Z: 2 },
B: { X: 1, Y: 2, Z: 3 },
C: { X: 2, Y: 3, Z: 1 },
}
const myMoveScores = {
X: 0,
Y: 3,
Z: 6,
}
let score = 0
for (const round of input) {
score += theirMoves[round[0]][round[1]] + myMoveScores[round[1]]
}
return score.toString()
}
run({
part1: {
tests: [
{
input: `
A Y
B X
C Z`,
expected: '15',
},
],
solution: part1,
},
part2: {
tests: [
{
input: `
A Y
B X
C Z`,
expected: '12',
},
],
solution: part2,
},
trimTestInputs: true,
// onlyTests: true,
})