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
String.split(text, "\n", trim: true)
|> Enum.map(fn line -> String.split(line)"\n", |> Enum.map(&String.to_integer(&1))trim: endtrue)
|> Enum.map(fn line ->
line
|> String.split()
|> Enum.map(&String.to_integer(&1))
end)
|> Enum.reduce([], fn x,total ->
Enum.chunk([0]++total++[0], 2, 1)
|> 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>
</lang>
 
{{out}}