Fibonacci challenge

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 35219 Views - Last Post: 13 May 2015 - 03:56 AM

#31 p.mo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 02-October 12

Re: Fibonacci challenge

Posted 02 October 2012 - 07:58 PM

This is my first post and challenge. While its not very compact should be functional functional.

Spoiler

Was This Post Helpful? 1
  • +
  • -

#32 HB-aka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 03-June 14

Re: Fibonacci challenge

Posted 09 June 2014 - 03:02 AM

this function will get Fibonacci numbers.
i used "long integers" because the number can get to big.
so...this is the code i'v made.
Spoiler

This post has been edited by Skydiver: 09 June 2014 - 08:22 PM
Reason for edit:: Put code in spoiler tags to keep challenge fresh for late comers.

Was This Post Helpful? 0
  • +
  • -

#33 tifuy95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-September 14

Re: Fibonacci challenge

Posted 26 September 2014 - 11:20 AM

I am a new programer can someone give me feedback on my code??
// Made by Max Bentata

//09/21/2014

#include <iostream>
using namespace std;



int main()
{
int x = 0; 
int fib = 0;
int sum = 1;
int marker = 0;


    cout << x << endl;
    x = fib + sum;
    cout << x << endl;
    fib = x + sum;
    cout << fib << endl;

    x = fib + sum;
    cout << x << endl;


    while (mkr < 15){
        sum = x + fib;
        cout << sum << endl;
        fib = sum + x;
        cout << fib << endl;
        x = fib + sum;
        cout << x << endl;
        marker++;
}

  return 0;
}


Was This Post Helpful? 0
  • +
  • -

#34 compscistud  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 21-October 14

Re: Fibonacci challenge

Posted 18 November 2014 - 01:20 AM

this was my assignment last week lol
Was This Post Helpful? 0
  • +
  • -

#35 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 755
  • View blog
  • Posts: 2,658
  • Joined: 31-December 10

Re: Fibonacci challenge

Posted 18 November 2014 - 12:04 PM

View Posttifuy95, on 26 September 2014 - 01:20 PM, said:

I am a new programer can someone give me feedback on my code??
// Made by Max Bentata

//09/21/2014

#include <iostream>
using namespace std;



int main()
{
int x = 0; 
int fib = 0;
int sum = 1;
int marker = 0;


    cout << x << endl;
    x = fib + sum;
    cout << x << endl;
    fib = x + sum;
    cout << fib << endl;

    x = fib + sum;
    cout << x << endl;


    while (mkr < 15){
        sum = x + fib;
        cout << sum << endl;
        fib = sum + x;
        cout << fib << endl;
        x = fib + sum;
        cout << x << endl;
        marker++;
}

  return 0;
}


One thing that stood out for me is that you use what are called "Magic Numbers", specifically, the while(marker < 15). What is that 15 supposed to represent? Would it be used more than once if this were a larger program? If so, what happens when you want to change the 15 to something else? You would have to go through the code and replace the number and hope that you don't miss any, or if you do, that it will be noticed and easily found.

The tip, would be to use a variable, specifically, a const variable that doesn't change throughout the program. This way, you can give the number a descriptive name which helps people reading the code to understand it a little easier. Also, it makes changing/maintaining the code easier because you only have to make the change in one place instead of many.
Was This Post Helpful? 0
  • +
  • -

#36 9644026902  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-November 14

Re: Fibonacci challenge

Posted 27 November 2014 - 08:03 AM

Spoiler

This post has been edited by Skydiver: 22 January 2015 - 10:48 PM
Reason for edit:: Put code in spoiler tags.

Was This Post Helpful? 0
  • +
  • -

#37 fj_j_greenhalgh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-December 14

Re: Fibonacci challenge

Posted 05 December 2014 - 06:04 PM

Template Metaprogramming C++11

Spoiler

This post has been edited by Skydiver: 22 January 2015 - 10:47 PM
Reason for edit:: Put code in spoiler tags.

Was This Post Helpful? 0
  • +
  • -

#38 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 4100
  • View blog
  • Posts: 13,080
  • Joined: 05-May 12

Re: Fibonacci challenge

Posted 22 January 2015 - 10:47 PM

fj_j_greenhalgh: See post #27.
Was This Post Helpful? 0
  • +
  • -

#39 its_MCD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 15

Re: Fibonacci challenge

Posted 21 February 2015 - 06:49 AM

I found a way to make a function for fibonacci's formula by using ading ect.
int fibonacci(){
    unsigned long long int nom1 = 0;
    unsigned long long int nom2 = 1;


    while(nom2 < 999999999){
        printf("%d \n",nom1 + nom2);
        int nom3 = nom1 + nom2;
        printf("%d \n",nom2 + nom3);
        nom1 = nom2 + nom3;
        printf("%d \n",nom3 + nom1);
        nom2 = nom3 + nom1;



    }


return 0;}


View Postits_MCD, on 21 February 2015 - 06:48 AM, said:

I found a way to make a function for fibonacci's formula by using ading ect.
int fibonacci(){
    unsigned long long int nom1 = 0;
    unsigned long long int nom2 = 1;


    while(nom2 < 999999999){
        printf("%d \n",nom1 + nom2);
        int nom3 = nom1 + nom2;
        printf("%d \n",nom2 + nom3);
        nom1 = nom2 + nom3;
        printf("%d \n",nom3 + nom1);
        nom2 = nom3 + nom1;



    }


return 0;}
sorry i don't know how the code should come
Was This Post Helpful? 0
  • +
  • -

#40 disceresui  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-April 15

Re: Fibonacci challenge

Posted 25 April 2015 - 10:50 AM

Reference: http://www.nayuki.io...acci-algorithms

I simply used the matrix exponentiation identity to achieve a runtime of O(n).
Also, the recursive version of the power function can reduce the runtime to O(logn).


Matrix Exponentiation
Spoiler

Was This Post Helpful? 0
  • +
  • -

#41 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 11315
  • View blog
  • Posts: 42,619
  • Joined: 27-December 08

Re: Fibonacci challenge

Posted 25 April 2015 - 11:23 AM

Solving the recurrence by hand, then using the closed form solution is actually faster than using the matrix multiplication method. A common approach to speed up matrix multiplication is to diagonalize the matrix and write it in terms of similar matrices. The diagonal matrix of eigenvalues are exactly the eigenvalues of the recurrence.

The matrix trick is still a neat one that many overlook! Good show with it. :)
Was This Post Helpful? 1
  • +
  • -

#42 santosh5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-May 15

Re: Fibonacci challenge

Posted 13 May 2015 - 03:56 AM

Here's my way of generating the Fibonacci numbers. The algorithm is same.

Spoiler

This post has been edited by Skydiver: 13 May 2015 - 08:53 AM
Reason for edit:: Put code in spoiler tags to keep this fresh for everyone.

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3