문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top