A simple modification that enables the algorithm
to work where others fail:

ess3=: 4 : 0  
 t=. (y$x)#:i.>:x#.(i.x),(<:y%x)#i.-x
 t=. t #~ *./(y%x)=+/"1 (i.x)=/t
 t #~ ((i.x) -: ~.)"1 t
)

   $ 4 ess 12
15400 12

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

Reply via email to