All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Only one below 5000 (Posted on 2016-03-11) Difficulty: 3 of 5
If you write out the numbers from 1 to 5000 in American English (e.g., THREE THOUSAND EIGHT HUNDRED SEVENTY-THREE), it turns out that only one of them has a unique number of characters.

Which is it?

Spaces and hyphens count as characters.

See The Solution Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 1 of 4
DECLARE SUB EnterNum ()
DECLARE SUB ProcPiece (piece$, MajorPower!)
DATA one,two,three,four,five,six,seven,eight,nine
DATA ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen
DATA eighteen,nineteen
DATA twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety
DATA thousand,million,billion,trillion,quadrillion,quintillion,sextillion
DIM SHARED unit$(19), ten$(10), major$(7)

DIM lenct(60), first$(60)

FOR i = 1 TO 19
  READ unit$(i)
NEXT
FOR i = 2 TO 9
  READ ten$(i)
NEXT
FOR i = 1 TO 7
  READ major$(i)
NEXT
DIM SHARED name$, num$
FOR n0 = 1 TO 5000
        num$ = LTRIM$(STR$(n0))
        IF num$ = "0" THEN
                name$ = "zero"
        ELSE
                name$ = ""
                MajorPower = 0
                DO
                        l = LEN(num$): IF l > 3 THEN l = 3
                        piece$ = RIGHT$(num$, l)
                        num$ = LEFT$(num$, LEN(num$) - l)
                        CALL ProcPiece(piece$, MajorPower)
                        MajorPower = MajorPower + 1
                LOOP WHILE LEN(num$) > 0
        END IF
        name$ = LTRIM$(RTRIM$(name$))
       ' PRINT name$, LEN(name$)
        lenct(LEN(name$)) = lenct(LEN(name$)) + 1
        IF lenct(LEN(name$)) = 1 THEN first$(LEN(name$)) = name$
        ' DO: a$ = INKEY$: LOOP WHILE a$ = ""
NEXT n0

FOR i = 1 TO 60
    IF lenct(i) = 1 THEN PRINT : PRINT : PRINT i; first$(i)
NEXT

SUB ProcPiece (piece$, MajorPower)
  piece = VAL(piece$)
  n$ = ""
  IF piece > 99 THEN
    n$ = unit$(piece \ 100) + " hundred "
    piece = piece MOD 100
  END IF
  IF piece > 19 THEN
    n$ = n$ + ten$(piece \ 10)
    piece = piece MOD 10
    IF piece > 0 THEN n$ = n$ + "-":  ELSE n$ = n$ + " "
  END IF
  IF piece > 0 THEN n$ = n$ + unit$(piece) + " "
  IF n$ > "" THEN name$ = n$ + major$(MajorPower) + " " + name$
END SUB

Finds "three thousand" as the only 14-character number name in the specified range, and verifies that this is the only such unique length.

  Posted by Charlie on 2016-03-11 15:28:34
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information