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()