diff --git a/2024/14/example.txt b/2024/14/example.txt deleted file mode 100644 index 2455da4..0000000 --- a/2024/14/example.txt +++ /dev/null @@ -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 diff --git a/2024/14/solution.nix b/2024/14/solution.nix deleted file mode 100644 index c14b1cc..0000000 --- a/2024/14/solution.nix +++ /dev/null @@ -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"; - -} diff --git a/2024/14/solution.test.nix b/2024/14/solution.test.nix deleted file mode 100644 index 03edf42..0000000 --- a/2024/14/solution.test.nix +++ /dev/null @@ -1,37 +0,0 @@ -{it, describe, ...}: let - pkgs = import {}; - 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; } - ]; - }; - }) -] diff --git a/2024/flake.lock b/2024/flake.lock index b6026cd..6a78e02 100644 --- a/2024/flake.lock +++ b/2024/flake.lock @@ -3,8 +3,8 @@ "aoc-inputs": { "flake": false, "locked": { - "lastModified": 1734173652, - "narHash": "sha256-jXnmQLoXNcaqYY/uupC8f8JQ27zdwSVBmxAnIxlennk=", + "lastModified": 1734085033, + "narHash": "sha256-UlLhIP9NbAywjOGRkrULOa0e+AtY2Eb7Vgem/o/pN7Y=", "path": "/tmp/aoc-inputs", "type": "path" }, diff --git a/2024/flake.nix b/2024/flake.nix index 3014a85..0cc8d51 100644 --- a/2024/flake.nix +++ b/2024/flake.nix @@ -25,7 +25,7 @@ inherit (pkgs) lib; - in (lib.range 1 14 + in (lib.range 1 13 |> map (i: let id = lib.fixedWidthNumber 2 i; in { name = "day-${id}"; value = let