/adventofcode2024

Advent of Code 2024

Primary LanguageTypeScriptMIT LicenseMIT

adventofcode2024

Deno CI

This repo contains TypeScript solutions for the Advent of Code 2024 puzzles. The scripts are written to executed in the Deno runtime.

Context

I have been using Deno for a while for personal scripting needs. Also, I always wanted to finish the Advent of Code puzzles. So, I decided to give a shot at solving this year's AoC using TypeScript. This way I can improve my TypeScript as well as solve the puzzles.

Thoughts

Typescript

So far, my experience with TypeScript has been subpar at solving AoC puzzles. Deno is a great runtime, but the TypeScript has been a bit of a pain to write data structures and algorithms. Coming from the Rust ecosystem, I missed some features very much.

  • Data is passed using references implicitly. If I change some value in a function, it changes the value in the caller function. Rust uses immutable borrow for this.
  • No hash function for objects. The Map and Set data structures uses object pointers for keys. So I can have new Set([[1, 2], [1, 2]]) with size 2 because the two arrays are different objects, even though they have the same values. I had to use string keys for objects when using them as keys in a map or set.
  • No standard data structure libraries. I had to maintain my own set, maps and other data structures.
    • Must say that jsr:@std/data-structures helped me with BinaryHeap.
  • Not strong typing and type inference. I had to write concrete types at some places.
  • Not strong pattern matching. I missed Rust's pattern matching very much.
  • No pairs, tuples or constant size arrays.
  • Footguns like == and === or const elem of array and const elem in array.

Deno

Deno has been great. I would have stopped using TypeScript if it weren't for Deno. The runtime is great, and the jsr:@std library is very useful. None of my solution uses any external dependencies except jsr:@std. Deno's test and assert libraries allowed me to test my solutions. I can use a single binary for everything. The lint and fmt commands kept my code clean.