fun solvePart1(pairs: Int = 40_000_000): Int = generator(startA, 16807) .zip(generator(startB, 48271)) .take(pairs) .count { it.first == it.second } fun solvePart2(pairs: Int = 5_000_000): Int = generator(startA, 16807).filter { it % 4 == 0 } .zip(generator(startB, 48271).filter { it % 8 == 0 }) .take(pairs) .count { it.first == it.second } private fun generator(start: Long, factor: Long): Sequence = generateSequence((start * factor) % 2147483647) { past -> (past * factor) % 2147483647 }.map { it.toShort() }