Giter Club home page Giter Club logo

aoc2021's Introduction

advent-of-code-2021

My Advent of Code 2021 ๐ŸŽ„ solutions.

Notes to self

  • NB: Using else in a case statement can save some debugging time if the input gets messed up
  • Sorting the input actually seems like a good idea. Should give it a try!
  • Used spaceship operator to turn a number into +1/0/-1
  • Reused self-creating Hash from last year
  • Looking into Wikipedia Line article was helpful
  • Alternative approach: calculate the result for each input entry; use Hash to cache the result for the same age
  • Presenting the digits as arrays of segments made it easy to derive digits from each other, but it was still manual work
  • Would be interesting to make a universal solution (constaint solver?)
  • Used what I guess is called flood fill algorithm
  • Got tripped by Ruby's negative array indices (expected nil)
  • And (more than once) by counting the previously visited cells in a recursive walkaround
  • Remembered that using [x, y] for a hash containing grid elements is often more convenient than [x][y]
  • That day I discovered Dijkstra's algorithm ๐Ÿง
  • However, the basic version wasn't any good for the 2nd part (250k cells). An optimization also described in the Wikipedia article (adding neighbour cells into the queue as we progress and removing them after the visit) helped.
  • Haven't tried A*, maybe for smth else!
  • Used a class to simplify the position tracking
  • TODO: rewrite using Ruby's StringScanner class, check out formal notation and theory on parsers

Running the code

  • Run bundle install to install dependencies
  • ruby day-<number>.rb
  • The input data is stored in /inputs directory. If there's no input and the session cookie is provided through the SESSION env var โ€” the framework will fetch the input from the AoC website on the first run.

Thanks to @Aquaj for the handy Ruby framework!

aoc2021's People

Contributors

wetterkrank avatar

Watchers

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