21. Roman to integer

EasyProgramFree10 points

Roman numerals use I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. Values are normally written largest first and added up, but a smaller value placed directly before a larger one is subtracted: IV is 4, XC is 90 and CM is 900.

Write romanToInt s, the value of the numeral s.

Examples

  1. InputromanToInt "III"Output3
  2. InputromanToInt "LVIII"Output58
  3. InputromanToInt "MCMXCIV"Output1994

Submitting also runs 8 hidden tests.

Constraints

  • Inputs are valid numerals from 1 to 3999.
Solution.lean
Loading editor…

Run checks your code against the examples and your custom inputs and records nothing. Submit also runs the hidden tests, confirms the axioms your proof uses and records the result. Each uses one compiler check.

ReadyLn 1, Col 1Lean 4
Draft saved in this browser