When you are stuck with a problem it usually helps to talk through what is happening. Often, simply talking through the problem will make a solution come to light. It’s technique that has been around for a long time, but often the credit goes to The Pragmatic Programmer book that I mentioned a week or so ago. The technique in the book is called rubber duck debugging.
If the problem is with a program that you are writing, simply talk through the code line by line outloud to an inanimate object. A person would also work, but that’s not often possible or the easiest solution. As you talk through each line and explain them you will often realize that the code might not be doing what you were planning for it to do – thus finding the problem and guiding yourself to a solution.
I’m going to post a link to an article that goes into a bit more detail about the psychology at play: https://www.thoughtfulcode.com/rubber-duck-debugging-psychology/