5
[DAY 4 : PART 1] Question (mostly about grep and rg)
(programming.dev)
An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
Everybody Codes is another collection of programming puzzles with seasonal events.
Solution Threads
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 |
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
Which input are you using? https://adventofcode.com/2024/day/4/input? It looks like you're not accounting right for times when XMAS appears multiple times per line. grep counts the number of lines where something appears, not the total number of times it appears. Here's a quick way to do it, although my numbers don't match yours:
So 198 instances of XMAS, appearing horizontally from left to right.
Also, yes, I could have just added up all the numbers, I didn't realize that right away.
Edit: Better: