Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Rosetta PGA-TRAM

by whakka (Hermit)
on Jun 16, 2009 at 17:06 UTC ( #772078=note: print w/ replies, xml ) Need Help??


in reply to Rosetta PGA-TRAM

Pretty straightforward to translate to a Java version:

import java.util.HashMap; public class pgaTram { private static HashMap<Character, Integer> rtoa = loadRTOA(); public static void main(String[] args) { String[] testdata = { "XLII", "LXIX", "mi" }; for (String t : testdata) { System.out.println(t + ": " + romanToDec(t)); } } public static int romanToDec(String s) { int t = 0; for (char c : s.toCharArray()) { int n = rtoa.get(Character.toUpperCase(c)); t += n - t % n * 2; } return t; } private static HashMap<Character, Integer> loadRTOA() { HashMap<Character, Integer> rtoa = new HashMap<Character, Inte +ger>(); rtoa.put('M', 1000); rtoa.put('D', 500); rtoa.put('C', 100); rtoa.put('L', 50); rtoa.put('X', 10); rtoa.put('V', 5); rtoa.put('I', 1); return rtoa; } }


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://772078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2015-07-07 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls