Loading RustViz Engine...
Convert Roman numeral string to integer using peekable iterator matching.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub fn roman_to_int(s: &str) -> i32 {
let mut total = 0;
let mut prev = 0;
for c in s.chars().rev() {
let val = match c {
'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50,
'C' => 100, 'D' => 500, 'M' => 1000,
_ => 0,
};
if val < prev { total -= val; } else { total += val; }
prev = val;
}
total
}