Quick actions

cmd+k|ctrl+k

Navigation

Languages

Divisors

Snippet info

Language

Haskell

Visibility

public

Author

davidkaste

Created

2017-09-26T11:34:58Z

Updated

2017-09-27T12:01:52Z

module Divisors where

divisors :: Integral a => a -> [a]
divisors x = filter ((== 0) . mod x) [1 .. x]

isPrime :: Integral a => a -> Bool
isPrime = (== 2) . length . divisors

main :: IO ()
main = do
    putStrLn "Get divisors of: "
    x <- getLine
    putStrLn $ unwords $ map show (divisors (read x))
    putStrLn $ x ++ (if isPrime (read x) then " is " else " isn't ") ++ "a prime number."
INFO