Add solution day 12

This commit is contained in:
monoid 2024-12-12 18:19:49 +09:00
parent e70b4189cf
commit b4f98c1ea3
8 changed files with 381 additions and 0 deletions

4
day_12/example_1.txt Normal file
View File

@ -0,0 +1,4 @@
AAAA
BBCD
BBCC
EEEC

5
day_12/example_2.txt Normal file
View File

@ -0,0 +1,5 @@
OOOOO
OXOXO
OOOOO
OXOXO
OOOOO

10
day_12/example_3.txt Normal file
View File

@ -0,0 +1,10 @@
RRRRIICCFF
RRRRIICCCF
VVRRRCCFFF
VVRCCCJFFF
VVVVCJJCFE
VVIVCCJJEE
VVIIICJJEE
MIIIIIJJEE
MIIISIJEEE
MMMISSJEEE

5
day_12/example_4.txt Normal file
View File

@ -0,0 +1,5 @@
EEEEE
EXXXX
EEEEE
EXXXX
EEEEE

6
day_12/example_5.txt Normal file
View File

@ -0,0 +1,6 @@
AAAAAA
AAABBA
AAABBA
ABBAAA
ABBAAA
AAAAAA

140
day_12/input.txt Normal file
View File

@ -0,0 +1,140 @@
KKUUIIIIIIIIIIIIMMMMMMMMMVVVVVVVVVVVVVVVVNNNNNTTTTTTTTTTMMBMYYKKKKRPPPPXXXXXXXXXXXXXXFFFFFFFFFFFNNNNNNNNNNNNNNNNNNNTTTTTTTTJJJFFFFFFIFMJEEEE
KKUUIIIIIIIIIIIIIMMMMMMMMMVVVVVVVVVVVVVVFAEEENNTTTTTTTTNMMMMYYKKKKKPPPPPPXXXXBBBXXXXXPFFFFFFFFFFNNNNNNNNTTTNNTTNNNTTTTTTTTTJJJFJFFFFFFJJJJEE
KKUUIIIIIIIIIIIIIIMMMMMMMMMVVVVVVVVVVTZVFEEENNTTTTTTTTTMMMMLKKKKKKKPPPPPXXXXBBBBXXXXXXFFFAFFFFFFFFNWWNTTTTTTTTTTTTTTTTTTTTJJJJJJFFFFFFFJJJJE
KKUUUUIIIIIIIIIIIIHEMMMMMMVVVVVVVVEEEEEEFFEEENTTUTTTTTMMMMMMKKKKKKKPPPPPPPPPBZBBXXBXXXXFFFF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PPPPPPPPPPPPCCCCCUUUMMMMMMMPPPPPPPPPPPPPPPPPPPDDDDDDGGGQDQQQQQQQQGGGGLGLGGZZZZZNNNNNNNPPPPPPPAAAUUUUUUUSSSSS
RRRRRRRROOOOOOOOOOXXXWXXXXXXXXUPPPPPPPPPPPPPPCCCUUUMMMMMMMMPPPPPPPPPPPPPPPPPPPDDDDDGGGGQQQQQGQQGQQGGGGGGGGZZZZZNNNNNNNPPPPPPPAAAUUUUUUUSSSSS
RRRRROOOOOOOOOOOOOOXOOOXXXXXXXUUPPPPPPPPPPPPCCCCCUCCMMMMMMMMPPPPPPPPPPPPPPGGPDDDDDDDGGGQGGQGGGGGQQQGGGGGGGGZZZZNNNNNNNNNNPNPAAAUUUUUUUUSSSSS
UROOOOOOOOOOOOOOOOOOOOOXUUXXXUUUPPPPPPPPPPPPPPPCCCCCMMMMMMMPPPPPPPPPPPPPPPGGDDDDDDDDDGGGGGQGGGGGQGGGGGGGGGGZZZNNNNNNNNNNNNNPAAAUUUUUSSSSSSSS
RROOOOOOOOOOOOOOOOOOOOOXUUXXUUUPPPPPPPPPPPPPPPCCCCCCCCCCMPPPPPPPPPPPPOPPPPPGGDDDDDZDDDDGGGGGGGGGGGGGGGGGGZZZZZNNNNNNNNNNNNNPAAAUUUUUSSSSSSSS

140
day_12/solve_1.ts Normal file
View File

@ -0,0 +1,140 @@
import { rgb8 } from "jsr:@std/fmt/colors"
export async function readGardenTypeMapData(path: string): Promise<string[][]> {
const txt = await Deno.readTextFile(path);
const lines = txt.split('\n');
return lines.map(line => line.trim().split(''));
}
export type GardenCell = {
type: string;
id: number;
}
export function toGardenMap(map: string[][]) {
const gardenMap: GardenCell[][] = [];
for (let i = 0; i < map.length; i++) {
gardenMap.push([]);
const row = map[i];
for (let j = 0; j < row.length; j++) {
gardenMap[i].push({ type: row[j], id: 0 });
}
}
let idGenerator = 1;
const typeMap = new Map<string, number>();
const idMap = new Map<number, string>();
function colorArea(x: number, y: number, type: string){
const stack = [{x, y}];
while (stack.length > 0) {
const {x, y} = stack.pop()!;
if (x < 0 || x >= gardenMap.length || y < 0 || y >= gardenMap[x].length) {
continue;
}
const cell = gardenMap[x][y];
if (cell.type !== type || cell.id !== 0) {
continue;
}
cell.id = idGenerator;
stack.push({x: x - 1, y});
stack.push({x: x + 1, y});
stack.push({x, y: y - 1});
stack.push({x, y: y + 1});
}
}
for (let i = 0; i < gardenMap.length; i++) {
const row = gardenMap[i];
for (let j = 0; j < row.length; j++) {
const cell = row[j];
if (cell.id === 0) {
colorArea(i, j, cell.type);
typeMap.set(cell.type, idGenerator);
idMap.set(idGenerator, cell.type);
idGenerator++;
}
}
}
return {
gardenMap,
typeMap,
idMap,
}
}
export function printGardenMap(map: GardenCell[][]) {
for (let i = 0; i < map.length; i++) {
const row = map[i];
console.log( row.map(cell => rgb8(cell.type, cell.id % 256)).join(''));
}
}
export function countGardenAreas(map: GardenCell[][]) {
const areas = new Map<number, number>();
for (let i = 0; i < map.length; i++) {
const row = map[i];
for (let j = 0; j < row.length; j++) {
const cell = row[j];
const currentArea = areas.get(cell.id) ?? 0;
areas.set(cell.id, currentArea + 1);
}
}
return areas;
}
export function getAreaById(map: GardenCell[][]) {
const areaById = new Map<number, number>();
for (let i = 0; i < map.length; i++) {
const row = map[i];
for (let j = 0; j < row.length; j++) {
const cell = row[j];
const currentArea = areaById.get(cell.id) ?? 0;
areaById.set(cell.id, currentArea + 1);
}
}
return areaById;
}
export function getPerimeterById(map: GardenCell[][]) {
const perimeterByType = new Map<number, number>();
for (let i = 0; i < map.length; i++) {
const row = map[i];
for (let j = 0; j < row.length; j++) {
const cell = row[j];
let currentPerimeter = perimeterByType.get(cell.id) ?? 0;
if (i === 0 || map[i - 1][j].type !== cell.type) {
currentPerimeter += 2;
}
if (j === 0 || map[i][j - 1].type !== cell.type) {
currentPerimeter += 2;
}
perimeterByType.set(cell.id, currentPerimeter);
}
}
return perimeterByType;
}
if (import.meta.main) {
const path = 'input.txt';
// const path = "example_1.txt";
// const path = "example_2.txt";
// const path = "example_3.txt";
const data = await readGardenTypeMapData(path);
const {gardenMap, idMap } = toGardenMap(data);
printGardenMap(gardenMap);
const areaById = getAreaById(gardenMap);
const perimeterById = getPerimeterById(gardenMap);
// console.log(areaById);
// console.log(perimeterByType);
const mixed = Array.from(areaById.keys()).map(id => ({
id,
type: idMap.get(id)!,
area: areaById.get(id)!,
perimeter: perimeterById.get(id)!,
}));
console.log(mixed);
const result = mixed.map(({ area, perimeter }) => area * perimeter).reduce((acc, val) => acc + val, 0);
console.log(result);
}

71
day_12/solve_2.ts Normal file
View File

@ -0,0 +1,71 @@
import { readGardenTypeMapData, toGardenMap, printGardenMap, getAreaById, getPerimeterById, GardenCell } from "./solve_1.ts";
const pattern = {
"0000": 4,
"1000": 4,
"0100": 0,
"1100": 2,
"0010": 4,
"1010": 4,
"0110": 2,
"1110": 4,
"0001": 0,
"1001": 2,
"0101": -2,
"1101": -2,
"0011": 0,
"1011": 2,
"0111": 0,
"1111": 0,
} as Record<string, number>;
function getSideById(gardenMap: GardenCell[][]) {
const sideById = new Map<number, number>();
function addSide(id: number, side: number) {
const currentSide = sideById.get(id) ?? 0;
sideById.set(id, currentSide + side);
}
for (let i = 0; i < gardenMap.length; i++) {
for (let j = 0; j < gardenMap[i].length; j++) {
const cell = gardenMap[i][j];
const id = cell.id;
const sides = [
gardenMap[i - 1]?.[j - 1]?.id ?? -1,
gardenMap[i - 1]?.[j]?.id ?? -1,
gardenMap[i - 1]?.[j + 1]?.id ?? -1,
gardenMap[i]?.[j - 1]?.id ?? -1,
];
const sideKey = sides.map(s => s === id ? 1 : 0).join('');
const addedSide = pattern[sideKey];
addSide(id, addedSide!);
}
}
return sideById;
}
if (import.meta.main) {
const path = 'input.txt';
// const path = "example_1.txt";
// const path = "example_3.txt";
// const path = "example_4.txt";
// const path = "example_5.txt";
const data = await readGardenTypeMapData(path);
const {gardenMap, idMap } = toGardenMap(data);
printGardenMap(gardenMap);
const areaById = getAreaById(gardenMap);
const sideById = getSideById(gardenMap);
// console.log(areaById);
// console.log(perimeterByType);
const mixed = Array.from(areaById.keys()).map(id => ({
id,
type: idMap.get(id)!,
area: areaById.get(id)!,
side: sideById.get(id)!,
}));
console.log(mixed);
const result = mixed.map(({ area, side }) => area * side).reduce((acc, val) => acc + val, 0);
console.log(result);
}