Skip to content

Instantly share code, notes, and snippets.

@simonkro
simonkro / roman.rb
Created December 2, 2012 22:15
Ruby Quiz Solution
def roman_to_arabic
{'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400,
'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40,
'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4,
'I' => 1}
end
def to_roman n
roman_to_arabic.map do |roman, arabic|
i, n = n.divmod(arabic)
# solves the puzzle from https://gist.github.com/1925593
# unpolished version - i'm tired
input = (<<EOF).split("\n").map{|row| row.split(//).map(&:intern)}
-------------
| |
| U
|* * * * *|
| |
| # |