Skip to content

Commit

Permalink
🕡✂️ Updated with Glitch: day 14, part 2 bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch (branch-three-oviraptor) committed Dec 16, 2023
1 parent 3cca157 commit ac837a7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing to aoc2023

Contributions welcome! Feel free to ask @dieseltravis any questions. ☺
Forks welcome! Feel free to ask @dieseltravis any questions. ☺
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "branch-three-oviraptor",
"version": "2023.12.15",
"version": "2023.12.16",
"description": "Travis's Advent of Code 2023",
"author": "Travis Hardiman",
"homepage": "https://branch-three-oviraptor.glitch.me/",
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"connect-timeout": "^1.9.0",
"eslint": "^8.55.0",
"eslint": "^8.56.0",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"semistandard": "^17.0.0",
Expand Down
46 changes: 30 additions & 16 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,22 +1324,32 @@
});
});
const render = () => input.map(r => r.map(c => c.isRound ? 'O' : c.isCube ? '#' : '.').join('')).join('\n');
const getLoad = () => input.reduce((acc, row) => {
return acc + row.reduce((acc2, c) => {
if (c.isRound) {
acc2 += c.load;
}
return acc2;
}, 0);
}, 0);
console.log(input.slice());
// progress
const pc = cycles / 100;
let p = 0;
let lastGrid = render();
let lastLoad = getLoad();
console.log('first grid:\n' + lastGrid);
console.log('first load:\n' + lastLoad);
for (let i = 0; i < cycles; i++) {
// N
for (let x = 0; x < xmax; x++) {
for (let y = 0; y < ymax; y++) {
if (input[y][x].isRound) {
if (input[y] && input[y][x] && input[y][x].isRound) {
let newY = y;
let lastY = y;
while (newY > 0) {
newY = newY - 1;
if (input[newY][x].isEmpty) {
if (input[newY] && input[newY][x] && input[newY][x].isEmpty) {
lastY = newY;
} else {
break;
Expand All @@ -1358,12 +1368,12 @@
// W
for (let y = 0; y < ymax; y++) {
for (let x = 0; x < xmax; x++) {
if (input[y][x].isRound) {
if (input[y] && input[y][x] && input[y][x].isRound) {
let newX = x;
let lastX = x;
while (newX > 0) {
newX = newX - 1;
if (input[y][newX].isEmpty) {
if (input[y] && input[y][newX] && input[y][newX].isEmpty) {
lastX = newX;
} else {
break;
Expand All @@ -1382,12 +1392,12 @@
// S
for (let x = 0; x < xmax; x++) {
for (let y = ymax; y--;) {
if (input[y][x].isRound) {
if (input[y] && input[y][x] && input[y][x].isRound) {
let newY = y;
let lastY = y;
while (newY < ymax - 1) {
newY = newY + 1;
if (input[newY][x].isEmpty) {
if (input[newY] && input[newY][x] && input[newY][x].isEmpty) {
lastY = newY;
} else {
break;
Expand All @@ -1406,12 +1416,12 @@
// E
for (let y = 0; y < ymax; y++) {
for (let x = xmax; x--;) {
if (input[y][x].isRound) {
if (input[y] && input[y][x] && input[y][x].isRound) {
let newX = x;
let lastX = x;
while (newX < xmax - 1) {
newX = newX + 1;
if (input[y][newX].isEmpty) {
if (input[y] && input[y][newX] && input[y][newX].isEmpty) {
lastX = newX;
} else {
break;
Expand All @@ -1429,26 +1439,28 @@
// console.log('E\n' + render());

// test (this doesn't seem to work):
/*
const newGrid = render();
if (lastGrid === newGrid) {
console.log('grid repeating', i, '\n' + newGrid);
break;
}
lastGrid = newGrid;
*/
const newLoad = getLoad();
if (lastLoad === newLoad) {
console.log('grid repeating', i, '\n' + newLoad);
//break;
}
lastLoad = newLoad;
if (i % pc === 0) {
console.log(p + '% ' + (new Date()).toISOString());
console.log(lastLoad, '\n', render());
p++;
}
// console.log('last grid:\n' + lastGrid);
}
const load = input.reduce((acc, row) => {
return acc + row.reduce((acc2, c) => {
if (c.isRound) {
acc2 += c.load;
}
return acc2;
}, 0);
}, 0);
const load = getLoad();
console.log(load);
return load;
}
Expand Down Expand Up @@ -1675,6 +1687,8 @@
console.log((i + 1) + ' of ' + startLen + ' ' + (new Date()).toISOString(), max);
});
console.log(max);
// 7965 too low
// 8079 too low
return max;
}
},
Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const f = require('./public/funs');
const limiter = rateLimit({
// 30 seconds
windowMs: 30 * 1000,
// 100 requests in that time
max: 100,
// Return rate limit info in the `RateLimit-*` headers
standardHeaders: true,
Expand Down

0 comments on commit ac837a7

Please sign in to comment.