ABC problem
editable example
Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.
ghul
use IO.Std.write_line
use Collections.List
use Ghul.Pipes
without(blocks: List[string], at: int) -> List[string] =>
blocks
|> index()
|> filter(block => block.index != at)
|> map(block => block.value)
|> collect()
can_spell(word: string, blocks: List[string]) -> bool =>
word.length == 0 \/
(blocks
|> index()
|> filter(block => block.value.contains(word[0]))
|> any(block =>
can_spell(word.substring(1), blocks |> without(block.index))))
let blocks = [
"BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS",
"JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM"
]
let can_make_word = (word: string) => can_spell(word.to_upper(), blocks)
for word in ["A", "BARK", "BOOK", "TREAT", "COMMON", "SQUAD", "CONFUSE"] do
write_line("can_make_word(\"{word}\") = {can_make_word(word)}")
od