Human VS Computer : OMG! The most frequent digit of 10000th Fibonacci Number...

Level pending

Given initial value for F1 = 0 and F2 = 1.We know that F3 = F2+F1 (the next term is the sum of the two preceding terms). What is the most frequent digit of the 10000th Fibonacci number?

6 9 8 7

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.

1 solution

Brock Brown
Jan 7, 2015

Why can't we be friends with computers?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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]
def most_frequent(n):
    count = {}
    for digit in str(n):
        if digit in count:
            count[digit] += 1
        else:
            count[digit] = 1
    biggest = 0
    most_occuring = 0
    for digit in count:
        if count[digit] > biggest:
            biggest = count[digit]
            most_occuring = digit
    return most_occuring
# build table to reduce
# recursion depth
for i in xrange(1, 10000):
    fib(i)
print most_frequent(fib(10000))

nice job! ..............

Mharfe Micaroz - 6 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...