3 ms·
I was reading the linked document titled "Quantum Programming in QCL" which contains the following definition of a Fibonacci function. As far as I can tell this
by lokedhs 10y ago
I was reading the linked document titled "Quantum Programming in QCL" which contains the following definition of a Fibonacci function. As far as I can tell this thing calculates nothing like the Fibonacci sequence. Can anyone explain what the thinking is behind this code?
int Fibonacci(int n) { // calculate the n-th
int i; // Fibonacci number
int f; // by iteration
for i = 1 to n {
f = 2*f+i;
}
return f;
}
- nylsaar 10y agoI don't even qualify as a novice, but it seems f(the first iteration) would need start with 0. With this sequence of numbers 1,1,2,3,5,8 it seems to be calculating f=0 as 2 * 0+1=1 ; f=1 as 2 * 1+1=3 ; f=2 as 2 * 2+1=5 ; f=3 as 2 * 3+2=8 ; then f=4 should be 2*5+3=13 I'm not sure how 2 is calculated unless i=0, but this is why I'm not even a novice.