Advertisement
Guest User

h11

a guest
Jan 27th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2.  
  3. strings :: Int -> [String]
  4. strings 0 = [""]
  5. strings n = concat (map (\x -> map (\tail -> x:tail) tails) ['a'..'z'])
  6.     where tails = strings (n-1)
  7.    
  8. --a
  9. palindromes :: [String]
  10. palindromes = filter (\x -> x ==(reverse x)) (palinHelper 0)
  11.         where
  12.                 palinHelper n = strings n ++ palinHelper (n+1)
  13.                
  14. --b
  15. divisors :: Int -> [Int]
  16. divisors x = filter (\y -> mod x y == 0) [1..div x 2]
  17.  
  18. perfects :: [Int]
  19. perfects = filter (\x -> x==sum(divisors x)) [1..]
  20.  
  21. --c
  22. semiperfects :: [Int]
  23. semiperfects = filter(\x ->(any(\y -> (sum y)==x))(subsequences (divisors x))) [2..]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement