Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO ()    -- This says that main is an IO action.
  2. main = return ()
  3.  
  4. data Auto = Auto {
  5. nombre :: String,
  6. nafta :: Int,
  7. velocidad :: Int,
  8. match :: String,
  9. truco :: String} deriving Show
  10.  
  11.  
  12. rochaMcqueen = Auto "rochaMcqueen" 300 0 "Ronco" "deReversa"
  13. --bianker Auto = Auto "bianker" 500 20 "Tinch" "impresionar"
  14. --gushtav Auto = Auto "gushtav" 200 130 "PetiLaLinda" "nitro"
  15. --rodra Auto = Auto "rodra" 0 50 "taisa" "fingirAmor"
  16.  
  17.  
  18. verTruco :: Auto -> String
  19. verTruco (Auto _ _ _ _ x) = x
  20.  
  21. impresionar :: Auto -> Auto
  22. impresionar unAuto = unAuto { velocidad = (* velocidad unAuto) 2  }
  23.  
  24. nitro :: Auto -> Auto
  25. nitro unAuto = unAuto { velocidad = (+ velocidad unAuto) 15}
  26.  
  27. fingirAmor :: Auto -> Auto
  28. fingirAmor unAuto = unAuto { match = cambiarNombre }
  29.  
  30. cambiarNombre :: String -> String
  31. cambiarNombre x = x
  32.  
  33. hacerTruco :: Auto -> Auto
  34. hacerTruco unAuto | verTruco unAuto == "impresionar" = impresionar unAuto
  35.                   | verTruco unAuto == "nitro" = nitro unAuto
  36.                   | verTruco unAuto == "fingirAmor" = fingirAmor unAuto
  37.                   | otherwise = unAuto
  38.  
  39.  
  40. obtenerMatch :: Auto -> String
  41. obtenerMatch (Auto _ _ _ x _ ) = x
  42.  
  43. cantVocales :: Auto -> Int
  44. cantVocales unAuto = length (filter vocales (obtenerMatch unAuto))
  45.  
  46. vocales :: Char -> Bool
  47. vocales letra = letra == 'a' || letra == 'e' || letra == 'i' || letra == 'o' || letra == 'u'
  48.  
  49. modificarVelocidad :: Auto -> Auto
  50. modificarVelocidad unAuto | cantVocales unAuto >= 1 && cantVocales unAuto <=2 = unAuto { velocidad = velocidad  + 15}
  51.                           | cantVocales unAuto >= 3 && cantVocales unAuto <=4 = unAuto { velocidad = velocidad  + 20}
  52.                           | cantVocales unAuto >= 4 = unAuto { velocidad = velocidad unAuto + 30}
  53.                           | otherwise = unAuto
  54.  
  55. --puedeHacerTruco unAuto x = unAuto { truco verificarTruco x}
  56.  
  57. --verificarTruco x = unAuto { nafta > 0 && velocidad < 100}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement