home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.apl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
- From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
- Subject: Partitions, Part II (Was: Question about recursion in J)
- Message-ID: <1992Aug15.141936.2514@yrloc.ipsa.reuter.COM>
- Organization: Iverson Software Inc.
- References: <1992Aug7.215222.13596@csus.edu> <1992Aug12.053055.23246@yrloc.ipsa.reuter.COM>
- Date: Sat, 15 Aug 92 14:19:36 GMT
- Lines: 32
-
- There is a multiply-recursive method of generating partitions which
- may be easier to understand, viz.:
-
- t=.i.0 0
- t=.t, '$.=.1+(1<x.)*.x.<y.'
- t=.t, '(((0<x.)*.x.<:y.),x.)$1>.y.*1=x.'
- t=.t, '; k (>:@[,.+)&.>(<:x.) <@part2 y.->:x.*k=.i.<.y.%x.'
- part2 =. '' : t " 0
-
- t=.i.0 0
- t=.t, 'p=.x. part2 y.'
- t=.t, 'z=.$0'
- t=.t, 'z=.z, *./ y. = +/"1 p' NB. sum
- t=.t, 'z=.z, x. = {:$p' NB. size
- t=.t, 'z=.z, (/:p) -: i.#p' NB. sorted
- t=.t, 'z=.z, *./ p (/:@[ -: ])"1 i.x.' NB. sorted within rows
- assert =. '' : t
-
- 3 part2 10 3 assert 10
- 1 1 8 1 1 1 1
- 1 2 7 3 assert 3
- 1 3 6 1 1 1 1
- 1 4 5 3 assert 1
- 2 2 6 1 1 1 1
- 2 3 5 0 assert 3
- 2 4 4 1 1 1 1
- 3 3 4 0 assert 0
- 1 1 1 1
-
- ------------------------------------
- Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario M5S 2K9
- Phone: (416) 925 6096; Fax: (416) 488 7559
-