Also, while we're sleeping, our brains will continue to work on things that we're stuck on. It's amazing how many times I wake up with a solution to something from the previous day.
Here's a tip: if you have a problem you're having trouble solving, work/think about it a bit before going to bed. It will be fresh in your mind, and as you sleep your brain will churn away at it.