Fix unused optimization in forms_pair?/4
This commit is contained in:
parent
8e7f5288ce
commit
8f4d06e24d
2 changed files with 8 additions and 12 deletions
|
@ -20,7 +20,6 @@ defmodule Day9Part1 do
|
||||||
end
|
end
|
||||||
|
|
||||||
def sum_in_preamble?([], _max, _number), do: false
|
def sum_in_preamble?([], _max, _number), do: false
|
||||||
|
|
||||||
def sum_in_preamble?([preamble_head | _], max, _number) when preamble_head >= max, do: false
|
def sum_in_preamble?([preamble_head | _], max, _number) when preamble_head >= max, do: false
|
||||||
|
|
||||||
def sum_in_preamble?([preamble_head | preamble_rest], max, number) do
|
def sum_in_preamble?([preamble_head | preamble_rest], max, number) do
|
||||||
|
@ -31,11 +30,10 @@ defmodule Day9Part1 do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def forms_pair?(_, [y | _], max, _number) when y > max, do: false
|
def forms_pair?(_x, [y | _], max, _number) when y > max, do: false
|
||||||
|
def forms_pair?(_x, [], _max, _number), do: false
|
||||||
def forms_pair?(x, preamble_rest, _max, number) do
|
def forms_pair?(x, [y | _], _max, number) when x + y == number, do: true
|
||||||
Enum.any?(preamble_rest, fn y -> x + y == number end)
|
def forms_pair?(x, [_y | rest], max, number), do: forms_pair?(x, rest, max, number)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Day9Part1.run()
|
Day9Part1.run()
|
||||||
|
|
|
@ -50,7 +50,6 @@ defmodule Day9Part1 do
|
||||||
end
|
end
|
||||||
|
|
||||||
def sum_in_preamble?([], _max, _number), do: false
|
def sum_in_preamble?([], _max, _number), do: false
|
||||||
|
|
||||||
def sum_in_preamble?([preamble_head | _], max, _number) when preamble_head >= max, do: false
|
def sum_in_preamble?([preamble_head | _], max, _number) when preamble_head >= max, do: false
|
||||||
|
|
||||||
def sum_in_preamble?([preamble_head | preamble_rest], max, number) do
|
def sum_in_preamble?([preamble_head | preamble_rest], max, number) do
|
||||||
|
@ -61,11 +60,10 @@ defmodule Day9Part1 do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def forms_pair?(_, [y | _], max, _number) when y > max, do: false
|
def forms_pair?(_x, [y | _], max, _number) when y > max, do: false
|
||||||
|
def forms_pair?(_x, [], _max, _number), do: false
|
||||||
def forms_pair?(x, preamble_rest, _max, number) do
|
def forms_pair?(x, [y | _], _max, number) when x + y == number, do: true
|
||||||
Enum.any?(preamble_rest, fn y -> x + y == number end)
|
def forms_pair?(x, [_y | rest], max, number), do: forms_pair?(x, rest, max, number)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Day9Part2.run()
|
Day9Part2.run()
|
||||||
|
|
Loading…
Reference in a new issue