Combine spilt and trim

This commit is contained in:
Adam Millerchip 2020-12-07 22:36:40 +09:00
parent a63c3aeb4e
commit b2503c0e5b
2 changed files with 2 additions and 4 deletions

View file

@ -30,8 +30,7 @@ defmodule Day7Part1 do
def input_to_tree(input) do def input_to_tree(input) do
input input
|> String.trim(".\n") |> String.split(".\n", trim: true)
|> String.split(".\n")
|> Enum.map(&String.split(&1, " bags contain ")) |> Enum.map(&String.split(&1, " bags contain "))
|> Map.new(fn [parent, child_spec] -> {parent, parse_children(child_spec)} end) |> Map.new(fn [parent, child_spec] -> {parent, parse_children(child_spec)} end)
end end

View file

@ -16,8 +16,7 @@ defmodule Day7Part2 do
def input_to_tree(input) do def input_to_tree(input) do
input input
|> String.trim(".\n") |> String.split(".\n", trim: true)
|> String.split(".\n")
|> Enum.map(&String.split(&1, " bags contain ")) |> Enum.map(&String.split(&1, " bags contain "))
|> Map.new(fn [parent, child_spec] -> {parent, parse_children(child_spec)} end) |> Map.new(fn [parent, child_spec] -> {parent, parse_children(child_spec)} end)
end end