Hi @cookdj0128,
This is a very hard question to answer!
The first thing that comes to mind is this: You should see programming as a form of communication. It happens between you, a slow and smart human and a computer, which is a fast and dumb machine.
To me, the easiest way to understand a problem you are trying to solve is generally to try and break it down to its simplest expression. Knowing exactly what kind of result you are trying to achieve, you can then start designing the simplestest step-by-step solution to your problem you can think of.
To help with that, some programmers speak the code out loud to themselves or try to explain it to a friend and some actually use a method involving a rubber duck!
Why would anyone do that, you ask? Well it’s simple. That’s what’s programming is all about: Explaining to a dumb computer every single steps it needs to take to perform a very smart and sometimes complex program you have imagined to solve a given problem.
But to be able to explain it to a computer, it helps to understand it yourself first.
Sometime this will be, as you have stated, almost instantaneous. Other times your brain will just have a hard time trying to wrap itself around the problem and this is just perfectly normal state of affair. When this happens, I usually just step back from the problem and start tackling another one or start doing something altogether different. Stepping away and coming back have proven to be a huge time saver for me because most of the time, I will end up finding the answer much more quickly than if I had spent the entire afternoon trying!.
Also, some people will stop when they get a program that just works. Others will not be content and will try and optimize the step-by-step solution into a more efficient one. Sometimes it will involve using less code or maybe using more complex mathematical concepts but most of the time this (and debugging) will be the most time-consuming part of a programmer’s job.
At the introductory level, I would say not to worry too much about optimization just yet. I would say that more important to thinking like a programmer is just experimenting a lot. Trying a lot of different solutions to a single problem. Changing the input of a given program and see what kind of effect it has on the output.
Trying to break a perfectly fine and working program, trying to make it fail and guess or predict what will happen can help you better understand how the computer interprets what you are trying to say to him with your code.
Have fun!