Skip to content

Instantly share code, notes, and snippets.

@code-shoily
Created December 5, 2020 19:10
Show Gist options
  • Save code-shoily/0097648d6aabc024251c34e460fdfdba to your computer and use it in GitHub Desktop.
Save code-shoily/0097648d6aabc024251c34e460fdfdba to your computer and use it in GitHub Desktop.
Advent of Code 2020, Day 5
def run_1_bin, do: input!() |> String.split("\n") |> Enum.map(fn d -> d |> String.replace("F", "0") |> String.replace("B", "1") |> String.replace("R", "1") |> String.replace("L", "0") |> String.to_integer(2) end) |> Enum.max()
def run_2_bin, do: input!() |> String.split("\n") |> Enum.map(fn d -> d |> String.replace("F", "0") |> String.replace("B", "1") |> String.replace("R", "1") |> String.replace("L", "0") |> String.to_integer(2) end) |> Enum.sort() |> (fn [_ | tail] = total -> total |> Enum.zip(tail) |> Enum.filter(fn {a, b} -> b - a != 1 end) |> (fn [{_, b}] -> b - 1 end).() end).() end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment