Fibonacci Series in Powershell

Scott Hanselman recently posted The Weekly Source 13 - Fibonacci Edition. . It was a very interesting read, but it was missing the Powershell version. As in the Ruby example, you can use multiple assignments in Powershell as well
Function Get-Fib ($n) {
     $current = $previous = 1;
     while ($current -lt $n) {
           $current;
           $current,$previous = ($current + $previous),$current}
     }
Get-Fib 100
Bruce's book, Powershell in Action, uses a slightly more terse version of this function in his discussion of multiple variable assignment.

Comments (3) -

for the Morris series in PowerShell:

thepowershellguy.com/.../...-challenge-part-9.aspx

Greetings /\/\o\/\/

Small correction to the above, correct me if i am wrong..


$n = Read-Host

function get-feb ($n) {

$current = 0 ;
$previous = 1;
while ($current -lt $n) {
$current;
$current,$previous = ($current+$previous),$current}
}
get-feb ($n)

Fibonacci series starts with 0

Flipkart coupons 1/14/2015 4:56:54 PM

Flipkart coupons, Flipkart coupon codes - http://www.couponcargo.in/

Comments are closed