small medium large xlarge

05 Jan 2012, 13:52
detectivist (2 posts)

Though there isn’t an error with the code per se, the example code in the back does not seem to fully solve the problem. It asks to make sure the string is a valid roman numeral. It checks to make sure each literal is a valid roman numeral, but it doesn’t check if the overall number is valid. For instance, the code provided will give you a value for IIIX even though that isn’t a valid roman numeral.

I think that putting in another piece of logic after the val checking would be helpful. For instance: if val < prev then, if val = the_character_before_it then puts ‘This is not a valid roman numeral.’ This would pick up on any situations, such as those mentioned above. Otherwise, X will continue to be the value for val, and you’ll just get a bunch of negative 1’s.

Just a thought.

16 Oct 2013, 16:12
johnn moon (1 post)


IIIX does make sense. It’s simply saying subtract 3 (III) from 10 (X). We are solving the problem in the new roman numeral, where if the number is smaller than the previous number it subtracts.

Not quite sure what doesn’t make sense in that answer.

  You must be logged in to comment