Eve said to me that she had in mind an even three-figure number that was divisible by 3.
She also told me that she had spelled out the number in words and that she had counted the number of letters used.
Knowing the number of letters would enable me to work out her number, she said.
Oddy said to me that he had in mind an odd three-figure number divisible by 3.
He told me that he, too, had written the number in words and that he had counted the number of letters used. He said that knowing the number of letters would again enable me to work out his number.
Given that their numbers had no digit in common - find their numbers.
Source: Enigma/New Scientist
DECLARE FUNCTION verify! (s1$, s2$)
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)
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$
open "clevsple.txt" for output as #2
FOR n = 102 TO 1000 step 6
' IF n / 10 = INT(n / 10) THEN PRINT n;
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$)
DO
i = verify(name$, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
IF i THEN name$ = LEFT$(name$, i - 1) + MID$(name$, i + 1)
LOOP UNTIL i = 0
PRINT#2, using "### ###"; len(name$);n
NEXT
close 2
open "clevsplo.txt" for output as #2
FOR n = 105 TO 1000 step 6
' IF n / 10 = INT(n / 10) THEN PRINT n;
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$)
DO
i = verify(name$, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
IF i THEN name$ = LEFT$(name$, i - 1) + MID$(name$, i + 1)
LOOP UNTIL i = 0
PRINT#2, using "### ###"; len(name$);n
NEXT
close 2
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
creates two files, one containing even 3-digit numbers divisible by 3 and the other odd.
The files contain the count of the numbers of letters in the spelled-out number words, along with each number.
The non-unique letter counts were eliminated, and what's left of the two files is:
10 600
11 900
12 300
24 378
13 201
The only odd possibility has a zero, so the only even solution that works, given no digit in common, is the one without the zero.
Their numbers are 378 and 201.
|
Posted by Charlie
on 2013-11-23 15:22:55 |