Summarize and say sequence: Difference between revisions
→{{header|Kotlin}}: Replaced existing code with faster version
(→{{header|REXX}}: used the exact high limit, added/changed comments and whitespace, changed output, optimized generator loop.) |
(→{{header|Kotlin}}: Replaced existing code with faster version) |
||
Line 2,432:
=={{header|Kotlin}}==
<lang scala>// version 1.1.2
const val LIMIT = 1_000_000
val sb = StringBuilder()
Line 2,443 ⟶ 2,445:
}
return sb.toString()
}
fun permute(input: List<Char>): List<List<Char>> {
if (input.size == 1) return listOf(input)
val toInsert = input[0]
for (perm in permute(input.drop(1))) {
for (i in 0..perm.size) {
val newPerm = perm.toMutableList()
newPerm.add(i, toInsert)
perms.add(newPerm)
}
}
return perms
}
fun main(args: Array<String>) {
val sieve = IntArray(LIMIT) // all zero by default
▲ val maxSeeds = mutableListOf<Int>()
val elements = mutableListOf<String>()
for (n in 1 until
elements.clear()
var next = n.toString()
elements.add(next)
Line 2,456 ⟶ 2,472:
next = selfRefSeq(next)
if (next in elements) {
val
if (n > 9)
}
}
break
}
Line 2,470 ⟶ 2,487:
}
}
for (n in 1 until LIMIT) {
if (sieve[n] < maxIterations) continue
println("$n -> Iterations = $maxIterations")
var next = n.toString()
|