Created
July 21, 2020 09:44
-
-
Save SQLDBAWithABeard/7a49bd4833d7a218721a7fc67faf0bbc to your computer and use it in GitHub Desktop.
FizzBuzz
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
1..100 | ForEach-Object { | |
$number = $Psitem | |
switch (($number % 5) -eq 0 -and ($number % 3 -eq 0)) { | |
$true { 'FizzBuzz' } | |
Default { | |
switch ($number % 3) { | |
0 { 'Fizz' } | |
Default { | |
switch ($number % 5) { | |
0 { 'Buzz' } | |
Default { $number } | |
} | |
} | |
} | |
} | |
} | |
} | |
1..100 | ForEach-Object { | |
if (($Psitem % 5) -eq 0 -and ($Psitem % 3 -eq 0)) { | |
'FizzBuzz' | |
} | |
elseif ($Psitem % 3 -eq 0) { | |
'Fizz' | |
} | |
elseif ($Psitem % 5 -eq 0) { | |
'Buzz' | |
} | |
else { | |
$Psitem | |
} | |
} | |
1..100 | ForEach-Object { | |
$number = switch ($Psitem) { | |
{ $Psitem % 3 -eq 0 } { "Fizz" } | |
{ $Psitem % 5 -eq 0 } { "Buzz" } | |
default { $Psitem } | |
} | |
If ($number -is [array]) { $number = "FizzBuzz" } | |
$number | |
} | |
# from here https://codegolf.stackexchange.com/questions/58615/1-2-fizz-4-buzz/58624#58624 | |
1..100|%{(($t="Fizz"*!($_%3)+"Buzz"*!($_%5)),$_)[!$t]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment