Hero coder finds bug in Lunar Lander after 55 years—'I suspect everybody else was just happy to play the game and have fun'

hero coder finds bug in lunar lander after 55 years—'i suspect everybody else was just happy to play the game and have fun'

Hero coder finds bug in Lunar Lander after 55 years—'I suspect everybody else was just happy to play the game and have fun'

Apollo 11 touched down on the moon's surface on July 20, 1969, an achievement for all humankind that put a full stop on the first iteration of the space race. Neil Armstrong stepped into history as the globe watched and among the millions in awe was 17 year-old schoolboy Jim Storer.

Based in Massachusetts and with a considerable grounding in mathematics, thanks partly to his physicist father, Storer was inspired by the very concept of a moon landing: the precise calculations and control required to safely bring a huge chunk of aluminium to rest on a barren, unfamiliar surface. Storer's school had a PDP-8, the first commercially successful minicomputer, and the young man set about writing a new program called "Lunar Landing Game".

Text-based and written in the early programming language FOCAL, Lunar Landing Game would ask the player for instructions on each turn, with the height, velocity, and remaining fuel of the lander calculated over each in-game second of the descent. Essentially it's a game about using your fuel supply to slow and control the craft's descent, and when the craft reaches the surface the player gets a report on their landing speed and remaining fuel.

The whole game is less than 50 lines of code, but its apparent simplicity belied the calculations underlying the simulation, and over the years the game became widely popular as a programming challenge. Even later, various popular commercial versions would add a visual layer (to give an idea of its longevity, Atari is currently in the process of developing an official sequel).

Software engineer Martin C. Martin has announced in a new blogpost that, while playing around with the original game's code, he found and fixed a bug that's lain dormant over the 55 years since the game was coded (first spotted by Ars Technica). Now retired, Martin's had a stellar career at the likes of Rockstar, Meta, and as a postdoc research fellow at MIT, and is exactly the type of individual who looks at something like Lunar Lander and decides to work out the optimal strategy for a perfect landing.

"I recently explored the optimal fuel burn schedule to land as gently as possible and with maximum remaining fuel," writes Martin. "Surprisingly, the theoretical best strategy didn’t work. The game falsely thinks the lander doesn’t touch down on the surface when in fact it does. Digging in, I was amazed by the sophisticated physics and numerical computing in the game. Eventually I found a bug: a missing 'divide by two' that had seemingly gone unnoticed for nearly 55 years."

Suicide burn

That is, Martin's perfect strategy wasn't being registered by the game as a successful landing. The coder was using what Kerbal Space Program players call the "suicide burn", whereby you maximise speed by not using fuel, then burn full-throttle at the last moment to reduce the speed to as close to zero just before you hit the surface.

"With some trial and error and a bit of (manual) binary search, you can find the schedule that just barely has you landing. You burn nothing for 70 seconds, then 164.31426784 lbs/sec for the next 10 seconds, then the max 200 lbs/sec after that," writes Martin.

"The game considers a perfect landing to be less than 1 MPH, but here we land at over 3.5 MPH and are told we 'could be better.' Yet burn even 0.00000001 more lbs/sec, and you miss the surface entirely, ascending at 114 MPH:

"How did we go from a hard landing to not landing at all, without a soft landing in between?"

When the coder started looking into why, he found that rather than "the simple Euler integration that's common in video games even today", underpinning the game's logic were more sophisticated equations: "Jim [Storer] used the exact solution, the Tsiolkovsky rocket equation, with a Taylor series expansion for the logarithm," writes Martin. "He also used some algebra to simplify it and reduce the amount of round off error. Very impressive for a high school senior in 1969."

Martin contacted Storer to confirm what he'd found, and ask about where this sophisticated math had come from. "I was skilled at calculus at the time and familiar with concepts like a Taylor series," says Storer, "but also my recollection is that my father, who was a physicist, helped me in the derivation of the equations."

Either way, the the rocket equation is what should make the suicide burn optimal, and the accuracy of the Taylor series suggests that's not the issue either. Instead the problem was contact: the moment where the Lander lands.

"Imagine the lander descending at the start of a 10-second turn but ascending by the end," writes Martin. "Simply verifying that it’s above the surface at both points isn’t enough. It might have dipped below the surface somewhere in between. When this happens, the program has to rewind and examine an earlier moment."

As Martin goes on to explain, the error creeps in when the game is trying to approximate the bottom of the trajectory. The coder presents his full working out in the blog post but, essentially, it comes down to Storer using an alternate form of a quadratic formula where for whatever reason "he’s missing the 2 in the denominator inside the square root! It was probably a simple error, either when deriving the formula or typing it into the computer." As Martin is careful to point out, Storer wouldn't have had access to algebra software and was doing this all with pencil and paper.

The missing "2" means that the game "consistently underestimates the time to the lowest point", which it then compensates for by adding a fraction of time (0.05 sec) and re-estimating. "And this explains why it misses the time of landing: the first estimate is while the lander is above the surface and still descending, then the second one is after reaching the bottom and ascending again, which takes less than 0.05 sec."

Martin goes on to explain the effect of fixing the bug, and spitball about some of the reasoning. Though he does note sadly that, even with the bug fixed, there are some optimal landing strategies but "the theoretical full-thrust-on-landing suicide burn, that takes around 148 seconds, eludes us."

Martin ends by paying tribute to the sophistication of Lunar Landing Game, coded in 1969 by a high-school student, and incorporating aspects of numeric computing that "I didn't learn until I was studying for a Ph.D. in robotics."

As for a bug surviving in a piece of popular software for 55 years?

"That’s probably because, even with the bug, it was a fun game, both difficult and possible to land gently," writes Martin. "The quest to not just win, but find the optimal strategy, can certainly lead to trying to understand small discrepancies. I suspect everybody else was just happy to play the game and have fun."

If you're interested in the history of Lunar Lander, this 40th anniversary retrospective speaks to Storer himself about the game's creation. And if you just like old bugs, here's a doozy: the developer who returned to his game after four decades, then found and fixed a typo so it actually worked.

OTHER NEWS

11 minutes ago

America's drinking water is under attack, with links back to China, Russia and Iran

16 minutes ago

NBCUniversal Believes In A.I. Miracles, Sets Tech-Assisted Al Michaels As Virtual Host Of Daily Paris Olympics Recaps On Peacock

17 minutes ago

Man Travels Solo After Girlfriend Can't Afford Flight: Is He Wrong for Not Covering Her Expenses?

17 minutes ago

Scientists make technological breakthrough that could prevent tons of hazardous e-waste: 'We have created a new formulation'

17 minutes ago

Bruce Campbell Remembers Spider-Man Co-Star Randy Savage

17 minutes ago

Rafael Romo relieved MLS “nightmare” is in the past

17 minutes ago

Humanoid Robots That Look Like Real People?

17 minutes ago

Liverpool reluctantly put deadline on Mo Salah contract talks as Slot picks Prem star as one of two replacements

17 minutes ago

Emiliano Martinez up to his old tricks as he causes uproar after late Argentina winner

17 minutes ago

Kenya's president Ruto withdraws finance bill after deadly protests

17 minutes ago

Phil Foden leaves England camp at Euro 2024 for birth of third child

17 minutes ago

When will home prices go down? Six economists weigh in.

17 minutes ago

Scientists share hiccup cure with '100 per cent' success rate

17 minutes ago

Foundation requests assistance as extreme weather unnerves local residents

17 minutes ago

Biden's new student loan relief plan is on pause. Here's what borrowers need to know

17 minutes ago

Google is testing facial recognition technology for campus security, starting at site near Seattle

17 minutes ago

Paramount Global set to ax more employees after ‘unacceptable’ profit drop

17 minutes ago

Emperor Naruhito dropped into London's Japan House during 'private engagements' before official state visit began - with Empress Masako sitting out the visit to pace herself

17 minutes ago

Video: Having a heatwave! Brits head to the beach, go for a swim and flock to Glastonbury as they try to cool down as 31C scorcher roasts UK

17 minutes ago

Video: Princess Diana's dresses up for auction - with items set to fetch more than £300,000 each

17 minutes ago

Video: Queen Camilla looks in her element surrounded by young readers as she visits primary school literary festival

21 minutes ago

The 12 men to beat Roger Federer at Wimbledon – ft. Rafael Nadal and Novak Djokovic

21 minutes ago

'Summer must-have' Roman midi dress launches in trending leopard print – and it's on sale for £30

23 minutes ago

After nationals scratch, Shilese Jones no longer in pain ahead of Olympic trials

24 minutes ago

‘Downton Abbey 3’ Opening Doors In Fall 2025

24 minutes ago

A24 Lands Horror Spec ‘Mice’ From Todd Spence & Zak White With David Bruckner Directing

24 minutes ago

Comedy Dynamics Acquires Tony Rock’s Debut Stand-Up Special ‘Rock The World’

24 minutes ago

ANALYSIS: DeMelo extension a meaningful start to busy week for Winnipeg Jets

24 minutes ago

IRS watchdog pushes for transparency on pandemic-era small business tax credit backlog

24 minutes ago

Staring at a screen the whole workday can hurt your eye health—4 ways to reduce strain

24 minutes ago

Sophie Wessex pays touching tribute to missing Kate Middleton at State Banquet

24 minutes ago

Three major UK banks offering free cash for switching accounts

24 minutes ago

Man Utd hold Bank of America ‘talks’ as they ‘consider selling Old Trafford naming rights’

24 minutes ago

Lavish state banquet menu enjoyed by King, Queen, Japanese monarch and Prince William revealed

24 minutes ago

What to know about combat sports at the 2024 Olympics

24 minutes ago

Tickets for NBC's Opening Ceremony coverage for Paris Olympics in IMAX theaters now on sale

24 minutes ago

Naomi Watts and Kai Schreiber, Maya Rudolph and Pearl Minnie and More Mother-daughter Pairs at Balenciaga's Fall 2024 Couture Show During Paris Fashion Week

24 minutes ago

Man Utd 'consider selling naming rights' to Old Trafford

24 minutes ago

Holidaymakers splash the cash on £250 of 'extras' while away, says HSBC survey

24 minutes ago

Newcastle want to keep Alexander Isak despite Chelsea and Arsenal interest