sigma(n) is just the sum of the divisors   +/divs

This was my first approach of sigmaTest:

sigmtest=: 4 : 0
  if. 0=x do. 1 return. end.
  if. 0=#y do. 0 return. end.
  if. x < {.y do. x sigmtest }.y
  else. ((x-{.y) sigmtest }.y ) +. x sigmtest }.y end.
)

This 'exact' translation makes it probably much slower.



Thanks


 


Hallo Raul Miller, je schreef op 28-01-10 15:20:
> On Thu, Jan 28, 2010 at 7:11 AM, Aai <[email protected]> wrote:
>   
>> fact 3: The sigma test. n is a Zumkeller number if and only if
>> (sigma(n)-2n)/2 is either zero or is a sum of distinct positive factors
>> of n excluding n itself.
>>     
> What definition of sigma are you using here?
>
> I can reverse engineer your code, but that will take a bit
> of time.
>
>   
>> divs=: 13 :'\:~ , > */&>/(^ i.@>:)&.>/__ q: y'
>>     
> This can be simplified slightly:
>
> divs=: 13 :'\:~ , */&>/(^ i.@>:)&.>/__ q: y'
>
>   
>> [1] with this kind of code Haskell seems much faster. Excerpt
>>
>> ....
>>
>>        sigmaTest 0 _ = True
>>        sigmaTest _ [] = False
>>        sigmaTest n (f:fs)
>>            | f > n     = sigmaTest n fs
>>            | otherwise = sigmaTest (n-f) fs || sigmaTest n fs
>>     
> Here is a literal translation of that into J:
>
> sigmaTest=: 4 :0
>   if. 0=x do.1 return.end.
>   if. 0=#y do.0 return.end.
>   f=.{.y
>   fs=.}.y
>   if. x<f do. x sigmaTest fs return.end.
>   if. (x-f) sigmaTest fs do.1 return.end.
>   x sigmaTest fs
> )
>
> With this definition, and
>
> zumkeller =: 3 : 0"0
>  s=. +/ fs=. divs y
>  if. (2|s) +. s < +: y do. 0 else.
>     (s&-&.+:y) sigmaTest fs end.
> )
>
>    zumkeller 80010
> 1
>
> FYI,
>
>   

-- 
Met vriendelijke groet,
=@@i

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to