Numbers k such that the last letter of k is the same as the first letter of k+1: Difference between revisions
Numbers k such that the last letter of k is the same as the first letter of k+1 (view source)
Revision as of 18:47, 1 July 2023
, 11 months ago→{{header|Julia}}
m (→{{header|Julia}}: minor speedups) |
|||
Line 325:
firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)
function firstletter(n)
n == 0 && return 'z'
j = 0
while n > 0
n, j = divrem(n, 1000)
end
return
end
function lastletter(n)
return n % 1000 == 0 ? (n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd') :
lastcache[
end
|