Giter Site home page Giter Site logo

adventofcode2022's Introduction

Advent of Code 2022

This year I tried every challenge, while learning Rust.
In the end there were only 5/50 puzzles that I missed:

  • Day 16 B: Part A was hard enough ๐Ÿ˜…
  • Day 19 A & B: Day 16 with extra steps
  • Day 24 B: Should work, but gives the wrong answer. Probably some edge case
  • Day 25 B: Only unlocked after completing all 49 other puzzles

I know that if I want to complete all the challenges next year, I'll need to learn more about Depth-first search and how to optimize it. I also realized that the Breadth-first search algorithm is very important to know well, as I used it in quite a few solutions. Other than that, it was pretty successful for only having started with Rust a few months ago.

As the puzzles got harder each day, I eventually started making drawings for a few (15, 16, 18, 21, 22) to test ideas visually instead of trying to imagine it. In some days you'll see a drawing that makes the puzzle or idea more understandable.

Highlights

Some of my most clean and favorite solutions:

  • Day 6: Highly optimized buffer reader that would work with a real stream as well
  • Day 7: A recursive data structure using Rc<RefCell<>> which wasn't easy in Rust
  • Day 12: First time using Breadth-first search and clean code overall
  • Day 13: A very clean and rusty compare() function that is fast and minimal
  • Day 16 A: After over 6 hours of working on this puzzle, I finally solved it with a big recursive algorithm and some shortcuts
  • Day 23: Very simple/short code to solve the whole puzzle with a neat observation
  • Day 24 A: A very efficient algorithm that finds the answer in only 60 milliseconds
  • Day 25 A: A logical and simple to follow algorithm with detailed comments

New day script

A script to create a new cargo package from the dayN/ template.

./new_day.sh [number]

Flamegraph

Flamegraph allows you to see what functions the program is most busy with, and might allow you to see what parts should be optimized.

This is more of a note to myself, but if you're on WSL2 and want to use cargo flamegraph you can use the following command where you likely need to change the 5.4.0-126 version number, as well as the -F frequency for how often to make a sample:

PERF=/usr/lib/linux-tools/5.4.0-126-generic/perf flamegraph -F 100000 -- ./target/release/day14b

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.