My attempt at making a verb that finds the total of all proper divisors of an
integer seems to work.
e.g. if n = 12, the sum of proper divisors is 1 +2 +3+4+6 = 16 (note 12 is not
included)
This verb is actually equal to the "sigma function" minus n.Wikipedia
explanation: http://en.wikipedia.org/wiki/Divisor_function
(I essentially used the equation for sigma_x(n) where x = 1)
my verb:
sum =.(((*/@:-&1@:{.)%~(*/@:-&1@:({.^(1&+@:,@:}.))))@:(2&p:))-]
This seems ok, but is not aesthetically pleasing, and seems to be very
bracketty, and given that the mathematical equation is pretty concise I am
surprised the J verb is so long. If anyone knows a nicer way of doing this I
would be grateful to see it.
Regards.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm