diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f948547..4665fe5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. ☺ diff --git a/package-lock.json b/package-lock.json index 00d9f4a..016db0a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "branch-three-oviraptor", - "version": "2023.12.15", + "version": "2023.12.16", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -39,9 +39,9 @@ } }, "@eslint/js": { - "version": "8.55.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.55.0.tgz", - "integrity": "sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==" + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", + "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==" }, "@humanwhocodes/config-array": { "version": "0.11.13", @@ -652,14 +652,14 @@ "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==" }, "eslint": { - "version": "8.55.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.55.0.tgz", - "integrity": "sha512-iyUUAM0PCKj5QpwGfmCAG9XXbZCWsqP/eWAWrG/W0umvjuLRBECwSFdt+rCntju0xEH7teIABPwXpahftIaTdA==", + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.56.0.tgz", + "integrity": "sha512-Go19xM6T9puCOWntie1/P997aXxFsOi37JIHRWI514Hc6ZnaHGKY9xFhrU65RT6CcBEzZoGG1e6Nq+DT04ZtZQ==", "requires": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.55.0", + "@eslint/js": "8.56.0", "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -1231,9 +1231,9 @@ } }, "globals": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", - "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "requires": { "type-fest": "^0.20.2" } diff --git a/package.json b/package.json index ba4dfec..2c5b3af 100644 --- a/package.json +++ b/package.json @@ -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/", @@ -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", diff --git a/public/funs.js b/public/funs.js index e31be01..781bc12 100644 --- a/public/funs.js +++ b/public/funs.js @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; } @@ -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; } }, diff --git a/server.js b/server.js index e1ffeb3..caa86c8 100644 --- a/server.js +++ b/server.js @@ -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,