Fine approach. I've before taken this route:
factors =: [: */&> [: { [: <@powers"1 [: |: 2&p:
powers =: {. ^ i.@:>:@:{:
2 p: 360 NB. prime ,: count
2 3 5
3 2 1
(powers L:_1) 2 3 ; 3 2 ; 5 1 [ boxdraw_j_ 1
+-------+-----+---+
|1 2 4 8|1 3 9|1 5|
+-------+-----+---+
factors 360 NB. typically raveled.
1 5
3 15
9 45
2 10
6 30
18 90
4 20
12 60
36 180
8 40
24 120
72 360
On 10/03/2017 08:00 AM, [email protected] wrote:
Date: Mon, 2 Oct 2017 15:14:42 -0700
From: Roger Hui<[email protected]>
To: Programming forum<[email protected]>
Subject: Re: [Jprogramming] (no subject)
Message-ID:
<camz_i_ay4dirb6vvgokazotxugaeqchq7ksidjbd0pjidtk...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
http://code.jsoftware.com/wiki/Essays/Divisors
What you have been asking for are computations on all possible subsets.
When dealing with all possible subsets, start with the boolean matrix
#:@i.@(2&^)@#
. You can then do B +/ .* x for all sums or B */ . (^~) x for all
products. Combinations are not the way to go because m comb n will get you
the indices for the subsets of size m, whereas you want subsets of size 0,
1, ..., n.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm