Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- strings :: Int -> [String]
- strings 0 = [""]
- strings n = concat (map (\x -> map (\tail -> x:tail) tails) ['a'..'z'])
- where tails = strings (n-1)
- --a
- palindromes :: [String]
- palindromes = filter (\x -> x ==(reverse x)) (palinHelper 0)
- where
- palinHelper n = strings n ++ palinHelper (n+1)
- --b
- divisors :: Int -> [Int]
- divisors x = filter (\y -> mod x y == 0) [1..div x 2]
- perfects :: [Int]
- perfects = filter (\x -> x==sum(divisors x)) [1..]
- --c
- semiperfects :: [Int]
- semiperfects = filter(\x ->(any(\y -> (sum y)==x))(subsequences (divisors x))) [2..]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement