Fibonacci number/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Fibonacci number/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Die Fibonacci-Zahlen-Folge ist eine Reihe von Zahlen: | |
| 2 | + | ||
| 3 | + | `0, 1, 1, 2, 3, 5, 8, 13, 21, ...` | |
| 4 | + | ||
| 5 | + | Die Idee dahinter ist, die zwei vorhergehenden Zahlen zu addieren um die nächste zu erhalten. Sie benannt nach [Leonardo Fibonacci](https://de.wikipedia.org/wiki/Leonardo_Fibonacci) einem Rechengelehrten (heute würde man sagen Mathematiker) aus Pisa. Bekannt war die Folge lt. Wikipedia aber schon in der Antike bei den Griechen und Indern. | |
| 6 | + | ||
| 7 | + | ## rekursive Art | |
| 8 | + | ||
| 9 | + | ``` pascal | |
| 10 | + | ||
| 11 | + | function FibonacciNumber( n : integer ): integer; | |
| 12 | + | begin | |
| 13 | + | if n > 1 then | |
| 14 | + | result := ( FibonacciNumber( n - 1 ) + FibonacciNumber( n - 2 ) ) | |
| 15 | + | else if n = 0 then | |
| 16 | + | result := 0 | |
| 17 | + | else | |
| 18 | + | result := 1; | |
| 19 | + | end; | |
| 20 | + | ``` | |
| 21 | + | ||
| 22 | + | ## iterative Art | |
| 23 | + | ||
| 24 | + | Diese ist vorzuziehen. | |
| 25 | + | ||
| 26 | + | ``` pascal | |
| 27 | + | function Fibonacci(n: Integer): Integer; | |
| 28 | + | var | |
| 29 | + | i, u, v, w: Integer; | |
| 30 | + | Begin | |
| 31 | + | if n <= 0 then | |
| 32 | + | Result := 0 | |
| 33 | + | else if n = 1 then | |
| 34 | + | Result := 1 | |
| 35 | + | else | |
| 36 | + | begin | |
| 37 | + | u := 0; | |
| 38 | + | v := 1; | |
| 39 | + | for i := 2 to n do | |
| 40 | + | begin | |
| 41 | + | w := u + v; | |
| 42 | + | u := v; | |
| 43 | + | v := w; | |
| 44 | + | end; | |
| 45 | + | Result := v; | |
| 46 | + | end; | |
| 47 | + | End; | |
| 48 | + | ``` | |
| 49 | + | ||
| 50 | + | ## Siehe auch ... | |
| 51 | + | ||
| 52 | + | - [Some assembly routine which uses the C calling convention that calculates the nth Fibonacci number](http://www.freepascal.org/docs-html/prog/progsu151.html) | |
| 53 | + | - [[Solution 3|Tao Yue Solution to Fibonacci Sequence Problem]] | |
| 54 | + | - [Wikipedia: Fibonacci-Folge](https://de.wikipedia.org/wiki/Fibonacci-Folge) | |
| 55 | + | ||
| 56 | + | --- | |
| 57 | + | *From the Free Pascal wiki, page "Fibonacci number/de", as it stood on 2020-01-12 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
