From: Gerald Ebberink Date: 2007-01-08T16:25:12+09:00 Subject: Re: Calculating roman numerals On Wed, 03 Jan 2007 06:35:02 +0900, Shiloh Madsen wrote: > Ok, I'm having trouble with another exercise in this book. It has > asked me to write a program that will calculate the old school roman > numeral value for a given modern number (up to the thousands). To > clarify, old school roman numerals didn't do the subtraction thing, so > 4 is IIII, nine is VIIII, etc. I've played around with a few options > using division, loops and modulus, but can't seem to get my brain > around the problem...any suggestions? > > Shiloh Many people have answered, but since I'm a beginner I would like to have some comments on the following. Which I think is pretty ruby-esque ans=0 roman="XVIII" {"X"=>10,"V"=>5,"I"=>1}.each_pair do |letter, number|ans+=roman.count(letter)*number end;ans Kind regards, Gerald