What your describing is the best part for me.
Obviously spending days languishing in confused and lonely impotence is horrible, but no job (in my experience so far) has the same high of going from producing nothing (ie. program doesnt work at all) to producing a perfect working product in one second, one line, one moment of insight.
As I get more experienced I get stuck or encounter problems less and less, I think I just keep doing more challenging or unfamiliar work in order to keep chasing that high.