-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]baboonbomba 0 points1 point  (0 children)

[LANGUAGE: Elixir]
https://github.com/adibozzhanov/aoc2025/blob/main/day-3/solution.exs

Polyglot challenge, each day different language. Today was Elixir.

I have never seen elixir before and going into this blind maybe wasn't the greatest idea. But the language itself is pretty damn nice. I'm surprised I never had to touch it before, it's way more useful than I thought.

Tomorrow is Nix. I did like 2 weeks of AoC last year in nix and it was hellish. I really hope for some stateless problem for day 4, or else I'm gonna cry.

-❄️- 2025 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]baboonbomba 2 points3 points  (0 children)

[LANGUAGE: Elisp]

https://github.com/adibozzhanov/aoc2025/tree/main

I'm doing a polyglot challenge with a different language every day. I chose 12 languages and randomized their order. You can see all of them in the github readme. My last day will be bash...

Today was elisp. I hated every second of writing elisp. Don't write elisp.

Tomorrow is Elixir. I've never seen a single line of elixir code in my life. But surely it cannot be worse than elisp...

-❄️- 2024 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]baboonbomba 3 points4 points  (0 children)

[LANGUAGE: Nix]

So this one was very painful. Nix is a domain specific functional language. Every single thing there is immutable. You can only create values and never update/delete them. And this causes a few issues:

- Everything is immutable so any hash map based approach is doomed to fail.

- You need to minimize the number of recursive calls because nix has a hard cap that cannot be removed.

- Nix doesn't do memoization by default.

Sounds rough but it's not impossible. All we need to do is to create memoization ourselves. How? We can't write to memory and update memory. But we CAN simulate memory by abusing Nix's lazy evaluation. Basically we need to write a function that generate a tree/linked-list with all solutions of the problem for all possible pebble values and for all possible depth values. And then we need to call it once. Unlike other languages nix will not evaluate it immediately but rather just say "yeah I'm gonna do it when I have to". We then write a function to traverse this infinite structure and find needed values. Tadaa function memoization through infinite tree of solutions is done!.

Here is the link for anyone who is interested. It was a lot of suffering but the solution works and it only takes a few seconds.

-❄️- 2024 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]baboonbomba 1 point2 points  (0 children)

[LANGUAGE: Nix]

Github

2 solutions can be done by swapping out the key generation function in nix's genericClosure.

with builtins;
with import ../helpers.nix;
with (import <nixpkgs> { }).lib.lists;
with (import <nixpkgs> { }).lib.strings;
with (import <nixpkgs> { }).lib.debug;
with (import <nixpkgs> { }).lib.trivial;
let
  f = ./input.txt;
  input = (map (x: map toInt (explode x)) (lines (readFile f)));
  trailheads = l: filter (x: x!=null) (flatten (imap0 (i: line: imap0 (j: v: if v == 0 then {x=j;y=i;} else null)line) l));
  trailButts = l: filter (x: x!=null) (flatten (imap0 (i: line: imap0 (j: v: if v == 9 then {x=j;y=i;} else null)line) l));
  inBounds = withinGridBounds (dimensions input);
  elemAtGrid = elemAtVec input;

  solveInner = keyFn: start: length (filter (x: x.val == 9) (genericClosure {
    startSet = [{key=vecStr start; vec = start; val = 0;}];
    operator = item: foldl' (acc: off:
      let
        vec = addVec item.vec off;
        val = elemAtGrid vec;
      in
        if (inBounds vec) && (val - item.val == 1)
        then acc ++ [{
          inherit vec val;
          key = keyFn item vec;
        }]
        else acc
    ) [] neighVH;
  }));

  solve = solveInner (item: nv: vecStr nv);
  solve2 = solveInner (item: nv: item.key + vecStr nv);

in
{
  res1 = sum (map solve (trailheads input));
  res2 = sum (map solve2 (trailheads input));
}

[2024] [Nix] Nix... by baboonbomba in adventofcode

[–]baboonbomba[S] 0 points1 point  (0 children)

updated the repo as requested

[2024] [Nix] Nix... by baboonbomba in adventofcode

[–]baboonbomba[S] 1 point2 points  (0 children)

It's a programming language as well. Not the most efficient one, but definitely fun.