So you’re on your way to the Moon. It’s been a long trip, and just as you’re finally about to land, your spaceship’s computer starts to spit out error message after error message. This is an extremely non-ideal situation, and sounds really terrifying, and it’s exactly what happened to the astronauts on Apollo 11, the first mission that landed humans on the Moon. In the end, the astronauts landed safely — and Margaret Hamilton, a computer scientist who worked for NASA in the 1960s and 70s, was why. Margaret rose through the ranks to eventually become the head of the Apollo flight software development team — and a pioneer for women in STEM fields. Hamilton has spent her life focused on errors: how to prevent them, and how to keep everything running when they come up. And her approach is what saved Apollo 11 from having to abort the mission. Hamilton was born on August 17, 1936 in a small town in southern Indiana. In 1958, she earned a Bachelor’s degree in math from Earlham College, with a minor in philosophy. She taught in a high school for a couple of years, then worked in a few different MIT programming labs. Eventually, Hamilton planned to pursue a PhD in abstract math, but then she got an offer: a lab at MIT was looking for programmers to work on the computer that would take humans to the Moon. So she took that job. Back then, programming software — the code that tells computers what to do — wasn’t really a thing people went to school for. The field was pretty new, and was developing quickly. So Hamilton, like a lot of early computer scientists, learned on the job. One of her first assignments was for an unmanned mission, and it involved designing the program that would tell the computer what to do if the mission aborted. According to Hamilton, NASA execs gave her the assignment because they didn’t think it was likely that the mission would abort. But then it did, and the computer ended up using her program. To write that program, Hamilton had to consider what would happen if a mission failed — like if a key instrument decided not to work, or if the craft ran out of fuel. It was a theme that would continue to come up during her time at NASA, and throughout her career. Like when it came time to program the computer for Apollo 8, the first manned mission to orbit the Moon. The software team tested their designs using simulators that would run the programs as though they were being used on a mission. While one of these tests was simulating the spacecraft in flight, Hamilton’s four-year-old daughter — who she’d brought into work that day — accidentally started a program that was meant to be used pre-launch, and the simulator crashed. Hamilton realized that this was an error that could easily come up during the mission itself, if an astronaut pushed the wrong button by accident. She wanted to program in a workaround. But first, she needed clearance from NASA, and they said no. They didn’t think an astronaut would actually make that mistake. Then Apollo 8 launched, and five days into the mission, one of the astronauts … yes, pushed the wrong button and started the pre-launch program … which erased part of the data the computer needed to get the astronauts home. It took NASA engineers 9 hours to come up with a fix, which involved sending a replacement set of data to the Apollo computer. But the problem could’ve been prevented if Hamilton had been allowed to plan for it. And then came Apollo 11! The errors that cropped up just as the crew was about to land, came from the fact that the computer was being asked to do more calculations than it could handle. The extra demand came from the rendezvous radar, which the landing module was using to keep track of the command module that stayed in orbit around the Moon. The program for the radar hadn’t been set up properly, and it was asking the computer to perform 6400 operations per second — about 13% of its total processing power. That’s not so much except that the computer needed to land on the Moon took up 90% of its processing power — so it was overloaded. Luckily, Hamilton and her team designed Apollo’s computer to take priorities into account — which was unusual for computers at the time. Instead of trying to do all the tasks it was assigned in order — which in this case, would have crashed the computer — it responded to an overload by focusing only on the high-priority tasks. Landing on the Moon was rated a much higher priority than messing with the rendezvous radar, so the computer concentrated on landing, and the astronauts made it to the Moon’s surface. After Apollo 11, Hamilton continued designing software for NASA, working on the computers used for the rest of the Apollo missions, as well as Skylab, America’s first space station. She’s now the CEO of Hamilton Technologies, a company she founded in 1986, which provides a way for software engineers to integrate different programs so they act like one big system. Integrating the programs this way helps prevent errors that can come from interfacing — when programs exchange information. Nearly 47 years after Apollo 11, Margaret Hamilton is still working on ways to get rid of software bugs. Thanks for watching this episode of SciShow, and thanks to Emerson for sponsoring it. If you want to keep getting smarter with us, just go to youtube.com/scishow and subscribe.