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

day 5

livebook/2022/day5.livemd

day 5

part 1

test_input = """
    [D]    
[N] [C]    
[Z] [M] [P]
 1   2   3 

move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
"""
defmodule P0 do
  def parse(input_str) do
    [stack, steps] =
      input_str
      |> String.split("\n\n", trim: true)

    steps |> parse_steps()
  end

  defp parse_steps(steps_str) do
    steps_str
    |> String.split("\n", trim: true)
    |> Enum.map(&parse_step/1)
  end

  defp parse_step("move " <> move <> " from " <> from <> " to " <> to) do
    dbg()
  end

  defp parse_step(_) do
    ""
  end
end

defmodule P1 do
  def calc() do
  end
end

P0.parse(test_input)

test 1

ExUnit.start(auto_run: false)

defmodule P1Test do
  use ExUnit.Case, async: false

  test "P0.parse/1" do
    assert

    """
    [D]    
    [N] [C]    
    [Z] [M] [P]
    1   2   3 

    move 1 from 2 to 1
    move 3 from 1 to 3
    move 2 from 2 to 1
    move 1 from 1 to 2
    """
    |> P0.parse()
    |> P1.calc() == 2
  end
end

ExUnit.run()