Given the following expression in J, how do I execute it n
times?
6?99
The only solution I could come up with was to turn it into a verb, which works nicely, but I suspect there's a better way:
(3 : '6?99')"0 i.100
Now, before anyone gets confused, this question is not about the specific expression 6?99
. It is a general question about the J programming language. Your answer should be general enough to apply to any J expression, not just 6?99
.
To evaluate an algebraic expression, you have to substitute a number for each variable and perform the arithmetic operations. In the example above, the variable x is equal to 6 since 6 + 6 = 12. If we know the value of our variables, we can replace the variables with their values and then evaluate the expression.
In the C programming language, an expression is evaluated based on the operator precedence and associativity. When there are multiple operators in an expression, they are evaluated according to their precedence and associativity.
To evaluate an algebraic expression means to find the value of the expression when the variable is replaced by a given number. To evaluate an expression, we substitute the given number for the variable in the expression and then simplify the expression using the order of operations.
The evaluation operator (=) EQUAL SIGN is used to evaluate a variable, function, or expression numerically. The Boolean equal to operator (=) CTRL+EQUAL SIGN is used to evaluate the equality condition in a Boolean statement. It is also used for programming, solving, and in symbolic equations.
Still turning it into a verb, but this time tacitly
(6 ? 99"_)"0 i.4
92 61 82 7 67 12
56 76 77 67 9 24
16 31 9 76 70 98
65 24 2 28 1 39
Depending on the verb this could be a little cleaner than explicit.
The usual way of doing this would be to make copies of the left argument, but I sense that is not what you would be looking for?
n=.4
6 ? n $ 99
43 55 79 71 35 33
41 56 67 3 78 24
38 34 7 61 14 13
95 63 43 47 73 29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With