diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-02-06 21:13:46 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-02-06 21:13:46 +1100 |
commit | 2a281ed2606e18459189a60cab9c18a659ab74e3 (patch) | |
tree | 656e961b32befc9b2e25bc2b322d90b089275ff4 /misc.hs | |
parent | cd5e13ba7979aa942326ddbc7199f91ca85425a9 (diff) |
Renamed remaining code from original fractran file more appropriately
Diffstat (limited to 'misc.hs')
-rw-r--r-- | misc.hs | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -0,0 +1,40 @@ + + + +isInt :: (RealFrac a) => a -> Bool +isInt x = + x == fromInteger (round x) + + + +modulo :: Int -> Int -> Int +modulo x y = + x - (x `div` y) * y + + + +primeFactors :: Int -> [Int] +primeFactors x = + let p = (\x e c -> if (x == 1) + then (reverse c) + else if (x `modulo` (head e) == 0) + then p (x `div` (head e)) e ((head e) : c) + else p x (tail e) c) + in p x euler [] + + + +euler :: [Int] +euler = + let f = (\list -> (head list) : (f (filter (\x -> x `modulo` (head list) /= 0) list))) + in f [2..] + + + +isPowerOf :: Int -> Int -> Bool +isPowerOf x y = + case (compare x y) of + LT -> False + EQ -> True + GT -> if (x `modulo` y == 0) then isPowerOf (x `div` y) y else False + |