From: Peter Szinek Date: 2008-11-15T18:27:12+09:00 Subject: Re: Unit Conversion (#183) On 2008.11.14., at 19:55, Trans wrote: > > > On Nov 14, 10:49 am, Matthew Moss wrote: >> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- >> >> The three rules of Ruby Quiz 2: >> >> 1. Please do not post any solutions or spoiler discussion for this >> quiz until 48 hours have passed from the time on this message. >> >> 2. Support Ruby Quiz 2 by submitting ideas as often as you can! >> Visit . >> >> 3. Enjoy! >> >> Suggestion: A [QUIZ] in the subject of emails about the problem >> helps everyone on Ruby Talk follow the discussion. Please reply to >> the original quiz message, if you can. >> >> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- >> >> ## Unit Conversion (#183) >> >> Google added a calculator to its search engine a while back. Enter >> "convert 50 miles to kilometers", or even just "50 mi to km", and the >> first "search" result will tell you that 50 miles is 80.4672 >> kilometers. This works for units other than length. Try "33 ml to >> gal", "6 hours to minutes", and"50 stones to lbs", and you'll see >> that >> Google's calculator knows a lot of different units and how to convert >> between them all. >> >> Your task is to write a units converter script. The input to the >> script must be three arguments: the quantity, the source units, and >> the destination units. The first example above would be run like >> this: >> >> $ ruby convert.rb 50 miles kilometers >> >> Or, using abbreviations: >> >> $ ruby convert.rb 50 mi km How about ruby convert.rb 100 mile per minute per second foot per second squared (read: 100 mile per minute per second *to* foot per second squared) Maybe we should allow ruby convert.rb x unit1 to unit2 or ruby convert.rb x long_unit_name even_longer_unit_name to avoid unnecessary complicated (or impossible) parameter parsing? Cheers, Peter ___ http://www.rubyrailways.com