Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
9
Task/Comma-quibbling/Haskell/comma-quibbling-1.hs
Normal file
9
Task/Comma-quibbling/Haskell/comma-quibbling-1.hs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
quibble ws = "{" ++ quibbles ws ++ "}"
|
||||
where quibbles [] = ""
|
||||
quibbles [a] = a
|
||||
quibbles [a,b] = a ++ " and " ++ b
|
||||
quibbles (a:bs) = a ++ ", " ++ quibbles bs
|
||||
|
||||
main = mapM_ (putStrLn . quibble) $
|
||||
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]] ++
|
||||
(map words ["One two three four", "Me myself I", "Jack Jill", "Loner" ])
|
||||
15
Task/Comma-quibbling/Haskell/comma-quibbling-2.hs
Normal file
15
Task/Comma-quibbling/Haskell/comma-quibbling-2.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import Data.List (intercalate)
|
||||
|
||||
quibble :: [String] -> String
|
||||
quibble ws
|
||||
| length ws > 1 =
|
||||
intercalate
|
||||
" and "
|
||||
([intercalate ", " . reverse . tail, head] <*> [reverse ws])
|
||||
| otherwise = concat ws
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_ (putStrLn . (`intercalate` ["{", "}"]) . quibble) $
|
||||
[[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]] ++
|
||||
(words <$> ["One two three four", "Me myself I", "Jack Jill", "Loner"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue