It never ceases to amaze me that you can be stuck on a problem for 2 days, say “screw it I’m going for a walk around town” and then solve it fifteen minutes into the walk.
@christianselig Mind wandering!
I recently came across two studies that back up exactly what you're saying. Not that I needed them because the same thing happens to me. Every hard programming problem I've ever solved was when I was away from the keyboard.
https://journals.sagepub.com/doi/full/10.1177/0956797618820626