Studio/SimpleExamples

From J Wiki
Jump to: navigation, search

In the following examples, the user's entry is indented 3 spaces to distinguish it from the computer's response.

   q=. 2 3 5 7 9                define q

   1 + 2 * q                    1 plus 2 times q
5 7 11 15 19

   +/ q                         sum q
26

   */\ q                        partial products of q
2 6 30 210 1890

   p=. 1 2 3 2 2                define p

   p </. q                      classify q by p
+-+-----+-+
|2|3 7 9|5|
+-+-----+-+

   p +//. q                     sum q classified by p
2 19 5

   p /:~ q                      sort q in order of p
2 3 7 9 5

   p % q                        p divided by q
0.5 0.6666667 0.6 0.2857143 0.2222222

   p % x: q                     p divided by rational q
1r2 2r3 3r5 2r7 2r9

   +/\ p % x: q                 partial sums
1r2 7r6 53r30 431r210 1433r630