Skip to content

Commit

Permalink
-- added Peter and Topher's solution --
Browse files Browse the repository at this point in the history
  • Loading branch information
clr committed Aug 20, 2009
1 parent 99135e5 commit 426c0a1
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions 002/original_spec/example_entry.rb
@@ -1,14 +1,59 @@
class RomanNumeral class RomanNumeral


def initialize( numeral_string ) def initialize( numeral_string )
@roman_string = numeral_string
end end


def +( numeral_string ) def +( numeral_string )
"MMX" self.to_I + numeral_string.to_I
end end


def -( numeral_string ) def -( numeral_string )
"MCMXCVI" self.to_I - numeral_string.to_I
end

def to_I
@roman_string.to_a.each do |letter|
if @roman_string.shorthand?
@longhand - Array( RomanNumeral.scratch_counts( letter ), "I" )
else
@longhand + Array( RomanNumeral.scratch_counts( letter ), "I" )
end
@roman_string = [ 1..( @roman_string.length - 1 ) ]
end
end

def shorthand?
@roman_string[ 1..( @roman_string.length - 1 ) ].detect{ |letter| RomanNumeral.letters.index( @roman_string[0] )
end

def self.scratch_counts( letter )
case letter
when 'I':
1
when 'V':
5
when 'X':
10
when 'L':
50
when 'C':
100
when 'D':
500
when 'M':
1000
else
raise "ERROR!! Wtf is that -- Greek?"
end
end

def self.letters
"MDCLXVI"
end

def self.has_shorthand?( letters )

end end
end end


0 comments on commit 426c0a1

Please sign in to comment.