43 lines
1.3 KiB
Plaintext
43 lines
1.3 KiB
Plaintext
val blocks = [("B", "O"),
|
|
("X", "K"),
|
|
("D", "Q"),
|
|
("C", "P"),
|
|
("N", "A"),
|
|
("G", "T"),
|
|
("R", "E"),
|
|
("T", "G"),
|
|
("Q", "D"),
|
|
("F", "S"),
|
|
("J", "W"),
|
|
("H", "U"),
|
|
("V", "I"),
|
|
("A", "N"),
|
|
("O", "B"),
|
|
("E", "R"),
|
|
("F", "S"),
|
|
("L", "Y"),
|
|
("P", "C"),
|
|
("Z", "M")]
|
|
|
|
pub fun get-remove( xs : list<a>, pred : a -> bool, acc: ctx<list<a>>) : (maybe<a>, list<a>)
|
|
match xs
|
|
Cons(x,xx) -> if !pred(x) then xx.get-remove(pred, acc ++ ctx Cons(x, _)) else (Just(x), acc ++. xx)
|
|
Nil -> (Nothing, acc ++. Nil)
|
|
|
|
fun check-word(word: string, blocks: list<(string, string)>)
|
|
match word.head
|
|
"" -> True
|
|
x ->
|
|
val (a, l) = blocks.get-remove(fn(a) a.fst == x || a.snd == x, ctx _)
|
|
match a
|
|
Nothing -> False
|
|
Just(_) -> check-word(word.tail, l)
|
|
|
|
fun can-make-word(word, blocks: list<(string, string)>)
|
|
check-word(word.to-upper, blocks)
|
|
|
|
fun main()
|
|
val words = ["", "a", "baRk", "booK", "treat", "COMMON", "squad", "Confused"]
|
|
words.map(fn(a) (a, can-make-word(a, blocks))).foreach fn((w, b))
|
|
println(w.show ++ " " ++ (if b then "can" else "cannot") ++ " be made")
|