45 lines
1.1 KiB
Kotlin
45 lines
1.1 KiB
Kotlin
|
import java.io.File
|
||
|
|
||
|
fun generateANext(current: Long): Long {
|
||
|
return (current * 16807) % 2147483647
|
||
|
}
|
||
|
|
||
|
fun generateBNext(current: Long): Long {
|
||
|
return (current * 48271) % 2147483647
|
||
|
}
|
||
|
|
||
|
fun generateACertain(current: Long): Long {
|
||
|
var toReturn = current
|
||
|
do {
|
||
|
toReturn = generateANext(toReturn)
|
||
|
} while (toReturn % 4L != 0L)
|
||
|
return toReturn
|
||
|
}
|
||
|
|
||
|
fun generateBCertain(current: Long): Long {
|
||
|
var toReturn = current
|
||
|
do {
|
||
|
toReturn = generateBNext(toReturn)
|
||
|
} while (toReturn % 8L != 0L)
|
||
|
return toReturn
|
||
|
}
|
||
|
|
||
|
fun main(args: Array<String>){
|
||
|
val initialAValue = 873L
|
||
|
val initialBValue = 583L
|
||
|
var i = 0
|
||
|
var count = 0
|
||
|
var currentA = initialAValue
|
||
|
var currentB = initialBValue
|
||
|
while(i < 5000000) {
|
||
|
currentA = generateACertain(currentA)
|
||
|
currentB = generateBCertain(currentB)
|
||
|
// println(currentA.toString(2))
|
||
|
// println(currentB.toString(2))
|
||
|
val firstA = currentA.toShort()
|
||
|
val firstB = currentB.toShort()
|
||
|
if(firstA == firstB) count++
|
||
|
i++
|
||
|
}
|
||
|
println(count)
|
||
|
}
|