In anhn's code, the performance degradation from the function call and recursion was offset by the exponential growth approach. I was trying to point out that for the linear growth implementations, your code would have been fast if you avoided Mod and implemented something similar to link.