Use String.to_charlist/1

This commit is contained in:
Adam Millerchip 2020-12-06 15:47:14 +09:00
parent 45292967af
commit d11d007be9
2 changed files with 5 additions and 5 deletions

View file

@ -5,9 +5,9 @@ defmodule Day6Part1 do
|> Stream.map(fn group -> |> Stream.map(fn group ->
group group
|> Enum.join() |> Enum.join()
|> String.split("", trim: true) |> String.to_charlist()
|> Enum.frequencies() |> Enum.frequencies()
|> Map.delete("\n") |> Map.delete(?\n)
|> Enum.count() |> Enum.count()
end) end)
|> Enum.sum() |> Enum.sum()

View file

@ -3,11 +3,11 @@ defmodule Day6Part2 do
File.stream!("input") File.stream!("input")
|> Stream.chunk_by(&(&1 == "\n")) |> Stream.chunk_by(&(&1 == "\n"))
|> Stream.map(fn group -> |> 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) |> Enum.count(fn {_, v} -> v == count end)
end) end)
|> Enum.sum() |> Enum.sum()