Working Notes: a commonplace notebook for recording & exploring ideas.
Home. Site Map. Subscribe. More at expLog.

Advent Of Code 2021

let nextImage = new Array(4).fill(new Array(4).fill("."));
  - which creates a 2-dimensional array, filled with the same array 4 times
  function step(p1, p2, p3) {
    w = inputs.next().value;
    x = z % 26 + p2;
    z = Math.floor(z / p1);
    if (x != w) {
      z = z * 26 + w + p3;
    }
    // console.log({step: ++i, w, x, y, z});
  }
  - Expanding this a little bit leads to constraints on the inputs: 1 <= input <= 9,
  - But we also want to make sure z reaches 0:
    - z can only reduce when p1 != 1
    - which explicitly sets up relationships on 7 values
    - the constants/parameters end up giving a range on the "free" values
    - setting the "free" values to their maximum & minimum possible values respectively solves the problem.
- And fairly curious about how Reddit did it:
  - Brute force with a reduced search space
  - Python to directly evaluate it by heavily relying on caching
  - A /few/ others who derived the constraints like I did
  - Using Z3 SMT Solver: https://gist.github.com/AdibSurani/c047a0f0d3d9bc294337cb58da16173e

((nil . ((lsp-disabled-clients . (jsts-ls ts-ls flow-ls)))))
- as a .dir-locals.el file in the directory of my advent of code solutions.

Kunal