------art_12330_31953538.1209754563680
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Fri, May 2, 2008 at 2:18 PM, Martin DeMello <martindemello / gmail.com>
wrote:

> On Fri, May 2, 2008 at 10:25 AM, Matthew Moss <matthew.moss / gmail.com>
> wrote:
> > > 1089 * 9  801
> >  > 2178 * 4  712
> >  > 10989 * 9  8901
> >  > 21978 * 4  7912
> >  > 109989 * 9  89901
> >  > 219978 * 4  79912
> >
> >  One of the interesting things I found is that those are all divisible
> >  by 9. I wonder if that is a property of all such numbers?
>
> Let the numbers be x  ....c and y  ....a
>
> then, if y divides x, so does (x-y)
>
> x  0^n a + 10b + c
> y  0^n c + 10 d + a
>
> x - y  a - c)(10^n-1) + 10 (b-d)
>
> the first term obviously divides by 9
>
> for the second term, note that b and d are reversals of each other. It
> can be shown that their difference again divides by 9 (again splitting
> off the first and last digit as above, or simply by induction on the
> number of digits, which come to think of it I should have done from
> the beginning)
>
> martin
>
>
With that info, I was able to get the code to run under 1 sec.

 c:\ruby-1.9.0\bin\ruby.exe quiz161.rb 
8712
9801
87912
98901
879912
989901

Execution time: 0.969 s


-- 
Shane Emmons
E: semmons99 / gmail.com

------art_12330_31953538.1209754563680--