Created
September 8, 2017 17:27
-
-
Save mvallebr/21f22e9afd9866bf96a37eebd9411f47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Applicative | |
| import Control.Monad | |
| import System.IO | |
| import Text.Printf | |
| factorial :: Integer -> [Integer] -> [Integer] | |
| factorial acc [] = [] | |
| factorial 0 (head:tail) = 1 : factorial (1 * head) tail | |
| factorial acc (head:tail) = (head * acc) : factorial (head * acc) tail | |
| power :: Double -> Double -> [Double] | |
| power x acc = acc : power x (x*acc) | |
| fe :: Double -> Double | |
| fe x = sum (zipWith (/) (take 10 (power x 1)) (map fromIntegral (factorial 0 i))) | |
| where | |
| i = take 10 (iterate (+1) 0) | |
| main :: IO () | |
| main = do | |
| n_temp <- getLine | |
| let n = read n_temp :: Int | |
| forM_ [1..n] $ \a0 -> do | |
| x_temp <- getLine | |
| let x = read x_temp :: Double | |
| --print (fe x) | |
| printf "%.4f\n" (fe x) | |
| getMultipleLines :: Int -> IO [String] | |
| getMultipleLines n | |
| | n <= 0 = return [] | |
| | otherwise = do | |
| x <- getLine | |
| xs <- getMultipleLines (n-1) | |
| let ret = (x:xs) | |
| return ret | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment