code-shoily / advent_of_code Goto Github PK
View Code? Open in Web Editor NEWAdvent of Codes with Elixir [2015 ~ 2023]
Advent of Codes with Elixir [2015 ~ 2023]
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.
In generator, 9th day will be day_09.ex
for file names and Day09
for modules. Helps things look sorted on file list view.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.