Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Apl > Re: Essays/Comb...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 1001 of 1022
Post > Topic >>

Re: Essays/Combination Sums: J is Easy?

by Gosi <gosinn@[EMAIL PROTECTED] > Apr 30, 2008 at 12:54 AM

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.




 4 Posts in Topic:
Essays/Combination Sums: J is Easy?
AAsk <AA2e72E@[EMAIL P  2008-04-29 22:34:23 
Re: Essays/Combination Sums: J is Easy?
Gosi <gosinn@[EMAIL PR  2008-04-30 00:54:14 
Re: Essays/Combination Sums: J is Easy?
RHui000@[EMAIL PROTECTED]  2008-04-30 10:09:32 
Re: Essays/Combination Sums: J is Easy?
RHui000@[EMAIL PROTECTED]  2008-04-30 22:17:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 6:35:36 CDT 2008.