Here's one of the fundamental rules of programming.
You're at the end of your day, you've gotten a lot of stuff done, and you have one more thing to get right before the feature is complete, and you're searching for the answer, trying all kinds of ideas, thoroughly confused, not wanting to get up until it's done, just slogging away and not getting it. Finally, you give up after a couple of hours of spinning your wheels, eat some dinner, watch a little basketball, have a glass of wine, read a little and crash for the night.
Get up the next morning, make some coffee, read the news, roll up your sleeves and start over with the problem.
Five minutes later it's done.
Happens every damned time.
The problem isn't intractable. It's just as difficult as all the other problems you solved the previous day. It just came after your mind shut down. So you might as well quit work a couple of hours earlier.
Programming isn't like digging trenches. The amount of work you get done is not directly proportional to the amount of time you work. Also believe it or not your mind is solving problems while you sleep. That's why the answer is apparent first thing in the morning. Even after 30 years of programming, I'm still learning this lesson.