[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

12.0. "Roman numerals" by HARE::STAN () Sun Jan 22 1984 19:49

James Gimpel gives an incredibly suave algorithm for converting
to roman numerals in his book, Algorithms in SNOBOL4
(John Wiley and Sons, New York: 1976).
It is so small (but tricky) that I reproduce it here for your
interest. It is written in SNOBOL4.

* ROMAN(N) will return a string equal to the Roman numeral
* equivalent of the integer N.
* N is assumed to be less than 4000 and non-negative.

	DEFINE('ROMAN(N)T')				:(ROMAN_END)
ROMAN	N	RPOS(1) LEN(1) . T =			:F(RETURN)
	'0,1I,2II,3III,4IV,5V,6VI,7VII,8VIII,9IX,'
+		T BREAK(',') . T			:F(FRETURN)
	ROMAN	= REPLACE(ROMAN(N), 'IVXLCDM', 'XLCDM**') T
+							:S(RETURN)F(FRETURN)
ROMAN_END
T.RTitleUserPersonal
Name
DateLines
12.1RANI::LEICHTERJWed Jan 25 1984 03:555
The same book also contains some other clever algorithms for things like
generating permutations.  It's well worth having a look at - although
you have to know at least some SNOBOL to make any sense of some of the
details.
							-- Jerry
12.2quick responseVINO::JMUNZERFri Jun 10 1988 14:237
    How does .0 work?  Is there nothing to distinguish the times-fives
    from the times-twos?  (I-to-V vs. V-to-X.)
    
    Are there accepted rules on Roman numerals?  VIII vs. IIX?  XCV
    vs. VC?  Is IMM legal?  Is CIM?
    
    John
12.31990?ESCROW::MUNZERMon Jan 29 1990 12:383
    ...and what is (are) the legitimate Roman representation(s) for 1990?
    
    John
12.4I guess MCMXCUTRUST::DEHARTOG925Mon Jan 29 1990 12:490
12.5MXMPULSAR::WALLYWally Neilsen-SteinhardtMon Jan 29 1990 15:2323
    Re:                       <<< Note 12.3 by ESCROW::MUNZER >>>

>    ...and what is (are) the legitimate Roman representation(s) for 1990?
    
    There are really two questions here:
    
    	What Roman numerals can be read as 1990?
    
    	How would a typical writer of Roman numerals represent 1990?
    
    The title of this note offers another answer to the first question.
    
    As I remember, the subtractive convention (IX for VIIII) was introduced
    some time after the fall of the Roman Empire, so no citizen of the
    empire would have used it.
    
    MDCCCCLXXXX is, I think, how a such a citizen would have represented
    1990, assuming the subject came up.
    
    But if you allow more recent writers of Roman numerals, then you have
    to guess at their conventions.  I know MCM=1900 is quite common, and I
    have never seen MLM=1950.  So I suspect that the title above is not a
    valid answer to the second question.
12.6As I rember it, .5 is correctCADSYS::COOPERTopher CooperMon Jan 29 1990 16:2513
    The "rule" which was added post-classically was something like this:
    
    		(1) V' I' I' I' I' -> I' X'
    		(2) I' I' I' I' -> I' V'
    
    where I', V', X' equals
    
    		I, V, X  or
    		X, L, C  or ... etc
    
    If the first subrule applies the second cannot be used.
    
    					Topher
12.7What would a Roman abacus look like?CHMIST::cjaBetter living through Chemistry!Tue Jan 30 1990 17:1214
re .-1
Ok, start with the classical version:

	MDCCCCLXXXX

applying rule 1) to the "DCCCC" part gives
	MCMLXXXX

applying rule 1) to the "LXXXX" part gives
	MCMXC
No further simplification is possible using those rules.  I don't see
how you can claim that "MXM" is correct using the rules you've given.

You just don't see these kind of arguments for Arabic numerals, do you?
12.8Confusion about antecedent.CADSYS::COOPERTopher CooperTue Jan 30 1990 19:167
RE: .7
    
    Sorry, my title to .6 lead to a misunderstanding -- I meant that the
    *body* of .5, which claimed that the *title* of .5 was illegal, was
    correct, i.e., that MXM is not an allowed combination.
    
    					Topher
12.9RAMBLR::MORONEYHow do you get this car out of second gear?Wed Jan 31 1990 21:143
See also note 2143 of MEIS::ASKENET.

-Mike
12.10AITG::DERAMOa most bodacious noterSat Apr 21 1990 03:523
        Would Mary Tyler Moore write it as MTM? :-)
        
        Dan
12.11BUSY::SLABOUNTYTrouble with a capital 'T'Wed Jun 14 1995 13:519
    
    	Does anyone have a DCL, BASIC or C program that will convert a
    	number to a roman numeral?
    
    	Or a program that will scan a file and convert ALL numbers to
    	roman numerals?
    
    	Thanks for any info.
    
12.12HANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Wed Jun 14 1995 14:131
Why would such be needed ?  
12.13CSC32::D_DERAMODan D'Eramo, Customer Support CenterWed Jun 14 1995 15:443
        Roman numeral output is built into VAX LISP.
        
        Dan
12.14Take it from hereEVMS::HALLYBFish have no concept of fireWed Jun 14 1995 17:1420
    The idea is to work the number left-to-right, replacing 
    
    		I,V,X,L,C with X,L,C,D,M
    
    respectively, and tacking on the next digit.
    
    Take 1492:
    
    (1a) Start with nothing
    (1b) tack on I from the 1
    (2a) I to X via replace
    (2b) tack on IV from the 4, "XIV" or 14
    (3a) XIV becomes CXL via replace
    (3b) tack on IX from the 9 for "CXLIX" or 149
    (4a) CXLIX becomes MCDXC
    (4b) tack on II from the 2 for "MCDXCII", 1492
    
    I never loearned Roman Numerals > 5000
    
      John
12.15HANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Wed Jun 14 1995 18:128
>    
>    I never loearned Roman Numerals > 5000
> 

	what's 5000 ?  Is there a letter ?  Or just MMMMM.


/Eric
12.16AUSSIE::GARSONachtentachtig kacheltjesWed Jun 14 1995 23:4210
    re .14
    
    That's fine if for some reason you require strictly sequential access
    to the input data.
    
    It seems better though to buffer the entire input number so that we
    know that the weight of the first digit is 1000 and then treat 1492 as
    1000,400,90,2 and then just substitute appropriate Roman numeral
    strings for each viz. M,CD,XC,II. (This would require a 10*4
    translation table but it's conceptually simple.)
12.17Critic's choiceEVMS::HALLYBFish have no concept of fireThu Jun 15 1995 12:1810
>    It seems better though to buffer the entire input number so that we
>    know that the weight of the first digit is 1000 and then treat 1492 as
>    1000,400,90,2 and then just substitute appropriate Roman numeral
>    strings for each viz. M,CD,XC,II. (This would require a 10*4
>    translation table but it's conceptually simple.)
    
    "Better" in what sense? I could just as easily argue it is "better" to
     define a 4999-entry table of strings, and do a lookup.
    
      John
12.18AUSSIE::GARSONachtentachtig kacheltjesThu Jun 15 1995 13:5911
    re .17
    
    Not a mathematical concept I admit.
    
    Better = ill-defined compromise between efficiency of execution, time
    to code correctly, ease of comprehension by maintenance programmer,
    ease of modification, weighted according to your priorities. Choice of
    language will of course impact these factors.
    
    A 4999 entry lookup table could be reasonable if it were program
    generated and memory wasn't tight.
12.19a .com to convert to roman numberalsHANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Thu Jun 15 1995 14:5151
$!
$!	Convert decimal number to roman numberals for
$!	busy busy Slabounty. (currently limited to 1 - 3999)
$!
$!	Usage:
$!
$!		@roman n
$!
$!	Author:  Eric Osman 14-Jun-1995
$!
$ one = "I"
$ five = "V"
$ ten = "X"
$ fifty = "L"
$ hundred = "C"
$ fivehundred = "D"
$ thousand = "M"
$ units = "one,five,ten"
$ tens = "ten,fifty,hundred"
$ hundreds = "hundred,fivehundred,thousand"
$ thousands = "thousand,unknown,unknown"
$ groups = "thousands,hundreds,tens,units"
$ quans = "1000,100,10,1"
$ forms = " !AS:n1 !AS!AS:n1,n1 !AS!AS!AS:n1,n1,n1 !AS!AS:n1,n2 !AS:n2" + -
	" !AS!AS:n2,n1 !AS!AS!AS:n2,n1,n1 !AS!AS!AS!AS:n2,n1,n1,n1 !AS!AS:n1,n3"
$ set = "set" ! use usual definition of "set"
$ set symbol/scope=(nolocal,noglobal) ! use usual definition of all others
$ on warning then exit ! stop as soon as something goes wrong
$ unknown = ""
$ n = p1
$ i = 0
$ if n .gt. 3999 .or. n .lt. 1
$ then
$	write sys$output "Not converting ", n
$	exit
$ endif
$ roman = ""
$ lup:
$ quan = f$int(f$ele(i,",",quans))
$ digit = n/quan
$ n = n - digit*quan
$ if digit .eq. 0 then goto next_i
$ form = f$ele(digit," ",forms)
$ group = 'f$ele(i,",",groups)'
$ n1 = 'f$ele(0,",",group)'
$ n2 = 'f$ele(1,",",group)'
$ n3 = 'f$ele(2,",",group)'
$ roman = roman + f$fao (f$ele(0,":",form), 'f$ele(1,":",form)')
$ next_i: i = i + 1
$ if i .lt. 4 then goto lup
$ write sys$output roman
12.20So why Roman Numerals??MROA::BERGARTJeff-the-refTue Oct 31 1995 17:1033
    
    A request for assistance (cross posted in Brain Bogglers...)
    
       <<< ROBTOB::ROBTOB$DKA300:[BRAIN_BOGGLERS]BRAIN_BOGGLERS.NOTE;4 >>>
                              -< Brain Bogglers >-
================================================================================
Note 409.10                      Roman numerals                         10 of 12
MROA::BERGART "Jeff-the-ref"                         23 lines  31-OCT-1995 17:06
              -< So why are the Roman Numerals what they are??? >-
--------------------------------------------------------------------------------
    I'll be teaching Roman Numerals very soon to a 6th grade class.
    The question is: Why are the roman numerals what they are?
    Your insights and/or inputs to the lesson plan are most welcome....
    
    I = 1		I looks like a single finger.
    V = 5		The shape of the thumb and first finger of a whole
    				hand (i.e. five fingers)?
    X = 10		Two V's connected bottom to bottom?
    L = 50
    C = 100
    D = 500
    M = 1000
    
    	And what examples can I use showing how these now impact our lives?
    
    I = 1	"I"  meaning me, a single person
    V = 5		
    X = 10	Deci/Deca means ten (e.g. decade) so why X, why is 500 a "D"?
    L = 50
    C = 100	"Cent" (1/100th of a dollar), "Century" (100 years)
    D = 500
    M = 1000	"Milli" (1/1000th of something)  "Millenium" (1000 yrs)
    
12.21AUSSIE::GARSONachtentachtig kacheltjesThu Nov 02 1995 06:2617
12.22try next doorJOBURG::BUCHANANThu Nov 02 1995 07:056
    	The real place to enquire about this is SMURF::SPQR, where all the
    staggeringly knowledgeable classical whizzes live. They can give you
    the total story.
    
    Cheers,
    Andy.
12.23EVMS::HALLYBFish have no concept of fireThu Nov 02 1995 13:377
> are US based. Maybe a more familiar sport also does this.
    
    Was that a set-up? In the States we number Super Bowls thusly.
    THE big TV event of the year, except for the occasional verdict or
    other surprise event.
    
      John C. Hallyburton II
12.24AUSSIE::GARSONachtentachtig kacheltjesThu Nov 02 1995 19:2213
re .23
    
>    Was that a set-up?
    
    Nope.
    
>    In the States we number Super Bowls thusly.
    
    I find bowls a somewhat boring game to watch. (-:
    
    
    But seriously, yes, that should give an example that the target
    audience can relate to.
12.25bad joke, not worth readingHANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Fri Nov 03 1995 14:386

I missed the first IX episodes, but Malcolm X was a pretty good movie.

/Eric