2024 day 19 part 1 but it actually finishes executing in javascript
This commit is contained in:
parent
136d031345
commit
196cde6dcb
|
@ -1,8 +1,6 @@
|
|||
|
||||
const input = (await Bun.file(Bun.argv[2]).text()).trim()
|
||||
|
||||
// const input = "12345";
|
||||
|
||||
const files = [];
|
||||
|
||||
const spaces = [];
|
||||
|
|
15
2024/19/solution.js
Normal file
15
2024/19/solution.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
const input = (await Bun.file(Bun.argv[2]).text()).trim()
|
||||
|
||||
const [towels, desired] = input.split("\n\n")
|
||||
|
||||
const regex = new RegExp(`^(${towels.split(", ").join("|")})+$`)
|
||||
|
||||
const lines = desired.split("\n")
|
||||
|
||||
let count = 0;
|
||||
for (const line of lines) {
|
||||
if (regex.test(line)) {count ++}
|
||||
}
|
||||
console.log(count)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
{input ? "", lib, ...}: let
|
||||
{input ? "", lib, pkgs, ...}: let
|
||||
inherit (builtins) elemAt filter length;
|
||||
|
||||
exampleIn = lib.readFile ./example.txt;
|
||||
|
@ -8,7 +8,7 @@
|
|||
towels = elemAt parts 0 |> lib.splitString ", ";
|
||||
regex = ''(${builtins.concatStringsSep "|" towels})+'';
|
||||
desired = elemAt parts 1 |> lib.splitString "\n";
|
||||
matches = desired |> map (lib.match regex);
|
||||
matches = desired |> map (e: lib.traceSeq e (lib.match regex e));
|
||||
in {
|
||||
inherit towels regex desired matches;
|
||||
count = matches
|
||||
|
@ -16,11 +16,17 @@
|
|||
|> length;
|
||||
};
|
||||
|
||||
input-file = pkgs.writeText "input.txt" input;
|
||||
bun-run = js-file: pkgs.runCommand "2024day9" {} ''
|
||||
${lib.getExe pkgs.bun} ${js-file} ${input-file} > $out
|
||||
'' |> builtins.readFile |> lib.trim;
|
||||
|
||||
in {
|
||||
example = mkSolution {
|
||||
text = exampleIn;
|
||||
};
|
||||
real = mkSolution {
|
||||
text = input;
|
||||
real = throw "lol this solution is wayy too slow for the real input";
|
||||
javascript = {
|
||||
part1result = lib.trace "this is a dumb and slow solution" (bun-run ./solution.js);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"aoc-inputs": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1734614378,
|
||||
"narHash": "sha256-vEsmquzc9r82OCVx2Q9WjdND7aOy39Oot3QDJcInhXk=",
|
||||
"lastModified": 1734622191,
|
||||
"narHash": "sha256-kWDExTEeBuscWOZNBCMXAqZtNQT0SiQCjp43yEPRQ3g=",
|
||||
"path": "/tmp/aoc-inputs",
|
||||
"type": "path"
|
||||
},
|
||||
|
|
|
@ -39,10 +39,6 @@
|
|||
input = (pkgs.lib.readFile "${aoc-inputs}/${id}");
|
||||
in {
|
||||
inherit solution;
|
||||
example = solution example;
|
||||
example2 = solution example2;
|
||||
example3 = solution example3;
|
||||
real = solution input;
|
||||
test = tix.run [
|
||||
./${id}/solution.test.nix
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue