2024-10-01 15:11:03 +02:00
|
|
|
|
<#
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Lists the Fibonacci numbers
|
|
|
|
|
.DESCRIPTION
|
2023-08-06 21:35:36 +02:00
|
|
|
|
This PowerShell script lists the first 100 Fibonacci numbers.
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-06 21:35:36 +02:00
|
|
|
|
PS> ./list-fibonacci.ps1
|
|
|
|
|
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
2024-10-28 14:20:47 +01:00
|
|
|
|
function fibo([int]$n) {
|
2022-09-02 19:34:22 +02:00
|
|
|
|
if ($n -lt 2) { return 1 }
|
2024-10-28 14:20:47 +01:00
|
|
|
|
return (fibo($n - 1)) + (fibo($n - 2))
|
2022-09-02 19:34:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($i in 0..100) {
|
2024-10-28 14:20:47 +01:00
|
|
|
|
Write-Host "$(fibo $i), " -noNewline
|
2022-09-02 19:34:22 +02:00
|
|
|
|
}
|
2022-09-06 21:42:04 +02:00
|
|
|
|
exit 0 # success
|