Uses iterative simulation instead of recursive to avoid recursion limit.