문제
I am a complete beginner to J. My first attempt at writing a function is something like the totient function. It takes an array, assumed to be i.num for some number, num. And then computes the number of elements coprime to the tally of the array.
If I do it manually like this:
numbers =: i.7
#(1=( #numbers)+./numbers)#numbers
it works. The result is 6.
So I want to turn this into a general function.
Tot =: monad :'(1=( #x)+./x)#x'
Tot i.11
This fails and I get a value error for x. I don't know why.
해결책
The monad's variable should be y
, not x
:
Tot =: monad :'(1=( #y)+./y)#y'
x
is the left argument of a dyad.
제휴하지 않습니다 StackOverflow