Fred Bone wrote:
> Cat=:3 : 0
> k =. +./+./ _ q: y
> 'H W' =. x: k %: y
> (+/ W ^ i.k),(W^i.>:k)+/ .*H^i.->:k
> )
This appears to do it. The verb gives correct results on more extensive
test input, and is better than other solutions I have seen. When the
problem was originally posed in 1991 integers were 32-bit, so behavior of
q: is not an issue.
input=:0 : 0
1 1
216 125
5764801 1679616
1024 243
2 1
4 1
1024 1
371293 248832
11 10
1 1
1048576 59049
483736625 481890304
125 64
64 1
81 64
)
output=:0 : 0
0 1
31 671
335923 30275911
121 3367
1 3
2 7
10 2047
22621 1840825
1 21
0 1
29524 4017157
615441 1931252289
21 369
6 127
9 217
)
(".&><;._2 output) -: Cat"1 ".&><;._2 input
1
John
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm