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?
I used the following Basic code to compile the list by length and show all that start with C.
DECLARE SUB RomanNumerals (num$)
DECLARE SUB RomanReplace (num$, Frm$, R$)
DECLARE FUNCTION Romans$ (n%)
CLS 0
OPEN ".output.txt" FOR OUTPUT AS #1
PRINT #1, "Length", "Decimal Value", "Roman Numeral"
DIM lngcnts%(1 TO 12)
FOR lng% = 1 TO 12
lngcnts%(lng%) = 0
FOR num% = 1 TO 1000
rmn$ = Romans$(num%)
IF LEN(rmn$) = lng% THEN
PRINT #1, lng%, num%, rmn$
lngcnts%(lng%) = lngcnts%(lng%) + 1
END IF
NEXT num%
NEXT lng%
PRINT #1, ""
PRINT #1, "Length", "Number of this length"
FOR i% = 1 TO 12
PRINT #1, i%, lngcnts%(i%)
NEXT i%
PRINT #1, ""
PRINT #1, "Values starting with C"
cnt% = 0
FOR num% = 1 TO 1000
rmn$ = Romans$(num%)
IF MID$(rmn$, 1, 1) = "C" THEN
cnt% = cnt% + 1
PRINT #1, num%, rmn$
END IF
NEXT num%
PRINT #1, "There are " + STR$(cnt%) + " numbers starting with C"
CLOSE #1
SUB RomanNumerals (num$)
x% = VAL(num$): num$ = "": IF x% < 1 THEN EXIT SUB
DIM Ones(10) AS STRING
Ones(0) = "": Ones(1) = "I": Ones(2) = "II"
Ones(3) = "III": Ones(4) = "IV": Ones(5) = "V"
Ones(6) = "VI": Ones(7) = "VII": Ones(8) = "VIII": Ones(9) = "IX"
Tens$ = "XLC": Hund$ = "CDM"
num$ = Ones(x% MOD 10)
n$ = Ones((x% 10) MOD 10): RomanReplace num$, n$, Tens$
n$ = Ones((x% 100) MOD 10): RomanReplace num$, n$, Hund$
num$ = STRING$(x% 1000, "M") + num$
END SUB
SUB RomanReplace (num$, Frm$, R$)
FOR t% = 1 TO LEN(Frm$)
MID$(Frm$, t%, 1) = MID$(R$, INSTR("IVX", MID$(Frm$, t%, 1)))
NEXT: num$ = Frm$ + num$
END SUB
FUNCTION Romans$ (n%)
t$ = STR$(n%): RomanNumerals t$: Romans$ = t$
END FUNCTION
<output too large for this post will try to put in seperate post>
Edited on May 17, 2009, 5:01 pm
Edited on May 17, 2009, 5:01 pm
|
Posted by Daniel
on 2009-05-17 14:11:26 |