Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Rosetta PGA-TRAM

by Arunbear (Parson)
on Jun 13, 2009 at 18:35 UTC ( #771280=note: print w/ replies, xml ) Need Help??


in reply to Rosetta PGA-TRAM

A Scala version (basically similar in form to the Perl/Python versions):

val rtoa = Map('M' -> 1000, 'D' -> 500, 'C' -> 100, 'L' -> 50, 'X' -> +10, 'V' -> 5, 'I' -> 1) def romanToDec(roman: String) : Int = roman.map((c) => rtoa(c.toUpperCase)).reduceLeft((x, y) => x + y - x + % y * 2) val testData = List("XLII", "LXIX", "mi") for(r <- testData) println(r + ": " + romanToDec(r))


Comment on Re: Rosetta PGA-TRAM
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://771280]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2014-09-03 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls