Skip to content

Commit

Permalink
Remove warnings during compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
code-shoily committed Jun 26, 2024
1 parent 4adffe2 commit 48185b5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/2020/day_16.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule AdventOfCode.Y2020.Day16 do
|> Enum.map(&String.to_integer/1)
end

def merge_ranges(a..b = r1, x..y = r2),
def merge_ranges(a..b//_ = r1, x..y//_ = r2),
do:
(Range.disjoint?(r1, r2) &&
[r1, r2]) || [((a < x && a) || x)..((b > y && b) || y)]
Expand Down
10 changes: 5 additions & 5 deletions lib/2023/day_19.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ defmodule AdventOfCode.Y2023.Day19 do
end)
end

defp range_reducer({c, :lt, v}, acc), do: Map.update!(acc, c, fn l.._ -> l..(v - 1) end)
defp range_reducer({c, :gt, v}, acc), do: Map.update!(acc, c, fn _..u -> (v + 1)..u end)
defp range_reducer({c, :lte, v}, acc), do: Map.update!(acc, c, fn l.._ -> l..v end)
defp range_reducer({c, :gte, v}, acc), do: Map.update!(acc, c, fn _..u -> v..u end)
defp range_combination({_, l..u}, acc), do: acc * (u - l + 1)
defp range_reducer({c, :lt, v}, acc), do: Map.update!(acc, c, fn l.._//_ -> l..(v - 1)//1 end)
defp range_reducer({c, :gt, v}, acc), do: Map.update!(acc, c, fn _..u//_ -> (v + 1)..u//1 end)
defp range_reducer({c, :lte, v}, acc), do: Map.update!(acc, c, fn l.._//_ -> l..v//1 end)
defp range_reducer({c, :gte, v}, acc), do: Map.update!(acc, c, fn _..u//_ -> v..u//1 end)
defp range_combination({_, l..u//_}, acc), do: acc * (u - l + 1)

defp parse_workflow(workflow) do
[_, name, instructions] = Regex.run(~r/(\w+)\{(.+)\}/, workflow)
Expand Down
12 changes: 6 additions & 6 deletions lib/2023/day_22.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ defmodule AdventOfCode.Y2023.Day22 do
defp drop(bricks),
do:
bricks
|> Enum.sort_by(fn {_, _, _, z1.._} -> z1 end)
|> Enum.sort_by(fn {_, _, _, z1.._//_} -> z1 end)
|> drop([])

defp drop([], settled), do: settled

defp drop([{_, _, _, 1.._} = brick | bricks], settled),
defp drop([{_, _, _, 1.._//_} = brick | bricks], settled),
do: drop(bricks, [brick | settled])

defp drop([{id, ax, ay, az} | bricks], settled) do
{_, _, _, _..bz2} =
{_, _, _, _..bz2//_} =
Enum.filter(settled, fn {_, bx, by, _} ->
not (Range.disjoint?(ax, bx) or
Range.disjoint?(ay, by))
end)
|> Enum.max_by(
fn {_, _, _, _..bz2} -> bz2 end,
fn {_, _, _, _..bz2//_} -> bz2 end,
fn -> {nil, nil, nil, 0..0} end
)

Expand All @@ -65,9 +65,9 @@ defmodule AdventOfCode.Y2023.Day22 do
defp support(bricks), do: support(bricks, bricks, %{})
defp support([], _, supports), do: supports

defp support([{_, ax, ay, az1.._} = current | rest], bricks, supports) do
defp support([{_, ax, ay, az1.._//_} = current | rest], bricks, supports) do
others =
Enum.filter(bricks, fn {_, bx, by, _..bz2} ->
Enum.filter(bricks, fn {_, bx, by, _..bz2//_} ->
bz2 == az1 - 1 and
not (Range.disjoint?(ax, bx) or
Range.disjoint?(ay, by))
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule AdventOfCode.MixProject do
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
deps: deps(),
elixirc_options: [warnings_as_errors: true]
]
end

Expand Down

0 comments on commit 48185b5

Please sign in to comment.