Skip to content

Commit

Permalink
day 6, part 2: progress but still too low
Browse files Browse the repository at this point in the history
  • Loading branch information
dieseltravis committed Dec 7, 2024
1 parent 65b7b6b commit 60de13f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,18 +447,23 @@
}
}
// look right for repeating
const lookrrotate = (guardrotation + 1) % 4;
const lookrchar = dirs[lookrrotate];
// const oppositechar = dirs[(guardrotation + 3) % 4];
const lookrchange = guard[lookrchar];
let lookrrotate = (guardrotation + 1) % 4;
let lookrchar = dirs[lookrrotate];
let lookrchange = guard[lookrchar];
let lookrpos = { y: guardpos.y + lookrchange.dy, x: guardpos.x + lookrchange.dx };
let safety3 = 1000;
while (safety3-- && inRange(lookrpos) && input[lookrpos.y][lookrpos.x] !== '#') {
// TODO: continue bouncing off of obsticles and looking for loop
while (safety3-- && inRange(lookrpos)) {
if (input[lookrpos.y][lookrpos.x] === lookrchar) {
count++;
break;
}
// TODO: continue bouncing off of obsticles and looking for loop
let safety4 = 5;
while (input[lookrpos.y][lookrpos.x] === '#' && safety4--) {
lookrrotate = (lookrrotate + 1) % 4;
lookrchar = dirs[lookrrotate];
lookrchange = guard[lookrchar];
}
lookrpos = { y: lookrpos.y + lookrchange.dy, x: lookrpos.x + lookrchange.dx };
}
guardpos = nextpos;
Expand All @@ -467,6 +472,7 @@
const grid = input.map(r => r.join('')).join('\n');
console.log(safety, steps, '\n' + grid, count);
// 508 too low
// 1631 too low
return count;
}
},
Expand Down

0 comments on commit 60de13f

Please sign in to comment.