Created
April 16, 2016 00:03
-
-
Save gr33n7007h/43c81151a41bd362dc68aa9c8e50217f to your computer and use it in GitHub Desktop.
Decode Roman Numerals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numeral_map = %w[M D C L X V I].zip([1000, 500, 100, 50, 10, 5, 1]).to_h | |
"MMXVI".chars.map { |c| numeral_map.fetch(c, 0) }.inject { |x, y| x < y ? -x + y : x + y } #=> 2016 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment