diff --git a/2024/25/index.ts b/2024/25/index.ts new file mode 100644 index 0000000..8417184 --- /dev/null +++ b/2024/25/index.ts @@ -0,0 +1,44 @@ +const fs = require('fs'); + +const input = fs.readFileSync(__dirname + '/input.txt', 'utf8'); + +const keyLocks = input.split("\n\n"); + +const keys: number[][] = []; +const locks: number[][] = []; + +keyLocks.forEach((s: string) => { + const rows = s.split("\n"); + const isKey = rows[0] === '.....'; + const columns: number[] = [-1, -1, -1, -1, -1]; + rows.forEach((row: string) => { + for (let i = 0; i < row.length; i++) { + if (row[i] === '#') { + columns[i]++; + } + } + }); + if (isKey) { + keys.push(columns); + } else { + locks.push(columns); + } +}); + +let matches = 0; + +for (let lock of locks) { + keyLoop: + for (let key of keys) { + for (let i in lock) { + if (lock[i] + key[i] >= 6) { + continue keyLoop; + } + } + matches++; + } +} + +console.log(locks); +console.log(keys); +console.log(matches);