The 5-character roman numbers under 300 are
XVIII 18 CLIII 153
XXIII 23 CLVII 157
XXVII 27 CLXII 162
XXXII 32 CLXIV 164
XXXIV 34 CLXVI 166
XXXVI 36 CLXIX 169
XXXIX 39 CLXXI 171
XLIII 43 CLXXV 175
XLVII 47 CLXXX 180
LVIII 58 CXCII 192
LXIII 63 CXCIV 194
LXVII 67 CXCVI 196
LXXII 72 CXCIX 199
LXXIV 74 CCIII 203
LXXVI 76 CCVII 207
LXXIX 79 CCXII 212
LXXXI 81 CCXIV 214
LXXXV 85 CCXVI 216
XCIII 93 CCXIX 219
XCVII 97 CCXXI 221
CVIII 108 CCXXV 225
CXIII 113 CCXXX 230
CXVII 117 CCXLI 241
CXXII 122 CCXLV 245
CXXIV 124 CCLII 252
CXXVI 126 CCLIV 254
CXXIX 129 CCLVI 256
CXXXI 131 CCLIX 259
CXXXV 135 CCLXI 261
CXLII 142 CCLXV 265
CXLIV 144 CCLXX 270
CXLVI 146 CCXCI 291
CXLIX 149 CCXCV 295
These can be fit into the grid as follows:
CCXXX
CLXXX
LXXXI
XXVII
XVIII
1072
CCLXX
CLXXX
XXXVI
XXXII
XVIII
1072
CCXXX
CLXXV
LXXXI
XXVII
XXIII
1072
CCLXX
CLXXV
XXXVI
XXXII
XXIII
1072
Regardless of which of the four possible arrays is used, the total is 1072.
DECLARE FUNCTION seq! (x$)
DIM SHARED rNo$(100), ct, rVal(100)
CLS
FOR n = 1 TO 300
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$) = 5 THEN
ct = ct + 1: rNo$(ct) = r$: rVal(ct) = n
row = (ct - 1) MOD 33 + 1: col = ((ct - 1) \\ 33) * 12 + 1
LOCATE row, col
PRINT r$;
PRINT USING "####"; n
END IF
NEXT
DO: LOOP UNTIL INKEY$ > ""
CLS
PRINT ct
FOR n1 = 1 TO ct - 4
PRINT n1;
FOR n2 = n1 + 1 TO ct - 3
FOR n3 = n2 + 1 TO ct - 2
FOR n4 = n3 + 1 TO ct - 1
FOR n5 = n4 + 1 TO ct
good = 1
FOR psn = 1 TO 5
vert$(psn) = MID$(rNo$(n5), psn, 1) + MID$(rNo$(n4), psn, 1)
+ MID$(rNo$(n3), psn, 1) + MID$(rNo$(n2), psn, 1) + MID$(rNo$(n1), psn, 1)
sq(psn) = seq(vert$(psn))
IF sq(psn) = n1 OR sq(psn) = n2 OR sq(psn) = n3 OR sq(psn) = n4
OR sq(psn) = n5 THEN good = 0: EXIT FOR
IF sq(psn) = 0 THEN good = 0: EXIT FOR
IF psn > 1 THEN
IF sq(psn) >= sq(psn - 1) THEN good = 0: EXIT FOR
END IF
NEXT psn
IF good THEN
PRINT
PRINT rNo$(n5): PRINT rNo$(n4): PRINT rNo$(n3)
: PRINT rNo$(n2): PRINT rNo$(n1)
tot = rVal(n1) + rVal(n2) + rVal(n3) + rVal(n4) + rVal(n5)
FOR psn = 1 TO 5
tot = tot + rVal(sq(psn))
NEXT
PRINT tot: PRINT
tot = rVal(n1) + rVal(n2) + rVal(n3) + rVal(n4) + rVal(n5)
FOR psn = 1 TO 5
tot = tot + rVal(sq(psn))
NEXT
'DO: LOOP UNTIL INKEY$ > ""
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
FUNCTION seq (x$)
FOR i = 1 TO ct
IF rNo$(i) = x$ THEN seq = i: EXIT FUNCTION
NEXT
seq = 0
END FUNCTION
From Enigma No. 1533, "Roman grid", by Richard England, New Scientist, 21 February 2009, page 24.
|