Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/usr/bin/env runhaskell
  2.  
  3. import Control.Applicative
  4. import Control.Monad.State
  5. import System.Random
  6.  
  7. main ::
  8. IO ()
  9. main =
  10. question
  11.  
  12. randomtemp ::
  13. (Random a, RandomGen g, Num a) =>
  14. State g a
  15. randomtemp =
  16. state (randomR (-15, 45))
  17.  
  18. randomele ::
  19. (Random a, RandomGen g, Num a) =>
  20. State g a
  21. randomele =
  22. state (\g -> let (p, h) = randomR (-10, 240) g
  23. in (p * 50, h))
  24.  
  25. randomqnh ::
  26. (Random a, RandomGen g, Num a) =>
  27. State g a
  28. randomqnh =
  29. state (randomR (990, 1030))
  30.  
  31. question ::
  32. IO ()
  33. question =
  34. let teq ::
  35. State StdGen (Int, Int, Int)
  36. teq =
  37. (,,) <$> randomtemp <*> randomele <*> randomqnh
  38. in do g <- newStdGen
  39. let (t, e, q) =
  40. evalState teq g
  41. isapressure =
  42. 1013
  43. isatemp =
  44. 15
  45. pa =
  46. fromIntegral e + (isapressure - fromIntegral q) * 30
  47. da =
  48. (fromIntegral t - isatemp + (pa / 500)) * 120 + fromIntegral e
  49. putStrLn . concat $
  50. [
  51. "Temperature: "
  52. , show t
  53. , "C\nElevation: "
  54. , show e
  55. , "ft\nQNH: "
  56. , show q
  57. , "hPa\n-----------------\n?Density Altitude"
  58. ]
  59. l <- getLine
  60. putStrLn . concat $
  61. [
  62. "Pressure Altitude: "
  63. , show pa
  64. , "\nDensity Altitude: "
  65. , show da
  66. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement