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

闘魂 Elixir ── Tuning Trouble

notebooks/toukonex/tuning_table.livemd

闘魂 Elixir ── Tuning Trouble

# Mix.install([{:benchee, "~> 1.1"}])

About

Answers

input = "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
input |> to_charlist()
judge = &(length(Enum.uniq(&1)) == 4)

true = judge.([1, 2, 3, 4])
false = judge.([1, 2, 3, 1])

:ok
"mjqjpqmgbljsphdztnvjfqwrcgsmlb"
|> to_charlist()
|> Enum.with_index()
|> Enum.reduce_while([], fn {x, i}, word ->
  new_word = Enum.take([x] ++ word, 4)

  case length(Enum.uniq(new_word)) do
    4 -> {:halt, i + 1}
    _ -> {:cont, new_word}
  end
end)
|> case do
  x when is_number(x) -> x
  _ -> :error
end