RosettaCodeData/Task/ABC-Problem/Elixir/abc-problem.elixir

17 lines
563 B
Text
Raw Permalink Normal View History

2015-11-18 06:14:39 +00:00
defmodule ABC do
def can_make_word(word, avail) do
2017-09-23 10:01:46 +02:00
can_make_word(String.upcase(word) |> to_charlist, avail, [])
2015-11-18 06:14:39 +00:00
end
defp can_make_word([], _, _), do: true
defp can_make_word(_, [], _), do: false
defp can_make_word([l|tail], [b|rest], tried) do
2017-09-23 10:01:46 +02:00
(l in b and can_make_word(tail, rest++tried, []))
2015-11-18 06:14:39 +00:00
or can_make_word([l|tail], rest, [b|tried])
end
end
blocks = ~w(BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM)c
~w(A Bark Book Treat Common Squad Confuse) |>
Enum.map(fn(w) -> IO.puts "#{w}: #{ABC.can_make_word(w, blocks)}" end)