npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aoc-copilot

v1.5.7

Published

Advent of Code automatic runner for examples and inputs

Downloads

496

Readme

Advent of Code Copilot

Advent of Code Copilot (AoCC) helps you iterate through cycles of code and test faster by automatically extracting examples from Advent of Code puzzles and running your solutions against them. After all examples pass, it runs your unique input and submits the answer.

Table of Contents

Years Supported

Currently, years 2019 - 2023 are fully tested and supported for all features.

Year 2018 is in process, with days 1 - 15 supported.

Q. What about 2024 and beyond? Can I use it as soon as a new puzzle drops? A. Yes, probably for most days. Advent of Code follows a very consistent structure from year-to-year, so most features of AoCC should work with 2024 and beyond. The availability of examples is the only thing that is likely to vary. AoCC uses a default search strategy for extracting examples from most puzzles. In 2023, the default search strategy automatically extracted examples for 18 out of 25 days. The other 6 days contained multiple examples each so they required example database entries to extract the examples. 2022 was very similar with the default search strategy working for 20 days. So, I expect 2024 will follow a similar pattern and AoCC will be able to automatically extract examples for most days.

Q. What do I do if AoCC doesn't properly extract examples for a day? Am I stuck? A. No, you're not stuck. You have two options when configuring the runner:

  1. Skip the examples and only run against actual inputs by setting skipTests to true
  2. Provide the addDb parameter to the runner so it knows where to find the examples. If you go this route then please consider contributing it to the example database so others can benefit as well!

Q. What about 2015 - 2018? A. Based on how differently 2019 was structured compared to more recent years, I don't expect any examples to be automatically available for 2018 or earlier. You can still use all the other features of AoCC, but plan to use one of the techniques above to skip the examples or provide their locations.

Installation

npm install aoc-cockpit

Preparation

Session Cookie

AoCC connects to the Advent of Code website to retrieve puzzles and inputs on your behalf. In order for this to work, you need to retrieve your session ID from the adventofcode.com cookie and store it in a .env file in the root of your project. If you're syncing with a repo like GitHub them make sure to add .env to your .gitignore file to prevent leaking your session ID.

Steps for Chromium-based browsers like Chrome and Edge:

  1. Browse to Advent of Code and log in
  2. Open Developer Tools (F12)
  3. Click the "Application" tab
  4. In the "Storage" section expand "Cookies"
  5. Click on https://adventofcode.com
  6. Copy the value from the session row
  7. Open or create a .env file in the root of your project
  8. Add a line AOC_SESSION_COOKIE="session=" and paste your session value after the equals sign

For example:

AOC_SESSION_COOKIE="session=**your_session_value**"

Corporate Networks and Self-Signed Certificates (Optional)

If you're on a network that has a self-signed certificate then you will receive a SELF_SIGNED_CERT_IN_CHAIN error when attempting to connect to the Advent of Code website. As above, make sure to add .env to your .gitignore file to prevent leaking sensitive information.

Steps to override the normal certificate authorities with your own certificate bundle:

  1. Browse to Advent of Code and log in
  2. Open Developer Tools (F12)
  3. Click on the Security tab (if you don't see it, click the "+" sign and add it)
  4. Click "View certificate"
  5. Click on the Details tab
  6. Select the root certificate (the one at the top of the hierarchy) and click Export and save it somewhere locally
  7. Repeat for the intermediate certificate (the second one in the hierarchy)
  8. Repeat for the primary certificate (the third one in the hierarchy)
  9. Open or create a .env file in the root of your project
  10. Add a line CERTIFICATE="" and paste the contents of the certificates inside the double quotes in reverse hierarchy order (primary, intermediate, root)

For example:

AOC_SESSION_COOKIE="session=**your_session_value**"
CERTIFICATE="-----BEGIN CERTIFICATE-----
**your_primary_certificate**
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
**your_intermediate_certificate**
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
**your_root_certificate**
-----END CERTIFICATE-----"

Getting Started

TypeScript

Create a new file named aocYYDD.ts where YY is the two-digit year and DD is the two-digit day of the puzzle you are solving and paste the following code:

import { run } from 'aoc-copilot';

async function solve(
    inputs: string[], // Contents of the example or actual inputs
    part: number,     // Indicates whether the solver is being called for part 1 or 2 of the puzzle
    test: boolean,    // Indicates whether the solver is being run for an example or actual input
    additionalInfo?: { [key: string]: string } // Additional info for some puzzles with multiple examples
): Promise<number | string> {
    let answer: number | string = 0;
    throw new Error('Not implemented'); // <-- Replace with your solution
    return answer;
}

run(__filename, solve);

Run it.

The console will show the example and expected answer.

Replace the throw new Error line of code with your solution and set answer to the result. Run it again.

First AoCC will run your solver against the example. If the example passes then AoCC will run it against the actual input and offer to submit the answer for you. If not it will stop and let you know.

Solver

The solve function, or "solver", is where you write code to solve the puzzle. See the inline comments in the TypeScript above for explanations of most of the parameters.

additionalInfo is an optional parameter that is only used with some puzzles that contain multiple examples. For example, part 2 of day 21, 2023 provides seven examples, and each one must be calculated for a different number of steps the elf takes, so in this case additionalInfo contains a steps attribute with the necessary value.

Runner

The run function, or "runner", takes your solver and automates running it. It's highly configurable, but only the simplest example is shown above. See the docs for more info.

Commands

AoCC supports a few different commands that can be useful during development and for troubleshooting. See the documentation.

Features

  • Automatically retrieves example inputs and answers
  • Runs your solution against the examples and checks for a matching answer
  • Runs your solution against the actual input after all examples pass
  • Submits the answer and reports back whether it was correct or not
  • Compares answer to previously know too high/too low answers and rejects them if they're still too high/too low
  • Regression tests your solution against the input if an answer was previously accepted

Contributing

Contributions to the example database are welcome and needed!

Acknowledgements

Thank you to Eric Wastl, the creator of Advent of Code!

AoCC attempts to honor Eric's wishes in the following ways:

  • Caches puzzles and inputs in order to be gentle, storing them in the user's home directory so that puzzles and inputs won't be stored in a public repository.
  • Remembers previous incorrect answers so it doesn't submit duplicates, and waits the required amount of time to submit new answers.
  • Identifies itself with the User-Agent header so that the Advent of Code site has a way to identify traffic generated by this project.

License

MIT