Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active August 17, 2019 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/2c5049cc71699f2d6bb3b5006afbc6c3 to your computer and use it in GitHub Desktop.
Save guitarrapc/2c5049cc71699f2d6bb3b5006afbc6c3 to your computer and use it in GitHub Desktop.
caldulate sum of odd number with powershell
# method + binary
(1..100).Where{($_ -band 1) -eq 0} | Measure -Sum
# pipeline + binary
1..100 | Where {($_ -band 1) -eq 0} | Measure -Sum
# method + division
(1..100).Where{[int]($_ / 2) * 2 -eq $_} | Measure -Sum
# pipeline + division
1..100 | Where{[int]($_ / 2) * 2 -eq $_} | Measure -Sum
# method + modulo
(1..100).Where{$_ % 2 -eq 0} | Measure -Sum
# pipeline + modulo
1..100 | Where {$_ % 2 -eq 0} | Measure -Sum
# method + shift
(1..100).where{($_ -shr 1) -shl 1 -eq $_} | Measure -Sum
# pipeline + shift
1..100 | where {($_ -shr 1) -shl 1 -eq $_} | Measure -Sum
@guitarrapc
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment