Giter Site home page Giter Site logo

pentracchiano / advent-of-code Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 192 KB

My solutions for Advent Of Code.

Home Page: https://adventofcode.com/

C# 100.00%
adventofcode aoc aoc-2022-in-csharp aoc2022 csharp competi competitiveprogramming aoc2023 aoc2023-in-csharp

advent-of-code's Introduction

Advent of Code

My solutions for the Advent Of Code, starting from 2022. In 2022 I was trying to learn a brand new language for me, C#, because I had just gotten my offer for Microsoft. I wanted to learn the language and the .NET ecosystem, so I decided to do the Advent of Code in C#. Now, in 2023, I am doing it again in the same language, and I am already seeing that I started disliking my old code - which to me is a sign of improvement! Speed of improvement = speed with which you start disliking your old code, I guess.

Structure partly inspired by https://github.com/ShootMe/AdventOfCode/.

Usage

All of the puzzles inherit from PuzzleSolution, offering a Setup to be initialized with the input and two different Solve methods.

Runner is the main file that runs the entire project: it's configurable from the terminal by optionally passing the day and year of the puzzle to run:

dotnet run [day] [year] ["real"|"example"]

If day is not provided, it will run all available puzzles. A puzzle is run by specifying the title of the problem, the name of the class, and the amount of time elapsed in milliseconds for each method run. The two Solve methods also come with a description, which is taken from a method attribute Description.

Example

This is an example with the day 7 specified:

PS C:\Users\Davide\Documents\advent-of-code-2022> dotnet run 7
Day 7 specified through command line.

Running Puzzle07: No Space Left On Device.
Setup completed. Elapsed: 6 ms.
Part one. Find all of the directories with a total size of at most 100000. What is the sum of the total sizes of those directories?
Result: "2104783". Elapsed: 4 ms.
Part two. Find the smallest directory that, if deleted, would free up enough space on the filesystem to run the update. What is the total size of that directory?
Result: "5883165". Elapsed: 1 ms.

Without specifying a day, the program will just launch all the solutions that are in the directory for the current year.

Implementation

In order to find a puzzle, Runner looks in the current directory for any Puzzle[day] subdirectories and then runs the corresponding class by leveraging the CodeDOM. It assumes that the classes are already loaded in the assembly: that is, it will not read the file and then compile it. It's effectively using the name of the directory just to know which classes are loaded, and to discern which input.txt file to feed the Solution object with.

Possible improvements

Assembly.GetTypes() could be used in order to enumerate the PuzzleSolution classes instead of relying on the directory structure. Better integration for multiple years. For now, I just archived 2022 because I just wanted to do the first puzzle without thinking too much :).

advent-of-code's People

Contributors

pentracchiano avatar

Watchers

 avatar  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.