Skip to content

Commit 562f220

Browse files
committed
refactor(2024/day/17): split out run function
1 parent 0f31993 commit 562f220

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

2024/day/17/part/1/solve.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
export default function solve(input: string) {
2-
const [top, bottom] = input.split("\n\n");
1+
function run(a: number, b: number, c: number, program: number[]) {
32
const output: number[] = [];
4-
let [a, b, c] = top.matchAll(/\d+/g)!.map(([v]) => +v);
5-
const program = bottom.split(": ")[1].split(",").map(Number);
63
function combo(operand: number) {
74
if (operand < 4) return operand;
85
switch (operand) {
@@ -53,5 +50,12 @@ export default function solve(input: string) {
5350
break;
5451
}
5552
}
56-
return output.join(",");
53+
return output;
54+
}
55+
56+
export default function solve(input: string) {
57+
const [top, bottom] = input.split("\n\n");
58+
const [a, b, c] = top.matchAll(/\d+/g)!.map(([v]) => +v);
59+
const program = bottom.split(": ")[1].split(",").map(Number);
60+
return run(a, b, c, program).join(",");
5761
}

0 commit comments

Comments
 (0)