Tracy Harms wrote:
> Recently I enjoyed producing the sequence of
> triangular numbers through the following code:
>
>    +/\}.i.>:
     Just curious and always trying to understand.

Following the e-mail thread you started about triangular numbers
triggered me in trying to understand what's going on in the result of
your experiment.

What I noticed is the following;

  ,/\i.>: 4
0 0 0 0 0
0 1 0 0 0
0 1 2 0 0
0 1 2 3 0
0 1 2 3 4

What I see is a redundant first row and first column compared to

  ,/\>:i. 4
1 0 0 0
1 2 0 0
1 2 3 0
1 2 3 4

leading to
  +/\>:i. 4
1 3 6 10

So by swapping i. and >: you may omit }. if I'm right?
Or is it just a matter of: there are several ways to compose this sentence.

A single number will be given by:

  triN=: +/\>:@:i.
  triN 3
6

Here are some variants

trigonNum=: -:@:(*>:)
or
trigonNum=: [:-:(*>:)
[: by following the e-mail thread ;-)

And how about all the other xxx-gon numbers?
f.i.

pentagons=: [:+/\ >:@:(3*])@:i.
hexagons=: [:+/\ >:@:(4*])@:i.

   pentagons 5
1 5 12 22 35

   hexagons 5
1 6 15 28 45

I translated this more or less from the Haskell functions:
pentagons = scanl1 (+) [1,4..] :: [Int]
hexagons = scanl (+) [1,5..] :: [Int]


Your experiment in some way did remind me to what
T.S. Elliot said:
   "poetry can communicate before it is understood" ;-)

...hoping you don't bother this comment,

@@i<=>arie


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

Reply via email to