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

day 06

2020/livebooks/day-06.livemd

day 06

Mix.install([
  {:kino, "~> 0.12.2"}
])

Section

input = Kino.Input.textarea("paste")
example = Kino.Input.textarea("paste")

Helper

Part 01

lines =
  input
  |> Kino.Input.read()
  |> String.split("\n\n", trim: true)
  |> Enum.reduce(0, fn people, acc ->
    Regex.scan(~r/[a-z]/, people)
    |> List.flatten()
    |> Enum.uniq()
    |> Enum.count()
    |> Kernel.+(acc)
  end)

Part 02

lines =
  input
  |> Kino.Input.read()
  |> String.split("\n\n", trim: true)
  |> Enum.reduce(0, fn people, acc ->
    people_count = people |> String.split("\n", trim: true) |> Enum.count()

    Regex.scan(~r/[a-z]/, people)
    |> List.flatten()
    |> Enum.frequencies()
    |> Enum.filter(fn {_, value} -> value == people_count end)
    |> Enum.count()
    |> Kernel.+(acc)
  end)