Last active
October 26, 2015 14:47
-
-
Save Takeru-chan/7095b29e128c6357ca7e to your computer and use it in GitHub Desktop.
Prime checker for 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
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