Pillsgood.AdventOfCode 3.0.2-alpha

This is a prerelease version of Pillsgood.AdventOfCode.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pillsgood.AdventOfCode --version 3.0.2-alpha
                    
NuGet\Install-Package Pillsgood.AdventOfCode -Version 3.0.2-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pillsgood.AdventOfCode" Version="3.0.2-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pillsgood.AdventOfCode" Version="3.0.2-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Pillsgood.AdventOfCode" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pillsgood.AdventOfCode --version 3.0.2-alpha
                    
#r "nuget: Pillsgood.AdventOfCode, 3.0.2-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pillsgood.AdventOfCode@3.0.2-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pillsgood.AdventOfCode&version=3.0.2-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pillsgood.AdventOfCode&version=3.0.2-alpha&prerelease
                    
Install as a Cake Tool

Pillsgood.AdventOfCode

Helpers for solving Advent of Code puzzles from unit tests. It handles:

  • Fetching your puzzle input
  • Converting input into convenient types
  • Submitting/validating your answers

Built for use with NUnit but probably works with other test frameworks too.

Quick start (NUnit)

  1. Add NuGet package Pillsgood.AdventOfCode to project.

    • Optionally, add Pillsgood.AdventOfCode.Login for interactive login (currently win-x64 only).
  2. Add a one-time startup/teardown to your test assembly to initialize the library.

    [SetUpFixture]
    public sealed class AdventSetup
    {
        private IDisposable? _app;
    
        [OneTimeSetUp]
        public void Start() => _app = Aoc.Start(cfg =>
        {
            cfg.WithSession("your_session_cookie_here"); // or cfg.WithLogin();
        });
    
        [OneTimeTearDown]
        public void Stop() => _app?.Dispose();
    }
    
  3. Create test classes that inherit from AocFixture. Use Input to read puzzle input and Answer to submit/validate.

    namespace Y2024;
    
    public class Day01Tests : AocFixture
    {
        [Test]
        public void Part1()
        {
            var numbers = Input.Get<int[]>();
            Answer.Submit(numbers.Sum());
        }
    }
    

Naming conventions

The library detects which puzzle you're solving by inspecting the call stack:

  • Year: any 20xx in the test class' full name (namespace or type name)
  • Day: DayN / DayNN in the test class' full name
  • Part: Part1 or Part2 in the test method name

If you prefer not to inherit from AocFixture, mark your own base class with [AocFixture] and resolve IPuzzleInputService / IAnswerAssertion from Locator.

Reading input

Input.Get<T>() converts the input to T: string, numbers, anything IParsable, and arrays, lists, sets or other collections of those (one element per line). Extra arguments are passed to the conversions that use them.

var text   = Input.Get<string>();
var lines  = Input.Get<List<string>>();
var set    = Input.Get<HashSet<long>>();
var binary = Input.Get<int[]>(NumberStyles.BinaryNumber);
var words  = Input.Get<string[]>(StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);

Lines are not trimmed unless you pass StringSplitOptions.

Custom types can be added with a converter. It's combined with the built-in conversions, so this also enables Point[], HashSet<Point> and so on:

cfg.AddInputConverter<string, Point>(Point.Parse);

For more control, implement IInputConverter<TIn, TOut> (generic converters are supported) and register it the same way.

Submitting/validating answers

Answer.Submit(12345);
await Answer.SubmitAsync("ABCDEF");

The answer is submitted if it isn't known yet. Once accepted, it's cached and later runs assert against it instead of re-submitting.

Configuration

  • WithSession("<session_cookie>"): the session cookie from adventofcode.com
  • WithLogin() (from Pillsgood.AdventOfCode.Login): login window that acquires and caches the session
  • WithSessionProvider(...): custom ISessionProvider
  • WithCachePath(".aoc-cache.db"): cache file for inputs, answers and the session (defaults to store.db)
  • SetEntryAssembly(...): only needed if your tests run from a different assembly than the one calling Aoc.Start
  • AddInputConverter(...): custom input conversions

An invalid/expired session is cleared and requested again.

License

See LICENSE.md.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pillsgood.AdventOfCode:

Package Downloads
Pillsgood.AdventOfCode.Login

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.12-alpha 0 12/5/2026
3.0.5-alpha 0 12/5/2026
3.0.2-alpha 0 12/5/2026
2.2.11-alpha 57 12/2/2026
2.2.10-alpha 63 12/2/2026
2.2.7-alpha 128 9/2/2026
2.2.6-alpha 132 9/1/2026
2.2.5-alpha 128 9/1/2026
2.2.3-alpha 129 8/31/2026
2.2.1-alpha 126 8/31/2026
2.1.15-alpha 128 8/31/2026
2.1.13 357 12/4/2025
2.1.12-alpha 268 12/4/2025
2.1.11-alpha 276 12/4/2025
2.1.7-alpha 282 12/4/2025
2.0.23 316 12/4/2025
2.0.22 782 12/2/2025
2.0.21 774 12/2/2025
2.0.20 773 12/2/2025
2.0.19 793 12/2/2025
Loading failed