At the end of "The Reichenbach Fall", Sherlock and Moriarty have a confrontation on the roof of the hospital. (I am not sure why Sherlock chose the roof in the first place, but that is neither here nor there.) It becomes clear to Sherlock that
- The code Moriarty hinted at when he visited Baker Street was not, in fact, the 'key' to any computer system in the world.
- Moriarty had snipers aiming at Watson, Mrs. Hudson, and Inspector Lestrade at that very moment, and they would shoot if Sherlock didn't jump off the building.
- There is a code or number somewhere that would call off those snipers without Sherlock jumping.
Once Moriarty realizes that Sherlock is capable of guessing the way to stop the snipers, he shoots himself in order to stop Sherlock winning.
Could Sherlock still have guessed the code and saved the day? Was the code related to the one Moriarty tapped on the chair at Baker Street, or was that really just a red herring?