Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 13, 2023
1 parent af7d3b0 commit e3221f4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/2023/day13.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ function equals(a, b, state) {

function isMirror(rows, i, smudges) {
const state = { smudges };
if (i + 1 >= rows.length) return false;
for (let j = 0; i - j >= 0 && i + j + 1 < rows.length; j++) {
if (!equals(rows[i - j], rows[i + j + 1], state)) return false;
}
return state.smudges === 0;
}

function getRowMirror(rows, smudges = 0) {
for (let i = 0; i < rows.length - 1; i++) {
if (isMirror(rows, i, smudges)) return i + 1;
}
function getRowMirror(rows, smudges) {
return rows.findIndex((row, i) => isMirror(rows, i, smudges)) + 1;
}

function rotate(patch) {
Expand Down

0 comments on commit e3221f4

Please sign in to comment.