October 04th   2014

Fibonacci sequence in Swift

  Swift

In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... Here is how we can implement it in Swift.

In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...

Here is how we can implement it in Swift:

var fibonacci = [0,1]

while fibonacci.count < 20 {
    fibonacci.append(fibonacci[fibonacci.count - 2] + fibonacci[fibonacci.count - 1])
}

«         »

Web Analytics