home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / apl / 949 < prev    next >
Encoding:
Text File  |  1992-08-15  |  1.5 KB  |  43 lines

  1. Newsgroups: comp.lang.apl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
  3. From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
  4. Subject: Partitions, Part II (Was: Question about recursion in J)
  5. Message-ID: <1992Aug15.141936.2514@yrloc.ipsa.reuter.COM>
  6. Organization: Iverson Software Inc.
  7. References: <1992Aug7.215222.13596@csus.edu> <1992Aug12.053055.23246@yrloc.ipsa.reuter.COM>
  8. Date: Sat, 15 Aug 92 14:19:36 GMT
  9. Lines: 32
  10.  
  11. There is a multiply-recursive method of generating partitions which
  12. may be easier to understand, viz.:
  13.  
  14. t=.i.0 0
  15. t=.t, '$.=.1+(1<x.)*.x.<y.'
  16. t=.t, '(((0<x.)*.x.<:y.),x.)$1>.y.*1=x.'
  17. t=.t, '; k (>:@[,.+)&.>(<:x.) <@part2 y.->:x.*k=.i.<.y.%x.'
  18. part2 =. '' : t " 0
  19.  
  20. t=.i.0 0
  21. t=.t, 'p=.x. part2 y.'
  22. t=.t, 'z=.$0'
  23. t=.t, 'z=.z, *./ y. = +/"1 p'             NB. sum
  24. t=.t, 'z=.z, x. = {:$p'                   NB. size
  25. t=.t, 'z=.z, (/:p) -: i.#p'               NB. sorted
  26. t=.t, 'z=.z, *./ p (/:@[ -: ])"1 i.x.'    NB. sorted within rows
  27. assert =. '' : t
  28.  
  29.    3 part2 10                3 assert 10
  30. 1 1 8                     1 1 1 1
  31. 1 2 7                        3 assert 3
  32. 1 3 6                     1 1 1 1
  33. 1 4 5                        3 assert 1
  34. 2 2 6                     1 1 1 1
  35. 2 3 5                        0 assert 3
  36. 2 4 4                     1 1 1 1
  37. 3 3 4                        0 assert 0
  38.                           1 1 1 1
  39.  
  40. ------------------------------------
  41. Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
  42. Phone: (416) 925 6096;  Fax: (416) 488 7559
  43.