http://code.jsoftware.com/wiki/Essays/Power_Set is an essay by Roger Hui about power sets, including a number of ways to generate these, such as:
ps0 =: #:@i.@(2&^)@# <@#"1 _ ] ps0 2 5 7 ┌┬─┬─┬───┬─┬───┬───┬─────┐ ││7│5│5 7│2│2 7│2 5│2 5 7│ └┴─┴─┴───┴─┴───┴───┴─────┘ Now your f can be: f =: 1 : '}. /:~ ; u/ each ps0 y' + f 2 5 7 2 5 7 7 9 12 14 * f 2 5 7 2 5 7 10 14 35 70 Ben ________________________________________ From: Programming [[email protected]] on behalf of Skip Cave [[email protected]] Sent: Monday, October 02, 2017 18:49 To: [email protected] Subject: [Jprogramming] (no subject) Given a set of integers, what is the most concise and or efficient way to list the numbers along with the sum of all combinations of the numbers? the products of all combinations? for example: a =. 2 5 7 + f a NB. 2, 5, 7, (2+5), (2+7), (5+7), (2+5+7) 2 5 7 7 9 12 14 * f a NB. 2, 5, 7, (2*5), (2*7), (5*7), (2*5*7) 2 5 7 10 14 35 70 The function 'f' should work for any verb and any size right argument noun vector. Skip Skip Cave Cave Consulting LLC ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
