aoc-2023/day_13/solve_2.ts

25 lines
809 B
TypeScript
Raw Normal View History

2024-12-09 22:41:02 +09:00
import { readData, getBitsNumbers, getReflectionIndex, transpose, correctReflection } from "./solver.ts";
const input = await Deno.readTextFile("input.txt");
const maps = readData(input);
let verticalSum=0, horizontalSum = 0;
maps.forEach((map, index) => {
console.log("map", index);
const horizontal = map.map(x=> getBitsNumbers(x));
const vertical = transpose(map).map(x=> getBitsNumbers(x));
const hi = getReflectionIndex(horizontal);
const vi = getReflectionIndex(vertical);
const correctedHi = correctReflection(horizontal);
const correctedVi = correctReflection(vertical);
if (correctedHi > 0){
horizontalSum += correctedHi;
}
if (correctedVi > 0){
verticalSum += correctedVi;
}
});
console.log(horizontalSum * 100 + verticalSum);