Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/The-Name-Game/Haskell/the-name-game.hs
Normal file
41
Task/The-Name-Game/Haskell/the-name-game.hs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- The Name Game, Ethan Riley, 22nd May 2018
|
||||
import Data.Char
|
||||
|
||||
isVowel :: Char -> Bool
|
||||
isVowel c
|
||||
| char == 'A' = True
|
||||
| char == 'E' = True
|
||||
| char == 'I' = True
|
||||
| char == 'O' = True
|
||||
| char == 'U' = True
|
||||
| otherwise = False
|
||||
where char = toUpper c
|
||||
|
||||
isSpecial :: Char -> Bool
|
||||
isSpecial c
|
||||
| char == 'B' = True
|
||||
| char == 'F' = True
|
||||
| char == 'M' = True
|
||||
| otherwise = False
|
||||
where char = toUpper c
|
||||
|
||||
shorten :: String -> String
|
||||
shorten name
|
||||
| isVowel $ head name = map toLower name
|
||||
| otherwise = map toLower $ tail name
|
||||
|
||||
line :: String -> Char -> String -> String
|
||||
line prefix letter name
|
||||
| letter == char = prefix ++ shorten name ++ "\n"
|
||||
| otherwise = prefix ++ letter:[] ++ shorten name ++ "\n"
|
||||
where char = toLower $ head name
|
||||
|
||||
theNameGame :: String -> String
|
||||
theNameGame name =
|
||||
line (name ++ ", " ++ name ++ ", bo-") 'b' name ++
|
||||
line "Banana-fana fo-" 'f' name ++
|
||||
line "Fee-fi-mo-" 'm' name ++
|
||||
name ++ "!\n"
|
||||
|
||||
main =
|
||||
mapM_ (putStrLn . theNameGame) ["Gary", "Earl", "Billy", "Felix", "Mike", "Steve"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue