From 8f4d06e24de19cf9c896bb9ba2cf7110e02f810b Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Thu, 10 Dec 2020 00:30:54 +0900 Subject: [PATCH] Fix unused optimization in forms_pair?/4 --- day9/day9part1.exs | 10 ++++------ day9/day9part2.exs | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/day9/day9part1.exs b/day9/day9part1.exs index 057d207..82b1b1a 100644 --- a/day9/day9part1.exs +++ b/day9/day9part1.exs @@ -20,7 +20,6 @@ defmodule Day9Part1 do end 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 | preamble_rest], max, number) do @@ -31,11 +30,10 @@ defmodule Day9Part1 do end end - def forms_pair?(_, [y | _], max, _number) when y > max, do: false - - def forms_pair?(x, preamble_rest, _max, number) do - Enum.any?(preamble_rest, fn y -> x + y == number end) - end + def forms_pair?(_x, [y | _], max, _number) when y > max, do: false + def forms_pair?(_x, [], _max, _number), do: false + def forms_pair?(x, [y | _], _max, number) when x + y == number, do: true + def forms_pair?(x, [_y | rest], max, number), do: forms_pair?(x, rest, max, number) end Day9Part1.run() diff --git a/day9/day9part2.exs b/day9/day9part2.exs index e563478..6e0307c 100644 --- a/day9/day9part2.exs +++ b/day9/day9part2.exs @@ -50,7 +50,6 @@ defmodule Day9Part1 do end 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 | preamble_rest], max, number) do @@ -61,11 +60,10 @@ defmodule Day9Part1 do end end - def forms_pair?(_, [y | _], max, _number) when y > max, do: false - - def forms_pair?(x, preamble_rest, _max, number) do - Enum.any?(preamble_rest, fn y -> x + y == number end) - end + def forms_pair?(_x, [y | _], max, _number) when y > max, do: false + def forms_pair?(_x, [], _max, _number), do: false + def forms_pair?(x, [y | _], _max, number) when x + y == number, do: true + def forms_pair?(x, [_y | rest], max, number), do: forms_pair?(x, rest, max, number) end Day9Part2.run()