nbdelettres.py

Created by schraf

Created on September 16, 2018

526 Bytes

On part d’un nombre, par exemple 235, que l’on écrit en français chiffre par chiffre, ce qui donne “deuxtroiscinq”. Ce mot fait 13 lettres qui, transformé en français, fait “untrois”. Ce mot lui-même fait 7 lettres (“sept”) d’où 4 lettres (“quatre”) puis 6 lettres (“six”) puis “trois”, “cinq” et à nouveau “quatre”.

On s’arrête lorsque l’on retombe sur un nombre que l’on a déjà obtenu. Donnons un autre exemple :

>> nb(171)
unseptun
huit
quatre
six
trois
cinq
'quatre'


chiffres = ["zero","un","deux","trois","quatre","cinq","six","sept","huit","neuf"]

def suiv(n):
  return "".join(map(code, str(n)))

def code(n):
  return chiffres[int(n)]

def nb(n):
  vus = []
  s=suiv(n)
  while s not in vus:
    print(s)
    vus.append(s)    
    s=suiv(len(s))
  return s
  
# Version 2

def suiv2(n):
  return "".join(map(lambda n:chiffres[int(n)], str(n)))

def nb2(n):
  vus = []
  s=suiv2(n)
  while s not in vus:
    print(s)
    vus.append(s)    
    s=suiv2(len(s))
  return s

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.