Powered by AppSignal & Oban Pro

2025 Advent of Code Day 11

2025/adv11.livemd

2025 Advent of Code Day 11

Mix.install([
  {:pythonx, "~> 0.4.2"},
  {:kino_pythonx, "~> 0.1.0"}
])
[project]
name = "project"
version = "0.0.0"
requires-python = "==3.13.*"
dependencies = [
  "graphviz"
]

Section

import shutil
shutil.which("dot")
defmodule Solution do
  def parse_line(s) do
    {node, children} = s |> String.trim() |> String.split(": ") |> List.to_tuple()
    {node, String.split(children, " ")}
  end
end
graph = "inp.txt"
|> File.stream!()
|> Enum.map(&Solution.parse_line/1)
|> Map.new()
from graphviz import Graph
g = Graph()

for node, children in graph.items():
  for child in children:
    g.edge(node.decode('utf-8'), child.decode('utf-8'))

g.node('svr', color='green')
g.node('dac', color='green')
g.node('fft', color='green')
g.node('out', color='green')

g_png = g.pipe(format="png")
binary = Pythonx.decode(g_png)
base64_image = Base.encode64(binary)
source = "data:image/png;base64,#{base64_image}"

# Set specific width and height via CSS
Kino.HTML.new("""
#{source}" />
""")