From: Shane Emmons Date: 2008-05-03T02:26:43+09:00 Subject: Re: [QUIZ] Reverse Divisible Numbers (#161) ------=_Part_11994_29308504.1209749203709 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, May 2, 2008 at 12:44 PM, Rob Biedenharn wrote: > > On May 2, 2008, at 12:10 PM, Ken Bloom wrote: > > On Fri, 02 May 2008 10:28:00 -0500, Matthew Moss wrote: > > > > > Quiz #161 > > > Reverse Divisible Numbers > > > > > > This week's quiz is borrowed from Jon Galloway > > > (http://tinyurl.com/5jvf37). > > > Don't read the comments or solution there without trying this first! > > > > > > Your task is to write a bit of Ruby code that will find and report all > > > integers that are divisible by their reverse. For example, 9801 is > > > divisible by 1089. > > > > > > Your script should accept a single, optional argument to specify the > > > upper > > > limit of your search. If not provided, the default should be one > > > million. > > > > > > There are two extra rules for finding these "reverse divisible" > > > numbers: > > > > > > 1. Don't count palindromes; they are obviously reverse-divisible. 2. > > > Don't count numbers ending with zero. Reversing such numbers forces > > > you > > > to drop leading zeros on the divisor, and that's not as much fun. > > > > > > > Here's what I've found: > > > > 1089 * 9 = 9801 > > 2178 * 4 = 8712 > > 10989 * 9 = 98901 > > 21978 * 4 = 87912 > > 109989 * 9 = 989901 > > 219978 * 4 = 879912 > > > > real 0m55.234s > > user 0m53.995s > > sys 0m0.012s > > > > --Ken > > > > -- > > Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. > > Department of Computer Science. Illinois Institute of Technology. > > http://www.iit.edu/~kbloom1/ > > > > 2178 * 4 = 8712 > 1089 * 9 = 9801 > 21978 * 4 = 87912 > 10989 * 9 = 98901 > 219978 * 4 = 879912 > 109989 * 9 = 989901 > > real 0m13.113s > user 0m12.411s > sys 0m0.081s > > While I find them in a slightly different order, I'm surprised by the 4x > speedup. I wonder if there's a better way to post comparisons that would > negate machine differences and focus on algorithmic distinctions without > posting code? > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob@AgileConsultingLLC.com > > > H:\personal\RubyQuiz>ptime quiz161.rb ptime 1.0 for Win32, Freeware - http://www.pc-tools.net/ Copyright(C) 2002, Jem Berkes === quiz161.rb === 8712 9801 87912 98901 879912 989901 Execution time: 7.691 s -- Shane Emmons E: semmons99@gmail.com ------=_Part_11994_29308504.1209749203709--