Compare commits

..

No commits in common. "ef621d0fdb1f6880f00f9b7f997ebf555a5621e3" and "77390e08f3b8ba741e41b5e6996bb0fab76b0d0d" have entirely different histories.

5 changed files with 3 additions and 136 deletions

View file

@ -1,12 +0,0 @@
p=0,4 v=3,-3
p=6,3 v=-1,-3
p=10,3 v=-1,2
p=2,0 v=2,-1
p=0,0 v=1,3
p=3,0 v=-2,-2
p=7,6 v=-1,-3
p=3,0 v=-1,-2
p=9,3 v=2,3
p=7,3 v=-1,2
p=2,4 v=2,-3
p=9,5 v=-3,-3

View file

@ -1,84 +0,0 @@
{lib, ...}: input: let
inherit (lib.strings) trim splitString toIntBase10;
inherit (builtins) match elemAt filter length genList concatStringsSep;
# real
width = 101;
height = 103;
# example
# width = 11;
# height = 7;
getQuadrants = {width, height}: robots: let
mid.x = width / 2;
mid.y = height / 2;
tl = robots |> filter ({pos, ...}: pos.x < mid.x && pos.y < mid.y);
tr = robots |> filter ({pos, ...}: pos.x > mid.x && pos.y < mid.y);
dl = robots |> filter ({pos, ...}: pos.x < mid.x && pos.y > mid.y);
dr = robots |> filter ({pos, ...}: pos.x > mid.x && pos.y > mid.y);
in {inherit tl tr dl dr;}
;
robots = input
|> trim
|> splitString "\n"
|> map (line: line
|> match ''p=([0-9]+),([0-9]+) v=(-?[0-9]+),(-?[0-9]+)''
|> (nums: {
pos = {
x = elemAt nums 0 |> toIntBase10;
y = elemAt nums 1 |> toIntBase10;
};
vel = {
x = elemAt nums 2 |> toIntBase10;
y = elemAt nums 3 |> toIntBase10;
};
})
)
;
pass = time: {pos, vel}: let
x = lib.mod (pos.x + (vel.x * time)) width;
y = lib.mod (pos.y + (vel.y * time)) height;
in {
pos = {
x = if x < 0 then width + x else x;
y = if y < 0 then height + y else y;
};
};
printMap = robots: genList (y:
genList (x:
robots
|> filter ({pos,...}: pos == {inherit x y;})
|> length
|> (amt: if amt == 0 then "." else toString amt)
) width
|> concatStringsSep ""
) height
|> concatStringsSep "\n";
anim = {start, period}: 100 |> genList (i: let
seconds = (i * period) + start;
in robots |> map (pass (seconds)) |>
(room: ''
seconds: ${toString seconds}
${printMap room}
'')
) |> concatStringsSep "\n";
in {
inherit width height pass getQuadrants robots printMap;
part1result = robots
|> map (pass 100)
|> getQuadrants {inherit width height;}
|> ({tl, tr, dr, dl}: (length tl) * (length tr) * (length dr) * (length dl))
;
part2result = # figured these settings out after observing the first 500 seconds:
anim {start = 14; period = 101;}
|> builtins.toFile "robots-anim";
}

View file

@ -1,37 +0,0 @@
{it, describe, ...}: let
pkgs = import <nixpkgs> {};
solution = import ./solution.nix pkgs;
in [
(it "splits the stupid thing into quadrants" {
actual = (solution "").getQuadrants {width = 7; height = 5;} [
{ pos.x = 2; pos.y = 1; }
{ pos.x = 4; pos.y = 1; }
{ pos.x = 2; pos.y = 3; }
{ pos.x = 4; pos.y = 3; }
{ pos.x = 0; pos.y = 2; }
{ pos.x = 1; pos.y = 2; }
{ pos.x = 2; pos.y = 2; }
{ pos.x = 3; pos.y = 2; }
{ pos.x = 4; pos.y = 2; }
{ pos.x = 3; pos.y = 0; }
{ pos.x = 3; pos.y = 1; }
{ pos.x = 3; pos.y = 2; }
{ pos.x = 3; pos.y = 3; }
{ pos.x = 3; pos.y = 4; }
];
expected = {
dl = [
{ pos.x = 2; pos.y = 3; }
];
dr = [
{ pos.x = 4; pos.y = 3; }
];
tr = [
{ pos.x = 4; pos.y = 1; }
];
tl = [
{ pos.x = 2; pos.y = 1; }
];
};
})
]

View file

@ -3,8 +3,8 @@
"aoc-inputs": { "aoc-inputs": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1734173652, "lastModified": 1734085033,
"narHash": "sha256-jXnmQLoXNcaqYY/uupC8f8JQ27zdwSVBmxAnIxlennk=", "narHash": "sha256-UlLhIP9NbAywjOGRkrULOa0e+AtY2Eb7Vgem/o/pN7Y=",
"path": "/tmp/aoc-inputs", "path": "/tmp/aoc-inputs",
"type": "path" "type": "path"
}, },

View file

@ -25,7 +25,7 @@
inherit (pkgs) lib; inherit (pkgs) lib;
in (lib.range 1 14 in (lib.range 1 13
|> map (i: let id = lib.fixedWidthNumber 2 i; in { |> map (i: let id = lib.fixedWidthNumber 2 i; in {
name = "day-${id}"; name = "day-${id}";
value = let value = let