re: Daily Challenge #106 - Average Fuel Consumption VIEW POST

FULL DISCUSSION
 

Haskell

average :: Float -> Float -> Float -> Float -> Float
average x1 x2 y1 y2 =
    (fromIntegral $ round $ (y1 * y2 - x1 * x2) * 100 / (y2 - x2) / 100 * 10) / 10

main :: IO ()
main = do
    print $ average 7.9 100 7 200 -- 6.1
    print $ average 7.9 500 7 600 -- 2.5
    print $ average 7.9 100 7 600 -- 6.8

Playground

Hosted on Repl.it.

code of conduct - report abuse