How to rewrite halve function in J?

in J programming language ,

-: i. 5 

the above function calculates the halves of all integers in [0,4]. Now let me say that I would like to rewrite the function: :, just for fun. So far i guessed

]&%.2

but it doesn’t seem to cut. How do you do this?

+3
source share
3 answers
%&2    NB. divide by two
0.5&*  NB. multiply by one half
+6
source

Note that]% 2: will also work, but to ensure the correct grammar, you either want to use this as a name definition or want to put the expression in parentheses.

+1
source

, %. , , , " ".

, , , , , , , , J, - , ( ) , , .

, , , , % .

, 101 (http://projecteuler.net/problem=101), Google Jsoftware.com. , , ax ^ 2 + bx + c = y, x y, a, b c. , , , , .

, Matrix Algebra, .

+1

Source: https://habr.com/ru/post/1724238/


All Articles