Shane Emmons
5/2/2008 6:56:00 PM
[Note: parts of this message were removed to make it a legal post.]
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 = 9801
> > > 2178 * 4 = 8712
> > > 10989 * 9 = 98901
> > > 21978 * 4 = 87912
> > > 109989 * 9 = 989901
> > > 219978 * 4 = 879912
> >
> > 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 = a....c and y = c....a
>
> then, if y divides x, so does (x-y)
>
> x = 10^n a + 10b + c
> y = 10^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