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

Content added Content deleted
Line 325: Line 325:
firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)
firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)


function firstletter(n)
function inOEIS363659(n)
lastchar = n % 1000 > 0 ? lastcache[n % 1000] : n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd'
n == 0 && return 'z'
n += 1
j = 0
j = 0
while n > 0
while n > 0
n, j = divrem(n, 1000)
n, j = divrem(n, 1000)
end
end
return firstcache[j]
return firstcache[j] == lastchar
end
end

function lastletter(n)
return n % 1000 == 0 ? (n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd') :
lastcache[n % 1000]
end

inOEIS363659(n) = lastletter(n) == firstletter(n + 1)


""" test the sequence """
""" test the sequence """