Giter Site home page Giter Site logo

code-shoily / advent_of_code Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 3.0 1.48 MB

Advent of Codes with Elixir [2015 ~ 2022]

Elixir 93.54% HTML 0.26% Erlang 6.21%
advent-of-code advent-of-code-2015 advent-of-code-2016 advent-of-code-2017 advent-of-code-2018 advent-of-code-2019 advent-of-code-2020 advent-of-code-2021 advent-of-code-2022 algorithms elixir-lang programming-challenges

advent_of_code's People

Contributors

byte-chakra avatar code-shoily avatar mafinar-cmb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

advent_of_code's Issues

Remove macro and use Transformer functions.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.