[Challenge] Fibonacci Sequence

Welcome to CPAElites - the original incentive CPA affiliate marketing forum online, solely based on "Cost Per Action".

Be a part of something great, join today! Learn CPA marketing with CPAElites, we will teach you everything such as the best CPA networks, CPA offers with highest payouts and best conversion rates, unsaturated CPA niches, most effective traffic sources and more.

Oloty

Well-known member
Joined
August 6, 2013
Messages
61
Reaction score
0
Heyy y'all,

I'm going to provide you with a snippet that solves for the Fibonacci sequence using two variables.
Write me a proof that explains why this works.
Alternatively, write your own piece of code using two variables.

Code:
static int[] Fib(int length)
{
    int x = 0;
    int y = 1;
    int[] fib = new int[length];
    for (int i = 0; i < length; i++)
    {
        fib[i] = y += x;
        i++;
        fib[i] = x += y;
    }
    return fib;
}
 

Jonte

Well-known member
Joined
August 27, 2013
Messages
72
Reaction score
0
Here's a simple Fibonacci sequence that I wrote in my class yesterday. It uses 4 variables but meh. Here it is anyways in good old VB.NET xD:

Code:
Public Class Form1
    Dim intNumber As Integer = 1
    Dim intFirstPrev As Integer = 1
    Dim intSecPrev As Integer = 0
    Dim intLoop As Integer


    Private Sub btnComp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComp.Click
        Do
            intLoop = intLoop + 1
            calculate()
            lstFib.Items.Add(intNumber)
        Loop Until intLoop = 10

    End Sub

    Sub calculate()
        intNumber = intFirstPrev + intSecPrev
        intSecPrev = intFirstPrev
        intFirstPrev = intNumber
    End Sub
End Class
 
 
Top Bottom