There is some speed to gain at the cost of space by making the sigma
test tacit.

   ts '(#~zumkeller) 6+i.4995'
4.648012 143936

   ts '(#~zumkeller2) 6+i.4995'
1.412875 441408

   ((#~zumkeller)-:(#~zumkeller2)) 6+i.4995
1


=========== Code ================

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
)

zumkeller =: 3 : 0 " 0
  s=. +/ fs=. divs y
  if. (2|s) +. s < +: y do. 0
  else. fs sigmaTest~ s&-&.+:y end.
)

sigmat =: [(($:}.)`1:@.((-{.)$:}...@]))`0:@.(0...@])`1:@.(0=[)>:#]

zumkeller2 =: 3 : 0 " 0
  s=. +/ fs=. divs y
  if. (2|s) +. s < +: y do. 0
  else. fs sigmat~ s&-&.+:y end.
)



-- 
Met vriendelijke groet,
=@@i

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

Reply via email to