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

Day 24

day24.livemd

Day 24

# Note: when making the next template, something like this works well:
#   `cat day04.livemd | sed 's/24/04/' > day04.livemd`
# When inspecting lists of numbers, use "charlists: :as_lists"
#
Mix.install([
  # Join the string so a copy of dayN to dayM doesn't destroy it.
  {:kino, "~> 0.1" <> "4.2"}
])

# Join the string so a copy of dayN to dayM doesn't destroy it.
IEx.Helpers.c("/Users/johnb/dev/2" <> "0" <> "2" <> "4adventOfCode/advent_of_code.ex")
alias AdventOfCode, as: AOC
alias Kino.Input

Installation and Data

input_example = Kino.Input.textarea("Example Data", monospace: true)
input_puzzleInput = Kino.Input.textarea("Puzzle Input", monospace: true)
input_source_select =
  Kino.Input.select("Source", [{:example, "example"}, {:puzzle_input, "puzzle input"}])
data = fn ->
  (Kino.Input.read(input_source_select) == :example &amp;&amp;
     Kino.Input.read(input_example)) ||
    Kino.Input.read(input_puzzleInput)
end

Solution

defmodule Day24 do
  def parse(text) do
    text
    |> AOC.as_single_lines()
  end

  def solve1(text) do
    parse(text)
  end

  def solve2(text) do
    parse(text)
  end
end

# Example:

IO.inspect(Time.utc_now())
data.()
|> Day24.solve1()
|> IO.inspect(label: "\n*** Part 1 solution (example: )")
IO.inspect(Time.utc_now())
# 

# IO.inspect(Time.utc_now())
# data.()
# |> Day24.solve2()
# |> IO.inspect(label: "\n*** Part 2 solution (example: )")
# IO.inspect(Time.utc_now())
#