Questions tagged [fibonacci]
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.
2,364
questions
1
vote
3
answers
39
views
Variable assignment difference [duplicate]
I'm currently on an exercise to produce the position of a given Fibonacci number.
My initial code was :
n = int(input())
a = 0
b = 1
new_list = []
for i in range(n+1):
new_list.append(a)
a = ...
-1
votes
0
answers
12
views
MIPS Fibonacci Series
Need to diplay the nth number of the fibonacci series using MIPS assembly language.
Code:
.data
n: .asciiz "n= "
ans: .asciiz "ans= "
.text
main:
li $v0, 4 #printf("n= &...
0
votes
2
answers
70
views
Fibonacci sequence javascript on a loop
I'm studying and making exercise of the Fibonacci sequence and I don't understand where is the "i" value goes to?
function fibonacciGenerator (n) {
var output = [];
if (n === 1) ...
-4
votes
0
answers
25
views
How to optimize Recursive Fibonacci in Python [duplicate]
I've implemented the Fibonacci sequence in Python using a recursive approach, as shown below:
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-...
-5
votes
0
answers
28
views
How to print fibonacci series in python? [closed]
a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
I have tried solving these question but it was ...
-3
votes
0
answers
53
views
How to print fibonacci series in C++? [duplicate]
fibonacci series is aa series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers.
I want how to print fibonacci series in c++.
it is a little bit confusing, i ...
-1
votes
3
answers
150
views
How to calculate nth term of higher order GENERALIZED Fibonacci sequence using matrix exponentiation in C++? [duplicate]
I am interested in calculating the nth term of higher order Fibonacci sequence in C++, using matrix exponentiation, while allowing n to be reasonably large (in the range of hundreds).
The sequences I ...
0
votes
1
answer
54
views
Modifying prolog code to generate a list of lists
I have this Prolog code that generates a list of the Fibonacci numbers up to N.
Giving for example
?- fib(L, 3)
L=[0,1,1,2]
% Define the Fibonacci sequence
fibb(0, 0).
fibb(1, 1).
fibb(N, F) :-
...
-1
votes
1
answer
46
views
fibonacci number in dart [closed]
** fibonacci series **: a series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
void main() {
List fi = ...
0
votes
2
answers
50
views
Staircase problem - Varying base cases in different coditions
This questiion is related to
Staircase problem - explanation of recursive approach
But about the base cases.
One variation of the problem is as follows:
There are n stairs, a person standing at the ...
1
vote
1
answer
70
views
Staircase problem - explanation of recursive approach
The problem goes like this:
There are n stairs, a person standing at the bottom wants to climb stairs to reach the nth stair. The person can climb either 1 stair or 2 stairs at a time, the task is to ...
2
votes
1
answer
59
views
What's wrong with my variable assignment?
I'm trying to code a fibonacci function that takes an input int as length of sequence. Here's my code:
function fib {
local len=$1
echo "len = $len"
local arr=(0 1 1)...
0
votes
2
answers
92
views
Return the number of nodes in Fibonacci Recursion
I want to write a function that returns the number of nodes in the Fibonacci recursion tree, knowing that the number of nodes equals the number of additions required to compute the n-th Fibonacci ...
-1
votes
0
answers
22
views
How do you convert a list of numbers into binary without the bin() function? [duplicate]
I am supposed to create a program that first generates a number of terms in the Fibonacci sequence then convert the entire list of numbers into binary without the bin() function.
I got the first part ...
3
votes
2
answers
215
views
Fibonacci using DCG
I am in the process of trying to create the fibonacci series using DCG in prolog. I have this for starters, however I have no idea why the code is not being carried out.
Here is the code below:
fib --&...
2
votes
2
answers
128
views
Fibonacci for letters
I was programming a code for a case provided by my university. It was about making a Fibonacci function, but for letters. For example, if f(0) -> a, f(1) -> b, then f(2) -> ba, and so on. I ...
-1
votes
0
answers
83
views
the most optimal, recursive algorithm for calculating Fibonacci numbers [duplicate]
Is there a more optimal,recursive algorithm for calculating Fibonacci numbers than this?
unordered_map<int, long long> memory;
long long fib(int n)
{
if (n<=1) return n;
if (memory....
1
vote
0
answers
49
views
R while loop for fibonacci numbers smaller than 1 million [closed]
Like the title says, I have to write a short block of code which saves the fibonacci numbers smaller than 1 million in a vector using a while-loop. The code I wrote runs for such a long time that I ...
0
votes
5
answers
238
views
Dynamic Fibonacci program
Not entirely sure if I implemented it correctly, but I tried to use memoization for this fib programme and it turns out to be slower than if I just ran it without,
does anyone know why this is ...
-4
votes
2
answers
58
views
Fibonnacci sequence in 6502 assembler
I am trying to build a Fibonacci sequence in a 6502 assembler. It needs at least one add function, a least one branch function, and at least one compare function. I know how to add and store integers, ...
0
votes
1
answer
71
views
General Memoization function in F#
I have a question about this general memoization function in Fsharp:
let memoize f =
let dict = new Dictionary<_,_>()
fun n ->
match dict.TryGetValue(n) with
| (true, ...
0
votes
0
answers
20
views
Recursive fibonacci series not working well [duplicate]
I recently tried recursive programming in c and I tried to implement the same logic as a loop but in a recursive manner. I tried printing the answer in two places. One in the main function and one in ...
1
vote
1
answer
53
views
which numbers among the first N Fibonacci numbers can be given in the form (1 less than a certain cube)?
I have the task to determine all numbers among the first N Fibonacci numbers that can be given in such a form: w^3 - 1.
For example, i have such a simple part of the program:
public static List<...
0
votes
1
answer
58
views
I'm trying to make the Fibonacci sequence but each digit is a specific coloured square, how do I do it?
I am trying to make a piece of code in python that generates the Fibonacci sequence and then colour code each digit.
So far I have:
import time
a = 1
b = 1
while True:
al = str(list(str(a)))
bl = ...
-1
votes
3
answers
113
views
"How can I optimize a recursive algorithm for calculating Fibonacci numbers in C++?" [closed]
I'm working on a project that involves calculating Fibonacci numbers in C++ using a recursive algorithm. My current implementation follows the traditional recursive approach, but it exhibits ...
2
votes
3
answers
77
views
Trouble understanding Fibonacci Series
def fibo(n):
if n <= 0:
return []
elif n <= 1:
return [1]
elif n <= 2:
return [0, 1]
else:
fibo_s = fibo(n - 1) # Can someone please explain ...
1
vote
3
answers
50
views
Printing the recursive calls for fibonnaci numbers
How to print the result of the fibonnaci recursive calls such that the output looks like this
Rec results is
Fib(1) is: 1
Fib(0) is: 0
Fib(2) is: 1
Fib(1) is: 1
Fib(3) is: 2
Fib(1) is: 1
Fib(0) is: 0
...
0
votes
2
answers
10
views
How I append the list of Fibonacci series using Generator?
I tried to print appending list, but I get "None" in the output. When I debug the python code it displays list with series.
`def fib():
a,b = 0, 1
while True:
yield a
...
-1
votes
2
answers
51
views
Python Fibonacci trouble understanding a, b = b, a +b
Dear members I have a query, I understand the concept from the below :
https://stackoverflow.com/a/21990958/22419694
Python a, b = b, a +b
but what if we code the program this way ?
n=int(input("...
0
votes
1
answer
28
views
I am facing this problem and I don't know how to solve it ( Syntax error at input '[' )
fib_extension_levels = [0.0, 0.382, 0.618, 1.0]
The error is on the top line
error message : Syntax error at input '['
I tried to solve it myself but didn't know ...... Tried to solve it with chatGPT ...
0
votes
0
answers
39
views
WASM+UDF in ScyllaDB, test the performance of WASM
I want to test the performance of WASM in ScyllaDB.While I use the Fibonacci(n=50),showing
InvalidRequest: Error from server: code=2200 [Invalid query] message="UDF error: Calling wasm function ...
0
votes
0
answers
63
views
limited Fibonacci sequence
I want to implement a function that generates the Fibonacci sequence from N to N+K and returns array[K] items, with terms (0<=N<=370; 0<=N+K<=371; 0<=K<=255).
the last try n2 is out ...
0
votes
1
answer
26
views
How the local instance is not reset during an recursive call in python
I was practicing a problem to find the nth number of a Fibonacci series using dynamic programming.
Here is my python code:
def fib(n,memo=[1,1]):
if n<=len(memo):
return memo[n-1]
...
1
vote
2
answers
71
views
Printing inside of a function without changing the return type
I am trying to calculate n fibonacci numbers. This works, but i want to print every number calculated on the way to n, which seems to manipulate the return type of the function.
I'm a haskell beginner ...
0
votes
2
answers
273
views
Execution time of recursive Fibonacci function is slower in C than equivalent Nim and Pascal code
At this link there is a benchmark about a recursive Fibonacci function written in various languages. I tried some examples(specifically Nim and Pascal) and verified that the execution time was about ...
1
vote
1
answer
94
views
Even Fibonacci Numbers
I have write this code
function fiboEvenSum(n) {
const array = [1, 2];
const array2 = [];
let sum = 0;
for (let i = 2; i < n; i++) {
num = array[i - 2] + array[i - 1];
array....
3
votes
1
answer
119
views
Delaunay triangulation of a Fibonacci sphere
I have generated a set of (x,y,z) coordinates on a unit sphere using the Fibonacci sphere algorithm. Plotted with a 3d scatter plot, they look alright:
https://i.imgur.com/OsQo0CC.gif
I now want to ...
0
votes
1
answer
270
views
Fibonacci sequence in RISC V using recursion
I am trying to write a recursive function in RISC-V where it calculates the Fibonacci sequence in RISC V of a number n, in this case n=7. So the expected answer of fib(n) where n=7 should be 13.
addi ...
0
votes
1
answer
42
views
Recursive function with table values
I have a table evenfib that looks like this:
id
n
1
10
2
100
3
1000
I need to get sum of all even Fibonacci numbers that are lower than the given number n
I figured out how to get a fiboacci ...
0
votes
1
answer
48
views
Find fibonacci series upto N terms using list comprehension
Need to find the Fibonacci series up to N terms.
n=int(input("Enter the n terms: "))
f_val=0
fib_list=[f_val:=f_val + i for i in range(n)]
print(fib_list)
While executing the above program, ...
0
votes
0
answers
19
views
How to deal with Infinite Loop in Fibonacci in Assembly X86-64? [duplicate]
I'm working on x86-64 assembly language on my MacOS on VIM and I'm trying to be able to print the nth number of the fibonacci sequence.
Unfortunately I get an infinite loop that says "The 1th ...
-1
votes
1
answer
75
views
fibonacci sequence in mips assembly
So, I have been trying for two days to write a program in mips assembly to exercise for my exams in a few days but yeah, my brain keeps lagging and I don't understand how it should work and what I ...
1
vote
4
answers
210
views
Efficient implementation of the N fibonacci numbers using complex algorithm
I am looking for an even faster method of calculating the first N fibonacci numbers. I am already aware of the recursive method of solving this problem using memoization as well as the simpler method ...
0
votes
1
answer
45
views
Memoization of recursive calls on separate lines
I am attempting to solve Leetcode problem 70 by first trying to visualize the tree and then implement the solution. The tree is simple in that the left branch is a single step and the second branch is ...
-1
votes
4
answers
162
views
Looking for a good way to use openMP with recursive code?
I wanted to optimize recursion with openMP. So, I started from this question:
best-way-to-parallelize-this-recursion-using-openmp
While looking to optimize recursive functions I was first interested ...
2
votes
1
answer
97
views
Finding a path between two nodes in a k-th order fibonacci tree
There is a binary fibonacci tree where the left subtree has order(n-2) and right subtree has order(n-1). When we construct the tree, we label the nodes in pre-order way with root starting with 0, so ...
0
votes
0
answers
23
views
I have this MIPS code for a Fibonacci Function. How can I extend the code for printing the given position in terminal?
I have this MIPS code for a Fibonacci function,one pass a natural number in terminal and the program returns the Fibonacci number in that position, but it's not working, how can I modify the code to ...
0
votes
0
answers
64
views
MIPS assembly code about Fibonacci function
I am working on a Fibonacci function using MIPS assembly code, which initially make F(0) = F(1) = 1, and produces two results: $v0 for indicating whether the n for F(n) is negetive or not(the value is ...
-3
votes
1
answer
98
views
fibonacci with huffman Encoding
If the frequencies of n symbols are represented by the first n Fibonacci number
(1,1,2,3,5,…), then what is the average number of bits required to represent the n
symbols by Huffman coding algorithms?
...
0
votes
3
answers
183
views
Find Fibonacci prime numbers [closed]
#include <stdio.h>
int main(void) {
int n1 = 0, n2 = 1, n3, count, input_num;
printf("Please enter the number of terms: ");
scanf("%d", &input_num);
...