From d11d007be95163aca7097292343e108223baf46d Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Sun, 6 Dec 2020 15:47:14 +0900 Subject: [PATCH] Use String.to_charlist/1 --- day6/day6part1.exs | 4 ++-- day6/day6part2.exs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/day6/day6part1.exs b/day6/day6part1.exs index 7122d42..86f2653 100644 --- a/day6/day6part1.exs +++ b/day6/day6part1.exs @@ -5,9 +5,9 @@ defmodule Day6Part1 do |> Stream.map(fn group -> group |> Enum.join() - |> String.split("", trim: true) + |> String.to_charlist() |> Enum.frequencies() - |> Map.delete("\n") + |> Map.delete(?\n) |> Enum.count() end) |> Enum.sum() diff --git a/day6/day6part2.exs b/day6/day6part2.exs index 34ad11f..ed74694 100644 --- a/day6/day6part2.exs +++ b/day6/day6part2.exs @@ -3,11 +3,11 @@ defmodule Day6Part2 do File.stream!("input") |> Stream.chunk_by(&(&1 == "\n")) |> Stream.map(fn group -> - frequencies = group |> Enum.join() |> String.split("", trim: true) |> Enum.frequencies() + frequencies = group |> Enum.join() |> String.to_charlist() |> Enum.frequencies() - count = frequencies["\n"] + count = frequencies[?\n] - Map.delete(frequencies, "\n") + Map.delete(frequencies, ?\n) |> Enum.count(fn {_, v} -> v == count end) end) |> Enum.sum()