From: Ken Bloom Date: 2008-05-03T04:40:06+09:00 Subject: Re: [QUIZ] Reverse Divisible Numbers (#161) On Fri, 02 May 2008 11:44:21 -0500, 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? I did it in a *really* stupid way for my first pass. That's all. --Ken -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/