final nonrecursive version
towers(n,i,a,f)