Fibonacci Puzzle

Find the smallest Fibonacci number which contains all digits ( 0 9 0-9 ).

Note: The digits may be repeated.


The answer is 2504730781961.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

7 solutions

Kartik Sharma
Mar 28, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
>>> def fibo(n):
    a = 0
    b = 1
    for i in range(1,n):
        c = b
        b = a+b
        a = c
    return b
>>> a = 1
>>> G = ['0','1','2','3','4','5','6','7','8','9']
>>> while(sorted(set(list(str(fibo(a)))))!=G):
    a = a+1
>>>print fibo(61)

Bill Bell
Mar 27, 2015

+1 for generator functions and sets! :)

Brock Brown - 6 years, 2 months ago

Log in to reply

Thank you!

Bill Bell - 6 years, 2 months ago
Brock Brown
Mar 27, 2015

Python 2.7:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def goal(n):
    number = str(n)
    for digit in '1234567890':
        if digit not in number:
            return False
    return True
memo = {1:0,2:1}
def fib(n):
    if n in memo:
        return memo[n]
    memo[n] = fib(n-1)+fib(n-2)
    return memo[n]
n = 1
while not goal(fib(n)):
    n += 1
print "Answer:", fib(n)

Nice! My method was little different.

Kartik Sharma - 6 years, 2 months ago

Nice!! Python!! Impressive.

Calvin Rieder - 6 years, 2 months ago
Aryan Gaikwad
Mar 27, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public static void main(String args[]){
    DecimalFormat df = new DecimalFormat("###.#");
    double a = 1, b = 1;
    while(true){
        a += b;
        b += a;
        if(numchk(df.format(a)))
            System.out.println(a);
        else if(numchk(df.format(b)))
            System.out.println(b);
    }
}

static boolean numchk(String n){
    return n.contains("0") && n.contains("1") && n.contains("2") && n.contains("3") && n.contains("4") &&
    n.contains("5") && n.contains("6") && n.contains("7") && n.contains("8") && n.contains("9");
}

Execution time ~ 0.08 seconds

Rishabh Sood
Feb 25, 2016

What? You guys used codes to calculate all this, I constructed the whole fibbonnacci table till 100 digits and then found the answer

What..... you did so much donkey's work :P lol

Ashish Menon - 5 years, 3 months ago
Rahul Badenkal
May 30, 2015

Python code

Natsir Muhammad
Mar 28, 2015

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...