Day 22 part 1
This commit is contained in:
parent
89445f1df9
commit
04350e219a
2 changed files with 2173 additions and 0 deletions
17
2024/src/main/kotlin/day22.kt
Normal file
17
2024/src/main/kotlin/day22.kt
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
fun main() {
|
||||||
|
val part1 = readInput("day22.txt")
|
||||||
|
.map { it.toLong() }
|
||||||
|
.map { randomSequence(it).elementAt(2000) }
|
||||||
|
.sum()
|
||||||
|
|
||||||
|
println("Part 1: $part1")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun prune(x: Long) = x % 16777216
|
||||||
|
fun mix(a: Long, b: Long) = a xor b
|
||||||
|
|
||||||
|
fun randomSequence(start: Long) = generateSequence(start) { current ->
|
||||||
|
val a = prune(mix(current, current * 64))
|
||||||
|
val b = prune(mix(a, a / 32))
|
||||||
|
prune(mix(b, b * 2048))
|
||||||
|
}
|
2156
2024/src/main/resources/day22.txt
Normal file
2156
2024/src/main/resources/day22.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue