Advertisement
SepandMeenu

Prime Test

Feb 27th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Type problem
  2.  
  3. -- simple prime test
  4. prime :: Integral a => a -> Bool
  5. prime 1 = True
  6. prime n
  7.   | n < 1 = False
  8.   | otherwise = ptestn m0
  9.   where
  10.     m0 = n `div` 2
  11.     ptestn :: Integral a => a -> Bool
  12.     ptestn 1 = True
  13.     ptestn m = n `mod` m > 0 && ptestn (m - 1)
  14.  
  15. -- foo
  16. foo :: Integral a => a -> Bool
  17. foo n = n == sqr n
  18.   where
  19.     sqr :: Integral b => b -> b
  20.     sqr 1 = 1
  21.     sqr m = m*m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement