fibonacci Questions
3
Solved
Here's the code I wrote for finding the n-th Fibonacci number:
unsigned long long fib(int n)
{
unsigned long long u = 1, v = 1, t;
for(int i=2; i<=n; i++)
{
t = u + v;
u = v;
v = t;
}
...
13
Solved
In Haskell, how can I generate Fibonacci numbers based on the property that the nth Fibonacci number is equal to the (n-2)th Fibonacci number plus the (n-1)th Fibonacci number?
I've seen this:
fi...
4
Solved
In Excel, I would like to round to the nearest fibonacci number.
I tried something like (sorry with a french Excel):
RECHERCHEH(C7;FIBO;1;VRAI) -- HLOOKUP(C7, FIBO, 1, TRUE)
where FIBO is a nam...
Lightweight asked 28/6, 2011 at 15:47
22
Solved
I know how to make the list of the Fibonacci numbers, but I don't know how can I test if a given number belongs to the fibonacci list - one way that comes in mind is generate the list of fib. numbe...
10
I have a question on my homework for class and I need to know how to return nth number of Fibonacci sequence using iteration (no recursion allowed).
I need some tips on how to do this so I can bet...
4
Solved
I have the memoization fibonacci code and I am having trouble figuring out what the time complexity is of it:
function fibMemo(index, cache) {
cache = cache || [];
if (cache[index]) return cache...
Levulose asked 6/3, 2017 at 3:52
14
Solved
I am new to python, and I was wondering if I could generate the fibonacci series using python's list comprehension feature. I don't know how list comprehensions are implemented.
I tried the follow...
Overcast asked 21/2, 2017 at 14:44
16
Solved
I am following the go tour on their official website and I have been asked to write a Fibonacci generator. Here it is:
package main
import "fmt"
// fibonacci is a function that returns
// a fu...
24
Solved
I know there is nothing wrong with writing with proper function structure, but I would like to know how can I find nth fibonacci number with most Pythonic way with a one-line.
I wrote that code, b...
17
function fib(n) {
const result = [0, 1];
for (var i = 2; i <= n; i++) {
const a = (i - 1);
const b = (i - 2);
result.push(a + b);
}
return result[n];
}
console.log(fib(...
Overturn asked 30/6, 2018 at 4:59
10
Solved
I'm trying to recall an algorithm on Fibonacci recursion. The following:
public int fibonacci(int n) {
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci...
13
Solved
The following Q&A covers a few methods of generating Fibonacci numbers in Swift, but it's quite outdated (Swift 1.2?):
Sum of Fibonacci term using Functional Swift
Question: How could we ge...
10
Solved
Project Euler problem 25:
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, ...
21
I need to make a program that asks for the amount of Fibonacci numbers printed and then prints them like 0, 1, 1, 2... but I can't get it to work. My code looks the following:
a = int(raw_input('G...
Pilfer asked 17/10, 2010 at 15:0
5
Solved
Is there a way to get the last number from the range() function?
I need to get the last number in a Fibonacci sequence for first 20 terms or should I use a list instead of range()?
14
Solved
I'm new to Javascript and was reading up on it, when I came to a chapter that described function recursion. It used an example function to find the nth number of the Fibonacci sequence. The code is...
9
Solved
I have a homework assignment that I'm stumped on. I'm trying to write a program that outputs the fibonacci sequence up the nth number. Here's what I have so far:
def fib():
n = int(input("Please...
Bristol asked 4/4, 2013 at 19:59
17
Solved
Is there any algorithm to compute the nth fibonacci number in sub linear time?
Brose asked 6/10, 2009 at 13:16
5
Solved
I've created a memoized function of the recursive version of fibonacci.
I use this as an example for other kinds of functions that would use memoization.
My implementation is bad since if I include...
Wye asked 5/3, 2015 at 5:53
16
Solved
#include <iostream>
using namespace std;
int main()
{
int num1 = 0;
int num2 = 1;
int num_temp;
int num_next = 1;
int n;
cin >> n;
for (int i = 0; i < n; i++){
cout <<...
10
Solved
Fibonacci numbers have become a popular introduction to recursion for Computer Science students and there's a strong argument that they persist within nature. For these reasons, many of us are fami...
Underbody asked 31/12, 2010 at 18:24
4
Solved
I started Project Euler. I am on problem 2 and came up with this code to come up with the sum of even fibonacci numbers up to 4 million. The code seems to do pretty much what I want it to. I do see...
Astrix asked 19/8, 2015 at 3:14
25
Solved
#!/usr/bin/python2
"""
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 8...
52
Solved
var x = 0;
var y = 1;
var z;
fib[0] = 0;
fib[1] = 1;
for (i = 2; i <= 10; i++) {
alert(x + y);
fib[i] = x + y;
x = y;
z = y;
}
I'm trying to get to generate a simple Fibonacci Sequence b...
Mulch asked 30/10, 2011 at 9:50
24
Solved
I was wondering about how can one find the nth term of fibonacci sequence for a very large value of n say, 1000000. Using the grade-school recurrence equation fib(n)=fib(n-1)+fib(n-2), it takes 2-3...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.