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

m
Line 553:
from num2words import num2words
 
spelledcachesspelledcache = [num2words(n) for n in range(1000)]
firstcache, lastcache = [s[0] for s in spelledcache], [s[-1] for s in spelledcache]
 
def nonzerogroupingsfirstletter(n):
if n == 0:
""" Return groupings of a thousand if not 0, least significant first. The word
return groups'z'
representation of integers is via nonzero groups of three consecutive digits
groupsj = []0
except for numbers > 1000 which are divisible by 1000 """
groups = []
while n > 0:
n, rj = divmod(n, 1000)
return if r > 0:firstcache[j]
groups.append(r)
return groups
 
def firstletter(n):
return spelledcache[nonzerogroupings(n)[-1]][0]
 
def lastletter(n):
return lastcache[n % 1000] if n % 1000 > 0 else 'o' if n == 0: else \
return 'o' if n == 0 else 'n' if n % 1_000_000 == 0 else 'd'
return spelledcache[nonzerogroupings(n)[0]][-1]
 
def qualifies(n):
4,107

edits