From: Benoit Daloze Date: 2009-11-12T04:59:29+09:00 Subject: Re: Roman Numerals (Arrgh!) --0016364176d523309804781dddbe Content-Type: text/plain; charset=ISO-8859-1 Well, being student as well, I'd love to study Ruby instead of this (****) Java. (Where are you studying?) But that's not the point. So, here is my piece of advice: Using $numerals = [ [1000, "M"], [900, "CM"], [500, "D"], [400, "CD"], [100, "C"], [90, "XC"], [50, "L"], [40, "XL"], [10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"] ] ,you should iterate on each of them, seeing how much your number have of this kind (/) and what is the rest after that, to use it for the next step(%)... (if you use Array#each, you'll get a new array(let's say a) like a=[dec, romanString]. You can then take them separetely by a[0] and a[1]. Even if this method is not that beautiful in Ruby, it's the easiest way to understand how to do it). That the way used in a very known book of Ruby. You just need to manage how to save this in your String at each step. (You can multiply a String by "X" * 3, and concatenate using << (or +=)) Give us your script when you'll got one working ;) Hope you'll find this tip usefull, Benoit 2009/11/11 Paul Smith > On Wed, Nov 11, 2009 at 4:17 PM, Gennady Bystritsky > wrote: > > > > On Nov 11, 2009, at 7:56 AM, Paul Smith wrote: > > > >>> > >>> Now you intrigued me ;-). So I am asking directly -- given the > following $numerals: > >>> $numerals = [[1000, "M"], [500, "D"], [100, "C"], [50, "L"], [10, "X"], > [5, "V"], [1, "I"]] > >> > >> $numerals = [[1000, "M"], [900, "CM"], [500, "D"], [400, "CD"], [100, > >> "C"], [90, "XC"], [50, "L"], [40, "XL"], [10, "X"], [9, "IX"], [5, > >> "V"], [4, "IV"], [1, "I"]] > > > > Oops, true. No morning coffee takes its dues ;-) -- I suspected that's > what was implied, however somehow started thinking that the 2-character > strings might be multiplied by that algorithm. My bad, it works indeed. > > Yes indeed, you can't get doubles of the 2 character strings, because > their values are always more than half of the preceeding value. In > other words, inorder to get a "CMCM" type mistake, your value must be > at least 1800. But if it's at least 1800, you'd still be processing > the M's. > > > > > Thank you guys, > > Gennady. > > > >> > >>> > >>> ...how one can transform it so that the original algorithm would > produced shortened roman numbers? Please present the exact value of > $numerals satisfying the above condition. > >>> > >>> Gennady. > >>> > >> > >> > >> > >> -- > >> Paul Smith > >> http://www.nomadicfun.co.uk > >> > >> paul@pollyandpaul.co.uk > >> > > > > > > > > > > -- > Paul Smith > http://www.nomadicfun.co.uk > > paul@pollyandpaul.co.uk > > --0016364176d523309804781dddbe--