Advent of Code 2020 in Elixir - Day 6

Custom Customs

defmodule Aoc2020.Day6 do
  @moduledoc "Custom Customs"

  def parse_group(group) do
    group
    |> String.split("\n")
    |> Enum.map(&String.codepoints/1)
  end

  def parse_input() do
    File.read!("priv/inputs/2020/day6.txt")
    |> String.trim()
    |> String.split("\n\n")
    |> Enum.map(&parse_group/1)
  end

  def group_count(group) do
    group
    |> Enum.flat_map(& &1)
    |> Enum.uniq()
    |> length
  end

  def group_intersect(group) do
    [first | rest] = group

    Enum.reduce(
      rest,
      MapSet.new(first),
      fn person, acc ->
        MapSet.intersection(acc, MapSet.new(person))
      end
    )
    |> MapSet.size()
  end

  def part_1() do
    parse_input()
    |> Enum.map(&group_count/1)
    |> Enum.sum()
  end

  def part_2() do
    parse_input()
    |> Enum.map(&group_intersect/1)
    |> Enum.sum()
  end

  def run do
    part_2()
  end
end