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

Home > Numbers > Sequences
Spelled Out Settlement (Posted on 2010-08-24) Difficulty: 2 of 5
All the positive integers starting with 1 are considered in ascending order of magnitude and spelled out in conformity with the American system, but disregarding hyphens, spaces, commas and, the word "and" - resulting in this infinite string:

onetwothreefourfivesixseveneightnineteneleventwelve
thirteenfourteenfifteensixteenseventeeneighteennineteen
twentytwentyonetwentytwotwentythreetwentyfour...........

Determine the 2010th letter in the above pattern. What is the 20100th letter in the above pattern?

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 3 of 6 |

DECLARE SUB ProcPiece (piece$, MajorPower#)
DECLARE FUNCTION verify# (s1$, s2$)
DEFDBL A-Z
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)
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$
        CLS
        goal = 2010
        FOR n = 1 TO goal
          num$ = LTRIM$(RTRIM$(STR$(n)))

          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$ = UCASE$(name$)
          ' PRINT name$;
          DO
            i = verify(name$, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            IF i THEN name$ = LEFT$(name$, i - 1) + MID$(name$, i + 1)
          LOOP UNTIL i = 0
          PRINT "  "; name$
          totlen = totlen + LEN(name$)
          IF totlen >= goal THEN
            p = goal - (totlen - LEN(name$))
            PRINT p; name$; " "; MID$(name$, p, 1)
            END
          END IF
        NEXT

SUB EnterNum
 DO
  INPUT "Enter number:", num$
  num$ = LTRIM$(RTRIM$(num$))
  num = 1
  FOR i = 1 TO LEN(num$)
    IF INSTR("0123456789", MID$(num$, i, 1)) = 0 THEN num = 0: EXIT FOR
  NEXT
  IF num = 0 THEN PRINT "Must be numeric."
 LOOP WHILE num = 0
END SUB

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

FUNCTION verify (s1$, s2$)
  FOR i = 1 TO LEN(s1$)
    IF INSTR(s2$, MID$(s1$, i, 1)) = 0 THEN verify = i: EXIT FUNCTION
  NEXT
  verify = 0
END FUNCTION

finds, for the 2010 case

15 ONEHUNDREDSIXTYFOUR Y

meaning that the 15th letter, Y, of ONEHUNDREDSIXTYFOUR, is the 2010th letter of the sequence.

When 20100 is used in place of 2010, the result is

 18 ONETHOUSANDEIGHTYFIVE F
 
indicating that the 18th letter, F, of ONETHOUSANDEIGHTYFIVE, is the 20,100th letter of the sequence.

Most of the code is from a pre-existing number-to-text program.


  Posted by Charlie on 2010-08-24 13:03:37
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 (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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