He Cloned My App, Then Sued Me for Stealing ItChapter 9

Optimal in O(n log n), Allegedly

Halcyon's website had a trademark symbol on a mathematical claim, which should have been my first warning that someone was selling something.

**Optimal Settle™**, the banner said, over a smiling photograph of friends on a rooftop. *The mathematically fewest payments. Always. In milliseconds. For groups of any size.*

I read the sentence in the cold gray light of Tuesday morning, one week and a few days into the lawsuit, standing at the kitchen counter with a rice spoon in my hand. The spoon was a prop. I had been about to eat. I put it down.

Tallybird had passed 1.2 million downloads. Halcyon's account posted the figure every morning with a different emoji, like a man stepping on a scale and announcing he'd gained a pound of muscle. Patungan, meanwhile, remained invisible in the stores. My subscribers' renewals were failing one by one, and somewhere in a dashboard I wasn't supposed to look at, a graph that used to be a mountain was now a cliff.

Jett had given the line a platform. On his podcast he said: "Raka's app uses what we call a greedy algorithm. Ours is provably optimal. That's the difference between a guy who hacks and a team that does math."

He said *provably.*

I stood very still, because I recognized the shape of this one. Not the shape of a lie, exactly. The shape of a claim that sounds like a fact because it uses a word from a field the listener has never visited.

Let me tell you what the problem actually is, and why one sentence on a rooftop banner is mathematically suspicious.

Suppose five friends have shared a trip. When all the expenses are added up, each person's net balance is either positive (the group owes them) or negative (they owe the group). The balances always sum to zero. Money has to flow from the debtors to the creditors. The question: what is the smallest number of payments that settles everyone?

The easy answer is a greedy one. Take the person owed the most, and the person who owes the most. Have the biggest debtor pay the biggest creditor as much as possible. That zeroes out at least one person. Repeat. Every payment clears at least one person, and the final payment clears two, so for n people, you never need more than n − 1 payments. It runs in a fraction of a second, even for thousands of people, because all you need is a sorted list: the work grows like n log n.

That is what Patungan does. It says so on its own help page: *Settle up in at most n − 1 payments.* I wrote that sentence myself and I chose "at most" on purpose.

The question is whether greedy is *optimal.* Could you sometimes do better?

Yes. And finding out how is the entire problem.

Here is why. A group of people can sometimes be split into smaller clusters, each of which is already balanced internally. If a cluster of three friends has balances that sum to zero among themselves, it can settle in two payments, regardless of who is outside it. The more such zero-sum clusters you can find, the fewer payments you need: the minimum is n minus the number of clusters. So the problem is to carve the group into the largest possible number of zero-sum subsets.

That is a partitioning problem, and partitioning is famously hard. It is in the same family as subset-sum, a problem the field has known about since the seventies. Nobody has found a fast algorithm for the general case, and most computer scientists believe none exists. Finding the true minimum number of payments is, in the technical language, NP-hard. A Dutch computer scientist named Tom Verhoeff wrote a note on exactly this, in 2004.

You can solve it exactly for small groups. A program can try every subset of the people, remembering the best answer for each, in time that grows like two to the power n, times n. For twenty people, that is about twenty million steps; a laptop does it before you finish blinking. For thirty, it takes a minute and a gigabyte of memory. For forty, you need a terabyte, and the age of the universe, give or take.

So "mathematically fewest payments, always, for groups of any size" is a claim that, if true, would settle one of the largest open questions in computer science. Jett had printed a trademark on it.

I did not need to take that on faith. I could show it.

Fajar brought a second spare phone and a thermos of black tea. We sat on the floor, as we do. I opened a new group in each app: Patungan on my own old handset, which still ran its installed copy; Tallybird on the spare. Five people. I named them Arief, Bayu, Citra, Dewi, and Eko.

I entered expenses to create exactly these net balances, in thousands of rupiah:

Arief **+100**. Bayu **+90**. Citra **−90**. Dewi **−60**. Eko **−40.**

They add to zero: 190 up, 190 down.

I did the arithmetic by hand first, because you always do the answer by hand before you trust a machine to confirm it.

Is there a cluster that sums to zero? Bayu's +90 and Citra's −90. That is a complete cluster. The other three: Arief +100, Dewi −60, Eko −40, also zero. Two clusters among five people. The minimum number of payments is 5 − 2 = **3.** Citra pays Bayu 90. Dewi pays Arief 60. Eko pays Arief 40.

Three payments.

I tapped *Settle up* in Patungan.

It proposed four.

> Citra → Arief: 90 > Dewi → Bayu: 60 > Eko → Bayu: 30 > Eko → Arief: 10

That was greedy, walking through exactly as I had designed. Biggest debtor to biggest creditor; then the next. It had cleared everyone in four moves, one fewer than n, as promised. It was *correct.* It was not minimal.

"That's the part that is going to hurt him," Fajar said softly.

"Wait."

I took the second phone. *Optimal Settle™.* A button the color of sunrise. I pressed it.

The animation ran, the coins slid and stacked. A little badge appeared, gold, with a laurel: **Fewest possible payments!**

> Citra → Arief: 90 > Dewi → Bayu: 60 > Eko → Bayu: 30 > Eko → Arief: 10

Four. The same four. In the same order, with the same pairing.

Fajar laughed once, softly, like a man who has been hit by a very small car.

I screen-recorded it. Forty seconds. First Patungan's four payments. Then Tallybird's four, with its laurel and its **fewest possible.** Then a cut to a plain text file where I had written, without flourish, a twelve-line exact solver that tried all subsets and reported three. I ran it. 0.0004 seconds. *3 payments.*

Then I said what I had come to say, to the camera, in a voice that was calmer than my hands:

"This is not an argument about who copied whom. It's a claim about arithmetic. The best plan has three payments. Tallybird's 'Optimal Settle' produces four. It also produces the exact same four, in the exact same order, as a greedy algorithm that was published for free two years ago. I'm not saying greedy is bad. I use it. It's fast, it never fails, and it's never worse than n minus one. I'm saying that 'always optimal for any group size' is not something a product can promise, because the underlying problem has no known fast solution. Please don't take my word. Here is the solver. Run your own group."

I posted it at 10:40 a.m.

The comments came at the usual speed, but the character was different. Not the roar of the first week. Something I had not seen before: working engineers writing, *I never thought about this.* Someone ported my solver to Python. Someone ported it to Rust and reported that twenty-five people took a couple of seconds, and thirty-two took several minutes and four gigabytes of RAM. A professor of discrete mathematics in Bergen tweeted, *This is a perfect undergraduate exercise. NP-hard in the wild, with a marketing department.*

Then, at 1:15 p.m., Cormac Reyes responded.

It was a long technical post on the Halcyon engineering blog, with a tone of weary expertise. *Our "Optimal Settle" is exact for groups up to eight members. For larger groups it applies proprietary heuristics. The marketing copy is shorthand.* There was also, buried in the last paragraph, a sentence I read three times: *Our implementation shares a heritage with the open-source settle_core algorithm and we're proud to build on the community's work.*

"Heritage," I said.

"That's a very good word," said Fajar. "It means nothing and it's got a nice jacket."

But the clarification was a decent counter. I had to admit that. For groups up to eight, exact solving is nothing; and my demonstration had used five. Cormac, who is not a stupid man, had conceded the weak flank, narrowed the claim to what was true, and made the rest sound like a footnote.

Which left a tidy puzzle. If Tallybird was exact for groups up to eight, why had it returned four payments for my group of five?

I retested. I made the group again. I pressed the sunrise button, three times.

Four. Four. Four.

Either the exact solver was missing a case, or "exact for up to eight" was no more true than the rooftop. I posted the second video at 3:00 p.m. without commentary: the group, the three clicks, the same four payments.

At 6:20 p.m., Halcyon's marketing page changed. The banner now said *Smart Settle™: fewer payments, intelligently.* Under it, no claim of math.

It was a small, ridiculous victory. A word had been removed from a website. I felt almost embarrassed by how good it felt.

At 9:02 p.m., my phone buzzed. A message from Hostly, the hosting company where my sync servers lived. It said, in the faintest corporate prose:

*We have received a notice of alleged infringing content hosted on your account. In accordance with our policy, your account has been suspended pending resolution.*

I held the phone in both hands.

It was not the app stores. It was not the repository. It was the thing in the middle, the place where eight thousand people's group balances lived, the servers that let a woman in Surabaya see the last payment her brother had made.

"Raka," Fajar said.

"Wait."

I opened my status page. Red. All of it. Four hundred thousand active users, and a spinning wheel waiting for a server that someone had unplugged in a datacenter somewhere with a notice that I had never seen.

It took me nineteen hours to rebuild from a local weekly export, on a machine in the office of Fajar's cousin, with three cups of coffee and a plate of cold martabak. I got the sync back at 4 p.m. the next day. I could not undo the nineteen hours. The eleven sisters in Surabaya, who had a funeral to settle, could not use the app on the one day they most needed it.

I learned that I should have kept a backup somewhere else. I should have learned it earlier.

The only thing that got me through the night was an email, forwarded by Mari at 11:55 p.m., headed with the court's seal.

*NOTICE OF HEARING. Plaintiff's Motion for Preliminary Injunction. Tuesday, 9:00 a.m. Pacific. Courtroom 7, Hon. Harriet Oyelaran, presiding. Defendant may appear by video.*

Under it, Mari had typed three words:

*It's time, Raka.*