24 lines
461 B
Elixir
24 lines
461 B
Elixir
defmodule AoC.Util.String do
|
|
@doc """
|
|
Transposes the string when it represents
|
|
a grid of newline separated rows and each
|
|
character is a column.
|
|
|
|
iex> AoC.Util.String.transpose(
|
|
iex> ~s(abc
|
|
iex>def
|
|
iex>ghi)
|
|
iex>)
|
|
~s(adg
|
|
beh
|
|
cfi)
|
|
"""
|
|
def transpose(str) do
|
|
AoC.Util.Enum.transpose(
|
|
str
|
|
|> String.split("\n")
|
|
|> Enum.map(&String.graphemes(&1))
|
|
|
|
)|> Enum.map(&Enum.join(&1,"")) |> Enum.join("\n")
|
|
end
|
|
end
|