Advertisement
Guest User

Complete Code

a guest
Mar 22nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fatc :: Integer -> Integer
  2. fatc n | n==0 = 1
  3.        | n>0 = fatcauda n 1
  4.  
  5. fatcauda :: Integer -> Integer -> Integer
  6. fatcauda n parcial | n==0 = parcial
  7.            | n>0 = fatcauda (n-1) (n*parcial)
  8.  
  9. size :: [Int] -> Int
  10. size []         = 0
  11. size (head: body)   = 1 + size body
  12.  
  13. divi :: Int -> [Int]
  14. divi n = [x | x<-[1..n], mod n x == 0]
  15.  
  16. divip :: Int -> [Int]
  17. divip n = [x | x<-[2..n-1], mod n x == 0]
  18.  
  19. primo :: Int -> Bool
  20. primo n | [x | x<-[2..n-1], mod n x == 0] == [] = True
  21.     | otherwise = False
  22.    
  23. primos :: Int -> [Int]
  24. primos n | n> 2 = [x | x<-[1..n], primo x]
  25.  
  26. multi :: Int -> Int -> [Int]
  27. multi n i = [x*n | x<-[1..i]]
  28.  
  29. --pi :: Int -> Double
  30. --pi n = (426880 * sqrt 10005) / divpi n
  31.  
  32. divpi :: Integer -> Double
  33. divpi k = (((fatc (6*k)) * ((545140134*k) + 13591409))/((fatc (3*k)) * (pot (fatc k) 3) * (pot (-262537412640768000) k)))
  34.  
  35. pot :: Integer -> Integer -> Integer
  36. pot base expo | expo == 0 = 1
  37.               | otherwise = base * (pot base (expo-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement