How much of the solution can you work out in your head, before you ever sit down at your desk?
I find that if I define the problem, and then give myself the time to work on it as I’m doing other things, then when I get to the keyboard, the solution is ready to go. A recent re-write on an arrangement only took fifteen minutes to complete in the end – fifteen minutes plus the ten days since I defined the problem and worked on other things.
Give yourself the time and space, and be ready when the solution comes.