On 03.05.2008 10:37, Robert Klemme wrote:
> On 02.05.2008 18:44, 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:
> 
>>> 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?
> 
> My pretty straightforward solution:
> 
> robert@fussel /cygdrive/c/Temp
> $ time ./quiz-161.rb 1_000
> 
> real    0m0.591s
> user    0m0.045s
> sys     0m0.170s
> 
> robert@fussel /cygdrive/c/Temp
> $ time ./quiz-161.rb 1_000_000
> 8712
> 9801
> 87912
> 98901
> 879912
> 989901
> 
> real    0m3.981s
> user    0m3.764s
> sys     0m0.108s
> 
> robert@fussel /cygdrive/c/Temp
> $ time ./quiz-161.rb 10_000_000
> 8712
> 9801
> 87912
> 98901
> 879912
> 989901
> 8799912
> 9899901
> 
> real    0m38.022s
> user    0m37.530s
> sys     0m0.155s
> 
> robert@fussel /cygdrive/c/Temp
> $ time ./quiz-161.rb 100_000_000
> 8712
> 9801
> 87912
> 98901
> 879912
> 989901
> 8799912
> 9899901
> 87128712
> 87999912
> 98019801
> 98999901
> 
> real    6m21.099s
> user    6m19.639s
> sys     0m0.108s
> 
> robert@fussel /cygdrive/c/Temp
> $ wc quiz-161.rb
>   8  36 173 quiz-161.rb
> 
> robert@fussel /cygdrive/c/Temp
> $

robert@fussel /cygdrive/c/Temp
$ cat quiz-161.rb
#!/bin/env ruby

limit = (ARGV.shift or raise "No limit given!").to_i

21.upto limit do |n|
   r = n.to_s.reverse.to_i
   n % r == 0 and n % 10 != 0 and r != n and puts n
end

robert@fussel /cygdrive/c/Temp
$

Cheers

	robert