Take all the Roman numbers (using the modern standard subtractive notation in which IV = 4, IX = 9, XL = 40, XLIX = 49, XC = 90, etc.) from I to M (1 to 1000)...
1. Which number has the most Roman letters?
2. If you group them by the number of Roman letters, which group has the most members?
3. How many numbers start with C?
4. There is something interesting about the groupings in #2. What is it?
1. The longest has 12 letters: DCCCLXXXVIII = 888
2. The group with the most members is length 6:
1 2 3 4 5 6 7 8 9 10 11 12
7 24 62 123 180 208 180 123 62 24 6 1
3. There are 500 beginning with C: the 100's, 200's, 300's, 400's and 900's.
4. The pattern is symmetrical except for the 7 that have length 1 vs the 6 of length 11 and 1 of length 12.
CLS
DIM lCt(20)
FOR n = 1 TO 1000
q = n \ 1000: r = n MOD 1000
r$ = STRING$(q, "M")
n2 = r
q = n2 \ 100: r = n2 MOD 100
SELECT CASE q
CASE 9: r$ = r$ + "CM"
CASE 5 TO 8: r$ = r$ + "D" + STRING$(q - 5, "C")
CASE 4: r$ = r$ + "CD"
CASE 0 TO 3: r$ = r$ + STRING$(q, "C")
END SELECT
n2 = r
q = n2 \ 10: r = n2 MOD 10
SELECT CASE q
CASE 9: r$ = r$ + "XC"
CASE 5 TO 8: r$ = r$ + "L" + STRING$(q - 5, "X")
CASE 4: r$ = r$ + "XL"
CASE 0 TO 3: r$ = r$ + STRING$(q, "X")
END SELECT
n2 = r
q = n2
SELECT CASE q
CASE 9: r$ = r$ + "IX"
CASE 5 TO 8: r$ = r$ + "V" + STRING$(q - 5, "I")
CASE 4: r$ = r$ + "IV"
CASE 0 TO 3: r$ = r$ + STRING$(q, "I")
END SELECT
IF LEN(r$) > longestSize THEN
longestSize = LEN(r$): longest$ = r$: longestn = n
END IF
lCt(LEN(r$)) = lCt(LEN(r$)) + 1
IF LEFT$(r$, 1) = "C" THEN cCt = cCt + 1
NEXT
PRINT
PRINT longestSize, longest$, longestn
FOR i = 1 TO 12
PRINT lCt(i);
NEXT
PRINT
PRINT cCt
|
Posted by Charlie
on 2009-05-17 15:53:13 |