Published on 28 April 2022 (Updated: 25 January 2023)

Welcome to the Roman Numeral in Dart page! Here, you’ll find the source code for this program as well as a description of how the program works.

Current Solution

voidmain(List<String>args){try{Mapnumerals=numeral_map();List<int>values=[0];for(inti=0;i<args[0].length;i++){values.add(numerals[args[0][i]]);}intsum=values[values.length-1];for(inti=1;i<values.length;i++){sum=(values[i]>values[i-1])?sum-values[i-1]:sum+values[i-1];}print(sum);}onRangeError{print("Usage: please provide a string of roman numerals");}onNoSuchMethodError{print("Error: invalid string of roman numerals");}}Mapnumeral_map(){varnumerals=newMap();numerals['I']=1;numerals['V']=5;numerals['X']=10;numerals['L']=50;numerals['C']=100;numerals['D']=500;numerals['M']=1000;returnnumerals;}

Note: The solution shown above is the current solution in the Sample Programs repository as of Oct 21 2019 18:06:11. The solution was first committed on Oct 20 2019 18:59:46. As a result, documentation below may be outdated.