Lob Developers
Published in

Lob Developers

Writing a Word Game in Elixir: Spelling Bee

Spelling Bee: an elegant and satisfying word game
"lobceit" 
|> String.graphemes()
|> MapSet.new()
#MapSet<["b", "c", "e", "i", "l", "o", "t"]>
word = "beetle"
<<letter::binary-size(1)>> <> tail = word
# letter is "b"
# tail is "eetle"
defp wordlist_exists(wordlist) do
case File.exists?(wordlist) do
true -> :ok
false -> {:error, "Wordlist #{inspect(wordlist)} does not exist"}
end
end
defp wordlist_not_dir(wordlist) do
case File.dir?(wordlist) do
true -> {:error, "The wordlist at #{inspect(wordlist)} is a directory"}
false -> :ok
end
end
with :ok <- wordlist_exists(wordlist),
:ok <- wordlist_not_dir(wordlist) do
# Do something with vetted wordlist
end
iex> IEx.configure(inspect: [limit: :infinity, printable_limit: :infinity])iex> SpellingBee.solutions("lobteic", "b", min_length: 4){:ok,
["tobe", "titbit", "tibi", "tibet", "tebet", "oboe", "obit", "lobe", "libet", "libel", "elbe", "collectible", "cocobolo", "cobol", "coble", "cobble", "ceibo", "bottle", "botte", "bootee", "boot", "boole", "booboo", "boob", "bolti", "bolt", "bolo", "boll", "bolete", "bole", "boil", "bocce", "bobble", "blot", "bloc", "blob", "bleb", "bitt", "bito", "bite", "biotitic", "biotite", "biotic", "biol", "billet", "bill", "bile", "bilbo", "bice", "bibliotic", "bible", "betel", "bete", "belt", "bello", "belli", "belle", "bell", "belittle", "belie", "beetle", "beet"]}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store