diff --git a/README.md b/README.md index 7eed949..5e8db07 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ | 9 | Movie Theater | ⭐ | 🌓 | | 10 | Factory | ⭐ | ⏱️ | | 11 | Reactor | ⭐ | | +| 12 | Christmas Tree Farm | | | ### Symbols diff --git a/src/__tests__/day_12_test.ts b/src/__tests__/day_12_test.ts new file mode 100644 index 0000000..85fc278 --- /dev/null +++ b/src/__tests__/day_12_test.ts @@ -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", + ); +}); diff --git a/src/exercises/assets/day_12_test_input.txt b/src/exercises/assets/day_12_test_input.txt new file mode 100644 index 0000000..e5e1b3d --- /dev/null +++ b/src/exercises/assets/day_12_test_input.txt @@ -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 diff --git a/src/exercises/day_11.ts b/src/exercises/day_11.ts index 094ce0f..977832d 100644 --- a/src/exercises/day_11.ts +++ b/src/exercises/day_11.ts @@ -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 { const txt_file = await Deno.readTextFile(path); const raw_device_list = txt_file.split("\n"); diff --git a/src/exercises/day_12.ts b/src/exercises/day_12.ts new file mode 100644 index 0000000..da0ac00 --- /dev/null +++ b/src/exercises/day_12.ts @@ -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 { + 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, + }; +}