Compare commits

...

2 Commits

4 changed files with 49 additions and 0 deletions

View File

@ -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."

View File

@ -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 == '?'

View File

@ -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

View File

@ -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