Advent of Code 2020 - Day 5

I guess you’ve found the same solution as mine.

WARNING: Huge Exploits!!

Don’t look at my solution until you find your own.

Part 1

#!/usr/bin/env elixir

"day5.txt"
|> File.stream!()
|> Enum.map(&String.trim/1)
|> Enum.map(fn s ->
    s
    |> String.replace(["F", "L"], "0", global: true)
    |> String.replace(["B", "R"], "1", global: true)
    |> String.to_integer(2)
end)
|> Enum.max()
|> IO.puts()

Part 2

#!/usr/bin/env elixir

"day5.txt"
|> File.stream!()
|> Enum.map(&String.trim/1)
|> Enum.map(fn s ->
    s
    |> String.replace(["F", "L"], "0", global: true)
    |> String.replace(["B", "R"], "1", global: true)
    |> String.to_integer(2)
end)
|> Enum.sort()
|> Enum.chunk_every(2, 1, :discard)
|> Enum.find(&match?([a, b] when a != b - 1, &1))
|> Enum.reduce(&+/2)
|> Kernel.div(2)
|> IO.puts()

I’m still working on the legitimacy of this approach.