Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Number Wordle

deprecated_number_wordle.livemd

Number Wordle

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Return Home Report An Issue

Number Wordle

Wordle is a popular game where players get six attempts to guess a word. They are given feedback clues to guess the word.

  • Green if the letter is in the word and in the correct spot.
  • Yellow if the letter is in the word but in the incorrect spot.
  • Gray if the letter is not in the word.

For example for the word “TOAST” the guess “TARTS” would be

flowchart LR
style 1 fill:green
style 2 fill:gray
style 3 fill:gray
style 4 fill:yellow
style 5 fill:yellow

1[T] --- 2[A] --- 3[R] --- 4[T] --- 5[S]

You’re going to create a wordle game but for numbers.

It should provide feedback for a guess and and answer.

NumberWordle.feedback(3689, 3598)
[:green, :gray, :yellow, :yellow]

Ensure you handle numbers with multiple of the same digit. For example,

NumberWordle.feedback(1113, 2221)
[:yellow, :gray, :gray, :gray]

NumberWordle.feedback(1113, 2211)
[:yellow, :gray, :green, :gray]

NumberWordle.feedback(1111, 2111)
[:gray, :green, :green, :green]

Enter your solution below.

defmodule NumberWordle do
  @doc ~S"""
  Returns feedback on the given `guess` as it relates to the given `answer`.

  ## Examples

      iex> NumberWordle.feedback(1113, 2221)
      [:yellow, :gray, :gray, :gray]

      iex> NumberWordle.feedback(1113, 2211)
      [:yellow, :gray, :green, :gray]

      iex> NumberWordle.feedback(1111, 2111)
      [:gray, :green, :green, :green]

  """
  def feedback(guess, answer) 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 number-wordle-exercise
$ git add .
$ git commit -m "finish number wordle exercise"
$ git push origin number-wordle-exercise

Create a pull request from your number-wordle-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.