Guest User

Untitled

a guest
Jan 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Midterm Solutions (Coding)
  2.  
  3. subsets [] = pp[[
  4. subsets (x:xs) = subsets xs ++ addToEach x (subsets xs)
  5.  
  6. addToEach x [] = []
  7. addToEach x (xs:xss) = (x:xs) : addToEach x xss
  8.  
  9. comb _  0 = [[]]
  10. comb [] _ = []
  11. comb (x:xs) n = addToEach x (comb xs (n-1)) ++ comb xs n
  12.  
  13. primeFactors n = pfHelper n 2
  14.  
  15. pfHelper n f | n < f = []
  16.          | (mod n f == 0) = f : pfHelper (div n f)
  17.          | otherwise = pfHelper n (f+1)
  18.  
  19. checkBase n = noDups (primeFactors n)
  20.  
  21. noDups [x] = True
  22. noDups x:y:xs = (x /= y) && noDups (y:ys)
  23.  
  24. idiv2 [] = []
  25. idiv2 [x] = []
  26. idiv2 (x:y:xs) = x: idiv2 xs
Add Comment
Please, Sign In to add comment