From 697f4ab914d9798c34d87e23ea74e473c69264f5 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 5 Oct 2020 12:13:59 +0200 Subject: [PATCH] Add tasks --- Exercise 1/2.hs | 2 ++ Exercise 1/3.hs | 10 ++++++++++ Exercise 1/9.hs | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 Exercise 1/2.hs create mode 100644 Exercise 1/3.hs create mode 100644 Exercise 1/9.hs diff --git a/Exercise 1/2.hs b/Exercise 1/2.hs new file mode 100644 index 0000000..d5a6ff7 --- /dev/null +++ b/Exercise 1/2.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Hello world" diff --git a/Exercise 1/3.hs b/Exercise 1/3.hs new file mode 100644 index 0000000..1d9f7f3 --- /dev/null +++ b/Exercise 1/3.hs @@ -0,0 +1,10 @@ +main :: IO () +main = do + putStrLn $ show $ 1 + 2 * (3+4) + 4/2 - 1 + + let minutter = 355 :: Int + + let timer = minutter `div` 60 + let minutterIgjen = minutter `mod` 60 + + putStrLn $ show $ show minutter ++ " minutter blir " ++ show timer ++ " timer og " ++ show minutterIgjen ++ " minutter" diff --git a/Exercise 1/9.hs b/Exercise 1/9.hs new file mode 100644 index 0000000..d3530e2 --- /dev/null +++ b/Exercise 1/9.hs @@ -0,0 +1,14 @@ +main :: IO () +main = do + input <- promptLine "Skriv inn h: " + let h = read input :: Double + putStrLn $ show $ tetraederVolum h + +promptLine :: String -> IO String +promptLine prompt = do + putStr prompt + getLine + +tetraederVolum :: Double -> Double +tetraederVolum h = sqrt 2 * a / 12 + where a = 3 / sqrt 6 * h