Yesterday I had no time to post my solution in Elixir, but there is!
defmodule AdventOfCode.Day6 do def part1(file_path) do file_path |> read_all_answers() |> Enum.map(&how_many_answers(&1, :step1)) |> Enum.sum() end def part2(file_path) do file_path |> read_all_answers() |> Enum.map(&how_many_answers(&1, :step2)) |> Enum.sum() end defp read_all_answers(file_path) do file_path |> File.read!() |> String.split("\n\n", trim: true) |> Enum.map(&String.split/1) end defp how_many_answers(list, :step1), do: how_many_answers(list, &MapSet.union/2) defp how_many_answers(list, :step2), do: how_many_answers(list, &MapSet.intersection/2) defp how_many_answers(list, f) do list |> Enum.map(&String.to_charlist/1) |> Enum.map(&MapSet.new/1) |> Enum.reduce(f) |> Enum.count() end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yesterday I had no time to post my solution in Elixir, but there is!