Created
August 26, 2012 01:26
-
-
Save ngsw-taro/3472962 to your computer and use it in GitHub Desktop.
はすけるで素数判定
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
module Prime( | |
prime | |
) where | |
prime :: Int -> Bool | |
prime x | x < 0 = error "the argument should be larger than zero." | |
| x == 1 = False | |
| x == 2 = True | |
| mod x 2 == 0 = False | |
| otherwise = all (\y -> mod x y /= 0 || x == y) (take (x - 3) [3, 5..]) |
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
import Test.HUnit | |
import Prime | |
tests = test [prime 1 ~?= False, | |
prime 2 ~?= True, | |
prime 3 ~?= True, | |
prime 4 ~?= False, | |
prime 5 ~?= True, | |
prime 6 ~?= False, | |
prime 7 ~?= True, | |
prime 8 ~?= False, | |
prime 9 ~?= False, | |
prime 10 ~?= False, | |
prime 11 ~?= True, | |
prime 12 ~?= False, | |
prime 13 ~?= True, | |
prime 14 ~?= False, | |
prime 15 ~?= False, | |
prime 16 ~?= False, | |
prime 17 ~?= True, | |
prime 18 ~?= False, | |
prime 19 ~?= True, | |
prime 20 ~?= False] | |
main = do | |
runTestTT tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment