Last active
December 8, 2017 16:12
-
-
Save donpandix/63af768772d46c3fc9d3 to your computer and use it in GitHub Desktop.
Serie de Fibonnacci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// haciendo la serie de Fibonacci | |
// valor inicial de la serie | |
var valorInit:Int = 1; | |
// valor del segundo elemento de la serie | |
var valorNext:Int = 1; | |
print("Serie de Fibonacci") | |
print("==================") | |
// Ciclo que repite 91 veces el cáculo, más de 91 se cae el framework | |
for i in 1...91 { | |
// Solo imprime el valor 1 para el primer y segundo elemento de la serie | |
if ( i < 3 ) { | |
print("\(i) 1") | |
} else { | |
var nuevoValor = valorInit + valorNext; | |
print("\(i) \(nuevoValor)") | |
valorInit = valorNext | |
valorNext = nuevoValor | |
} | |
} | |
// Retorno de la funcionalidad | |
/* | |
Serie de Fibonacci | |
================== | |
1 1 | |
2 1 | |
3 2 | |
4 3 | |
5 5 | |
6 8 | |
7 13 | |
8 21 | |
9 34 | |
10 55 | |
11 89 | |
12 144 | |
13 233 | |
14 377 | |
15 610 | |
16 987 | |
17 1597 | |
18 2584 | |
19 4181 | |
20 6765 | |
21 10946 | |
22 17711 | |
23 28657 | |
24 46368 | |
25 75025 | |
26 121393 | |
27 196418 | |
28 317811 | |
29 514229 | |
30 832040 | |
... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment