diff --git a/solutions/block1/bob-1.hs b/solutions/block1/bob-1.hs new file mode 100644 index 0000000..8431799 --- /dev/null +++ b/solutions/block1/bob-1.hs @@ -0,0 +1,17 @@ +module Bob (responseFor) where +import Data.Char ( isSpace, isAlpha, isUpper ) + +isYelling :: [Char] -> Bool +isYelling stmt = any isAlpha stmt && all isUpper (filter isAlpha stmt) + +isQuestion :: [Char] -> Bool +isQuestion stmt = last (filter (not . isSpace) stmt) == '?' + +responseFor :: String -> String +responseFor prompt + | all isSpace prompt = "Na gut. Dann eben nicht!" + | isQuestion prompt && isYelling prompt = "Chill mal, ich bin da schon dran!" + | isQuestion prompt = "Klar." + | isYelling prompt = "Whoa, entspann dich!" + | otherwise = "Whatever." + \ No newline at end of file diff --git a/solutions/block1/bob-2.hs b/solutions/block1/bob-2.hs new file mode 100644 index 0000000..da62929 --- /dev/null +++ b/solutions/block1/bob-2.hs @@ -0,0 +1,15 @@ +module Bob (responseFor) where +import Data.Char ( isLetter, isSpace, isUpper ) + +responseFor :: String -> String +responseFor input + | null text = "Na gut. Dann eben nicht!" + | isShouting && isAsking = "Chill mal, ich bin da schon dran!" + | isShouting = "Whoa, entspann dich!" + | isAsking = "Klar." + | otherwise = "Whatever." + where + text = filter (not . isSpace) input + letters = filter isLetter text + isShouting = all isUpper letters && any isUpper letters + isAsking = last text == '?' diff --git a/solutions/block1/darts.hs b/solutions/block1/darts.hs new file mode 100644 index 0000000..1514f04 --- /dev/null +++ b/solutions/block1/darts.hs @@ -0,0 +1,8 @@ +module Darts (score) where + +score :: Float -> Float -> Int +score x y + | x^2 + y^2 <= 1 = 10 + | x^2 + y^2 <= 25 = 5 + | x^2 + y^2 <= 100 = 1 + | otherwise = 0 diff --git a/solutions/block1/leap.hs b/solutions/block1/leap.hs new file mode 100644 index 0000000..3d3f38d --- /dev/null +++ b/solutions/block1/leap.hs @@ -0,0 +1,9 @@ +module LeapYear (isLeapYear) where + +isLeapYear :: Integer -> Bool +isLeapYear year + | year `mod` 400 == 0 = True + | year `mod` 100 == 0 = False + | year `mod` 4 == 0 = True + | otherwise = False + \ No newline at end of file