Created
April 14, 2014 07:22
-
-
Save pohatu/10623903 to your computer and use it in GitHub Desktop.
some fizz buzz solutions in powershell
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
function fizzbuzz(){ | |
for ($i=1; $i -lt 101; $i++){ | |
$db=0; | |
if ($i%3 -eq 0){$db = $db -bor 1} | |
if ($i%5 -eq 0){$db = $db -bor 2} | |
switch($db) | |
{ | |
1 { Write-Output "Fizz"} #01 | |
2 { Write-Output "Buzz"} #10 | |
3 { Write-Output "FizzBuzz"} #11 | |
default {Write-Output $i} #00 | |
} | |
} | |
} | |
function fizzbuzz2(){ | |
$a = 1..101 | % {""} | |
for ($i=3; $i -le 100; $i +=3){$a[$i]="Fizz"} | |
for ($i=5; $i -le 100; $i +=5){$a[$i]+="Buzz"} | |
for ($i=1; $i -le 100; $i++){if ($a[$i] -eq ""){$a[$i]=$i}} | |
return $a | |
} | |
function fizzbuzz3(){ | |
$a = 1..101 | % {""} | |
$b = 1..101 | % {""} | |
$d = 1..101 | % {""} | |
for ($i=3; $i -le 100; $i +=3){$a[$i]="Fizz"} | |
for ($i=5; $i -le 100; $i +=5){$b[$i]="Buzz"} | |
for ($i=1; $i -le 100; $i++){ | |
$d[$i] = $a[$i] + $b[$i] | |
if ($d[$i] -eq ""){$d[$i]=$i} | |
} | |
return $d | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment