chore: current WIP day 7b and 8

This commit is contained in:
2025-12-09 15:54:15 +01:00
parent 2e86795761
commit 28e400f221
6 changed files with 1278 additions and 18 deletions

View File

@@ -44,33 +44,70 @@ export function count_bean_splits(tm: TachyonManifold): number {
export function count_quantum_splits(tm: TachyonManifold): number {
const full_tree = generate_full_quantum_tree(tm);
console.log(">> Tree\n", full_tree.map((row) => row.join("")).join("\n"));
const init_x = tm[0].findIndex((value) => value === "S");
console.log(
">> Full tree\n",
full_tree.map((row) => row.join("")).join("\n"),
);
let total = 0;
return count_quantum_paths(full_tree, init_x, 1);
console.log("==", tm[tm.length - 2]);
for (let i = 0; i < tm[0].length; i++) {
if (tm[tm.length - 2][i] === "|") {
total += count_quantum_paths_upwards(tm, i, tm.length - 2) + 1;
}
}
return total;
}
export function count_quantum_paths(
export function count_quantum_paths_upwards(
tm: TachyonManifold,
initial_x: number,
initial_y: number,
): number {
let total_paths = 0;
if (initial_y === tm.length - 2) {
console.log(">> exit on ", { initial_y, initial_x });
return tm[initial_y][initial_x] === "|" ? 1 : 0;
}
while (tm[initial_y][initial_x]) {
const point = tm[initial_y][initial_x];
if (point === "^") {
console.log(">> split on ", { initial_y, initial_x });
total_paths += count_quantum_paths(tm, initial_x + 1, initial_y + 1);
total_paths += count_quantum_paths(tm, initial_x - 1, initial_y + 1);
}
initial_y += 1;
if (initial_y === 0) {
return 0;
}
return total_paths;
let total = 0;
let current_bean = tm[initial_y][initial_x];
while (current_bean !== "." && initial_y > 2) {
switch (current_bean) {
case "|": {
const left_point = tm[initial_y][initial_x - 1];
const right_point = tm[initial_y][initial_y + 1];
// WRONG: the splitter existing does not mean that it has a bean
if (left_point === "^" && right_point === "^") {
total += 1;
}
if (left_point === "^") {
total += count_quantum_paths_upwards(
tm,
initial_x - 1,
initial_y - 1,
);
}
if (right_point === "^") {
total += count_quantum_paths_upwards(
tm,
initial_x + 1,
initial_y - 1,
);
}
if (left_point === "^" || right_point === "^") {
const contiues_upwards = tm[initial_y - 1][initial_x] === "|";
if (contiues_upwards) {
total += 1;
}
}
}
}
initial_y--;
current_bean = tm[initial_y][initial_x];
}
return total;
}
export function generate_full_quantum_tree(