See also the "Divisors" essay in the J Wiki:
http://www.jsoftware.com/jwiki/Essays/Divisors



----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Wednesday, November 22, 2006 4:14 pm
Subject: Re: [Jprogramming] Avoiding fills

> Two of the possibilities for finding all divisors
> of a number:
> 
>   ] p=: q: 24
> 2 2 2 3
>   ] b=: #: i.2^#p
> 0 0 0 0
> 0 0 0 1
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> 0 1 0 1
> 0 1 1 0
> 0 1 1 1
> 1 0 0 0
> 1 0 0 1
> 1 0 1 0
> 1 0 1 1
> 1 1 0 0
> 1 1 0 1
> 1 1 1 0
> 1 1 1 1
>   b */ .(^~) p
> 1 3 2 6 2 6 4 12 2 6 4 12 4 12 8 24
>   ~. b */ .(^~) p
> 1 3 2 6 4 12 8 24
> 
>   __ q: 24
> 2 3
> 3 1
>   */&> , { (^i.@>:)&.>/__ q: 24
> 1 3 2 6 4 12 8 24
> 
> 
> 
> ----- Original Message -----
> From: Arved Sandstrom <[EMAIL PROTECTED]>
> Date: Wednesday, November 22, 2006 4:03 pm
> Subject: [Jprogramming] Avoiding fills
> 
> > Another novice question. I trying to get the factors of a number 
> > N. I use q:
> > to get the prime factors. As many of those as there are, say M, 
> I 
> > generatethe 2^M binary numbers using
> > 
> > #: i.(2^M)
> > 
> > For M=3 we therefore have
> > 
> > 0 0 0
> > 0 0 1
> > 0 1 0
> > 0 1 1
> > 1 0 0
> > 1 0 1
> > 1 1 0
> > 1 1 1
> > 
> > Now, any given item of this, when used as the left operand to #, 
> > with q: N
> > being the right, gives me a combination of prime factors that I will
> > multiply with */ to get a possible factor. I'd just finish off 
> > with ~. to
> > clean up the list of factors.
> > 
> > My problem is in taking that list of binary numbers and using 
> each 
> > item to #
> > the prime factors. In the above example the longest copy will 
> > result in a
> > list of shape 3, and so every result item has shape 3.
> > 
> > I had a really ugly work around that replaced all the zeros with 
> > one's,after doing the #, and seeing as how I followed with */ 
> that 
> > worked. But I
> > didn't like it.
> > 
> > Is there a more elegant solution? Or I should say, what might it 
> > be? Could
> > it involve boxes?


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to