generated from kotlin-hands-on/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path02.kt
55 lines (41 loc) · 1.33 KB
/
02.kt
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
fun main() {
fun part1(input: List<String>): Int {
var points = mapOf('X' to 1, 'Y' to 2, 'Z' to 3)
var draw = mapOf('A' to 'X', 'B' to 'Y', 'C' to 'Z')
var loss = mapOf('C' to 'Y', 'A' to 'Z', 'B' to 'X')
var score = 0;
for(element in input){
var li = element.split("\\s".toRegex()).toTypedArray()
if(li[1][0] == draw[li[0][0]]){
score += 3
}else if(li[1][0] != loss[li[0][0]]){
score+=6
}
score+= points[li[1][0]]!!
}
return score
}
fun part2(input: List<String>): Int {
var draw = mapOf('A' to 1, 'B' to 2, 'C' to 3)
var loss = mapOf('C' to 2, 'A' to 3, 'B' to 1)
var win = mapOf('C' to 1, 'A' to 2, 'B' to 3)
var score = 0;
for(element in input){
var li = element.split("\\s".toRegex()).toTypedArray()
if(li[1][0] == 'X'){
score+=0
score+=loss[li[0][0]]!!
}else if(li[1][0] == 'Y'){
score+=3
score+=draw[li[0][0]]!!
}else{
score+=6
score+=win[li[0][0]]!!
}
}
return score
}
val input = readInput("Day02")
println(part1(input))
println(part2(input))
}