Coder Social home page Coder Social logo

adventofcode's Introduction

Advent of Code (2015-2023)

C# solutions to the Advent of Code problems.

This project is best used as a template for your own AoC repository and a guide in solving the puzzles. I put a lot of effort into my solutions. I aim for clarity which means that they are not super effective or super short, but hopefully more readable.

Due to copyright requirements I'm not allowed to include my input files within this repository so you cannot just clone it and run. However I wanted to have a self contained documentary for myself that I can later refactor, so I decided to commit the encrypted version of the input files. It doesn't violate the copyright since it's just random garbage for everyone else but when I check it out, a plugin called git-crypt decrypts all my inputs transparently, so I can work with them freely. On commit the whole process is reversed and the files get encrypted again.

Dependencies

  • This project is based on .NET 8 and C# 12.
  • AngleSharp is used for problem download.

Use it as a solution template:

  1. Install .NET Core
  2. Clone the repo
  3. Remove all solution folders
> cd repo-dir
> rm -fr 20*
  1. Install and initialize git-crypt:
> brew install git-crypt
> cd repo-dir
> git-crypt init
> git-crypt export-key ~/aoc-crypt.key
  1. Don't commit aoc-crypt.key into a public repo, back it up in some protected place. If you need to clone your repo later you will need to unlock it using this key such as:
> git clone ...
> cd repo-dir
> git-crypt unlock ~/aoc-crypt.key
  1. Get help with dotnet run and start coding.
Usage: dotnet run [arguments]
1) To run the solutions and admire your advent calendar:

 [year]/[day|all]      Solve the specified problems
 today                 Shortcut to the above
 [year]                Solve the whole year
 all                   Solve everything

 calendars             Show the calendars

2) To start working on new problems:
login to https://adventofcode.com, then copy your session cookie, and export 
it in your console like this

 export SESSION=73a37e9a72a...

then run the app with

 update [year]/[day]   Prepares a folder for the given day, updates the input,
                       the readme and creates a solution template.
 update today          Shortcut to the above.

3) To upload your answer:
set up your SESSION variable as above.

 upload [year]/[day]   Upload the answer for the selected year and day.
 upload today          Shortcut to the above.

4) Don't forget to tip the maintainer https://github.com/sponsors/encse.

Working in Visual Studio Code

If you prefer, you can work directly in VSCode as well.

Open the command Palette (โ‡ง โŒ˜ P), select Tasks: Run Task then e.g. update today.

Work on part 1. Check the solution with the upload today task. Continue with part 2.

Note: this feature relies on the "Memento Inputs" extension to store your session cookie, you need to set it up in advance from the Command Palette with Install Extensions.

How can I help?

If you find this useful, please support me.

adventofcode's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adventofcode's Issues

Command update [year/day] fails if no year folder exists in root

I was trying to make use of this AOC framework to solve AOC challenges myself, but it seems to break if no year folder exists

execute, for example, dotnet run update 2021/1

Updating https://adventofcode.com/2021/day/1
Unhandled exception. System.AggregateException: One or more errors occurred. (Sequence contains no elements)
 ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.MinInteger[T](IEnumerable`1 source)
   at AdventOfCode.Updater.Update(Int32 year, Int32 day) in ...RepoPath...\Lib\Updater.cs:line 52
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Program.<>c__DisplayClass0_1.<<Main>$>b__16() in ...RepoPath...\App.cs:line 17
   at Program.<Main>$(String[] args) in ...RepoPath...\App.cs:line 111

In Updater.Update():

...
var years = Assembly.GetEntryAssembly().GetTypes()
    .Where(t => t.GetTypeInfo().IsClass && typeof(Solver).IsAssignableFrom(t))
    .Select(tsolver => SolverExtensions.Year(tsolver));

UpdateProjectReadme(years.Min(), years.Max());
...

the Enumerable years variable seems to be empty and it breaks when attempting to get the Min() and Max() of the collection.

I think something like this would solve the issue:

...
var years = Assembly.GetEntryAssembly().GetTypes()
    .Where(t => t.GetTypeInfo().IsClass && typeof(Solver).IsAssignableFrom(t))
    .Select(tsolver => SolverExtensions.Year(tsolver));

if (years.Count() == 0) {
    years = new int[] { year };
}

UpdateProjectReadme(years.Min(), years.Max());
...

Code is not licensed

Loving this repo - it provides a very good starting point for solving the advent of code problems, but the code doesn't have a license associated with it, which means that it cannot really be used by me (or someone else) to provide our own solutions.

Is it possible to add a license to the repository?
See https://help.github.com/en/articles/licensing-a-repository for more information about licenses.

Bring back the 'test' feature

I got it removed, because I never used it, but I see that @FaustVX started to use it, so I'll add it back.
Things are not that simple if you have a user...

2023-day23-part2: error with my input

Hi David,

I am totally stuck with part 2 of day 24. Your solution trips on line 111. I don't know if it's due to my input file,

I cannot seem to get a valid result from cameronaavik or penguin solutions either. See: https://github.com/Bogdanp/awesome-advent-of-code?tab=readme-ov-file#c-1 They are the only other C# solutions to day 24 part2 that I could find.

I have attached my input file.

I find it very frustrating not being able to get the final star. So if ever you feel like having a look, it would make me very happy if you could spot the issue.

Kind regards.
Erik

Remove puzzle descriptions

The puzzle descriptions for Advent of Code are not licensed for duplication or redistribution. You do not have permission to rehost them in this repository. Please remove them.

2022 Day 21

Hi David,

There seems to be an issue with the solution for Monkey Math (2022/21 ). The local function buildExpr within the Parse function, complains about 'name not found'. This happens when the name is looked up the context dictionary, while building the expression tree (before simplify is called).

This happens both with file included in the repo as well as with my personal input file. In repo file complains about 'rcmw'. In my personal file this is 'jwcp'.

I have observed that both are a defined by a sum operation and are used once, as input to a multiplication operation. The name/sum operation is part of the dictionary before it builds the expression tree.

I would have loved to contribute via a PR, but I cannot seem to find the issue.

My compliments for your very smart and elegant solutions. They have inspired me to make my code better. tipped me about how to get the puzzle solved. And last few days, simply to produce my answer, when I I was not able to solve it. Thank you!

Kind regards,
Erik Linthorst
Amsterdam, The Netherlands

aoc-y2022-d21-erik.txt

with-repo-input-file

with-eriks-input-file

jwcp-occurrances-in-eriks-input-file

rcmw-occurrances-in-repo-input-file

Debug folder as working dir.

Hello. I was searching some solutions for AoC and I saw yours. I cloned repo and tried run a solver but unfortunately i had a problem.

I tried to run in MacOS and Windows11. In windows 11 i tried to update and it give me same problem when loading font for svg. In MacOS I tried to run a solver and i got the below error.
1db16205-5c0f-49b9-b145-41d09c6055e9

It work in debug folder not main working dir.

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.