Fibonacci several ways to resolve the number of columns

Fibonacci number

definition:

It refers to a number of a column: 0,1,1,2,3,5,8,13,21, ...... mathematically
Fibonacci sequence is defined in the following recursive method:
the Fn = the Fn. 1- + Fn-2 (n> = 2, n∈N *),
words that is the Fibonacci columns columns may begin with any natural integer, after the Fibonacci number by the factor two with respect to the number of the previous plus,
F0 = 0, Fl = 1, the default sequence beginning from 0 or 1

php and python solve problems similar number of columns

Tencent interview a few months ago, which has a number of questions on this column and related topics as follows:

There are a number of columns:

aa = 0,1,1,2,3,5,8 ... asked to enter the index can get the appropriate value, you can use their own familiar language python / shell / php solutions such

At that time I used python to solve the following:

#coding:utf-8

# 递归方法
def res(n):
    assert n>=0, "n>0"
    if n<=1

Guess you like

Origin blog.csdn.net/knight_zhou/article/details/103778140