Saved this. My doggo is nearly 15 and whole he's still healthy I am much too afraid of losing him. I suspect I'll need a reminder like this in the future.
Zikeji
Javascript
After smashing out a functional version in 20 minutes, I converted it into a OOP approach for a more appealing solution.
Solution
const input = require('fs').readFileSync('input-day4.txt', 'utf-8');
class PrintingDepartmentMap {
/** @param {string} input */
constructor(input) {
/** @type {number[][]} */
this.map = input.split("\n").map(r => r.split('').map(v => v === '@' ? 1 : 0));
}
/**
* @param {number} x
* @param {number} y
* @returns {number} the value of that tile, or -1 if invalid
*/
getCoord(x, y) {
if (x < 0 || y < 0 || x >= this.map[0].length || y >= this.map.length) {
return -1;
}
return this.map[y][x];
}
/**
* @param {number} x
* @param {number} y
* @returns {number} the number of adjacent tiles that are >= 1
*/
countAdjacent(x, y) {
return [
// top-left
this.getCoord(x - 1, y - 1) >= 1,
// top
this.getCoord(x, y - 1) >= 1,
// top-right
this.getCoord(x + 1, y - 1) >= 1,
// right
this.getCoord(x + 1, y) >= 1,
// bottom-right
this.getCoord(x + 1, y + 1) >= 1,
// bottom
this.getCoord(x, y + 1) >= 1,
// bottom-left
this.getCoord(x - 1, y + 1) >= 1,
// left
this.getCoord(x - 1, y) >= 1
].reduce((acc, v) => !!v ? acc + 1 : acc, 0);
}
/**
* transform in place the map replacing any rolls (1) with (2) if they are accessible
* @returns {PrintingDepartmentMap}
*/
markAccessable() {
for (let y = 0; y < this.map.length; y += 1) {
for (let x = 0; x < this.map[0].length; x += 1) {
if (this.map[y][x] < 1) continue;
if (this.countAdjacent(x, y) < 4) {
this.map[y][x] = 2;
}
}
}
return this;
}
/** @returns {number} the number of removed rolls */
removeAccessable() {
let removed = 0;
for (let y = 0; y < this.map.length; y += 1) {
for (let x = 0; x < this.map[0].length; x += 1) {
if (this.map[y][x] === 2) {
removed += 1;
this.map[y][x] = 0;
}
}
}
return removed;
}
}
const map = new PrintingDepartmentMap(input);
let removed = 0;
while (true) {
const justRemoved = map.markAccessable().removeAccessable();
if (removed === 0) {
console.log(`Part 1 Answer: ${justRemoved}`);
}
if (justRemoved === 0) break;
removed += justRemoved;
}
console.log(`Part 2 Answer: ${removed}`);
Sure, which makes the transition suck even lol.
:(
Time to switch to yarn or something.
Javascript
More bruteforcing! There are probably better ways to do this but I'm happy enough with this lol.
Solution
You can replace the require('fs') on the first line with the input and run it in your browser console as well.
const input = require('fs').readFileSync('input-day2.txt', 'utf-8');
let idsPart1 = [];
let idsPart2 = [];
input.split(',').forEach(range => {
const [start, end] = range.split('-').map(v => parseInt(v, 10));
let cursor = start;
while (cursor <= end) {
const cursorString = cursor.toString(10);
// part 1 check
let halfLength = Math.floor(cursorString.length / 2);
let left = cursorString.slice(0, halfLength);
let right = cursorString.slice(halfLength, cursorString.length);
if (left === right) {
idsPart1.push(cursor);
}
// part 2 check
let sequenceLength = 1;
while (sequenceLength <= halfLength) {
const sequence = cursorString.slice(0, sequenceLength);
let builtString = sequence;
while (builtString.length < cursorString.length) {
builtString = `${builtString}${sequence}`;
}
if (builtString === cursorString) {
idsPart2.push(cursor);
break;
}
sequenceLength += 1;
}
cursor += 1;
}
})
const answer1 = idsPart1.flat().reduce((acc, cur) => acc += cur, 0);
const answer2 = idsPart2.flat().reduce((acc, cur) => acc += cur, 0);
console.log(`Part 1 Answer: ${answer1}`);
console.log(`Part 2 Answer: ${answer2}`);
A straightforward day 1 for a Javascript / NodeJS solution.
Poorly Optimized JS Solution
let position = 50;
let answer1 = 0;
let answer2 = 0;
const sequence = require('fs').readFileSync('input-day1.txt', 'utf-8');
sequence.split('\n').forEach(instruction => {
const turn = instruction.charAt(0);
let distance = parseInt(instruction.slice(1), 10);
while (distance > 0) {
distance -= 1;
if (turn === 'L') {
position -= 1;
} else if (turn === 'R') {
position += 1;
}
if (position >= 100) {
position -= 100;
} else if (position < 0) {
position += 100;
}
if (position === 0) {
answer2 += 1;
}
}
if (position === 0) {
answer1 += 1;
}
});
console.log(`Part 1 Answer: ${answer1}`);
console.log(`Part 2 Answer: ${answer2}`);
Streaming like movies and TV, or like Twitch?
And free as in the legal free ones, or illegal free ones?
It's worth noting that Ozempic face is a side effect of rapid weight loss, not a side effect of Ozempic.
If I didn't know Trump was a flip flopping erratic personality him saying they have a lot on common would be very concerning lol.
Does not appear to be the correct MR. Comments on the issue allude to "they never pushed it" so sounds like there never was an MR. Watching the announcement where they demo'd it, it wrote much more than is in that MR. Not to defend OpenAI, I hate vibe coded solutions that add so many useless comments.
Write. Readable. Code.
THERE'S NO LAWS AGAINST THE POKEMON BATMAN
Javascript
Short and sweet. Basically just handle all the range overlaps for part 2 and then do basic subtraction to get the answer.
spoiler