contents = File.read!("inputs/day3.txt") directions = String.codepoints(contents) move = fn "^", {x, y} -> {x, y - 1} "<", {x, y} -> {x - 1, y} ">", {x, y} -> {x + 1, y} "v", {x, y} -> {x, y + 1} end coordinates = Enum.scan(directions, {0, 0}, move) unique_coordinates = Enum.uniq(coordinates) IO.puts("Unique Households for Just Santa: #{length(unique_coordinates)}") get_shared_coords = fn offset -> Enum.with_index(directions) |> Enum.filter(fn {_, i} -> rem(i, 2) == offset end) |> Enum.map(fn {val, _} -> val end) |> Enum.scan({0, 0}, move) end regular_santa_coordinates = get_shared_coords.(0) robo_santa_coordinates = get_shared_coords.(1) shared_coordinates = regular_santa_coordinates ++ robo_santa_coordinates unique_shared_coordinates = Enum.uniq(shared_coordinates) IO.puts("Unique Households for Santa and RoboSanta: #{length(unique_shared_coordinates)}")