AdventOfCodeLibrary 1.0.2

dotnet add package AdventOfCodeLibrary --version 1.0.2                
NuGet\Install-Package AdventOfCodeLibrary -Version 1.0.2                
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="AdventOfCodeLibrary" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AdventOfCodeLibrary --version 1.0.2                
#r "nuget: AdventOfCodeLibrary, 1.0.2"                
#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.
// Install AdventOfCodeLibrary as a Cake Addin
#addin nuget:?package=AdventOfCodeLibrary&version=1.0.2

// Install AdventOfCodeLibrary as a Cake Tool
#tool nuget:?package=AdventOfCodeLibrary&version=1.0.2                

AdventOfCodeLibrary

Simple AdventOfCode helper library

I created this library to assist in faster gathering and submission for problems from AdventOfCode.

Usage

Use developer tools to get your session cookie from AOC. This will be used for retrieving your user specific input, and submitting your results.

AdventOfCodeSession

If using inside a repository that will be pushed remotely, I recommend saving it in a file that is in your .gitignore, or saving it into environment variables to load into your application.

Create a class that inherits from AdventOfCodeDay for the problem on a given day, for example:

public class Aoc15_1 : AdventOfCodeDay
{
    public Aoc15_1(string session = "") : base(2015, 1, session) { }
    public override string PartOne(string input)
    {
        return String.Empty;
    }
    public override string PartTwo(string input)
    {
        return String.Empty;
    }
}

This sets up the necessary framework to let your problem solving begin.

When testing your code, you can call the PartOne and PartTwo methods with a specific string directly. If no string is used, the parent class will use the input retrieved using the session cookie you provided. If an invalid session cookie is provided, a System.Net.WebException will be thrown. This will happen on initialization of the class instance.

Once your class is written, and you're ready to test, inside your program, you can create an instance of your class, specifying the session, and do any testing, as shown in this example:

class Program
{
    static void Main()
    {
        var aoc15_1 = new Aoc15_1("SOME_SESSION_COOKIE_VALUE");
        var your_input = aoc15_1.Input;
        var testingInput = "5 9 2 8\n9 4 7 3\n3 8 6 5";
        var testresult2 = aoc15_1.PartTwo(testingInput);

        var result1 = aoc15_1.PartOne();
        var result2 = aoc15_1.PartTwo();

        int isCorrect1 = aoc15_1.SubmitPartOne(result1);
        int isCorrect2 = aoc15_1.SubmitPartTwo(result2);

        if (isCorrect2 == 0) Console.WriteLine("got it right");
        else if (isCorrect2 == 1) Console.WriteLine("Answer was too high");
        else if (isCorrect2 == -1) Console.WriteLine("Answer was too low");
        else throw new Exception("what happened here");

        Console.WriteLine(result2);
    }
}

You can also use this library from within F#, for example:

open AdventOfCodeLibrary

type aoc15_1(session:string) =
  inherit AdventOfCodeDay(2015, 1, session)
  override this.PartOne input:string =
    input
    |> String.filter (fun s -> (s > '0' && s < '9'))
    
  override this.PartTwo input:string =
    input
    |> String.replicate 3

let myaoc151 = aoc15_1 "SOME_SESSION_COOKIE_VALUE"
let res = myaoc151.PartTwo ()
printfn "%s" myaoc151.Input
printfn "%s" res

One thing to note is that the SubmitPartOne and SubmitPartTwo methods return an int i by reading the response from the server:

  • 0 if your result equals the expected (AKA you're correct)
  • 1 if your result is too high
  • -1 if your result is too low
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 192 12/18/2023
1.0.1 92 12/18/2023
1.0.0 111 12/18/2023