Here's a version of my code which seems to be equivalent
to Roger Hui's code (which, unlike mine, can be relied on to
be correct):
parts=: (] #~ (%~ [EMAIL PROTECTED]) = +/"[EMAIL PROTECTED]) [: #:@i. 2&^&.<:
pieces=: [ ([EMAIL PROTECTED]@[ */ ]) parts
combos=: (#~ ~."1 -:"1 /:[EMAIL PROTECTED]@{.)@(+"1/ #~&(,/) 0 = [: +/"1
*"1/)/@pieces
cannon=: /:[EMAIL PROTECTED]
4 (cannon -: ess3) 12
1
Unfortunately, I still get a limit error for somewhat larger cases
4 cannon 16
|limit error
Also, my approach seems only slightly faster (factor of 3 for the case
of the example I tested) which suggests that I have not done anything
useful about the underlying exponential growth problem.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm