Questions tagged [fibonacci-sequence]
The Fibonacci sequence is the sequence defined by F(0) = 0, F(1) = 1, F(n + 2) = F(n) + F(n + 1). The first few terms are 0, 1, 1, 2, 3, 5, 8.
192
questions
1
vote
1
answer
110
views
Fibonacci calculator
I'm trying to learn Rust and for this reason I'm reading the Rust Book. It contains the following exercise:
Generate the nth Fibonacci number.
Here's my take. Note I'm only using material from ...
0
votes
1
answer
125
views
Can I optimize my implementation of generating Fibonacci series using recursion?
My function accepts a number, which generates total Fibonacci numbers. I am using recursion.
Please follow the code below,
...
-3
votes
1
answer
181
views
Calculate the sum of even Fibonacci numbers
This is my solution for problem 2 of Project Euler using Python:
...
1
vote
3
answers
130
views
Printing the first n numbers of the Fibonacci sequence
I have written a code below for printing the first n fibonacci numbers,
the code is as follows
...
5
votes
0
answers
128
views
A Python 3 script that generates art using matplotlib
I am always super interested in both science and art, science and art are two different ways to describe the objective reality, they are two sides of the same coin, in many areas they overlap, and ...
1
vote
1
answer
437
views
Functional Fibonacci in OCaml
I'm very new to OCaml, and as an exercise I decided to implement the nth Fibonacci algorithm (return a specific Fibonacci number, given an index) in different ways, using what I've learned so far.
I ...
1
vote
1
answer
176
views
JavaScript function that generates Fibonacci like sequences of given order
Generalizations of Fibonacci numbers
Fibonacci numbers of higher order
A Fibonacci sequence of order \$n\$ is an integer sequence in which each
sequence element is the sum of the previous \$n\$
...
2
votes
1
answer
221
views
Python functions that calculate first n terms of a given order of Fibonacci sequences
I have written two functions that calculate the first n terms of a given order o of Fibonacci sequence, and return the result as ...
3
votes
1
answer
100
views
Iterative Fibonacci number generator in Kotlin
I have very limited experience in Java and slightly more in C# (just doing Advent of Code problems last month), so I'm not familiar with how to write idiomatic Kotlin.
This class implements an ...
2
votes
1
answer
431
views
Project Euler Problem #755
As the title indicates this is one of the last most problems of Project Euler. The problem is straightforward. However, similar to the rest of the Euler Project problems either ...
1
vote
1
answer
77
views
Generating the N-bonacci numbers
I'm new to Haskell, and this is one of the more interesting programs I've made with it so far. I understand there are already solutions to this problem that use much less code, but to me this one ...
0
votes
3
answers
144
views
Fibonacci generator python implementation
I wrote this code for a fibonacci sequence generator. Can anyone tell me whether my code is designed well? if not, why?
...
2
votes
2
answers
275
views
Cython Fibonacci Sequence
For my current job, I've been told that soon I'm going to be porting our Python code to Cython, with the intent of performance upgrades. In preparation of that, I've been learning as much about Cython ...
1
vote
1
answer
227
views
Fibonacci sequence array in Javascript
This is my third day of learning Javascript through an online class. I learned about arrays and while/for loops today, and to practice all of that stuff the challenge I'm working on is to make a ...
9
votes
3
answers
2k
views
n-th Fibonacci number with memoization
I am learning Rust and decided to create a simple program to calculate n-th Fibonacci number. It uses a vector for memoization. The program works, but what would you suggest to improve here? Maybe ...
1
vote
2
answers
925
views
6
votes
2
answers
816
views
C++17 Recursive Fibonacci calculation with memoization
Compiler is g++ 4.2. I'm new to C++, but I've done a lot of data science, web scraping, and some socketing stuff in Python. This code generates the nth Fibonacci number, either with a naive ...
1
vote
1
answer
409
views
MASM) assembly implementation of recursive Fibonacci
I'm trying to teach myself assembly via MASM, below is my first implementation of the recursive form of the fibonacci sequence. I timed it against an equivalent C implementation in release mode and ...
5
votes
2
answers
1k
views
Fibonacci sequence output
Here's the code I'm having trouble shortening. I am currently a beginner in Python 3.x.
...
5
votes
4
answers
2k
views
A Fibonacci series
I am having trouble with time and complexity analysis. I have done a fibonacci series in a recursive way. I think it is O(n2). Can you find out the time analysis? If possible, could you elaborate it?
<...
3
votes
1
answer
153
views
Fibonacci Sequence using Recursion with Memoisation
File fibonacci.aec:
...
3
votes
3
answers
918
views
Fibonacci series
I have written the following code for my 1st year project, the Fibonacci series. I programmed it without searching Google. Is my code good enough to get me an A or a B? Can I make the code more ...
4
votes
2
answers
1k
views
Recursive vs. non-recursive implementations of Fibonacci sequence
I have 2 functions to get the n-th fibonacci number. The 1st one uses recursive calls to calculate the power(M, n), while the 2nd function uses iterative approach for power(M, n). Theoretically (at ...
2
votes
2
answers
279
views
Fibonacci iterator
I've implemented the following Fibonacci iterator:
lib.rs
...
4
votes
5
answers
1k
views
Asking for Fibonacci numbers, up till 50
I am learning Python, and this is one of the program assignments I have to do.
I need to write code to prompt user to enter Fibonacci numbers continuously until it's greater than 50. If everything ...
3
votes
0
answers
71
views
Fibonacci and Lucas sequence generator using Boost and GMP
I implemented this console application that generates Fibonacci and Lucas sequence numbers using boost and GMP for multiprecision.
There is an iterator-like class which can do any sequence based on ...
0
votes
1
answer
75
views
Choosing between 2 Fibonacci alternatives [closed]
Task:
Return the fibonacci value at a given index.
e.g: input: 6, return: 8.
Algorithm 1:
...
0
votes
1
answer
98
views
Fibonnaci sequence calculation [closed]
Below are two ways to calculate an element of the Fibonacci series. Can someone please help me understand why fib1 is so much faster (over 60x) than ...
3
votes
1
answer
84
views
Implement Fibonacci range
I am implementing a Fibonacci range in C++17 such that it supports
...
2
votes
2
answers
119
views
Get the Nth Term in the Fibonacci Sequence
I'm trying out a new editor (CLion) and I decided to try an old well known programming problem. I also decided to try out C99 rather than C89.
This program calculates the nth term of the Fibonacci ...
12
votes
2
answers
1k
views
Calculating Fibonacci sequence in several different ways
I'm doing an experiment trying to freshen up my unit-testing and learn dynamic programming. Every test passes but I'm curious of the result of some of them and worried if I'm doing the testing ...
16
votes
5
answers
5k
views
Project Euler # 25 The 1000 digit Fibonacci index
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1
= 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
...
4
votes
4
answers
5k
views
Find the nth term of a sequence that consists of Fibonacci and prime numbers interleaved
I have given a series problem 1,2,1,3,2,5,3,7,5.... in which the odd terms forms the Fibonacci series and even terms form the prime number series. I have to write a code in which I have to find the ...
10
votes
8
answers
6k
views
Python program for fibonacci sequence using a recursive function
A Fibonacci sequence is the integer sequence of 0, 1, 1, 2, 3, 5, 8.....
The first two terms are 0 and ...
3
votes
3
answers
568
views
Calculate the nth Fibonacci number, mod m
I was trying to output F(n) mod m to find the remainder of Fibonacci number, where F(n) could be a very big number:
...
2
votes
1
answer
346
views
Fibonacci sequence binary tree console logger
I wrote code to show the structure of a Fibonacci sequence pattern in a graphical way. First I structure a tree given a variable the user inputs for how many iterations of the sequence they want to ...
4
votes
2
answers
2k
views
Foobar Challenge: Lovely Lucky Lambs
I've been able to reduce my solution to constant time. Is it possible to reduce this by any constant factor further? (Besides trivialities i.e. inserting constants, not lazy importing). Specifically, ...
4
votes
1
answer
185
views
Time(n) Complexity of Fibonacci Algorithms
It is my first use of classes in Python. I wanted to create something useful and try some new things as I learn this cool language: strategy pattern, testing with nanoseconds precision, curve/poly ...
3
votes
0
answers
362
views
Calculate huge Fibonacci Numbers in C++ using GMP and boost::multiprecision
Problem Statement
Calculate the exact value of the n-th Fibonacci number, say the one-billionth.
Algorithm
The algorithm is based on the idea that Fibonacci numbers can be represented as 2x2 ...
2
votes
2
answers
150
views
Write in file the n-th term in iccanobiF series
Siruri2 | www.pbinfo.ro
Fibonacci, a famous Italian mathematician in the Mediaeval Era, had discovered
a series of natural numbers with multiple applications, a string that
bears his name:
<...
0
votes
2
answers
1k
views
Fibonacci Nth term using tail recursion [closed]
I have created a program that prints the Nth term of the Fibonacci sequence. The fib function needs to use tail recursion. If what I have coded isn't tail recursion, I would like to know how to change ...
12
votes
2
answers
3k
views
Recursive Fibonacci in Rust with memoization
I'm trying to come up with an "elegant" way of calculating Fibonacci for number in Rust, using recursion and memoization (self-imposed requirements).
This is what I have so far:
...
0
votes
1
answer
2k
views
Javascript Fibonacci with dynamic programming
Trying to applying what seen on What Is Dynamic Programming and How To Use It (here: https://www.youtube.com/watch?v=vYquumk4nWw )
Obviuously this is the final code, after removing the recursion.
I ...
1
vote
2
answers
82
views
Output string length and classical Fibonacci sequence in a web page
I wrote a JavaScript and XHTML webpage. I think the format of the output is not better or the validation process is not as it is supposed to be. How can I improve the code? How can I make it more ...
7
votes
2
answers
4k
views
alternating Fibonacci and prime series
The task is to print the following series
1 2 1 3 2 5 3 7...
The elements at odd positions are Fibonacci series terms and the elements at even positions are ...
6
votes
2
answers
213
views
Project Euler #2 with a fibSequence and result
I have a background in Linguistics and my journey as an aspiring developer has just begun.
I was hoping you could give me a feedback on the solution I have come up with for the second challenge of ...
1
vote
1
answer
138
views
Display Fibonacci numbers
I just started coding programs with python. As a challenge I wanted to program something to print out the Fibonacci Numbers. It looks like I've done what I wanted to do (I checked the first few ...
6
votes
3
answers
2k
views
Performance of dynamic Fibonacci generator and dead rabbits
I would like to improve my code style and its efficiency.
I'm just moving beyond the standard recursive approach to a lot of simple algorithms.
This post has two code snippets with slightly ...
3
votes
1
answer
365
views
Fibonacci calculator in Haskell
I'm just starting to look into Haskell. I've written a naive Fibonacci implementation, and I've also written a more advanced one that uses tail-call recursion for efficiency.
...
5
votes
1
answer
1k
views
Dynamic Fibonacci algorithm in x86 (MASM)
My task was to implement this algorithm that uses memoization to calculate fibonnaci numbers:
...