Anagram Solver
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
Anagram Solver
Two words that contain all the same letters are anagrams. For example bored and robed are anagrams.
You are going to create an AnagramSolver
with a solve/1
function that accepts a word and
returns every possible permutation of the anagram. Each permutation does not need to be a real word.
For example,
AnagramSolver.solve("cat")
[
"cat",
"cta",
"act",
"atc",
"tac",
"tca"
]
You can expect that the number of answers for a word of given length n
will be n!
.
So a word with 3 letters has 6 solutions, a word with 4 letters has 24 answers, a word with
5 letters has 120 answers.
Enter your solution in the Elixir cell below,
defmodule AnagramSolver do
def solve(word) do
end
end
Mark As Completed
file_name = Path.basename(Regex.replace(~r/#.+/, __ENV__.file, ""), ".livemd")
progress_path = __DIR__ <> "/../progress.json"
existing_progress = File.read!(progress_path) |> Jason.decode!()
default = Map.get(existing_progress, file_name, false)
form =
Kino.Control.form(
[
completed: input = Kino.Input.checkbox("Mark As Completed", default: default)
],
report_changes: true
)
Task.async(fn ->
for %{data: %{completed: completed}} <- Kino.Control.stream(form) do
File.write!(progress_path, Jason.encode!(Map.put(existing_progress, file_name, completed)))
end
end)
form
Commit Your Progress
Run the following in your command line from the curriculum folder to track and save your progress in a Git commit.
Ensure that you do not already have undesired or unrelated changes by running git status
or by checking the source control tab in Visual Studio Code.
$ git checkout solutions
$ git checkout -b anagram-solver-exercise
$ git add .
$ git commit -m "finish anagram solver exercise"
$ git push origin anagram-solver-exercise
Create a pull request from your anagram-solver-exercise
branch to your solutions
branch.
Please do not create a pull request to the DockYard Academy repository as this will spam our PR tracker.
DockYard Academy Students Only:
Notify your instructor by including @BrooklinJazz
in your PR description to get feedback.
You (or your instructor) may merge your PR into your solutions branch after review.
If you are interested in joining the next academy cohort, sign up here to receive more news when it is available.