Very minor day 2 refinement.
This commit is contained in:
parent
4bf79c0e89
commit
782d12c048
@ -50,21 +50,18 @@ fun main() {
|
||||
fun checkGood(i: List<Int>): Boolean {
|
||||
val dir = i[1] - i[0]
|
||||
return if (dir < 0) {
|
||||
!i.runningReduce { acc, elem -> if ((elem < acc) and (elem >= acc - 3)) elem else Int.MIN_VALUE }.contains(Int.MIN_VALUE)
|
||||
!i.runningReduce { acc, elem -> if ((elem < acc) and (elem >= acc - 3)) elem else Int.MIN_VALUE }
|
||||
.contains(Int.MIN_VALUE)
|
||||
} else if (dir > 0) {
|
||||
!i.runningReduce { acc, elem -> if ((elem > acc) && (elem <= acc + 3)) elem else Int.MAX_VALUE }.contains(Int.MAX_VALUE)
|
||||
!i.runningReduce { acc, elem -> if ((elem > acc) && (elem <= acc + 3)) elem else Int.MAX_VALUE }
|
||||
.contains(Int.MAX_VALUE)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun part1(input: List<String>): Int {
|
||||
val ilist = input.map { it.splitInts() }
|
||||
var sum = 0
|
||||
for (i in ilist) {
|
||||
if (checkGood(i)) sum++
|
||||
}
|
||||
return sum
|
||||
return input.map { it.splitInts() }.count(::checkGood)
|
||||
}
|
||||
|
||||
fun part2(input: List<String>): Int {
|
||||
|
Loading…
Reference in New Issue
Block a user