Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created December 4, 2016 11:39
Show Gist options
  • Save chrisbrownie/1111c7a922008b7f857f6cb7a19aaa59 to your computer and use it in GitHub Desktop.
Save chrisbrownie/1111c7a922008b7f857f6cb7a19aaa59 to your computer and use it in GitHub Desktop.
My PowerShell solution to the fizzbuzz question https://blog.codinghorror.com/why-cant-programmers-program/
# https://blog.codinghorror.com/why-cant-programmers-program/
function FizzBuzz {
0..100 | % {
if ( ( $_ % 3 -eq 0 ) -and ( $_ % 5 -eq 0 ) ) {
"$_ fizzbuzz"
} elseif ( $_ % 3 -eq 0) {
"$_ fizz"
} elseif ( $_ % 5 -eq 0) {
"$_ buzz"
} else {
$_
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment