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.
176
questions
5
votes
3answers
419 views
Outputting Fibonacci numbers
My program gets some input values and outputs Fibonacci values.
Generally, I'm adding single numbers from the right to left, and I'm saving it in the sum value and get rest of it and add to string. (...
14
votes
1answer
13k views
Recursive Memoized Fibonacci in C++
I was reading an article on Wikipedia about memoization, so I wanted to try and apply it. I am fairly new to this subject, so I thought I'd start small. Does the program use memoization correctly? Is ...
6
votes
2answers
246 views
Rob Pike's Golang presentation excercise of day 1
I'm following this presentation. At the very end there's an exercise about solving Fibonacci and says that instead of addition, make the operation setteable by a function.
Is the following is a good ...
5
votes
2answers
7k views
Calculate the Fibonacci sequence using bash
I would like your opinion on my shell script that prints the Fibonacci sequence.
...
0
votes
1answer
345 views
Fibonacci Sequence - Faster method?
Just decided to make a quickie Fibonacci Sequence via jQuery and I was wondering if anybody can think of a faster way to interpret it? I can type pretty much any number in and it returns in a fraction ...
9
votes
4answers
819 views
Project Euler #2 in Python
Here is my Python code for Project Euler #2:
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, ...
5
votes
1answer
691 views
Recursive Fibonacci generator
I decided to write a function that would generate an index of the Fibonacci sequence making use of Python's mutable default parameter. It's inspired by a question I answered on Stack Overflow where ...
12
votes
1answer
256 views
The dwindling Fibonacci
I've recently taken a renewed interest in non-standard languages like Brainfuck and TIS-100. I'm currently writing a Fibonacci generator in Brainfuck which differs a bit in approach from the usual ...
1
vote
1answer
370 views
SPOJ - POWFIB (Fibo and non fibo) Time Limit Exceeds
Problem
Find (a^b)%M, where
a = Nth non-fibonacci number
b = Nth fibonacci number modulo M
M = 1000000007
Consider fibonacci series 1,1,2,3,.....
INPUT
First line ...
7
votes
1answer
421 views
7
votes
4answers
19k views
Fibonacci sum with memoization
Problem:
Using the recursion approach, find a Fibonacci sum without repetition of computation.
...
6
votes
4answers
952 views
Two Fibonacci functions
These are two of tasks, which I had to do for the recruitment process to be started in some company. Unfortunately they didn't like it so I've decided to share it here for discussion.
Add up all the ...
2
votes
1answer
118 views
Avoid branching code for degenerate cases in Fibonacci generator
I was writing a simple function that would return the Fibonacci sequence up to the nth term and for whatever reason started wasting a lot of time on it. Here's what I came up with:
...
3
votes
1answer
251 views
Testing Fibonacci conjecture
The sequence of Fibonacci numbers is defined as F1 = 1, Fn = Fn−2 +
Fn−1. It has been conjectured that for any Fibonacci number F, F2 + 41
is composite.
... [T]ask is to either prove the ...
2
votes
1answer
205 views
Project Euler #2: sum of even Fibonacci numbers, using generators
I am currently working on Project Euler problem #2 which requires you to print the sum of all even fibonacci numbers below 4 million.
I just recently learned about generators and from my ...
3
votes
1answer
966 views
Finding the nth element of generalized Fibonacci sequences
I solved the Fibonacci Golf problem on checkio.org:
The Fibonacci numbers or Fibonacci sequence are the numbers in the
following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21...
This is not ...
2
votes
2answers
120 views
Sequence generation problem - Fibonacci
Below is the representation and user interface fib_sequence for generating a Fibonacci sequence:
...
3
votes
2answers
228 views
Sequence processing problems
Problem 1:
Sum the even numbers for the first n fibonacci numbers
Solution:
...
3
votes
1answer
1k views
Memoization of Fibonacci using generic Int => Int helper
I'm trying to understand memoization using Scala. I took the Fibonacci sequence as an example because of the high cost of recursively computing numbers in the sequence without memoization.
...
3
votes
1answer
5k views
Project Euler 25 - 1000-digit Fibonacci Number
I have recently completed problem 25 from the project Euler site.
The Fibonacci sequence is defined by the recurrence relation:
\$\qquad F_n = F_{n−1} + F_{n−2}\$, where \$F_1 = 1\$ and \$F_2 =...
69
votes
2answers
5k views
I HAZ A FIBO, RLY
First LOLCODE program, run here. This program inputs a Fibonacci number from the user, then determines and prints whether the number is in the Fibonacci series. What do you think?
...
2
votes
2answers
1k views
Tail Recursive Fibonacci
Please critique my implementation of a tail-recursive method for generating the Fibonacci sequence:
...
8
votes
3answers
2k views
Project Euler #2 (Fibonacci Sequence)
Challenge: 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, 89.
Consider a ...
6
votes
1answer
230 views
Evaluating Fibonacci-sequence-based recurrence relation (SPOJ Flibonakki)
I have a function fib2 which returning two values as Tuple but I want to print the product of tuples returned by function fib2. I am new to Haskell so please ...
12
votes
3answers
1k views
Lock-free thread-safe Fibonacci number generator
Here is my implementation of a lock-free thread-safe Fibonacci number generator. Is it correct? The idea is to use an immutable holder for previous and current numbers (since it's hard to change two ...
11
votes
8answers
1k views
Fibonacci checker
I wrote a simple Fibonacci checker using HTML, CSS, and JS. This is my first JS program, so be sure to tell me everything that is wrong with it. Check it out here (http://jsfiddle.net/z49fyypt/1/), ...
4
votes
1answer
996 views
Clojure Fibonacci
I'm a Clojure novice working through 4Clojure problems. In one problem I am supposed to create a function that takes a number and returns that number of Fibonaccis. My first thought was to create a ...
3
votes
2answers
168 views
Project Euler #2 in F#
Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million.
My first attempt at this problem using functional programming with F#. I would've liked to use some kind of ...
6
votes
2answers
2k views
Project Euler #2 Efficiency
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:
...
7
votes
4answers
172 views
2
votes
1answer
357 views
7
votes
1answer
1k views
Iterative Fibonacci sequence using standard library functions
We're all aware of Fibonacci sequence calculators but they look like C-style code. I want to avoid that and take advantage of the standard library. This code is very short, so I'm focusing on ...
10
votes
1answer
287 views
Project Euler #2 - Sum of even Fibonacci numbers to 4,000,000
This particular problem has already been posted here before, but the community is ok with me to post it again, so I can have feedback on my own implementation.
I tried to keep things simple, with ...
4
votes
1answer
71 views
Zeckendorf numbers the Clojure way
I'm just getting into Clojure, and I wanted to make sure I am writing code the "Clojure way". The challenge I took on is Zeckendorf numbers (fairly trivial).
...
20
votes
4answers
3k views
Project Euler #2 (Even Fibonacci numbers) in Swift
I figured working through Project Euler problems in Swift would be a good way to learn any tips or tricks. For example, tuples are something I'm not used to using, but they proved useful here. Using ...
8
votes
6answers
9k views
Program for finding Fibonacci primes
I think it could have been designed with more object orientation. I don't like how one of my methods calls another from within the method, but I wasn't sure how to return the result because it is a ...
12
votes
2answers
819 views
Project Euler #2 Even Fibonacci numbers
Problem:
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, 89, ...
...
5
votes
2answers
343 views
Comparison of Fibonacci (Multinacci) Functions in Python3
After coming up with a formula on this Stack Overflow question, defeating recursion limits and finding a few new ways of calculating these numbers (as per this Stack Overflow question), I decided that ...
12
votes
5answers
7k views
Dynamic programming with Fibonacci
I have written the following code using a dynamic programming technique. Can I use ArrayList here? Please let me know if I can improve this code.
...
6
votes
1answer
3k views
Memoized Fibonacci
I went ahead and implemented a method to calculate Fibonacci numbers using memoization.
...
12
votes
4answers
464 views
I'm not sure if I still love Fibonacci, but my code is getting better. How much better?
Technically, this is a follow up to these two questions, but I have taken a radically different approach.
Everybody Loves Fibonacci
Does everyone still love Fibonacci
I finally allowed myself to be ...
5
votes
1answer
1k views
Fibonacci number function: convert to tail-recursion?
I've been implementing a function for calculating the nth Fibonacci number in F#. So far the best implementation I could come up with is this:
...
32
votes
4answers
2k views
Standardly deviated Fibonacci
I'm new to C++ (about 4 weeks with no prior programming experience in other languages) and am writing a program that's supposed to do the following:
Define an array of 100 sequential numbers of type <...
12
votes
3answers
1k views
Does everyone still love Fibonacci?
I'm following up on this question. I made a few decisions about my model and implemented recommendations accordingly.
TL;DR the link
Uses a loop algorithm to return a Fibonacci number \$Fn\$ of ...
40
votes
4answers
5k views
Everyone loves Fibonacci
I was bored and burnt out on more serious projects.... until I saw this Computerphile video on YouTube. Now I'm inspired again. Now I feel like spending some time implementing that recursive algorithm ...
2
votes
2answers
306 views
Testing whether sums of cubes are Fibonacci numbers
I'm trying to iterate through all the combinations of pairs of positive long integers in Java and testing the sum of their cubes to discover if it's a Fibonacci ...
4
votes
3answers
746 views
How would you count in the Fibonacci Sequence?
I was wondering if I did this in a remotely acceptable way:
...
7
votes
2answers
8k views
Calculate fibonacci in O(log n)
This program calculates the \$n\$th fibonacci number, in \$O(\log n)\$ time. I'm looking for code review, optimizations, and best practices.
...
8
votes
4answers
2k views
Another even Fibonacci numbers implementation
This is intended as something of a comparative study. I'm including not just one, but two separate implementations of code to implement the Project Euler problem to sum the even Fibonacci numbers up ...
7
votes
1answer
1k views
Four algorithms to find the Nth Fibonacci number
I'm implementing some basic algorithms in Go as an introductory exercise. Here are four different algorithms to find the Nth Fibonacci number.
I'm looking for general feedback, but I'm specially ...