This week on CBS’ Person of Interest, Part 2 of the midseason “trilogy” adopted a very cool narrative device, as Team Machine faced the Kobayashi Maru scenario.

With Greer having sicced Samaritan on the world financial markets to instant, devastating effect, the salvation of the global economy rested inside one briefcase in Root’s grasp, via an override device that needs to be deployed on site, in the bowels of the stock market.

With Shaw busy on a subway car trying to talk down a random bomber and get an access code from a security guard, it was up to Finch, Reese, Fusco and Root to get the job done. But almost as soon as they broached the basement, they were cornered in a trap. The Machine then computed the myriad options and outcomes available to the team. The one she picks — No. 336,742 — gets Finch shot dead in the server room, finds Reese and Fusco surrounded by Martine’s men, and gets Shaw arrested after popping the antsy bomber.

But it was only a simulation that we were watching.

The Machine then resets to real time and recalculates, this time going with option No. 506,738, which sends Fusco and Reese to the server room, with Fusco commandeering a dead goon’s comm to throw Greer off their scent. Reese shoots their way into the server room, but when Samaritan’s troops show up and the firefight gets too hot, he sends Fusco away, only to die in a hail of bullets. (That said, Reese has the last laugh, blowing everyone up with a grenade.) Meanwhile, while overriding the elevator controls with Finch, Root hails Shaw on her comm to point out how “perfect” they are for each other, which she will figure out “some day.” Maybe some day, Shaw allows (though in a very precise, end-of-world scenario) — and then we realize that Root was making a farewell speech, about to be gunned down by Martine’s men.

Option 833,333 shows the most promise — was it Fusco’s lucky kiss? — in that Shaw deters the bomber and gets the code, while Root & Co. all go to the server room. (In this “simplified simulation,” everyone speaks in shorthand a la “Overt Come-On” versus specific dialogue, and it’s very funny.) Alas, even after saving the stock market and overriding the elevator, there’s only a 2.07% average survival rate.

In the final, actual approach, Fusco doesn’t plant his kiss, Root saves the Degas that Finch is fond of, Shaw gets the code and the elevator cable is cut, but Reese gets shot in back while protecting Finch. Root, too, is shot, prompting her to launch into her previous “We’re perfect together” conversation with Shaw… only Shaw has arrived on the scene. With the added firepower, everyone is able to make it to the elevator, except it won’t move. An override button across the gunfire-filled hall needs to be pressed, so Shaw — after silencing Root’s protests with a passionate kiss — makes a dash for it and activates the elevator.

And as the doors close with her friends inside, Shaw is perforated by a hail of bullets. In the final seconds, Martine hovers above her, ready to take a head shot.

And then: Bang.