Advertisement
karlicoss

first steps :)

Jul 2nd, 2011
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. firstSatisfying :: (a -> Bool) -> [a] -> a
  2. firstSatisfying f l
  3.     | f (head l) == True = head l
  4.     | otherwise          = firstSatisfying f (tail l)
  5.  
  6. primeFactorisation :: (Integral a) => a -> [a]
  7. primeFactorisation x
  8.     | x <= 0    = error "Wrong number"
  9.     | x == 1    = []
  10.     | otherwise = [firstDivisor] ++ primeFactorisation (x `div` firstDivisor)  
  11.     where
  12.         divisorList = [2..x]
  13.         firstDivisor = firstSatisfying (\y -> x `mod` y == 0) divisorList
  14.  
  15. main = putStrLn (show (primeFactorisation (2 * 9 * 7 * 100500)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement