chore: day 12 WIP

This commit is contained in:
2025-12-16 18:46:19 +01:00
parent 23ec60cde9
commit 534075f543
5 changed files with 158 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
| 9 | Movie Theater | ⭐ | 🌓 |
| 10 | Factory | ⭐ | ⏱️ |
| 11 | Reactor | ⭐ | |
| 12 | Christmas Tree Farm | | |
### Symbols

View File

@@ -0,0 +1,7 @@
import { read_situation_summary } from "../exercises/day_12.ts";
Deno.test("Day 12 - A", async () => {
const summary = await read_situation_summary(
"src/exercises/assets/day_12_test_input.txt",
);
});

View File

@@ -0,0 +1,33 @@
0:
###
##.
##.
1:
###
##.
.##
2:
.##
###
##.
3:
##.
###
##.
4:
###
#..
###
5:
###
.#.
###
4x4: 0 0 0 0 2 0
12x5: 1 0 1 0 2 2
12x5: 1 0 1 0 3 2

View File

@@ -36,6 +36,35 @@ export function count_all_out_paths(list: Device[], init: string): number {
return total;
}
// const REQUIREMENT_1 = "fft";
// const REQUIREMENT_2 = "dac";
// export function find_all_out_complex_paths(
// list: Device[],
// init: string,
// path: string[],
// ): string[][] {
// let total = 0;
// const current_device = list.find((d) => d.name === init);
//
// // Default exits
// // NOTE: how to avoid circular connections
// if (!current_device) {
// return [];
// }
// if (current_device.output_list.length < 1) {
// return 0;
// }
// if (current_device.output_list.includes(END)) {
// return 1;
// }
//
// current_device.output_list.forEach((output) => {
// total += count_all_out_paths(list, output);
// });
//
// return total;
// }
export async function read_device_list(path: string): Promise<Device[]> {
const txt_file = await Deno.readTextFile(path);
const raw_device_list = txt_file.split("\n");

88
src/exercises/day_12.ts Normal file
View File

@@ -0,0 +1,88 @@
enum Point {
FILLED = "#",
EMPTY = ".",
}
type Present = Point[][];
type Region = {
width: number;
height: number;
};
interface Tree {
region: Region;
presents: number[];
}
interface SituationSummary {
presents: Present[];
trees: Tree[];
}
export default async function ChristmasTreeFarm() {
}
function do_presents_fit(tree: Tree, presents: Present[]): boolean {
}
function do_present_pair_fit(tree: Tree, p_a: Present, p_b: Present): boolean {
}
function rotate_present_90_deg(present: Present): Present {
}
function flip_present_horizontal(present: Present): Present {
}
function flip_present_vertical(present: Present): Present {
}
export async function read_situation_summary(
path: string,
): Promise<SituationSummary> {
const txt_input = await Deno.readTextFile(path);
// NOTE: should be done with splits to avoid performance issues on final sample
const block_list = txt_input.split("\n\n");
const present_list: Present[] = [];
const tree_list: Tree[] = [];
block_list.forEach((block) => {
if (block.includes("x")) {
// Tree
const raw_trees = block.split("\n");
raw_trees.forEach((t) => {
if (!t || t.length < 1) {
return;
}
const [raw_region, raw_presents] = t.split(": ");
const region: Tree["region"] = {
width: parseInt(raw_region.split("x")[0]),
height: parseInt(raw_region.split("x")[1]),
};
const presents: Tree["presents"] = raw_presents.split(" ").map((p) => {
const p_n = parseInt(p);
if (p_n === p_n) {
return p_n;
}
return undefined;
}).filter((p) => p !== undefined);
tree_list.push({ region, presents });
});
} else {
// Present
const raw_present = block.split("\n").slice(1);
const present: Present = raw_present.map((line) =>
line.split("").map((p) =>
p === Point.FILLED ? Point.FILLED : Point.EMPTY
)
);
present_list.push(present);
}
});
return {
presents: present_list,
trees: tree_list,
};
}