Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
38
Task/ABC-problem/Haskell/abc-problem-2.hs
Normal file
38
Task/ABC-problem/Haskell/abc-problem-2.hs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import Data.Char (toUpper)
|
||||
import Data.List (delete)
|
||||
|
||||
|
||||
----------------------- ABC PROBLEM ----------------------
|
||||
|
||||
spellWith :: [String] -> String -> [[String]]
|
||||
spellWith _ [] = [[]]
|
||||
spellWith blocks (x : xs) = blocks >>= go
|
||||
where
|
||||
go b
|
||||
| x `elem` b = (b :) <$> spellWith (delete b blocks) xs
|
||||
| otherwise = []
|
||||
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
( print
|
||||
. ((,) <*>)
|
||||
(not . null . spellWith blocks . fmap toUpper)
|
||||
)
|
||||
[ "",
|
||||
"A",
|
||||
"BARK",
|
||||
"BoOK",
|
||||
"TrEAT",
|
||||
"COmMoN",
|
||||
"SQUAD",
|
||||
"conFUsE"
|
||||
]
|
||||
|
||||
blocks :: [String]
|
||||
blocks =
|
||||
words $
|
||||
"BO XK DQ CP NA GT RE TG QD FS JW"
|
||||
<> " HU VI AN OB ER FS LY PC ZM"
|
||||
Loading…
Add table
Add a link
Reference in a new issue