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

Advent of Code 2015 Day 12 Part 1

2015_day12_part1.livemd

Advent of Code 2015 Day 12 Part 1

Mix.install([
  {:kino_aoc, "~> 0.1"}
])

Get Inputs

{:ok, puzzle_input} =
  KinoAOC.download_puzzle("2015", "12", System.fetch_env!("LB_SESSION"))

My answer

puzzle_input
|> String.split("\n")
|> Enum.map(fn row -> Jason.decode!(row) end)
defmodule SumIntegers do
  def sum_integers(data) when is_integer(data), do: data

  def sum_integers(data) when is_map(data) do
    data
    |> Map.values()
    |> Enum.map(&sum_integers/1)
    |> Enum.sum()
  end

  def sum_integers(data) when is_list(data) do
    data
    |> Enum.map(&sum_integers/1)
    |> Enum.sum()
  end

  def sum_integers(_data), do: 0
end
puzzle_input
|> String.split("\n")
|> Enum.map(fn row -> Jason.decode!(row) end)
|> SumIntegers.sum_integers()