Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/ABC-problem/Haskell/abc-problem-1.hs
Normal file
15
Task/ABC-problem/Haskell/abc-problem-1.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import Data.List (delete)
|
||||
import Data.Char (toUpper)
|
||||
|
||||
-- returns list of all solutions, each solution being a list of blocks
|
||||
abc :: (Eq a) => [[a]] -> [a] -> [[[a]]]
|
||||
abc _ [] = [[]]
|
||||
abc blocks (c:cs) = [b:ans | b <- blocks, c `elem` b,
|
||||
ans <- abc (delete b blocks) cs]
|
||||
|
||||
blocks = ["BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS",
|
||||
"JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM"]
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ (\w -> print (w, not . null $ abc blocks (map toUpper w)))
|
||||
["", "A", "BARK", "BoOK", "TrEAT", "COmMoN", "SQUAD", "conFUsE"]
|
||||
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