Skip to content

Instantly share code, notes, and snippets.

@Takeru-chan
Last active October 26, 2015 14:47
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 Takeru-chan/7095b29e128c6357ca7e to your computer and use it in GitHub Desktop.
Save Takeru-chan/7095b29e128c6357ca7e to your computer and use it in GitHub Desktop.
Prime checker for PowerShell.
Param($num)
$msg = @("Prime.", "NOT prime.", "Not Applicable.")
$ret = 2
if ($num -ge 2) {
$ret = 0
if ($num -gt 3) {
if (($num % 2) -eq 0) {
$ret = 1
} else {
:loop foreach ($exam in 3..[Math]::Ceiling([Math]::Sqrt($num))) {
if (($num % $exam) -eq 0) {
$ret = 1
break loop
}
}
}
}
}
$msg[$ret]
exit $ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment