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 maxSeedsperms = mutableListOf<IntList<Char>>()
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
var maxIterations = 0
val maxSeeds = mutableListOf<Int>()
val elements = mutableListOf<String>()
for (n in 1 until 1_000_000LIMIT) {
elements.clearif (sieve[n] > 0) continue
elements.clear()
var next = n.toString()
elements.add(next)
Line 2,456 ⟶ 2,472:
next = selfRefSeq(next)
if (next in elements) {
val countsize = elements.size
ifsieve[n] (count= > maxIterations) {size
if (n > 9) maxIterations = count{
maxSeedsval perms = permute(n.toString().cleartoList())
maxSeeds.addfor (nperm in perms) {
} if (perm[0] == '0') continue
else if (count = val k = maxIterationsperm.joinToString("").toInt() {
maxSeeds.add(n) sieve[k] = size
}
}
break
}
Line 2,470 ⟶ 2,487:
}
}
forval (nmaxIterations in= maxSeedssieve.max() {!!
for (n in 1 until LIMIT) {
if (sieve[n] < maxIterations) continue
println("$n -> Iterations = $maxIterations")
var next = n.toString()
9,482

edits