Skip to main content

advent_of_code

Deno GitHub stars GitHub license GitHub forks GitHub issues


A CLI tool help initialize and run Typescript/JavaScript files to solve advent-of-code challenges written for Deno. It was heavily inspired by @ksmithut’s advent-of-code npm package.

Installation

deno install --unstable --allow-env --allow-read --allow-write --allow-net -f -n aoc https://deno.land/x/advent_of_code/cli.ts

Usage

# Create a day file from a template file and get the input file
aoc init <day>

# Example:
aoc init 1

# Runs a day file based on the given arguments. Can pipe the input into
# the command with `-` instead of having it read the input file.
aoc run <day> <part> [input]

# Example
aoc run 1 1 - < input.txt

# Get description of other options.
aoc -h

Configuration

aoc can be configured using a json file called advent_of_code.json. If you pass in command-line arguments, they will override your advent_of_code.json configuration.

JSON config (advent_of_code.json template)

aoc configuration can be provided as a JSON file:

{
  // Optional but highly recommended
  "$schema": "https://deno.land/x/advent_of_code/schema.json",

  "year": 2020,
  "nameTemplate": "day_${num}.ts",
  "templateFile": "https://deno.land/x/advent_of_code/templates/day.ts",
  "inputFile": "input.txt"
}

Debugging

aoc leverages the debug module. Setting DEBUG=aoc will print out debug information. When reporting bugs, please have the output from this handy so that the issue can be determined more quickly.

Disclaimer

I am not affiliated with adventofcode.com or any of their sponsors, employees, pets, or anything relating to them. I am an active participant, and I wanted to make a tool to make it easier to setup and run advent of code things. Please don’t abuse adventofcode.com. This tool could be used to make a lot of automated requests to their site. If you find that you’re making too many requests to adventofcode.com because of this module, please let me know so I can resolve any issues. If this module is used to abuse adventofcode.com, I will unpublish it from deno.land and remove this code from github.

TODO

Summary of progress tracking for the project:

  • Improve test suite
  • Flush out examples
  • Implement aoc --init: Initialize a default config file.
  • Implement aoc submit: Submit answers to Advent of Code puzzles.
  • Create programmatic API (similar to advent-of-code-client) the mirrors the CLI functions (e.g. get input, run, submit). This would make the project not be a pure cli tool anymore.
  • Add proper caching. Instead of relying on the file existing. I would like to use the Deno cache library, but it’s still very new and doesn’t support modifying the headers when fetching the files.

Contributing

Refer to CONTRIBUTING.md: Please follow the Code of Conduct. Pull request, issues and feedback are very welcome. Code style is formatted with deno fmt and commit messages are done following Conventional Commits spec.

License

Copyright (c) 2020-present Bryan Hoang. All rights reserved. MIT license.