The third challenge – number spellings

Hello everyone … we hope you will enjoy working on the problem below from the UK and Kenya! Please post your comments below.

First think of an integer written out in letters e.g. sixteen.

Take the number of letters in this number e.g. 7

Write this number out e.g. seven

Take the number of letters in this number e.g. 5

Write this number out e.g. five

Take the number of letters in this number e.g. 4

Write this number out e.g. four

Now we have converged to the number four.

Try this process with other numbers and see what happens.

Is it the same in other languages?

You may want to use the power of Python programming language to explore this further. You can make the Trinket below fullscreen by clicking on the three parallel lines in the top left corner and then clicking fullscreen (and do this again to stop it being fullscreen).

9 thoughts on “The third challenge – number spellings”

  1. Tis a very hard problem and making the dictionnary go to every number would take weeks! But its still really fun to do

  2. pretty sure i’ve got a working code for english – looking forward to trying to replicate in latin and spanish ^_^

  3. All the numbers we tried (in English) seemed to converge towards 4, at which point there is an endless loop, because four as 4 letters

  4. Hello me and my friend tried this problem and where far from succeeding but we were on the right path.
    you can try to improve it.
    good luck.:)
    # You will need some sort of dictionary that maps the number
    # to the spelling of the number
    #
    #
    # A dictionary in python always has curly brackets {} and colons between
    # the “key” and “value” e.g. 1 is the key and “one” is the value in the
    # first item below
    #
    # Here is a dictionary to get you started

    numbers={1:”one”,2:”two”,3:”three”,4:”four”,5:”five”}

    # This asks the user to pick a number

    choice=int(input(“pick a number between 1 and 5”))

    # This prints the spelling of the number by looking it up in the
    # dictionary above

    spelling=numbers[choice]
    ByOne = [
    “zero”,
    “one”,
    “two”,
    “three”,
    “four”,
    “five”,
    “six”,
    “seven”,
    “eight”,
    “nine”,
    “ten”,
    “eleven”,
    “twelve”,
    “thirteen”,
    “fourteen”,
    “fifteen”,
    “sixteen”,
    “seventeen”,
    “eighteen”,
    “nineteen”
    ]

    ByTen = [
    “zero”,
    “ten”,
    “twenty”,
    “thirty”,
    “forty”,
    “fifty”,
    “sixty”,
    “seventy”,
    “eighty”,
    “ninety”
    ]

    zGroup = [
    “”,
    “thousand”,
    “million”,
    “billion”,
    “trillion”,
    “quadrillion”,
    “quintillion”,
    “sextillion”,
    “septillion”,
    “octillion”,
    “nonillion”,
    “decillion”,
    “undecillion”,
    “duodecillion”,
    “tredecillion”,
    “quattuordecillion”,
    “sexdecillion”,
    “septendecillion”,
    “octodecillion”,
    “novemdecillion”,
    “vigintillion”
    ]

    #strNum = input(“Please enter an integer:\n>> “)
    strNum=”1”

    # A recursive function to get the word equivalent for numbers under 1000.

    def subThousand(inputNum):
    num = int(inputNum)
    if 0 <= num <= 19:
    return ByOne[num]
    elif 20 <= num <= 99:
    if inputNum[-1] == "0":
    return ByTen[int(inputNum[0])]
    else:
    return ByTen[int(inputNum[0])] + "-" + ByOne[int(inputNum[1])]
    elif 100 <= num <= 999:
    rem = num % 100
    dig = num / 100
    if rem == 0:
    return ByOne[dig] + " hundred"
    else:
    return ByOne[dig] + " hundred and " + subThousand(str(rem))

    # A looping function to get the word equivalent for numbers above 1000
    # by splitting a number by the thousands, storing them in a list, and
    # calling subThousand on each of them, while appending the correct
    # "zero-group".

    def thousandUp(inputNum):
    num = int(inputNum)
    arrZero = splitByThousands(num)
    lenArr = len(arrZero) – 1
    resArr = []
    for z in arrZero[::-1]:
    wrd = subThousand(str(z)) + " "
    zap = zGroup[lenArr] + ", "
    if wrd == " ":
    break
    elif wrd == "zero ":
    wrd, zap = "", ""
    resArr.append(wrd + zap)
    lenArr -= 1
    res = "".join(resArr).strip()
    if res[-1] == ",": res = res[:-1]
    return res

    # Function to return a list created from splitting a number above 1000.

    def splitByThousands(inputNum):
    num = int(inputNum)
    arrThousands = []
    while num != 0:
    arrThousands.append(num % 1000)
    num /= 1000
    return arrThousands

    ### Last part is pretty much just the output.

    intNum = int(strNum)

    if intNum < 0:
    print ("Minus",)
    intNum *= -1
    strNum = strNum[1:]

    if intNum < 1000:
    spell= (subThousand(strNum))
    else:
    spell (thousandUp(strNum))
    print(spell)

    print(spelling)

    # This would print how many letters are in the spelling of the word
    # using a special command called len

    length=len(spelling)
    print(length)

    # Uncomment the lines below and work out what this while loop is doing

    #x=1
    #while x!=6:
    # print(x)
    # x=x+1

    # Challenge – can you write a program using ideas from above to
    # check many numbers for the converging numbers problem?

    # How about in different languages?

  5. I’ve tried with Latin and it ends with an infinite loop between 4 and 8. German , like English always finishes with 4. Fictional languages
    like Matoran or Galifreyan aren’t really applicable.

  6. Please choose either English or Spanish. spanish
    Por favor, elige un numero entre 1 y 99. 99
    noventaynueve que tiene 13 letras
    trece que tiene 5 letras
    cinco que tiene cinco letras, asi que esto continuara para siempre.
    – Spanish version!

Leave a Reply

Your email address will not be published. Required fields are marked *