A book like https://www.amazon.com/Make-Stick-Science-Successful-Learnin... is accessible and provides a good survey of what we know about how the brain learns and remembers things, and how it relates to existing practices.
It's pretty good.
The main idea is that learning is supposed to feel hard. That sense of frustration and confusion is what building new neural connections feels like.
If you only spent a few weeks working on that new project, then you probably didn't spend near the amount of time Bill Gates spent writing, thinking about, and reviewing his Altair BASIC code. Even though he whipped up his code in less than a month or two prior to the first MITS demo, he likely spent weeks or months after that demo modifying and polishing the BASIC interpreter for subsequent releases. You didn't mention your experience level, but Gates' years of prior programming experience likely benefited him as well, providing him with a nice cognitive framework to which lots of these facts could "stick."
One additional thing: when Gates says he still knows the source code for Altair BASIC by heart, it probably doesn't mean "completely, line-by-line" by heart. I'm guessing it means he still remembers some snippets by heart, or that he believes he could re-write it from scratch from memory (which would still be exceedingly impressive).
Some useful resources on memory and learning:
Memory and Learning: Myths and Facts (http://www.supermemo.com/articles/myths.htm)
Want to Remember Everything You'll Ever Learn? Surrender to This Algorithm (http://archive.wired.com/medtech/health/magazine/16-05/ff_wo...)
Make It Stick: The Science of Successful Learning (http://www.amazon.com/Make-It-Stick-Successful-Learning/dp/0...)