← Back to context

Comment by numpad0

2 days ago

this doesn't need if statement but 3 variables: nm2 = 0; nm1 = 1; n; f_next(){n = nm1 + nm2; nm2 = nm1; nm1 = n;}

Fibonacci sequence is defined as "F0 = 0, F1 = 1, Fn = F(n-1) + F(n-2)". The author implemented F1 as a special case but it doesn't need to be. That's the weird part.