1) The task is mundane or repetitive.
2) I think the task is trivial. "Oh, thats something I can bang out in a few hours, and I've got all week to work on it"
3) There is a tricky problem within the task that I haven't figured out yet."
You've nailed it, especially number 3. I'll take out my pencil & paper, start sketching out things. The moment something stumps me, I put it down and get up 'for a drink of water.' While I'm up, might as well see what's on USA. Maybe White Collar or Burn Notice...and three hours pass.
If I may ask, how old are you? And why are you 'angry'
That is the problem with most solutions you find printed in books or on the web. They only show the problem and the fully refactored solution. Refactored solutions, even when fully explained, are just another form of obfuscation. Behind every tough problem, there are notebooks and whiteboards and hundreds/thousands of lines of discarded code that you never see. That is where the magic happens. You just have to do the work, you have to make your own ah-ha! moment.
This process is a lot easier if you use a language that has a REPL - like python, ruby, or the various lisp dialects. It is easier to work through problems this way, regardless of what your final target language may be.
Oh god, yes. I realized recently that in practice, it's not done that way. Hard habit to break, though. I used to think that being smart meant that solutions were obvious.
1) The task is mundane or repetitive.
2) I think the task is trivial. "Oh, thats something I can bang out in a few hours, and I've got all week to work on it"
3) There is a tricky problem within the task that I haven't figured out yet.
The key to it all was realizing I'm not as smart as I think I am. I needed to make a plan. This is hard, I've never kept an appointment book, I don't make to do lists, those are for dumb people. Not me, I can reason out any problem and keep track of it in my head! Bullshit.
Sit down with a pencil and a stack of paper. Draw your problem out. Make a list of all the gotchas. Make a list of all the 'easy' things. Quickly you start to realize that even with trivial problems, there is a lot of stuff to do. Yeah, you are smart, so most of those things will only take 2 minutes, but when you see them all laid out on paper, they add up. Oh shit, no time for you tube. I've actually thought about the problem, I've got skin in the game now, I've got some motivation.
When you started this trivial task of making a plan, you thought it would take 5 minutes because you are so damn smart. Two hours later you are still pushing papers around your kitchen table. Revising, looking for the common connections, refactoring, making a better list, making better software.