Seven Lines of Julia (examples sought)

Your code still wastes memory to create the useless vector fill(F, n). Also, it doesn’t support the case n=0. Just do this instead

Fn(x, n) = foldl((y,_) -> F(y), 1:n; init=x)

Edit: of course one can use a StaticArrays.SVector{3} to sqeeze out the last bit of performance.

3 Likes