16 lines
343 B
Elixir
Executable File
16 lines
343 B
Elixir
Executable File
#!/usr/bin/env elixir
|
|
|
|
pos = IO.read(:stdio, :line)
|
|
|> String.split(",")
|
|
|> Enum.map(&Integer.parse/1)
|
|
|> Enum.map(fn {n, _} -> n end)
|
|
|
|
{a, b} = Enum.min_max pos
|
|
|
|
for loss <- [&(&1), &(div(&1*&1+&1, 2))] do # [part 1, part 2]
|
|
a..b
|
|
|> Enum.map(fn x -> Enum.map(pos, &(loss.(abs(&1 - x)))) |> Enum.sum end)
|
|
|> Enum.min
|
|
|> IO.inspect
|
|
end
|