Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove macro and use Transformer functions. #39

Closed
code-shoily opened this issue Nov 27, 2022 · 0 comments
Closed

Remove macro and use Transformer functions. #39

code-shoily opened this issue Nov 27, 2022 · 0 comments
Assignees

Comments

@code-shoily
Copy link
Owner

code-shoily commented Nov 27, 2022

Oh this is going to be a big one. When I first started this challenge, I was fairly new to Elixir and the file structure for inputs was different. So to save myself some time figuring out the relativity of locations (maybe) I decided to use Macro and include it everywhere.

I recently restructured the input file locations (by moving them to /priv/input_files) and this makes it easier to just use functions. There are 97 modules that use the macro and the task is to replace them with function calls.

As an example:

If we previously had:

use AdventOfCode.Helpers.InputReader, year: 2015, day: 1

def run_1, do: input!() |> floor(0)
def run_2, do: input!() |> to_basement(0, 0)

They will now become:

  alias AdventOfCode.Helpers.InputReader

  def input(), do: InputReader.read_from_file(2015, 1)

  def run(input \\ input()) do
    input = parse(input)
    {run_1(input), run_2(input)}
  end

  def run_1(input), do: ...
  def run_2(input), do: ...
  def parse(input), do: ...

And then on tests, remove individual tests for run_1 and run_2 and make them a single run test. As an example -

THIS

defmodule AdventOfCode.Y2020.Day01Test do
  ...
  test "Year 2020, Day 1, Part 1" do
    assert Solution.run_1() == 1_014_624
  end

  test "Year 2020, Day 1, Part 2" do
    assert Solution.run_2() == 80_072_256
  end
end

SHOULD BECOME THIS

defmodule AdventOfCode.Y2020.Day01Test do
  ...
  test "Year 2020, Day 1" do
    assert Solution.run_1() == {1_014_624, 80_072_256}
  end

Basically, use turns into alias and we add a new @input that is read_from_input(year, day) (which is in the use macro now).

After the change is done, we should ensure it didn't break anything by running mix test --only y151 (15 = 20(15) and 01 = day 01 -- days < 10 are 0 padded ). Thankfully, I had them test cases covered 🤓

In addition, we moved some common functionalities into Transformers module. Like String.split(&1, "\n") became Transformers.lines(). If while changing this, we encounter some of those, then we can change those as well.

I will be opening up PRs that solve fraction of these and add a checkbox in here.

Will add tool to visualize/find them here soon.

@code-shoily code-shoily self-assigned this Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant