Remove unneeded max_x when parsing input

This commit is contained in:
Adam Millerchip 2024-12-10 17:40:41 +09:00
parent 4d74260d8a
commit b9ca148096

View file

@ -30,13 +30,13 @@ defmodule Day10 do
def input do def input do
with [input_filename] <- System.argv(), with [input_filename] <- System.argv(),
{:ok, input} <- File.read(input_filename) do {:ok, input} <- File.read(input_filename) do
{grid, zeros, _, _, _} = {grid, zeros, _, _} =
for <<char::binary-1 <- input>>, reduce: {%{}, [], 0, 0, 0} do for <<char::binary-1 <- input>>, reduce: {%{}, [], 0, 0} do
{grid, zeros, x, max_x, y} -> {grid, zeros, x, y} ->
case char do case char do
"\n" -> {grid, zeros, 0, x, y + 1} "\n" -> {grid, zeros, 0, y + 1}
"0" -> {Map.put(grid, {x, y}, 0), [{x, y} | zeros], x + 1, max_x, y} "0" -> {Map.put(grid, {x, y}, 0), [{x, y} | zeros], x + 1, y}
char -> {Map.put(grid, {x, y}, String.to_integer(char)), zeros, x + 1, max_x, y} char -> {Map.put(grid, {x, y}, String.to_integer(char)), zeros, x + 1, y}
end end
end end