Rework with File.stream!/1
This commit is contained in:
parent
07773441f7
commit
45292967af
2 changed files with 10 additions and 16 deletions
|
@ -1,13 +1,13 @@
|
||||||
defmodule Day6Part1 do
|
defmodule Day6Part1 do
|
||||||
def run do
|
def run do
|
||||||
File.read!("input")
|
File.stream!("input")
|
||||||
|> String.trim()
|
|> Stream.chunk_by(&(&1 == "\n"))
|
||||||
|> String.split("\n\n")
|
|
||||||
|> Stream.map(fn group ->
|
|> Stream.map(fn group ->
|
||||||
group
|
group
|
||||||
|> String.replace("\n", "")
|
|> Enum.join()
|
||||||
|> String.split("", trim: true)
|
|> String.split("", trim: true)
|
||||||
|> Enum.frequencies()
|
|> Enum.frequencies()
|
||||||
|
|> Map.delete("\n")
|
||||||
|> Enum.count()
|
|> Enum.count()
|
||||||
end)
|
end)
|
||||||
|> Enum.sum()
|
|> Enum.sum()
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
defmodule Day6Part2 do
|
defmodule Day6Part2 do
|
||||||
def run do
|
def run do
|
||||||
File.read!("input")
|
File.stream!("input")
|
||||||
|> String.trim()
|
|> Stream.chunk_by(&(&1 == "\n"))
|
||||||
|> String.split("\n\n")
|
|
||||||
|> Stream.map(fn group ->
|
|> Stream.map(fn group ->
|
||||||
count =
|
frequencies = group |> Enum.join() |> String.split("", trim: true) |> Enum.frequencies()
|
||||||
group
|
|
||||||
|> String.to_charlist()
|
|
||||||
|> Enum.count(&(&1 == ?\n))
|
|
||||||
|> Kernel.+(1)
|
|
||||||
|
|
||||||
group
|
count = frequencies["\n"]
|
||||||
|> String.replace("\n", "")
|
|
||||||
|> String.split("", trim: true)
|
Map.delete(frequencies, "\n")
|
||||||
|> Enum.frequencies()
|
|
||||||
|> Enum.count(fn {_, v} -> v == count end)
|
|> Enum.count(fn {_, v} -> v == count end)
|
||||||
end)
|
end)
|
||||||
|> Enum.sum()
|
|> Enum.sum()
|
||||||
|
|
Loading…
Reference in a new issue