Code Monkey home page Code Monkey logo

advent_of_code's Introduction

AdventOfCode

Advent of Code puzzle solutions in Elixir. It's work in progress and starting year 2015 to 2022, random days are attempted.

Code Organization

All solution modules reside in lib/<year>/day_<day>.ex and associated tests have the same structure in test/ folder. Input files are in lib/data/inputs/<year>_<day>.txt.

Stubs

To make the experience boilerplate-free and give all solutions uniform (more or less) structure, type mix gen --year <year> --day <day> or mix gen <year> <day> to have the structure and stub generated. Optionally, if you have COOKIE environment variable storing your cookie then it will download the input file and add the title on the moduledocs for you. Type mix help gen for more.

To solve the problem for a particular year/day, type in mix solve --year <year> --day <day> or mix solve <year> <day> and you will see the result of the mentioned year/day if it is valid and has been solved. Type mix help solve for more.

Introducing a new year

During December 1 of a new year (if Advent of Code is happening that year), the following steps should be taken (this should be more streamlined in future):

  • Create a new folder XXXX (in year format) under /lib or /test
  • Update the @latest_year attribute on advent_of_code.ex
  • Double check your session cookie (in case you're using it)

All commands should work from then on.

Testing

run mix test to ensure all solutions are working okay. To run test for a particular year and day, type mix test --only y<last-two-digits-of-year><zero-padded-day>. For example: mix test --only y1501 tests for 2015 as year and 1 as day.

Updating README and Stats

If you want to update the README.md (i.e. this file) please do not update README.me directly, instead update the static content (not stats related) on priv/partials/readme_content.md and then run mix readme to regenerate this file.

The stats, both in <year>/README.md and the bottom part of README.md are autogenerated by pulling from the live code state. To keep the stats updated, run mix update_stats command. This does the following two things:

  • Runs mix gen_stats to update the relevant README.md so that the latest stats are always displayed.
  • Runs mix gen_readme to update the main README.md to reflect all the stars.
  • Runs mix gen_tags to update tags.md with latest tag summary
  • Runs mix gen_difficulties to update difficulties.md with latest difficulty summary

Note that you can call those commands independently and also set up pre-commit hooks to run it for you.

Pages

Note: All files mentioned above are autogenerated and are created by running mix update_stats task.

๐Ÿ† 291/450

Day 2015 2016 2017 2018 2019 2020 2021 2022 2023
๐ŸŒŸ 48 22 34 15 15 44 24 45 44
1 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
2 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
3 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
4 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
5 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
6 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
7 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
8 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
9 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
10 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
11 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
12 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
13 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
14 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
15 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
16 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡
17 ๐Ÿฅ‡ ๐Ÿฅ‡
18 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
19 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
20 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡
21 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡
22 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡
23 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡
24 ๐Ÿฅ‡ ๐Ÿฅˆ ๐Ÿฅ‡ ๐Ÿฅ‡
25 ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡ ๐Ÿฅ‡

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.