On Apr 30, 5:34=A0am, AAsk <AA2e...@[EMAIL PROTECTED]
> wrote:
> http://www.jsoftware.com/jwiki/Essays/Combination_Sums
>
> I like the template/style used to present the solution very much.
>
> I am somewhat ashamed by my own illiteracy in J; this is so severe
> that I cannot even begin to make sense of the code. I know that J has
> (some) language structures/enhancements that simply do no exist in
> APL; nonetheless, can someone translate this into APL?
>
> [There is only so much time to learn new things.]
I guess what you are refering to is the folowing code made by Roger
Hui
"
comb=3D: 4 : 0 M. NB. All size x combinations of i.y
if. (x>:y)+.0=3Dx do. i.(x<:y),x else. (0,.x comb&.<: y),1+x comb y-1
end.
)
cs=3D: 4 : 0
({.,#)/.~ +/"1 x comb y
)
combsum=3D: 4 : 0 M.
if. (x>:y)+.0=3Dx do. (x<:y)#,:2!x,2
else. (~.@[EMAIL PROTECTED]
,. +//.)/ |: (((x-1),0)+"1 x combsum&<: y),(x,0)+"1 x
combsum y-1 end.
)
combsumcheck=3D: 4 : 0
z=3D. x combsum y
assert. (-:<.) z
assert. ($z) -: 2,~m=3D. 1+x*y-x
assert. ({."1 z) -: (2!x) (+i.) m
assert. (+/{:"1 z) =3D x!y
assert. (-:|.) {:"1 z
assert. ({.z) -: (2!x),1
assert. ({:z) -: ((x*y-x)+2!x),1
)
"
What part of it would you like explained?
As far as I am concerned most of it is straight forward and clear as
is usual from Roger.
Obviously other parts of it may look like magic.
Explaining without basic knowledge of how J works may be very lengthy.
Probably the best way to study the code would be to take it and study
it part by part in the J studio.


|