From: Rob Biedenharn Date: 2009-11-11T11:43:43+09:00 Subject: Re: Roman Numerals (Arrgh!) On Nov 10, 2009, at 8:49 PM, Gennady Bystritsky wrote: > On Nov 10, 2009, at 5:37 PM, Rob Biedenharn wrote: > >> On Nov 10, 2009, at 6:56 PM, Rick Barrett wrote: >> >>> I have a homework assignment where I have to convert an inputted >>> integer >>> into Roman Numerals. I was doing fine building upon the previous >>> steps >>> >> >> P.S. I saw Gennady's post, but I'd argue that no one would really >> want >> to solve the problem that way. And Nik's way doesn't give any help > > Why not that way? It works and it is short ;-) > > Gennady. Not that it doesn't work, just that it might be easier/quicker to rewrite than to understand. Short isn't *always* a virtue and if there's a reason (performance?) to be terse, then there ought to be a comment by way of explanation. There are few truly necessary uses of Enumerable#inject and this isn't one of them, but if it were, I'd make it at least slightly more readable: def roman_numeral(number) $numerals.inject(["", number]) { |(answer, number), (arabic, roman)| [ answer + roman * (number / arabic), number % arabic ] }.first end And with an appropriately formed $numerals array, the "subtraction rule" is already covered. ;-) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com