Skip to content

akosasante/Advent-Of-Code-Helper-Elixir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code Helper Build Status codecov Hex.pm hexdocs.pm

This Elixir package allows you to quickly grab inputs for Advent of ode puzzles, and not have to worry about manually pasting them in! After you've got a puzzle input for the first time, the result is stored on disk so every subsequent request bypasses the need to download it from the server again.

Usage

Via Mix Tasks

There are two mix tasks included in this library: advent.setup_day and advent.run_day.

For creating a new directory and .ex file for a given Advent puzzle, use the setup command:

mix advent.setup_day <year> <day> or mix advent.setup_day <day>

where year is a four-digit integer (eg: 2022) and day is a number between 1 and 25. Year will be inferred as the current year if it's not passed in. A folder will be created under the lib directory of the mix project, and a skeleton module will be generated.

To run the code you've added to the generated template file, use the run command:

mix advent.run_day day=<day> year=<year> bench=<boolean> split=<splitOption> sep=<sep> trim=<boolean>

Only day is a required argument. Year will be inferred as current year if it's not given, otherwise it should be a 4-digit number. If bench is true, the task will run the day's puzzles through benchee and return the benchmark results.

By default, (if no split or sep options are passed in), the puzzle input will be read as a string, split on newlines, and the resulting list will be passed into the puzzle module to be run. You can change this behaviour by passing in either list, stream, or false for split. This will split the string into a List, a Stream, or leave the input as-is, respectively. The separator to use as the split boundary can be changed by passing in a sep argument; trimming extra newlines/whitespace can be enabled by setting trim to true.

Directly calling AdventOfCodeHelper

There are two main functions for fetching the puzzle input:

AdventOfCodeHelper.get_input(year,day) # Specify year and day for puzzle

AdventOfCodeHelper.get_input(day) # Automatically gets puzzle from most recent year

Both of these functions will simply return a tuple {:ok, value} if they succeed, where value is the puzzle input in the form of a String, or {:fail, message} if there was something wrong.

You can also use the provided helpers for splitting the string input into a List or Stream: split_to_list/2 and split_to_stream/2.

Configuration

There are two configuration directives that are also needed to make this package work correctly. Simply add the following to your config/config.exs

config :advent_of_code_helper,
session: "<session string>",
cache_dir: ".cache/" # this is a sensible default, but feel free to put it wherever you have write access

The session string will need to be taken from adventofcode.com, it will be under cookies as session. You can extract the value using the inspector/devTools in your browser of choice.

Installation

This package can be installed by adding advent_of_code_helper to your list of dependencies in mix.exs:

def deps do
  [
    {:advent_of_code_helper, "~> 0.3.1"}
  ]
end

About

Access your advent of code inputs, right from elixir!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages