-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay16AuntSue.kt
More file actions
98 lines (90 loc) · 4.28 KB
/
Day16AuntSue.kt
File metadata and controls
98 lines (90 loc) · 4.28 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package adventofcode.year2015
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day16AuntSue(
customInput: PuzzleInput? = null,
) : Puzzle(customInput) {
private val aunts by lazy {
input
.lines()
.map { aunt ->
val id =
aunt
.split(": ")
.first()
.split(" ")
.last()
.toInt()
val fields = aunt.substring(4 + id.toString().length + 2).split(", ").map { it.split(": ") }
val children = fields.find { it.first() == "children" }?.last()?.toInt()
val cats = fields.find { it.first() == "cats" }?.last()?.toInt()
val samoyeds = fields.find { it.first() == "samoyeds" }?.last()?.toInt()
val pomeranians = fields.find { it.first() == "pomeranians" }?.last()?.toInt()
val akitas = fields.find { it.first() == "akitas" }?.last()?.toInt()
val vizslas = fields.find { it.first() == "vizslas" }?.last()?.toInt()
val goldfish = fields.find { it.first() == "goldfish" }?.last()?.toInt()
val trees = fields.find { it.first() == "trees" }?.last()?.toInt()
val cars = fields.find { it.first() == "cars" }?.last()?.toInt()
val perfumes = fields.find { it.first() == "perfumes" }?.last()?.toInt()
AuntSue(id, children, cats, samoyeds, pomeranians, akitas, vizslas, goldfish, trees, cars, perfumes)
}
}
override fun partOne() =
aunts
.asSequence()
.filter { it.children == null || it.children == TICKER_TAPE_SUE.children!! }
.filter { it.cats == null || it.cats == TICKER_TAPE_SUE.cats!! }
.filter { it.samoyeds == null || it.samoyeds == TICKER_TAPE_SUE.samoyeds!! }
.filter { it.pomeranians == null || it.pomeranians == TICKER_TAPE_SUE.pomeranians!! }
.filter { it.akitas == null || it.akitas == TICKER_TAPE_SUE.akitas!! }
.filter { it.vizslas == null || it.vizslas == TICKER_TAPE_SUE.vizslas!! }
.filter { it.goldfish == null || it.goldfish == TICKER_TAPE_SUE.goldfish!! }
.filter { it.trees == null || it.trees == TICKER_TAPE_SUE.trees!! }
.filter { it.cars == null || it.cars == TICKER_TAPE_SUE.cars!! }
.filter { it.perfumes == null || it.perfumes == TICKER_TAPE_SUE.perfumes!! }
.first()
.id!!
override fun partTwo() =
aunts
.asSequence()
.filter { it.children == null || it.children == TICKER_TAPE_SUE.children!! }
.filter { it.cats == null || it.cats > TICKER_TAPE_SUE.cats!! }
.filter { it.samoyeds == null || it.samoyeds == TICKER_TAPE_SUE.samoyeds!! }
.filter { it.pomeranians == null || it.pomeranians < TICKER_TAPE_SUE.pomeranians!! }
.filter { it.akitas == null || it.akitas == TICKER_TAPE_SUE.akitas!! }
.filter { it.vizslas == null || it.vizslas == TICKER_TAPE_SUE.vizslas!! }
.filter { it.goldfish == null || it.goldfish < TICKER_TAPE_SUE.goldfish!! }
.filter { it.trees == null || it.trees > TICKER_TAPE_SUE.trees!! }
.filter { it.cars == null || it.cars == TICKER_TAPE_SUE.cars!! }
.filter { it.perfumes == null || it.perfumes == TICKER_TAPE_SUE.perfumes!! }
.first()
.id!!
companion object {
private val TICKER_TAPE_SUE =
AuntSue(
children = 3,
cats = 7,
samoyeds = 2,
pomeranians = 3,
akitas = 0,
vizslas = 0,
goldfish = 5,
trees = 3,
cars = 2,
perfumes = 1,
)
private data class AuntSue(
val id: Int? = null,
val children: Int? = null,
val cats: Int? = null,
val samoyeds: Int? = null,
val pomeranians: Int? = null,
val akitas: Int? = null,
val vizslas: Int? = null,
val goldfish: Int? = null,
val trees: Int? = null,
val cars: Int? = null,
val perfumes: Int? = null,
)
}
}