2024-11-08 12:38:20 +01:00
|
|
|
The *list-fibonacci.ps1* Script
|
|
|
|
===========================
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
list-fibonacci.ps1
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Lists the Fibonacci numbers
|
|
|
|
.DESCRIPTION
|
2023-08-06 21:36:33 +02:00
|
|
|
This PowerShell script lists the first 100 Fibonacci numbers.
|
2022-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
2023-08-06 21:36:33 +02:00
|
|
|
PS> ./list-fibonacci.ps1
|
|
|
|
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
|
2022-11-17 20:02:26 +01:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
2024-11-08 12:35:11 +01:00
|
|
|
function fibo([int]$n) {
|
2022-11-17 20:02:26 +01:00
|
|
|
if ($n -lt 2) { return 1 }
|
2024-11-08 12:35:11 +01:00
|
|
|
return (fibo($n - 1)) + (fibo($n - 2))
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($i in 0..100) {
|
2024-11-08 12:35:11 +01:00
|
|
|
Write-Host "$(fibo $i), " -noNewline
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
exit 0 # success
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:55)*
|