import { readLines } from "../utils.ts"; export async function solveTask4part1() { const lines = await readLines('./4/example.txt'); console.log(lines) // left to right const l2r = lines .map(findXmas) .reduce((p,c) => p+c, 0) // right to left const r2l = lines .map( l => [...l].reverse().join("")) .map(findXmas) .reduce((p,c) => p+c, 0) // top to bottom const t2b = [...lines[0]] .map( (_, i) => lines.map( l => l[i]).join('') ) .map(findXmas) .reduce((p,c) => p+c, 0) // bottom to top const b2t = [...lines[0]] .map( (_, i) => lines.map( l => l[i]).join('') ) .map( l => [...l].reverse().join("")) .map(findXmas) .reduce((p,c) => p+c, 0) // console.log(t2b) console.log(l2r, r2l, t2b, b2t) // const all = l2r + r2l + t2b; // console.log(all); } function findXmas(line:string) { let count = 0; let searchPos = 0; let foundPos = -1; while ((foundPos = line.indexOf('XMAS', searchPos)) > -1) { searchPos = foundPos + 1; count++ } return count; }