Your original approach to the problem involved
mapping a boolean array to different values.
There is a set of techniques well-known from APL.  
For example:

   ] b=: 2 5 [EMAIL PROTECTED] 2
0 1 1 0 0
1 0 1 0 0
   
   4 + b       NB. 0 to 4, 1 to 5
4 5 5 4 4
5 4 5 4 4
   4 * b       NB. 0 to 0, 1 to 4
0 4 4 0 0
4 0 4 0 0
   4 ^ b       NB. 0 to 1, 1 to 4
1 4 4 1 1
4 1 4 1 1
   3 + 4 * b   NB. general linear transformation
3 7 7 3 3
7 3 7 3 3
   b { 4 7     NB. general transformation
4 7 7 4 4
7 4 7 4 4

The mapping used in the divisors problem is a 
variation of the 3rd one above, with a different 
mapping for each column:

   2 3 5 7 11 ^"1 b
1 3 5 1 1
2 1 5 1 1



----- Original Message -----
From: Arved Sandstrom <[EMAIL PROTECTED]>
Date: Thursday, November 23, 2006 2:26 am
Subject: [Jprogramming] Re: factors/divisors of a number

> Thank you for the advice. It made a lot more sense seeing that I'd 
> spentsome hours agonizing over the problem. What is really helping 
> me at this
> stage is seeing uses of @ and &, for example. I can usually figure 
> out the
> correct verbs - stringing them together is causing me most of my
> difficulties.
> 
> The link to the Essay on Divisors was most helpful.


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

Reply via email to