fix(day_7): B part fixed but inefficient
This commit is contained in:
@@ -5,6 +5,8 @@ export default async function Laboratories() {
|
|||||||
"src/exercises/assets/day_7_input.txt",
|
"src/exercises/assets/day_7_input.txt",
|
||||||
);
|
);
|
||||||
console.log(">> Bean splits: ", count_bean_splits(tachyon_manifold));
|
console.log(">> Bean splits: ", count_bean_splits(tachyon_manifold));
|
||||||
|
const total_splits = count_quantum_splits(tachyon_manifold);
|
||||||
|
console.log(">> Cuantum splits: ", total_splits);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function count_bean_splits(tm: TachyonManifold): number {
|
export function count_bean_splits(tm: TachyonManifold): number {
|
||||||
@@ -44,16 +46,49 @@ export function count_bean_splits(tm: TachyonManifold): number {
|
|||||||
|
|
||||||
export function count_quantum_splits(tm: TachyonManifold): number {
|
export function count_quantum_splits(tm: TachyonManifold): number {
|
||||||
const full_tree = generate_full_quantum_tree(tm);
|
const full_tree = generate_full_quantum_tree(tm);
|
||||||
console.log(
|
|
||||||
">> Full tree\n",
|
|
||||||
full_tree.map((row) => row.join("")).join("\n"),
|
|
||||||
);
|
|
||||||
let total = 0;
|
|
||||||
|
|
||||||
console.log("==", tm[tm.length - 2]);
|
// Downwards
|
||||||
for (let i = 0; i < tm[0].length; i++) {
|
const init = full_tree[0].findIndex((p) => p === "S");
|
||||||
if (tm[tm.length - 2][i] === "|") {
|
return count_quantum_paths_downwards(full_tree, init, 1);
|
||||||
total += count_quantum_paths_upwards(tm, i, tm.length - 2) + 1;
|
|
||||||
|
// Upwards
|
||||||
|
// let total = 0;
|
||||||
|
// for (let i = 0; i < tm[0].length; i++) {
|
||||||
|
// if (tm[tm.length - 2][i] === "|") {
|
||||||
|
// total += count_quantum_paths_upwards(full_tree, i, tm.length - 2) + 1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
function count_quantum_paths_downwards(
|
||||||
|
tm: TachyonManifold,
|
||||||
|
initial_x: number,
|
||||||
|
initial_y: number,
|
||||||
|
): number {
|
||||||
|
let total = 0;
|
||||||
|
const FILE_END = tm.length - 2;
|
||||||
|
const current = tm[initial_y][initial_x];
|
||||||
|
|
||||||
|
if (initial_y > FILE_END) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (initial_y === FILE_END && current === "|") {
|
||||||
|
return 1;
|
||||||
|
} else if (initial_y === FILE_END) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = tm[initial_y + 1][initial_x];
|
||||||
|
switch (next) {
|
||||||
|
case "|": {
|
||||||
|
total += count_quantum_paths_downwards(tm, initial_x, initial_y + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "^": {
|
||||||
|
total += count_quantum_paths_downwards(tm, initial_x - 1, initial_y + 1);
|
||||||
|
total += count_quantum_paths_downwards(tm, initial_x + 1, initial_y + 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user