Guest User

Practica 6

a guest
Apr 25th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 1
  2. f :: Int -> Int
  3. f 1 = 18
  4. f 4 = 131
  5. f 16 = 16
  6.  
  7. -- 2
  8. g :: Int -> Int
  9. g 8 = 16
  10. g 16 = 4
  11. g 131 = 1
  12.  
  13. -- 3
  14. h :: Int -> Int
  15. h 8 = f (g 8)
  16. h 16 = f (g 16)
  17. h 131 = f (g 131)
  18.  
  19. k :: Int -> Int
  20. k 1 = g (f 1)
  21. k 4 = g (f 4)
  22. k 16 = g (f 16)
  23.  
  24. -- 4
  25. f4 :: Int -> Int
  26. f4 n | n <= 10 = n
  27.      | n > 10  = n+1
  28.  
  29. g4 :: Int -> Int
  30. g4 n | esPrimo n = 1
  31.    n | otherwise = 0
  32.  
  33. esPrimo :: Int -> Bool
  34. esPrimo n | sinDivisoresHasta n n = True
  35. esPrimo n | otherwise = False
  36. -- ERROR "pruebas.hs":38
  37. -- Instance of Num Bool required for definition of sinDivisoresHasta
  38. sinDivisoresHasta :: Int -> Int -> Bool
  39. sinDivisoresHasta n t | t == 1 = True
  40. sinDivisoresHasta n t | mod n t == 0 = False
  41. sinDivisoresHasta n t | mod n t /= 0 = sinDivisoresHasta n t-1
  42.  
  43. sum4 :: Int -> Int
  44. sum4 n = sumarDesdeHasta 0 n 0
  45.  
  46. sumarDesdeHasta :: Int -> Int -> Int -> Int
  47. sumarDesdeHasta
  48. sumarDesdeHasta n m i | sumarDesdeHasta  n-1 g4()
Advertisement
Add Comment
Please, Sign In to add comment