Created
July 21, 2016 08:43
-
-
Save rhaseven7h/87b24d2995f7f382195554dcd3efcbee to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Haskell - Kundu And Bubble Wrap
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
solve n m = sum times | |
where oSize = fromIntegral $ n * m | |
oIndices = [ 1 .. oSize ] | |
singleProb = (\x -> x / oSize) | |
singleTime = (\n -> 1 / (singleProb n)) | |
times = map singleTime oIndices | |
main = do | |
raw <- readFile "input.txt" | |
let inStrArr = words $ head $ lines raw | |
let toInt = \o -> read o :: Int | |
let [n, m] = map toInt $ inStrArr | |
putStrLn . show $ solve n m |
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
2 2 |
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
8.3333333333333 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment