As as side note, am I the only one who would find the code easier to read if
it had some minimal formatting, as shown below, which includes basic
indentation, avoidance of low-information density lines like a bare "do.",
and a comment or two? I don't mean to single out Justin for criticism as
much of the example code also avoids this basic, helpful formatting.
alg=: 3 : 0
NB.* alg: Create full tree of card deck possibilities to test hi-lo
strategy.
fail=. 0$0 [ tree=. stack=. ,: 0 [ vals=. ,: _1
while. 0 < # stack do.
topStack=. {. stack
stack=. }. stack
game=. vals {~ topStack toRoot tree
p=. y poss game
numPoss=. # p
if. numPoss > 0 do.
vals=. vals , p
stack=. stack ,~ (# tree) + i. numPoss
tree=. tree , numPoss $ topStack
fail=. fail , y - numPoss
else. fail=. fail , 0 end.
end.
tree;vals
NB.EG (0 0 0 1 2;_1 0 1 1 0) -: alg 2
)
I also incorporated my own convention of a leading comment with an
explanation of what is intended and a trailing comment with an example
(showing the expected result, if feasible).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm