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

ABC043B - バイナリハックイージー

submit_1.livemd

ABC043B - バイナリハックイージー

問題

回答1

defmodule Main do
  def main do
    :stdio
    |> IO.read(:all)
    |> solve()
    |> IO.puts()
  end

  def solve(input) do
    input
    |> String.trim()
    |> String.codepoints()
    |> Enum.reduce([], fn key, acc ->
      case key do
        "B" -> if Enum.empty?(acc), do: [], else: tl(acc)
        new -> [new | acc]
      end
    end)
    |> Enum.reverse()
    |> Enum.join()
  end
end
"""
01B0
"""
|> Main.solve()
|> then(&(&1 == "00"))
"""
0BB1
"""
|> Main.solve()
|> then(&(&1 == "1"))
"""
1
"""
|> Main.solve()
|> then(&(&1 == 1))