(UPDATED) … Whoops, wrong alias name used in the USE IN command. Repaired now <g>
So Richard Stanton, part of the VFP Dev team and the author of all the great VFP Report enhancements in VFP 9, and I were going over a very cool algorithm. I can’t get into what it does as we haven’t decided what to do with it, but it’s slick.
You know what I mean by slick, right? In my experience, developers will ooh-and-ahh at great algorithms regardless of how useful they are. If the code is elegant we get a warm-and-fuzzy feeling. I have a pet theory that this asthetic appreciation gets developers into trouble sometime – we love th code so much we refuse to see it may not be the right solution.
So Richard mentioned an old project of his to convert Arabic numbers (our standard numbers) into Roman numbers. I thought about it, and replied that I thought I could do it in 30 lines of code or less, not including any setup code like asking for the number or creating data structures that can be re-used. He sort of challenged me on that, and here’s the result. Kinda cool but with very little real-world usefulness (heh). Sorry about the formatting.
* Arabic to Roman … John Koziol May 10, 2005
* Public domain: Share and enjoy.
cNum=INPUTBOX(“Enter a number between 1 and 3999″,”Enter number”)
=MESSAGEBOX(“Can’t even follow simple instructions?, Well begone!”,”Input Issue”,16)
SET DECIMALS TO0
USEAToRoman IN 0 ORDER main ALIAS ct
cRoman = “”
FORi = 3 TO 0 STEP -1
nVal=nVal- (nChrs* ct.narabic)
USE IN ct
CREATE TABLE AToRoman(narabic N(4,0), symb C(1),penta C(1), nona C(2))
INSERT INTO AToRoman VALUES (1000,”M”,””,””)
INSERT INTOAToRoman VALUES (100,”C”,”D”,”CM”)
INSERT INTOAToRoman VALUES (10,”X”,”L”,”XC”)
INSERT INTOAToRoman VALUES (1,”I”,”V”,”IX”)
INDEX ONnarabic TAG main