Jump to content

Numbers k such that the last letter of k is the same as the first letter of k+1: Difference between revisions

m
m (→‎{{header|Julia}}: minor speedups)
Line 325:
firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)
 
function firstletter(n)
""" Return first and last groupings of 3 digits, least significant first. """
n == 0 && return 'z'
function firstlastgroupings(n)
i = n % 1000
j = 0
while n > 0
n, j = divrem(n, 1000)
end
return i, firstcache[j]
end
 
firstletter(n) = n == 0 ? 'z' : firstcache[firstlastgroupings(n)[end]]
 
function lastletter(n)
return n % 1000 == 0 ? (n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd') :
lastcache[firstlastgroupings(n)[begin] % 1000]
end
 
4,107

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.