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:
$ grep -c XMAS words
112
$ grep -c 'XMAS.*XMAS' words
56
$ grep -c 'XMAS.*XMAS.*XMAS' words
22
$ grep -c 'XMAS.*XMAS.*XMAS.*XMAS' words
7
$ grep -c 'XMAS.*XMAS.*XMAS.*XMAS.*XMAS' words
1
$ grep -c 'XMAS.*XMAS.*XMAS.*XMAS.*XMAS.*XMAS' words
0
$ echo '1*5+(7-1)*4+(22-7)*3+(56-22)*2+(112-56)' | bc
198
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:
$ grep -o XMAS words | wc -l
198