One of an occasional series in which one of my consulting successes is anonymised and fictionalised.
“Who’s the client?” asked Big Joe Tracy.
Nick Bourbaki, Private Eye, tilted his head.
“He could tell you, but then he’d have to kill you,” said Fiona Drummond.
“I can neither confirm nor deny that a hollowed-out volcano is involved. In any case, I do the caring about the clients, you two do the problem-solving grunt-work. Unless you particularly want to do a few shifts of invoice-chasing, hm?”
A few grumbles, a sigh. Then “OK. Then what’s the problem?”
Bourbaki took a crumpled sheet of paper from his jacket pocket and made a decent effort at uncrumpling it on the table between them.
Tracy sat forward. Drummond sat back. “Code,” they both said, in somewhat different tones of voice.
“For the purposes of this problem, our client has a row of sensors, 32 of them. I can’t tell you what they’re sensing, because even if I understood, I wouldn’t be able to pronounce it.”
Drummond crisply folded a sheet of paper in half five times with a muted “ta-da”.
“The trouble is, there are occasional… ghost signals. Sometimes one event shows up in multiple neighbouring sensors. We want to make sure those events only appear once.”
“And this code…?”
“This is the code they’ve written that doesn’t work. Your job is to debug it.”
“Debug code off of a printout?”
“Without being able to run it or see the code it depends on?”
“Mhm. Although these…” … two more crumpled sheets … “are some output runs.”
“Hm,” said Tracy. “Challenge accepted. Whose turn is it to buy the coffee?”
This was a two-coffee-table problem. On one, the drinks; on the other, an A3 page covered in Tracy’s beautiful handwriting.
“It runs through the list of events, looks at the previous and next event in the list, and removes the first one if they’re in adjacent sensors. So it ought to leave just the last event in the list, which looks acceptable.” He took a sip of the whipped cream, under which there may or may not have been some coffee. “And in the cases where there are one or two hits, it looks like it works fine. In some of the three-hit cases, too.”
“How many of the three-hit cases?” piped up Drummond, who had been feigning a complete lack of attention.
“Uh… lemme see.” Tracy counted. “About half.”
“More detail, more detail. Are the three-hit cases together or apart?”
“Um… OK. When there are three separate hits, it works just fine. If there’s a distinct hit, and a pair elsewhere, it gets it right about two thirds of the time…”
---x---x----x----- < fine ----x----xx------- < 2/3
“And if it’s three together, about one in three?” She still hadn’t looked up from her phone.
----xxx----------- < 1/3
“… I hate it when you do that.”
Drummond permitted herself a smirk. “‘Next’ and ‘previous’ have two distinct meanings. My bet is that the list of events is ordered by time rather than by sensor.”
“Why does that…”
“Think about the one-and-two case. If could be that the first of the two is followed in time by the one and then the second of the two.”
---2--13------ < all three are counted
“… in which case…”
“… The code wouldn’t spot that the two were next to each other in space, because it’s only checking whether things are next to each other in space if they’re next to each other in time.”
“Nick? Are we meant to fix the code, or just tell them what’s wrong?”
“Why do you ask?”
“I’m hoping it’s ‘fix’, or else… this specimen… is going to be unbearable about this for the rest of time.”
She was already doing the “I cracked the case” dance.
“The brief is unclear,” said Bourbaki, “but it’s probably in everyone’s best interest if you fix the code too.”
* Big Joe’s code can be found here. He’s not just showing off his bit-fiddling, he was told there was practically zero memory budget and that arrays were out of the question.
Do you have a problem that doesn’t make sense? Drop me an email at firstname.lastname@example.org and let me know how I can help.