Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final romanNumbers = {
- "I": 1,
- "V": 5,
- "X": 10,
- "L": 50,
- "C": 100,
- "D": 500,
- "M": 1000
- };
- void main()
- {
- print('III: ${romanToInt('III')}');
- print('IV: ${romanToInt('IV')}');
- print('IX: ${romanToInt('IX')}');
- print('LVIII: ${romanToInt('LVIII')}');
- print('MCMXCIV: ${romanToInt('MCMXCIV')}');
- }
- int romanToInt(String roman)
- {
- return roman.split('')
- .reversed
- .map((n) => romanNumbers[n])
- .reduce((curr, next) => curr > 2 * next ? curr - next : curr + next);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement