-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay05DoesntHeHaveInternElvesForThis.kt
More file actions
32 lines (28 loc) · 1.1 KB
/
Day05DoesntHeHaveInternElvesForThis.kt
File metadata and controls
32 lines (28 loc) · 1.1 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
package adventofcode.year2015
import adventofcode.Puzzle
import adventofcode.PuzzleInput
class Day05DoesntHeHaveInternElvesForThis(
customInput: PuzzleInput? = null,
) : Puzzle(customInput) {
override val name = "Doesn't He Have Intern-Elves For This?"
override fun partOne() =
input
.lines()
.filter { str ->
str
.groupingBy { it }
.eachCount()
.filter { setOf('a', 'e', 'i', 'o', 'u').contains(it.key) }
.values
.sum() >= 3
}.filter { str -> ('a'..'z').any { str.contains(it.toString().repeat(2)) } }
.filter { str -> setOf("ab", "cd", "pq", "xy").none { str.contains(it) } }
.size
override fun partTwo() =
input
.lines()
.filter { str ->
('a'..'z').flatMap { a -> ('a'..'z').map { b -> "$a$b" } }.any { """$it\w*$it""".toRegex().containsMatchIn(str) }
}.filter { str -> ('a'..'z').any { """$it\w$it""".toRegex().containsMatchIn(str) } }
.size
}