user3234709
user3234709

Reputation: 405

Add ordinal number column to output of custom verb in J

If I type !i.10 it gives the factorial of first 10 numbers. However if I try to add a column of ordinal numbers >/.!i.10, 1+i.10, then J freezes or I get an "Out of memory" error. How do I create custom tables?

Upvotes: 1

Views: 92

Answers (1)

bob
bob

Reputation: 4302

I think that what is happening is that you are creating something much bigger than you expect. Taking it in steps:

   1+ i. 10 NB. list of 1 to 10
1 2 3 4 5 6 7 8 9 10
   10 , 1+ i. 10 NB. 10 prepended
10 1 2 3 4 5 6 7 8 9 10
   i. 10 , 1+ i. 10 NB. creates an 11 dimension array with shape 10 1 2 3 4 5 6 7 8 9 10 and largest value of 36287999

When you apply ! to that i. 10 , 1+ i. 10 you get some very large numbers. I am not sure what you are trying to do with the leading >/.

Is this what you had in mind?

   (!1 + i.10),. (1+i.10) NB. using parenthesis to isolate operations
       1  1
       2  2
       6  3
      24  4
     120  5
     720  6
    5040  7
   40320  8
  362880  9
3.6288e6 10

To give extended type and get rid of the 3.6288e6 we can use x:

 (x:!1 + i.10),. (1+i.10)
      1  1
      2  2
      6  3
     24  4
    120  5
    720  6
   5040  7
  40320  8
 362880  9
3628800 10

or tacit

   (x:@! ,. ]) @ (1+i.) 10
      1  1
      2  2
      6  3
     24  4
    120  5
    720  6
   5040  7
  40320  8
 362880  9
3628800 10

Or a version I find a little better

   ([: (,.~ !) 1x + i.) 10
      1  1
      2  2
      6  3
     24  4
    120  5
    720  6
   5040  7
  40320  8
 362880  9
3628800 10

Upvotes: 2

Related Questions