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

m
→‎{{header|Julia}}: minor speedups
(Added FreeBasic)
m (→‎{{header|Julia}}: minor speedups)
Line 322:
<syntaxhighlight lang="julia">using Formatting, SpelledOut, UnicodePlots
 
spelledcache = [spelled_out(n, lang = :en) for n in 01:999]
firstcache, lastcache = map(first, spelledcache), map(last, spelledcache)
 
""" Return groupingsfirst ofand alast thousandgroupings ifof not3 0digits, least significant first. The word"""
function firstlastgroupings(n)
representation of integers is via nonzero groups of three consecutive digits
except for numbers > 1000i which= aren divisible by% 1000 """
groupsj = []0
function nonzerogroupings(n)
groups = []
while n > 0
n, rj = divrem(n, 1000)
r > 0 && push!(groups, r)
end
return groupsi, j
end
 
firstletter(n) = spelledcachen == 0 ? 'z' : firstcache[nonzerogroupingsfirstlastgroupings(n)[end] + 1][begin]
 
function lastletter(n)
return n % 1000 == 0 ? (n == 0 ? 'o' : n % 1_000_000 == 0 ? 'n' : 'd') :
spelledcachelastcache[nonzerogroupingsfirstlastgroupings(n)[begin] + 1][end]
end
 
4,105

edits