Giter Site home page Giter Site logo

advent-of-code-2020's Introduction

AdventOfCodeBase

Template project for solving Advent of Code in C#, running on .NET Core 3.1. If you wish to use .NET 5, you can.

Features

  • Simple configuration with config.json.
  • Fetches puzzle input from adventofcode.com and stores it locally.
  • Includes various useful utilities for typical puzzle problems.

Getting started

If you haven't already, use the button shown below (or this link) to create a new repository of your own from this template.

use-this-template

Feel free to make any modifications you want. However, you probably do not want to remove any files outside of AdventOfCode/Solutions/ unless you know what you're doing.

If any solution files that you need are not already included, see Generating Previous Year's Solution Files.

Usage

Configuration

Create config.json with the following key/value pairs. If you run the program without adding a config.json file, one will be created for you without a cookie field. The program will not be able to fetch puzzle inputs from the web before a valid cookie is added to the configuration.

{
  "cookie": "session=c0nt3nt",
  "year": 2020,
  "days": [0] 
}

cookie - Note that c0nt3nt must be replaced with a valid cookie value that your browser stores when logging in at adventofcode.com. Instructions on locating your session cookie can be found here: wimglenn/advent-of-code-wim#1

year - Specifies which year you wish to output solutions for when running the project. Defaults to the current year if left unspecified.

days - Specifies which days you wish to output solutions for when running the project. Defaults to current day if left unspecified and an event is actively running, otherwise defaults to 0.

The field supports list comprehension syntax and strings, meaning the following notations are valid.

  • "1..4, 10" - runs day 1, 2, 3, 4, and 10.
  • [1, 3, "5..9", 15] - runs day 1, 3, 5, 6, 7, 8, 9, and 15.
  • 0 - runs all days

Running the project

Write your code solutions to advent of code within the appropriate day classes in the Solutions folder, and run the project. From the command line you may do as follows.

> cd AdventOfCode
> dotnet build
> dotnet run

Using dotnet run from the root of the repository will also work as long as you specify which project to run by adding -p AdventOfCode. Note that your config.json must be stored in the location from where you run your project.

Example projects

Notes

Generating Previous Year's Solution Files

Use the included PowerShell script AdventOfCode/UserScripts/GenerateSolutionFiles.ps1 to generate a year's solution files following the same layout as those already included.

Usage: GenerateSolutionFiles.ps1 [-Year <Int>]

If no value is provided it will generate files for the current year. The script will avoid overwriting existing files.

Requires PowerShell v3 or later due to the way $PSScriptRoot behaves. If you have Windows 8+ you should be set. Upgrades for previous versions, and installs for macOS and Linux can be found in Microsoft's Powershell Documentation

Using a Solution's Constructor

  • Code may be written in the solution constructor if it will be beneficial to both parts of the problem (such as parsing the data). Example:
public Day07() : base(07, 2015, "")
{
    string[] lines = Input.SplitByNewLine();
    foreach (string line in Lines)
    {
        //Parse out input here
    }
}

protected override string SolvePartOne()
{
    //Manipulations specific to Part 1 here
    return result;
}

protected override string SolvePartTwo()
{
    //Manipulations specific to Part 2 here
    return result;
}
  • The variable Input will contain your input as a long raw string.
  • If stuck you can set the DebugInput variable at the top of the constructor, and it will overwrite Input variable, so you won't need to change all your references.
  • The extension method SplitByNewLine() will do exactly that, example: string[] lines = Input.SplitByNewLine() will split your input into lines for enumeration.

Changing from .NET Core to .NET 5

Simply swap out the target framework in AdventOfCode.csproj.

-    <TargetFramework>netcoreapp3.1</TargetFramework>
+    <TargetFramework>net5.0</TargetFramework>

Contributing

Sure! Fork the project, make your changes, and create a pull request. Submitted issues and pull requests are quite welcome.

License

MIT

advent-of-code-2020's People

Contributors

msonnberger avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.