Skip to content

Instantly share code, notes, and snippets.

@softr8
Last active December 22, 2015 22:19
Show Gist options
  • Save softr8/6539707 to your computer and use it in GitHub Desktop.
Save softr8/6539707 to your computer and use it in GitHub Desktop.
Roman to integers in ruby
def solution(roman)
roman.scan(/IV|IX|CM|XC|I|V|L|X|C|M|D/).inject(0) do |final, current|
final += case current
when 'IV' then 4
when 'IX' then 9
when 'XC' then 90
when 'CM' then 900
when 'I' then 1
when 'V' then 5
when 'X' then 10
when 'L' then 50
when 'C' then 100
when 'D' then 500
when 'M'then 1000
else 0
end
final
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment