Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created April 16, 2016 00:03
Show Gist options
  • Save gr33n7007h/43c81151a41bd362dc68aa9c8e50217f to your computer and use it in GitHub Desktop.
Save gr33n7007h/43c81151a41bd362dc68aa9c8e50217f to your computer and use it in GitHub Desktop.
Decode Roman Numerals.
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