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