tvN just unveiled a new drama. They were marketing it as a “coding romance,” so my curiosity got the better of me and I watched the teaser—and wouldn’t you know it, around the 7-second mark some code shows up.

A still from the teaser showing code on screen

And this code—when you zoom in, you can actually make some of it out.

A close-up of the code from the teaser

Anyone can tell this is C++ code.

It looked like fun, so I went ahead and reimplemented it exactly as shown.

My reimplementation of the code from the teaser

Once I got it working, it turned out to be a simple bit of code that counts how many times string B appears in string A.

That piqued my interest, so I dug around and found something called the KMP algorithm, which lets you implement the same thing in O(N+M) time instead of O(N*M).

A KMP-based implementation of the string-counting code

Then I scoured Stack Overflow and managed to get the same functionality in a very short piece of code.

A very compact version of the string-counting code

That was fun!