Skip to content

Instantly share code, notes, and snippets.

@rhaseven7h
Created July 21, 2016 08:43
Show Gist options
  • Save rhaseven7h/87b24d2995f7f382195554dcd3efcbee to your computer and use it in GitHub Desktop.
Save rhaseven7h/87b24d2995f7f382195554dcd3efcbee to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Haskell - Kundu And Bubble Wrap
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
8.3333333333333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment