defmodule BinaryBoarding do
def parse(input) do
input
|> String.replace(~r/[F|L]/, "0")
|> String.replace(~r/[B|R]/, "1")
|> String.split_at(7)
|> Tuple.to_list()
|> Enum.map(&String.to_integer(&1, 2))
end
def calc_id([row, column]) do
row * 8 + column
end
end
boarding_passes =
File.read!("input")
|> String.split("\n", trim: true)
|> Enum.map(&BinaryBoarding.parse/1)
seats =
boarding_passes
|> Enum.map(&BinaryBoarding.calc_id/1)
IO.inspect(seats)
holes =
for row <- 0..127,
column <- 0..7,
BinaryBoarding.calc_id([row, column]) <= 955 do
seat = BinaryBoarding.calc_id([row, column])
# IO.inspect(row, label: "row")
# IO.inspect(column, label: "column")
# IO.inspect(seat, label: "seat")
if Enum.member?(seats, seat) do
# IO.inspect(seat, label: "MEMBER")
else
IO.inspect(seat, label: "NOT MEMBER")
end
end
IO.inspect(holes)
holes |> Enum.max() |> IO.inspect()