Summarize and say sequence: Difference between revisions

m (added highlighting to the sequences shown in the task's preamble, moved the "see" (link to OEIS) to the bottom of the task's preamble.)
Line 2,412:
19182716152413230000
]</lang></div>
 
=={{header|Julia}}==
<lang julia>const seen = Dict{Vector{Char}, Vector{Char}}()
int2chararray(n) = [s[1] for s in string.(split(string(n), ""))]
 
function findnextterm(prevterm)
counts = Dict()
reversed = Vector{Char}()
for c in prevterm
if !haskey(counts, c)
counts[c] = 0
end
counts[c] += 1
end
for c in sort(collect(keys(counts)))
if counts[c] > 0
push!(reversed, c)
for c in reverse(int2chararray(counts[c]))
push!(reversed, c)
end
end
end
reverse(reversed)
end
function findsequence(seedterm)
term = seedterm
sequence = Vector{Vector{Char}}()
while !(term in sequence)
push!(sequence, term)
if !haskey(seen, term)
nextterm = findnextterm(term)
seen[term] = nextterm
end
term = seen[term]
end
return sequence
end
 
function selfseq(maxseed)
maxseqlen = -1
maxsequences = Vector{Pair{Int, Vector{Char}}}()
for i in 1:maxseed
seq = findsequence(int2chararray(i))
seqlen = length(seq)
if seqlen > maxseqlen
maxsequences = [Pair(i, seq)]
maxseqlen = seqlen
elseif seqlen == maxseqlen
push!(maxsequences, Pair(i, seq))
end
end
println("\nThe longest sequence length is $maxseqlen.\n")
for p in maxsequences
println("\n Seed: $(p[1])")
for seq in p[2]
println(" ", join(seq, ""))
end
end
end
 
selfseq(1000000)
</lang> {{output}} <pre>
 
The longest sequence length is 21.
 
 
Seed: 9009
9009
2920
192210
19222110
19323110
1923123110
1923224110
191413323110
191433125110
19151423125110
19251413226110
1916151413325110
1916251423127110
191716151413326110
191726151423128110
19181716151413327110
19182716151423129110
29181716151413328110
19281716151423228110
19281716151413427110
19182716152413228110
 
Seed: 9090
9090
2920
192210
19222110
19323110
1923123110
1923224110
191413323110
191433125110
19151423125110
19251413226110
1916151413325110
1916251423127110
191716151413326110
191726151423128110
19181716151413327110
19182716151423129110
29181716151413328110
19281716151423228110
19281716151413427110
19182716152413228110
 
Seed: 9900
9900
2920
192210
19222110
19323110
1923123110
1923224110
191413323110
191433125110
19151423125110
19251413226110
1916151413325110
1916251423127110
191716151413326110
191726151423128110
19181716151413327110
19182716151423129110
29181716151413328110
19281716151423228110
19281716151413427110
19182716152413228110
</pre>
 
 
=={{header|Kotlin}}==
4,102

edits