REM ============================================ REM Author: Phaelax REM Challenge: Arabic to Roman [v.2] REM ============================================ arabic = 2369 roman$ = "" M = arabic / 1000 : arabic = arabic - M*1000 : roman$ = roman$ + pad$("M",M) D = arabic / 500 : arabic = arabic - D*500 : roman$ = roman$ + pad$("D",D) C = arabic / 100 : arabic = arabic - C*100 : roman$ = roman$ + pad$("C",C) L = arabic / 50 : arabic = arabic - L*50 : roman$ = roman$ + pad$("L",L) X = arabic / 10 : arabic = arabic - X*10 : roman$ = roman$ + pad$("X",X) V = arabic / 5 : arabic = arabic - V*5 : roman$ = roman$ + pad$("V",V) roman$ = roman$ + pad$("I",arabic) roman$ = replace$(roman$, "DCCCC", "CM") roman$ = replace$(roman$, "CCCC", "CD") roman$ = replace$(roman$, "LXXXX", "XC") roman$ = replace$(roman$, "XXXX", "XL") roman$ = replace$(roman$, "VIIII", "IX") roman$ = replace$(roman$, "IIII", "IV") print "Converting arabic 2369 to roman numeral: ",roman$ wait key end function replace$(source$, find$, replace$) i = indexOf(source$, find$) if i > -1 s$ = substr$(source$, 0, i) e$ = substr$(source$, i+len(find$), len(source$)) source$ = s$ + replace$ + e$ endif endfunction source$ function indexOf(source$, find$) L2 = len(find$) for i = 0 to (len(source$) - len(find$)) if substr$(source$, i, i+L2) = find$ then exitfunction i next i endfunction -1 function substr$(strSource$, startInc, endInc) strSource$ = left$(strSource$, endInc) strSource$ = right$(strSource$,endInc-startInc) endfunction strSource$ function pad$(char$,amount) c$ = "" for i = 1 to amount c$ = c$ + char$ next i endfunction c$