Printing Department
Advent of Code 2025 Day 4 The ease of Part 1 concerns me I've solved this puzzle at least a dozen times throughout Advent of Code. There is almost certainly going to be a unique twist in Part 2. Fo...

Source: DEV Community
Advent of Code 2025 Day 4 The ease of Part 1 concerns me I've solved this puzzle at least a dozen times throughout Advent of Code. There is almost certainly going to be a unique twist in Part 2. For now, it's time to solve this yet again. Writing another adjacent grid cell inspector First, I want to 'pad' the grid with a border of .s so I can safely check each original cell without having to account for out-of-bounds errors. I usually do this after converting the string into a 2-dimensional array. But this time, I will opt to create a new string by adding characters from a stringified array and replacing newline characters with dot-padded newline characters. Here's the single, long concatenation statement: let lineLength = input.indexOf('\n') input = new Array(lineLength + 2).fill('.').join('') + '\n.' + input.replaceAll('\n', '.\n.') + '.\n' + new Array(lineLength + 2).fill('.').join('') It turns this: ..@@.@@@@. @@@.@.@.@@ @@@@@.@.@@ @.@@@@..@. @@.@@@@.@@ .@@@@@@@.@ .@.@.@.@@@ @.@@@.