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

Day 12: Hot Springs

day-12.livemd

Day 12: Hot Springs

Mix.install([
  {:smaoc, git: "https://github.com/nettinho/smaoc"},
  {:kino, "> 0.0.0"}
])

Solution

# :ets.delete(:cache)

:ets.new(:cache, [
  :set,
  :public,
  :named_table,
  read_concurrency: true,
  write_concurrency: true
])
solution_module = Smaoc.Solution

defmodule Smaoc.Solution do
  def solve(:part1, input) do
    input
    |> parse_input()
    |> async_combinations()
    |> Enum.sum()
    |> dbg
  end

  def solve(:part2, input) do
    input
    |> parse_input()
    |> Enum.map(&unfold(&1, 5))
    |> async_combinations()
    |> Enum.sum()
    |> dbg
  end

  defp async_combinations(lines) do
    lines
    |> Task.async_stream(&combinations(&1), timeout: :infinity)
    |> Stream.map(fn {:ok, x} -> x end)
    |> Enum.to_list()
    |> dbg
  end

  defp unfold({springs, broken}, n) do
    {unfold(springs, ??, n), unfold(broken, [], n)}
  end

  defp unfold(list, sep, n) do
    list = for _ <- 1..n, do: list
    list |> Enum.intersperse(sep) |> List.flatten()
  end

  defp cache_read(key) do
    case :ets.lookup(:cache, key) do
      [{_key, value}] -> value
      _ -> nil
    end
  end

  defp cache_write(value, key) do
    :ets.insert(:cache, {key, value})
    value
  end

  defp maybe_cached(row, len) do
    key = {row, len}

    case cache_read(key) do
      nil ->
        row
        |> combinations(len)
        |> cache_write(key)

      count ->
        count
    end
  end

  defp combinations(row), do: combinations(row, 0)

  defp combinations({[?? | springs], broken}, len) do
    a = maybe_cached({[?. | springs], broken}, len)
    b = maybe_cached({[?# | springs], broken}, len)
    a + b
  end

  defp combinations({[?# | springs], broken}, len) do
    maybe_cached({springs, broken}, len + 1)
  end

  defp combinations({[?. | springs], broken}, 0) do
    maybe_cached({springs, broken}, 0)
  end

  defp combinations({[?. | springs], [len | rest]}, len) do
    maybe_cached({springs, rest}, 0)
  end

  defp combinations({[], []}, 0), do: 1
  defp combinations({[], [len]}, len), do: 1
  defp combinations(_line, _len), do: 0

  defp parse_input(input) do
    input
    |> String.split("\n", trim: true)
    |> Enum.map(&amp;parse_line/1)
  end

  defp parse_line(line) do
    [springs, broken] = String.split(line, " ", trim: true)
    springs = String.to_charlist(springs)
    broken = broken |> String.split(",") |> Enum.map(&amp;String.to_integer/1)
    {springs, broken}
  end
end

year = "2023"
day = "12"
run_config = ["puzzle", "part2"]

inputs = %{
  "puzzle" =>
    "??#??#??##.#???? 4,2,2,1,2\n.#?#.???#?.?? 3,3,1\n#???.#???#?.?.??.? 2,1,5,1,1\n??#??#???????? 1,5,1\n?..##????#???#? 1,8,1\n?#?##??#?#?#???? 12,1\n?#???##???.??????? 7,2,1\n?###??????.?#?.# 7,2,1,1\n?.??.???.?? 2,2\n??##?##?.###???##?#? 1,2,2,8,2\n#.#?.??.??#???#? 1,1,1,3,3\n.#???#.?#????# 5,1,2,1\n???#???..?????#?#. 5,8\n##?#??.????#?????? 6,5,1,2\n??.?#??##????# 1,8,1\n??.????.????.?#..? 1,1\n.??????...?##?.?. 2,2,4\n??.???#???#?#?#???? 1,1,7,1,1,1\n#?.?##.??. 1,2,1\n#?????#??#.??.. 1,1,2,1,1\n??#???.??#? 6,1,1\n#?..?.????.?? 1,1,3,1\n??#??.?#?.#??#.?.#?. 5,2,1,1,2\n.????#??.#??????. 7,7\n??#?.?#??. 4,2,1\n#?.?.#??.?????# 2,1,1,1,1\n???????????. 2,2\n.??##????? 3,1\n#.?.??.????#?##? 1,2,8\n??#.?.#?##????. 2,7\n?#?.??????.????#??? 2,1,1,1,8\n?????#??.?#?.#?. 1,5,1,1\n??#?#?????.???. 3,3,1\n.?.???.??## 1,1,4\n.##?..##?.???# 2,3,3\n.##??????.# 2,4,1\n?#??..#????? 2,1,1\n?###?.????? 4,1\n??#.#???#??#?#?## 1,1,1,10\n??#???.??..##...##?? 1,3,1,2,3\n##?????????.?#?.???. 6,3,2,1,1\n##?.??.???# 3,1,1\n.??????#?#?.???##?? 10,5\n??????..?#? 1,1,3\n#?##?#...?##?#?#??? 6,3,5\n?.?.??????#?#? 1,7,1\n????.###??????#??#?? 2,13\n???.?????.??. 2,1\n?#?????.???#???#??? 3,1,1,1,1,2\n?.?.?????#?#?#? 1,8\n.#??#?#?.????????.? 7,2,1,1,1\n?...??.?##?????#??? 3,2\n??.?###?#??.?????? 1,4,1,1,1,2\n???.????????????###? 1,2,10\n???.???????#???? 3,3,1,3\n?#??#?#????#.?? 1,7,1,2\n??#????#?#?#?#??.##? 1,2,11,2\n..??.????#? 1,2,1\n.?#?.???.????? 1,3,1\n?#?#???#?#???.??#?? 12,3\n??????##???###?#???? 1,1,3,11\n?#?.??.???????? 2,1,1,2\n??.?#??????#?? 1,4,2\n.??.?#??#?. 1,6\n??.????.???? 1,1,2,2\n#.#????#??? 1,2,3\n..??#?###????.??.? 11,1\n???#?.??#???. 1,2,2,1\n?#?##???#..#???? 5,3,1,1\n.???.#??#?? 1,1,2\n????#?.?????????.. 2,8\n.?#??##.??? 6,1\n?????#???. 1,5,1\n.#?#?#??????# 3,5,1\n?.???#???#????????? 4,2,5\n#??????#?#.?.#? 1,1,3,1,1\n#??????###??.?????? 12,1,2\n???#??#?.#?###.??. 1,2,1,5,2\n.???.?#???##?#?????? 1,1,6,1,1\n??..?.???#??. 1,1\n???.?#?##?.???#??#?? 1,4,7,1\n????#??#??#..??? 9,1,2\n.?.#??.?????#??? 1,2,8\n#??#?..?###?#?????# 1,1,9,1\n???..?.?#?. 1,1,2\n????##?????#?.??? 6,3,1\n..#??#?????.???? 7,3\n?.??#?#??##?.#... 8,1\n?##??.????#.?????? 4,1,1,1,1,1\n.?????#???#?#?.?. 1,3,4,1\n#?##??#?#.#...??? 7,1,1,2\n??.????.?????###? 1,2,7\n?.##????#????.??. 7,1\n??????#???#????? 1,6,1,1\n?#.??#??#?#?? 1,1,1,5\n?#????#.#??? 1,4,2,1\n#??.?.?????. 3,2,1\n????????#?.? 4,3\n#.??#?#????.?#????? 1,3,1,3,1,4\n???#???#?.#?.#. 2,2,1,1,1\n?.#????..##?????.? 4,7\n??#???????? 3,2\n??..?...?##?? 1,4\n#??#?.??#?? 5,1\n?#??#???????????##?? 3,1,1,2,1,2\n?????????.#.. 3,2,1\n.??????##??? 1,7\n?.??.??.#??. 1,1,1\n???#????#??????????? 1,3,1,7,1\n?#?.#??.????# 2,2,2,2\n???#?#???#???. 8,1\n???###.?#?#??#? 1,3,3,2\n?.#?????#??? 4,1,1\n????.?#??#??#?? 1,8\n.??..???##????#?? 1,6,1,1\n?##?##??#??#??#???#. 5,8,3\n?..?#?.????? 1,3,1,2\n?##.?#????? 3,4\n??#??#????## 5,1,2\n#..?#??..#? 1,3,1\n?#?#?.???###.# 1,1,5,1\n?????#?????.. 5,1,1\n?#??#.?.?? 4,1\n????#??#??.?#??? 5,2,4\n#??#?##??.????.???? 8,1,1,1\n?#??#??#..??##..??.? 2,5,1,2,1,1\n??##????####????? 6,9\n.??#??###??????#???# 1,8,1,1,1,1\n??##?..??#???.?? 3,4\n????#????????? 9,3\n?##??.???..?? 3,1,2,1\n#?.???#??#????#.?? 2,9,1,1\n#.???#?#?#??????.??? 1,1,8,1,1,1\n#.?.??#####?#?????? 1,12\n.??###?##????.???#?. 11,3\n?#????.?????#?.?? 5,2,1,2\n??##?#????.??#.????? 7,1,1,1,1,1\n.??????.???. 2,2,1\n??#?...?##??? 1,4\n..?????.???#?#? 3,6\n?.???????#?#?. 1,7\n??#??.??.. 3,1,1\n?.#?.????#?#??.??? 2,1,4,1,1,1\n#?##??#..? 1,5\n?????????.#?? 5,1,1,2\n.??.?????.?????##? 5,7\n?.#????#??? 1,5\n????#???.????? 3,2,1,1\n.??.?##???#? 2,3,3\n.???##??.??.##???.?? 7,1,5\n????.#???#? 1,1,3\n??????##?### 1,6\n?????#?##????? 6,1\n?#??#.??.??. 4,2\n?????.?????#???.#? 4,9,1\n??.???????..?.. 1,1\n?.??????##??#????. 1,5,2,2\n.??#?????? 1,3\n??#?.???.?#?##??#?? 1,8\n?.?#?#?##?#?#??. 1,9,2\n?????.?.???#?#?##?? 3,1,9\n.??.?#?.#?##?. 1,1,5\n#??????##..#???.#??? 1,6,2,1,1\n#?.?.???#. 2,1,1\n???#?#??????. 2,1,1,1\n##??.?##.?.????#? 2,3,1,3,2\n???.#?.?#????? 1,2,4\n#???.??#???. 1,1,4\n?..????????#???.?. 1,1,1,5,2,1\n????????.??..?.? 4,1\n?.?????.... 1,1\n.?#????..###?????#? 2,1,1,3,1,1\n..#.??#??????#?#?? 1,12\n.??#??##??.????#. 7,5\n?##??#?#??.?#???. 9,2,1\n?#?#?#???.#?#.#? 8,1,1,2\n?.??.???.#?? 1,1,1,1\n??????.?.#?? 5,2\n???#????.????????? 1,1,1,1,8\n??????##??#?????? 14,1\n???.#.?.???????####? 1,2,4\n.#.??#??#???.#??#??. 1,6,2,1,1\n.????#??????### 5,1,5\n.??..#?..? 2,2\n???#?????#..??# 6,2,3\n??????#?##.?#??#.??. 7,5\n????????##??.#? 2,2,3,1,1\n?..###?#??..??..#??? 5,1\n#????.??##?##?? 1,1,1,7\n#?????#???????. 1,1,4,2\n??????.??????#. 1,1,1,3\n???#..???????# 2,1,8\n#.??#??..???# 1,3,1,4\n????##?????##??.?#? 1,4,1,1,4,2\n?.???#?????.??? 1,1,1,1,2\n.???????#? 1,1,2\n.??#?.???.# 3,1\n...?#??????#.#?? 1,1,1,2,2\n??#?.????.??## 3,2,1,4\n??#?###??????. 7,1,1\n??.?????#?????.?#?.. 1,5,3,3\n..??##?????.#??? 4,2,1\n??#.????#??#.??? 2,1,2,1,1\n???#??.???.??#? 1,3,1,1,4\n?#???###????.??? 9,1,1,1\n?...?.??#.????? 1,2,2\n?#????##.?#???? 2,5,1,2\n?#??#??#??.?.??.?##. 2,6,1,2,2\n..??#?.##???? 1,2,2,1\n##?..#?#?..#??? 2,3,2,1\n??.??.??#????? 1,3,3\n.??#????#?? 2,1,2\n.?##?.#?##?..#? 4,4,1\n.??.?????? 1,1,1\n???..???##????. 1,2,2,1\n??#??????#??? 2,7\n???#.??????#???????# 1,1,1,5,3,1\n???.?#???#?#??# 1,1,1,2,4\n?..?#??.??##.???? 1,3,1,2,3\n##??????#?.?.?.?? 2,1,3,1,1\n.?..???#???#??#### 1,13\n?#??#..?.#?. 4,2\n??#???.??? 3,2,2\n..??##?#??..??? 6,3\n#.????????.??###?#?. 1,1,1,1,5,1\n???.?..?## 1,1,2\n?.?.???????.???????? 1,1\n???.??????..?. 1,2,2,1\n?.#????????###.?#. 1,3,1,2,3,1\n??#?????##??#?? 11,1\n??????#???? 1,2\n.##?.?????????#??? 3,4,2,4\n?#???.#.??? 3,1,1\n.???#.???.#. 1,1,1,1\n????.??#??#?#??.?? 1,2,6,1,1\n#?#?.#?????????#?# 1,2,1,2,5,1\n??.#??????#?. 1,1,2,2\n#?.?.##...#??#?# 2,1,2,6\n???#??..?? 6,1\n?????????#?#???.???? 1,1,11,2\n???#?#?#????..? 1,1,3,2,1\n??#???#??????##?#.?? 17,1\n????..???? 1,3\n??????#???##???#? 2,1,7\n####???.?? 5,1,1\n?.???????#?#?##?##?? 1,1,1,7,2,1\n???????.#?? 4,1,1\n??.##???.#???#??#?? 1,2,1,1,6\n.?#????????.?#?..?. 4,4,2,1\n??#?.??#??? 4,5\n#??????##??. 1,1,3\n#?????#.??#?.#?# 2,3,1,3\n???????#?#?????????. 14,2\n.??.#?#???##??#.. 1,9\n?????.?????#?#??? 2,1,6\n?????.?..??#??.#??? 1,1,1,5,1,1\n.?.#??.?.??.? 3,1\n?.##??###?????#???? 9,1,1,1\n?#.#??????#..??#?? 2,1,4,4\n?.?.??#??.??.??#?#? 1,5,5\n..#??.???.?###?. 2,1,3\n?????????? 3,1\n?#????#??????#?? 2,4,7\n.??.???????#???. 1,8\n.?????#???????#??? 1,11\n?.??.??????#???? 1,1,3,2,1\n.#.?##?#??#??# 1,5,2,2\n??????##?#??#??.? 1,8,1,1\n?#####?.##?#????.?? 7,4,3,1\n?#????#??# 4,2,1\n???#????.?. 1,5,1\n??#???#???.? 2,2,1,1\n.#?#?#?#????..?? 1,1,1,1,3\n??.????##??##?.?. 1,5,3,1\n?#??????.???? 2,1,1,4\n??.?.??????##???## 2,1,1,8\n.???.####??????#??. 1,4,6\n..????#.?????????? 2,1,1,4,1\n.?##???????##????. 3,7\n???##??#?????.????.. 9,1,4\n..?.??.??????.#?.?# 1,2,1,2,2,1\n?#????????##????#??? 1,2,6,1,1,1\n????####???????? 2,7,3\n.?.????..?.?????. 4,1\n???#???#?#???#?#? 2,11\n??.#?????.?.# 1,5,1,1\n?.?????##...??? 1,6,2\n???###???#????? 6,1,1,1\n??#????????.?.??.? 4,1,1,1,1,1\n?.???###???##??# 1,2,3,2,1\n?..?????#??.???.?#? 1,6,1,1,1\n??.?.??#???? 1,5\n.?.#????#??????#?# 1,7,1,1,1,1\n.???????#??#?? 1,7\n???.?????#.? 1,6\n?#??#?.??????? 1,2,1,4\n????#?#?.#????????? 3,3,1,6\n??##?.???? 2,2\n?#??.????#?? 2,1,5\n#?.??.?#?.??#?.??# 1,1,2,2,1,1\n?#?#??.??#?????? 5,3,1\n#?#?#????.??...?? 1,4,1,1\n????.?#?#?#. 2,4,1\n#?????#??????.?? 10,2,1\n.?.????#.?????? 1,4,1,2\n???#?#?##????#??? 9,3\n#??.#?????.???? 2,1,1,1,2\n??.????????#??? 2,1,1,1,3\n?#?.#???#???#??#?##. 2,15\n??#???#??????#? 8,3\n.??....???? 2,1,1\n?.???..#??.???????. 2,2,5\n.???????#?. 3,1\n????##?####??????#. 1,13,1\n?..?###??.???. 3,2\n?##?#?#?#?????.? 4,8\n##??.#???????# 4,1,1,2\n.???.????## 1,5\n????#????#????#???#? 2,7,6\n??#????#?#.????????? 1,1,1,1,1,8\n??.??.??##????????# 1,1,4,1,1,2\n??.????.??##?# 1,4,5\n?#?#?.?###??.?.. 4,6,1\n??.##?.?#? 2,2\n??#??.???..?? 3,2,1\n.#.?????.??. 1,1,1\n???????#????.?##? 6,2,1,4\n.????#?????????###? 6,1,2,4\n.??#????.????.. 1,4,3\n#.#?????#?#????.??.? 1,2,6,2,1,1\n?.???#.?#??????.?. 1,4,2,5\n???.?##.#?##. 2,2,1,2\n?.?####??#????#? 7,3\n?##.?#???#?#.?.??#. 3,1,4,1,1\n?????.????#???. 2,1,1\n...?#?#?#?.#?#?? 6,5\n?#?..??#?#? 2,5\n?#?..??????????# 2,1,1,4\n#.????????.???#?#. 1,1,5,2,1,1\n#???????#?. 2,4\n??????.###?.??????#? 1,1,3,5\n??????.##?????#? 3,8\n?#??.##???? 3,6\n???.?????#?.?#??? 5,1\n???#???#???.? 1,7,1\n?#..?.?.?# 1,1,1\n?.???#???#?? 4,4\n???????###???.#. 13,1\n??#???.#?#?#.??? 3,5,3\n##..##?#???? 2,4,1\n??..??.?#???? 1,2,2,1\n????????#???#??#?# 2,1,3,8\n??##?.?????#??#?..? 1,3,8\n###??#??#?#???#??#? 3,6,3,2\n.??.??.??##??? 2,1,3,1\n???#???#?#.#??#.? 1,5,1,1,1\n???#??##.????. 1,6,1\n#.??##??#?#??.???? 1,1,9,1,1\n.??.?##??#?. 4,1\n?.??#????????.#??? 3,5,2\n.??????#.? 1,3\n????#?#???????#?#. 1,2,1,1,7\n?.???#.#??#??#? 3,2,5\n???.#?#??.??#???.?. 4,3\n?.?????##?#?? 4,1\n??#???#???##??????? 2,14\n???????#?.. 3,2\n#???.?##?##???##... 1,10\n??????#??.??.. 6,2\n..#?.????###.#??# 2,5,4\n???.??.#???#?.# 2,1,1,3,1\n????.??#????#?.?? 2,2,1,3,1\n??##..?.???? 4,1\n.???#?#???#.?.#?#?## 9,6\n?....????####? 1,7\n?#??#?#???? 1,4,3\n#??#???..# 1,4,1\n???#????#??. 2,4,1,1\n???????.?..? 1,1,1,1\n?#??#?????????? 2,6,1,2\n?.#???.????#????#?? 1,7\n?????.#??#???#? 2,1,4,3\n.?###?????????. 8,4\n?.#?????????##??#? 1,1,1,10\n??#??????.. 1,3\n??#??#...?#.?#?????. 5,1,7\n?#?..??????.##.??? 3,6,2,1\n#.#.??.????#??????? 1,1,1,5,1,3\n#.??#?????#?#??.???? 1,12,2,1\n?##?..##??#???? 2,2,3,1\n.?#???.????#?? 1,2,3\n#?.???????#???# 1,1,1,6,1\n?.??.??#..??.#?## 2,2,1,1,2\n.???.????? 1,1,1\n?#???????? 4,1,1\n?????..????#??#? 1,6,1\n??#????#????????? 8,2\n?.???.?.???## 1,1,1,3\n?..?.?..?. 1,1\n?..???.?#?#?#?#? 1,8\n???###???#.?.#.?#??? 10,1,1,4\n#.?#??#?.??.? 1,6,1,1\n#??????????#?????? 8,2,2\n??##?.#??. 3,2\n.#?#??#??????#. 1,1,3,1,1\n???.?..??.??#?? 2,1,1,5\n.????#????#????..?? 1,8,1,1\n?##?##.??## 3,2,2\n??????.??.# 4,1\n??#.???#??.?#????#? 2,1,1,1,2,2\n.???#??###???#?# 4,3,5\n??##?#?#?#?..#??? 9,3\n?#?#???.?# 1,3,2\n????#?#??.? 1,5,1\n?.??????.? 1,3,1\n?.?.??.?#?..??#??? 1,1,3,1,4\n.??##???#?##??. 3,1,3\n??##?.??.?????. 4,1,1\n???##??#??#??..???? 1,2,5,1,1\n??????#????..? 1,2,5,1\n??#?.?.??# 1,1,1\n.????????.?? 1,1,1,1\n.?#?.?##?#?? 3,5,1\n???.???#?.. 2,2\n.???#??.??? 1,2,2\n??#??????????? 1,5,1\n??.?.?##..#? 1,1,3,1\n??????#??# 2,1,2\n#?.???##??.?? 2,1,3,2\n?..?#?.?????## 2,4\n#?##?.##??#?????#?? 5,8,3\n????#?..???? 2,4\n?.????#?#????? 2,5\n???#?????.????? 6,1,1,1\n#???#?????##?????? 2,5,4,3\n#?#?#.?#??? 5,2,1\n.?#??.?????#?###. 2,1,2,5\n??##???##????#??? 2,4,4\n???.#??????.???? 1,1,7,1,1\n??.???#???#?????? 1,2,1,1,7\n##???#???#???. 2,1,2,5\n??.#?...#?? 1,2\n?#????#.?#???#?#?#? 2,1,1,11\n?###???????# 6,3\n.??##?.??.????????# 4,1,3,4\n.?????#??? 1,3\n#????##?#??????? 2,2,6\n?#?.?????????.# 2,1,5,1,1\n??.?????#?? 1,1,3\n.?#####?.#??? 7,2\n..???##?..??? 5,1\n???##???#?? 2,4\n#.?#..???##????? 1,1,10\n?????????????? 7,2\n?.???.???# 1,2,3\n??#??????#?.??? 4,2\n?#??????..#?.?? 6,2,2\n??.?#?..#.?????# 1,2,1,2\n?.??#???.??#??? 4,2\n?#??.????.?????. 2,1,1,5\n..??.#?#.??#.???#? 1,1,1,1,1,3\n?#??#??.?. 3,1,1\n???????#??#??##?.? 11,2,1\n?#??##.#??.????#???? 6,1,1,8\n.?##?#?##????? 11,1\n??#?#???#????.?..??? 11,1,1,1\n???????..##.?##? 4,2,4\n??.#?#.??. 2,3,1\n????##.#??? 2,3,3\n?#..?.?#?#??.????# 2,6,5\n????#?????. 5,1\n???.?.????#. 3,5\n?.??#?###? 1,6\n?#?..???????? 2,6,1\n????????.???#?? 1,3,1,1\n.?###???????#???? 8,5\n????#???????? 8,2\n..???#??.#.# 1,2,1,1\n#???#?#.?? 1,5\n???#?.??#? 2,2,1\n?#??#?????#?#?. 2,2,1,1,1\n?#.?.#????.?#?????? 2,3,1,5,1\n.????#?.#?.?#?.?.?.? 5,1,1,1,1,1\n.?????###??##???.? 12,1\n?.???#.?#??##.?? 1,1,2,3,1\n?##?.????????##. 4,5,3\n#??????????. 1,1,2,2\n??#?????##?#. 1,7\n#????.??#?##???? 1,2,7,1\n???#??.??.## 6,1,2\n#???#..???? 5,1\n?..#??##.?.#??. 5,3\n?#?????#.#???? 2,4,3,1\n??#??#????? 4,2,1\n?.??##??.#??? 3,1\n???.#??#???????#?.? 3,4,4,1\n?#?#?#????.?.?#???? 9,3\n??#??##????#??????? 12,1\n??????.???#?? 3,4\n??#???#???##..#?. 11,1\n#?????.?.. 1,1,1\n.?????##?. 2,2\n???..??#?.? 1,3,1\n#??#???##?? 2,7\n???????#??.?? 1,3,2\n#..?#???.#?.??? 1,2,2,2,2\n?#???#.??.?.? 6,1,1,1\n??#?...??#??? 2,5\n?????#.##?#????? 4,1,2,5\n???.?.?.???.????? 2,1,2\n#.?..??????.???? 1,1,5,1,1\n??.???.???#??? 1,2,2,1\n?#??????????. 1,1,2,1\n.???##?.?.#.?##???. 2,2,1,4\n??.#????###??.#?.. 1,10,2\n.#?#?.?????? 4,2\n?.?#?????? 2,3\n..?#??????????..#?? 11,1\n.???#???##???????##? 1,3,3,1,3\n????#????? 1,1,1\n?#???????##??? 11,1\n???????#????#. 5,3\n?##?##???..#??.??? 5,1,1,1,3\n??..?.?##?#??????# 1,12\n.????????????#???? 4,1,1,3,2\n.????#???????.? 1,7\n?????#????#?????? 6,3,1\n?.?#??...?.???##??.. 3,3\n#??????#?????.? 4,1,2,1\n??#..??#??????? 1,1,3,1,1\n#??#?.??.?.??..#? 5,1,2,1\n?#?#????????????#.?? 4,7,3\n?#???.??#????#? 1,1,3,1,1\n??#?#???#?#.#?.#? 1,2,4,1,1\n???#???.#? 4,1\n?.?#.??##.???# 1,3,1,1\n#???????.?.????? 1,1,1,2,1\n?#??##?..???#???#??? 1,2,11\n?????.?????#???????? 1,1,5,3\n#?.???#???? 1,5\n???##???#.#. 9,1\n#.???????#? 1,5,2\n##?.??##?.?? 3,3,2\n???????????#????? 12,1\n???.###??????##?? 2,6,3\n??#.????.?? 1,4\n?.??????#?????# 1,2,5,1\n?????#???.?? 4,1\n???????#?#????.? 1,1,1,4,1\n?#.#.???????#???.??? 1,1,1,8,2\n???.?##??? 1,4,1\n???#????.?#.#?????# 1,6,1,1,1,2\n???.???#????#?????.? 2,1,7,3\n??##?????#? 5,1,1\n.?.##????#?. 1,2,2\n????.?#?.## 1,2\n??????.#??##??##?.# 1,3,1,2,4,1\n?#??#?????????.?#??? 8,2,1,2,2\n???#?????#?. 2,3\n???#??????# 6,1,1\n?#.#.?.??.?? 1,1,1,1\n???#??.?.???#???##? 3,9\n?#????###.?#? 1,1,3,2\n.?#?.???##. 1,2,2\n????#?.?#.???? 3,2,2\n???#????#???#???? 3,2,2,3,1\n??#?????????##???? 1,1,9\n#.?..#..?#?.? 1,1,1,3\n???#??.??#?#???. 4,6\n?.?.???#???##??#. 1,5,4,1\n#????#.??#??#?#?? 6,5,2\n??#.??#???#???#???? 1,10,1\n?#?#.##?.#?? 4,2,2\n????#??????##???? 1,1,5,2\n..##??##????? 2,5,1\n..?????????? 1,6\n?##?#?.????. 4,1\n???????#.???? 3,1,3\n#.#??????#????#. 1,2,1,1,3\n???#???.?????? 5,2\n..???#?#?.???? 1,1,1,4\n??.#??.?#? 1,1,1\n???#?.??.??????#???. 2,7\n???##????.??? 1,3,1,1\n?#..?#??.?? 1,2,1\n#.?#????.? 1,6\n?..?#??.###????# 1,3,3,2,1\n.#..??????#???.?? 1,9,1\n???????.?#..??????? 5,1,2,2,1\n??#.#??##.. 1,1,5\n#???????#????#?.?? 1,13,1\n?????.??#? 1,1,3\n#.?#???.?.#.#?#??? 1,4,1,1,1,1\n???##???.??#.?? 7,1\n.??#??#??.?.???? 8,3\n??#??????.????#? 7,1,1\n#??.?#.???.?????? 2,2,1,1,3\n.??.?.?.?#??? 1,5\n????.??#??##. 2,1,3,2\n???.??.?.???#???#.?? 1,1,1,1,8,1\n??##..???. 1,2,3\n..???#????? 1,4\n??.???????? 1,3,1\n??#.?##.???? 2,2,1\n.??#?##??.??#? 6,2\n.#??.#????#??#????? 1,9,2\n?#??#??????? 3,1,3,1\n??#?#??#????#.???. 10,1,1\n?????#?????##?? 1,3,7\n#???????.#???#???#?? 1,1,1,1,6,4\n.???###??## 1,3,3\n#?#?#?#??.?#####??. 1,1,3,8\n.???????????##? 1,5,3\n..?.?#?#?? 1,6\n#????#?..? 3,1,1\n????#??#?.??#???? 5,4\n????#.#?##??.??????? 4,5,1,2\n#???#?#??#??#..??#. 13,1\n.#???.##.?.??#??#?? 4,2,1,1,5\n??..?.????? 1,1,2\n??????????.?????#?? 10,3\n.??#??###??#??#?? 10,1,1\n.####.???.? 4,1,1\n?..?.###??.? 1,3,1\n???????..????????? 3,9\n?.??????????. 1,6\n.??.???#????? 2,1,3,1\n????#????#? 2,1,1\n???..??????? 1,3,1\n..???????.##?. 5,2\n?#??###??# 1,3,1\n???#..#??????? 1,1,3\n.???#??.?#.???????# 3,1,1,2,1,1\n?...#.??.?#?? 1,3\n???#?#???.#??. 1,3,1,2\n.????????????.??.. 7,1\n?.????????.#?.??#. 1,4,1,1,3\n??#?###.?..##?#?.? 5,5\n?#.?.?#?.?#?????. 2,2,6\n??##?#???.?#?#?????? 6,1,1,1,2\n??????.??? 1,1,1\n.?#???##??#??? 6,2\n??#????.??#???. 6,3\n?????????#??.? 2,5\n??##?????????? 2,1,1,1\n?????.?#??.# 3,2,1\n??#?#????.?? 5,1\n????.?#?#?#????#?.? 4,1,1,6,1\n.?????.???#. 1,1,2\n##????????#.????? 2,3,1,1,1\n#.??#???####.? 1,10\n??#???#.??????? 4,1,2,1,1\n?#?#??#.?#.?? 6,1,2\n??##??#????.??? 7,1\n?#?????#?#??#??? 2,7,1\n?????.????. 2,1\n?#???#??#.. 2,3,1\n.??##??????.. 5,2\n.??###??#??? 5,1\n??????####??##???? 3,11\n?.#?#?#?#??? 1,5\n?#??#..??????#### 5,1,1,1,4\n.??#..##?#??.#.#?? 1,1,4,1,1,3\n?????##??##?##?? 7,5\n.??.?#???...???#???. 1,5,4\n?#?#.??????.. 3,4\n??????.??. 2,2\n#..?????????#???? 1,1,1,4,1\n???????#???????# 9,2\n.#?.???#?#?? 2,1,2\n?##?#????##??? 3,1,1,5\n#??????#?.?#?.?? 1,2,4,3,1\n.?????##??#????# 1,7,1\n?????#?#??? 7,2\n#??????##?.#???. 5,2,2\n????##???#??##?.??? 14,2\n???.?.?????? 1,1,1,1\n?..?#.???????????? 1,2,9,2\n?????????.?#???.# 8,3,1,1\n.???#??.????.##??? 1,3,1,1,3\n??.?#??#????##.? 5,2\n??????.?????#??? 5,1,5\n?.?????..??#??..?. 5,3\n?.????????? 1,6,1\n???#?.?????. 1,2,5\n.##.#?##?#??????? 2,8,1\n??#?.????? 4,1,1\n?#????##.#.#??? 3,3,1,1,1\n??.?#.?????.. 2,4\n???#.??##. 2,2\n?????????? 5,1\n#????##?.? 1,4,1\n?#?###???.?.?. 1,6,1\n???####?#.?..?.#. 8,1,1\n??????????.?????#? 1,1,3,1,1,1\n????#?#?.?#??..## 7,1,1,2\n???.???#???# 1,5\n??.??????#?##??? 1,7,2,1\n#?.#???##??##?.?.? 2,2,7,1\n???????.????????. 1,1,2,7\n??#.?.??##? 2,1,4\n?#..????..? 2,1,1\n????#?#####???#??? 12,2,1\n#?#?#?#?#???????# 10,1,3\n??#.#?????.????????? 1,2,1,7\n????.?.#???.??? 1,4,1\n?????##??#?##... 1,8\n.##??????????? 3,2,1,1\n.#??.??#??.##?#? 3,3,5\n???#????.????? 7,2\n?.?.??????.??. 1,1,1,2\n..???????##????#??? 1,7,4\n???????#?.?#?#??.# 2,3,1,5,1\n???????#???# 4,2,2\n#????.??#?????#?. 1,3,1,2,1\n??.??.#??##. 1,5\n#??#?..##?#? 1,1,5\n???...????#????##??? 2,2,4,5\n#??#????.?.?????.#? 7,1,2,1,1\n??.?.?#??##???#?##?? 1,1,2,12\n?#?..??????#??#???? 2,6,4\n??.?????????#?.? 1,6,1,2\n?????#???#?#?##.??#. 12,2\n.####???#.???# 5,2,1,1\n???.????#? 1,2,2\n??##???#.? 4,2\n???..?#??#? 2,5\n##??#??#??#???? 2,5,2,1\n#?????.??#? 6,3\n??.????#???##? 2,6,2\n?????????##????##??? 1,3,11\n??????.???. 3,2\n.?.#.?????????????? 1,1,1,1,1,4\n.????.???#????#????. 3,8\n.??????????.#.#??? 9,1,4\n?#..?.?##???##?.# 1,1,9,1\n???#??#????.?# 3,1,2,1\n??.?.????? 1,1,2\n?.???#?..?? 1,2,2\n.?##?#???.?? 5,1,1\n??..?#?.???#??## 2,8\n.#??.#???.#?#???..? 2,2,1,3,1,1\n???.??##???#???#? 2,2,7\n??????#???##????.?# 2,1,4,2,1\n?????..????#?? 5,1,2,1\n??###??#??.??? 5,4,1\n???##???.# 5,1,1\n.???.???#?.?? 1,4\n????#????.#?.??#? 3,2,2,3\n?..???#?#???? 1,1,3,2\n?##?#?.?..? 3,2,1\n?..#?..?.?.##??? 1,1,1,5\n#??#?.#?...#? 1,2,1,2\n??...??..??.. 1,2,1\n?#?????#????#?#????? 1,1,1,1,1,7\n?.??#????#?# 1,1,1,5\n????????.?. 2,2,1\n?.???#?????#.#??? 1,10,1,1\n????..?.?.#????????? 3,1,1,4,4\n?#???.?.?#????.#???. 5,1,2,1,1,4\n??#???..?#??????? 1,1,5\n?#??#?????????? 1,3,7\n?#????...##?#?# 5,4,1\n.??.?..??##?????? 1,1,4,2,1\n#????#??.???#.##.? 8,1,1,2,1\n???#??.???####??? 1,3,7,1\n.????#?#.?#### 2,4,5\n?.#??.???#???#??##. 2,10\n???????????##. 9,2\n.??#?#?????#?? 5,5\n.?#???#??#?? 3,4\n???..?????..??? 1,1,1,2,3\n.##???#??????#?##? 7,5\n?#??####?#??????? 9,3\n??#?.??.?.####? 1,1,1,4\n#?##?#??.#?#???# 1,6,1,1,2\n.#?????#??#??? 2,1,6,1\n?.#.???#??? 1,1,1\n??#??#??#?.?? 3,1,1,1\n#???.#???#??##??#. 4,2,1,4,1\n?.??#?#??? 5,1\n???.?####?.???.????? 6,3\n???.##??#?? 1,2,1\n.???#??.#???##???.? 3,8\n.######???????? 6,3,1,1\n?.?#?.???..? 3,2,1\n??????#????#??????.# 14,1,1\n??.?#?##????.#.??#?? 1,1,2,2,1,4\n#?#?????#?#??#?.??. 1,2,8,1\n?#??.#???#??.##?.? 4,1,4,2,1\n?#??#????#??###??? 6,8\n??????#?#? 1,7\n????#?.?.???? 5,1,1,2\n???..?#?#?? 1,4\n??#?##?...?. 1,3\n#??.?#????### 1,1,4\n.#?##???.?#?? 4,1,1\n??.#.?????#???#??. 2,1,1,5,1,1\n?????.???. 1,1,3\n.?.???#???#.???#. 7,3\n???????#??????.???? 1,1,3,4,1\n#???...???###????##? 1,2,7,4\n?#???#???#??#?#?..# 6,1,1,1,1,1\n?????##?#?#??.#??? 10,2,1\n?????####?#??#??. 11,1,1\n?.???##??????.? 1,7,2,1\n#?.?????#??.??????.. 1,4,3\n??#???#??????#??.? 2,10\n??#??.????.. 2,2\n????#??..?? 1,4,1\n????????#?? 1,7\n??#?.??????.?.???? 1,1,4,1,3\n?.??#..??. 1,1,2\n?#.???????#?????.?.? 1,9\n?.?????????#.???? 10,1,1\n?#???#?????????????. 7,5\n?????#?.???.??#?. 2,1,1,2,4\n..?...??#.?#?#.###? 1,3,1,1,4\n??#.?##.??????. 2,3,1,1,1\n????.?#??#???# 1,1,9\n??#???###?#????# 8,6\n?##?#?#???#????. 3,5,4\n?#?#?????#??????#.?# 4,5,1,2,1,1\n..??#????#?? 1,1,1,1\n????#?#?#.#?? 2,1,3,3\n?????##???#???#. 6,6\n?.#...???##.????? 1,2\n?????....?# 1,1\n????????###??????#? 1,2,8,1,1\n?###?????#..????? 9,3\n????.??????.?. 1,2,2,1\n.??????#?????.?#?? 1,4,3,2\n..???????. 1,2\n??.??????? 1,1,1\n????????.?.??? 2,2,1,1\n?????????.? 6,1,1\n??#????##?#??#??#? 3,1,10\n?.??..#??????#?.? 1,2,8,1\n?.????..#?.. 2,2\n??.??????#??#????? 1,1,1,1,7,1\n????????#?.#?#?.# 8,1,1,1\n#.#?.#.??##?????? 1,2,1,7,1\n???????.???. 1,2,1,1\n.#???###???.?#. 3,5,1\n?????????#?? 1,1,5,1\n???????##???? 1,7\n??????.??#?# 3,1,2,1\n#???.?#???#? 3,4,1\n?????????#? 4,1,1\n...##?###?.?..?? 7,1\n??.?#??#?????????? 1,2,1,5,2\n????#???#?????? 2,1,6,1\n??#?.???????? 4,1,1,1\n###?????????#?.#?#?? 5,5,1,1,1,1\n??.??##?.?. 1,4\n????.????#???????? 1,3\n.?#??##??.??????#??. 8,8\n?..??#??#?.??. 5,1\n.#?#?????# 4,1,1\n?#??#..?#????? 1,1,4,2\n#??#.??????# 2,1,6\n??????..????.. 4,3\n.##????????#??#? 2,1,1,6\n.???.???##? 2,4\n?.??#?????#??. 1,5\n???#?.?##?? 2,3\n?#...?.#..?#?#?#?#?? 1,1,6,3\n???????###?? 2,5\n#?#.??#.#?.?#?? 1,1,2,1,3\n#???.?.?##. 3,1,3\n#?.??###??. 1,6\n..?????????.??# 4,1,1,1\n??.?????#??? 1,1,2\n??.?#???????? 1,5,1\n??.?.????????#?##? 1,1,2,8\n?###??.??. 6,1\n.?.#???#.? 1,1,1\n????????#?. 3,3\n#.###??#?#????? 1,8,1,1\n???????.#?#????.? 1,5\n??#????..??#??#?.# 1,1,1,1,4,1\n#??#??????????? 1,5,1,1,2\n??##.?#???#??? 2,5\n#.????#.??.? 1,1,1,1\n????###????. 6,1\n.#?###?#.?#??? 7,1,1\n??????.??.#????. 3,1\n?#???##??#.#?..? 9,1\n???????#?#? 3,4\n?#?????##?.?#?#???.? 2,6,7\n???#?.###??#?. 5,6\n???#?.##??#?#? 1,3,1,2\n???????#???#??????. 2,8,1,1,1\n.#?.??#..? 1,3\n????????..??? 2,3\n????#????.?# 5,1,2\n?##????.?.?. 5,1\n###?#?????#???#??.# 5,2,7,1\n??#?#..???? 3,3\n.??.??????.#?? 2,2,2\n.??.?#.??#???????? 2,1,1,1,1,1\n???#??##???..?? 1,9,2\n...#???.##?.?? 1,2\n#??.??.?..?#?? 3,1,1,1\n???#????.????#??. 2,2,2,3\n?.???.???..???#.? 1,1,4\n?.??#?#?#?.#??#??#? 8,7\n?#..????#? 1,2,2\n?#.#.#????????###? 1,1,1,10\n.????????? 5,2\n????#?#.??.??# 7,1,1,1\n?????##??????.???.# 1,1,6,1,3,1\n???.????#.? 1,5\n??#????#?#? 6,2\n.#.?##?#?? 1,2,1\n.?????#??#???.#? 3,3,4,1\n.#.????#?.??? 1,6,2\n????#??#??#?#? 1,2,7\n?#????.#?#??#??#? 2,2,3,6\n??#??#?.??????. 7,2\n##?.???.##???##?# 2,3,7,1\n??????##?#.????? 8,1\n..#?#??????#??#?. 1,1,9\n?#????.#.????????#?# 1,1,1,1,9\n????#???#?.??##? 3,6,4\n.???.#?#.??##?#?? 2,3,6\n??.?#??.#???.?.?#?#? 2,2,1,2,1,4\n##???#???.?#??.?#??? 6,2,1,1\n##?#???.??#????? 5,1,3,2\n?#?????????#??.?.?? 1,3,5,1,1,2\n.????.?##.#?#.#. 1,3,1,1,1\n?????###?#?????? 8,2,2\n?.?#????#???#???. 1,2,1,1,5\n???.??????.??.?#??#? 1,5,1,5\n???#??#??#??? 6,3,1\n???#??.??#.?.?.. 3,1,1,1,1\n?#?#?????.. 5,1\n???.???##???#?? 1,2,3,1\n#???????#? 3,1,3\n?##?.?.?.???? 3,1,1,2\n????????..??#??? 1,1,6\n??????#?.#.? 4,1,1\n.?#?##?##?#.???# 10,2,1\n???#?#??.? 1,3\n??##????????.?? 1,7,1,1\n?#??.###?? 2,3\n...?#?????.?? 5,1\n????.??.??#? 2,2,2\n???#?????????? 1,2,6,1\n????#??.??.???## 5,2,4\n##.??#???...#???#?? 2,1,2,7\n?..??.?.#???? 1,1,2,1\n?#?##????##?#? 1,3,4,2\n????#?##???#?.? 3,8,1\n?.??.##??.? 1,2,1\n??#?????#??#?..?##?? 4,6,3\n??##??..???.# 6,1,1,1\n?????#???##?????.?# 6,7,1\n.??.???.??.??#???. 1,3,2,4\n...???????#.???##?? 1,6,7\n??.#.????. 1,4\n????????#.?.?????? 8,1,3,1\n??.???.##?##??#??? 1,8\n???.???.?#???## 1,1,1,1,6\n.#????#????? 1,4,1,1\n???#??#.?.#????.. 1,1,1,1,5\n???#.?.#???#? 4,5\n?#?#?##???.#. 1,1,4,1\n??????.??..#??#??#? 5,1,8\n??#?#?##??#??#? 1,1,1,5,1\n??#??????#??? 1,1,4,1\n?????.???##.??.?## 3,1,2,2,1,3\n?###????.????#???. 4,8\n??#?##?.##?#???##??? 1,1,2,6,4\n???#????????.? 6,1,2\n#.?#.?????.??#? 1,2,4,1,1\n???#???#??.???#?#??# 5,2,3,4\n???#??.???? 1,2,1\n???????.?..????. 3,3,1\n????##?#.?.?.?????#? 6,6\n???.##???.??#? 1,1,5,2\n?????##?##??..????. 1,9,4\n??#.#?#???.??? 1,1,3,1\n???#??##????#?#. 1,7,4\n#?#?#?..??. 3,2,2\n.?#.??.#??????.#??? 2,1,2,1,2,1\n#??#????#? 5,2\n?????.??.#??. 3,1\n??.??.####?#?? 2,4,3\n?#?.?????#?#???.??# 1,8,3\n####???#??#?.#?? 11,1\n????.####.? 1,4\n????#??.#..??????#? 5,1,1,8\n????????#??#.? 1,6,1,1\n??#?#????#?.???? 2,7,1,1\n.????.?????? 1,1,4\n??.????#?#?..?#.? 1,1,4,2,1\n.??????#????????? 3,1,2,2,1\n.?#?#?##??.#.???# 7,1,2,1\n#???#???#???.#?? 5,3,1,1,1\n",
  "example" =>
    "???.### 1,1,3\n.??..??...?##. 1,1,3\n?#?#?#?#?#?#?#? 1,3,1,6\n????.#...#... 4,1,1\n????.######..#####. 1,6,5\n?###???????? 3,2,1"
}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, solution_module.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})