Anonymous user
Maximum triangle path sum: Difference between revisions
m
→{{header|Elixir}}: replace deprecated `Enum.chunk/3` with `Enum.chunk_every/3`, Use bare variables in the first part of a function chain. https://github.com/christopheradams/elixir_style_guide#bare-variables
m (→{{header|Elixir}}: replace deprecated `Enum.chunk/3` with `Enum.chunk_every/3`, Use bare variables in the first part of a function chain. https://github.com/christopheradams/elixir_style_guide#bare-variables) |
|||
Line 764:
<lang elixir>defmodule Maximum do
def triangle_path(text) do
text
|
|> Enum.map(fn line ->
line
|> String.split()
|> Enum.map(&String.to_integer(&1))
end)
|> Enum.reduce([], fn x,total ->
|> Enum.chunk_every( 2, 1)
|> Enum.map(&Enum.max(&1))
|> Enum.zip(x)
|> Enum.map(fn{a,b} -> a+b end)
end)
|> Enum.max()
end
end
Line 797 ⟶ 803:
"""
IO.puts Maximum.triangle_path(text)
</lang>
{{out}}
|