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.
5
votes
2answers
115 views
Print routes on the stairway when only 1 or 2 steps are possible
Given a staircase with N steps, you can go up with 1 or 2 steps each
time. Output all possible ways you go from bottom to top.
I'm looking for code review, best practices, optimizations etc. ...
2
votes
2answers
135 views
Fibonacci series, topdown and bottom up approaches, stairway climbing
I have solved fibonacci series and then used the topdown and bottom up approaches to solve it. Also I have included the stairway climbing question as follows "You are climbing a stair case. Each time ...
0
votes
1answer
63 views
Time Limit Exceed Problem [closed]
When I submitted below code in codepad.org, it shows "Time limit exceed" problem. Please provide alternative solution :
Problem Statement :
Given a number K, find the smallest Fibonacci number that ...
5
votes
3answers
79 views
Is this Fibonacci function right?
Is this a correct method of Fibonacci with recursion?
function fibb($limit,$first_numer=0,$second_number=1){
echo $first_numer."\n";
echo $second_number."\n";
if($limit > ...
3
votes
2answers
74 views
More efficient solution for Project Euler #2 (sum of Fibonacci numbers under 4 million)
I would like to get some feedback on my code. I am starting to program after doing a few online Python courses.
Would you be able to help me by following my track of thinking and then pinpointing ...
11
votes
4answers
356 views
Fibonacci sequence in C
I'm very new to C, so pointing out better ways of doing things, errors, bad practices, etc would be optimal at this stage.
Code on GitHub
#include <stdio.h>
#include <stdlib.h>
int ...
3
votes
3answers
276 views
Project Euler Question #2: Sum of even Fibonacci numbers under 4 million
The question is:
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, ...
4
votes
0answers
53 views
Optimize RecursionArray interface
I created a class a while ago that I named a "Recursion Array". It is a way to create dynamically memoized sequences such as the Fibonacci sequence or the factorial numbers sequences. The concept is ...
1
vote
1answer
104 views
Better way of calculating Project Euler #2 (Fibonacci sequence)
Even Fibonacci numbers
Problem 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, ...
2
votes
3answers
106 views
Does this code violate the Single Responsibility Principle?
This is my solution to Project Euler problem 2:
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
The class ...
3
votes
2answers
107 views
Fibonacci using cache
This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (fibResults), it's very very fast.
fibResults = []
defaultMax = 1000
nrMax = defaultMax
fibonacci = (n) ...
2
votes
2answers
115 views
Returning a Fibonacci list
def fib_m_through_n(m, n):
"""(number, number) -> list
A function which returns a list containing the mth through the nth
fibonacci numbers.
SHOULD BE MODIFIED IN THE FUTURE so it ...
0
votes
1answer
316 views
Fibonacci generator with golang
This is my fibonacci generator:
package main
import "fmt"
func main() {
for i, j := 0, 1; j < 100; i, j = i+j,i {
fmt.Println(i)
}
}
It's working, but I don't know how can I ...
2
votes
2answers
551 views
Fibonacci sequence implementation
This was too slow for my computer:
int f(unsigned int x)
{
if(x <= 1) return 1;
else return f(x-1)+f(x-2);
}
/* main */
int main()
{
for(int i = 0; i < 50; i++) cout << f(i) ...
2
votes
3answers
544 views
Project Euler - Shortening Problem 2
You might have read my question on shortening my code to a one-liner for Problem 1. So, I was wondering, is there any more tricks of the trade to shorten my Problem 2 solution:
fib = [0, 1]
final = 1
...
3
votes
3answers
240 views
Python how to make this reduce() fibonacci generator better?
Recently discoverer how cool reduce could be. Want to do this:
>>> a = [1, 1] + [0] * 11
>>> count = 1
>>> def fib(x,n):
... global count
... r = x + n
... if ...
3
votes
1answer
161 views
Euler 2 : Simple Fibonacci
I'm just starting to experiment with F# (from a C# background). I think I'm starting to get into the right way of thinking, but this code still seems pretty awkward. Is there a better (more terse) ...
2
votes
2answers
2k views
Python Solution for Project Euler #2 (Fibonacci Sums)
I'm a fairly new programmer (just started yesterday!). I decided to tackle Project Euler #2 today, as I did #1 yesterday without many problems. I came up with what seems to me to be a working ...
5
votes
1answer
295 views
Project Euler question 2 in CoffeeScript
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
fib = (x) ->
return 0 if x == 0
return 1 if x == 1
...
6
votes
0answers
221 views
Efficient, clean, readable, Python code [closed]
Me and a friend setup a competition between ourselves with the goal: Print out all numbers in the Fibonacci sequence that are less than or equal to 3000 using Python. The winner was whoever could ...
1
vote
2answers
268 views
Is there a better solution to this Fibonacci implementation in Go?
At the end of the Day 1 Go Course slides (pdf) there is an exercise stated as follows (NOTE: the course in the linked presentation is considered obsolete. If you are looking to learn Go the suggested ...
2
votes
2answers
311 views
Producing full list of Fibonacci numbers which fit in Int…
I am progressing through the problems listed at projecteuler.com as I learn Scala (my blog where I am covering this experience: fromjavatoscala.blogspot.com). I have written a function to produce all ...
15
votes
3answers
1k views
Project Euler Problem 2 in Clojure
I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach.
; Returns ...