Create Valid Perl by Smearing Paint on the Wall Interactively

Create Valid Perl by Smearing Paint on the Wall Interactively

· 6 min read

I was browsing Hacker News recently and came across this post: 93% of paint splatters are valid Perl programs, which seems to be a recurring post on HN, but was new to me

In February 2019, Adrienne Porter Felt tweeted that she’d rather her kid smeared paint on the wall than learned to code. Jake Archibald replied with the real question:

“is it possible to smear paint on the wall without creating valid Perl?”

Colin McMillen took that seriously enough to write a paper about it: 93% of Paint Splatters are Valid Perl Programs, accepted at SIGBOVIK 2019, the April Fools’ conference at Carnegie Mellon. The answer turns out to be yes, you can. But only 7% of the time.

What he did in his research was the following:

  1. Take 100 paint splatter images
  2. Use Tesseract OCR on it
  3. Check if the result of the OCR is valid Perl

It turned out it is, about 93% of the time.

How he tested it

There is no standard dataset of paint splatters, and ImageNet was down that day, so he searched Pinterest for “paint splatter wallpaper” and saved 100 images. Anything with a watermark went out.

Every image went through Tesseract, the open-source OCR engine. He limited it to printable ASCII and switched off the English dictionary, so it wouldn’t try to turn blobs into words. Tesseract has three engines (legacy, LSTM, and a mix of the two) and several page segmentation modes, so he ran every image through 3 engines × 4 modes and kept whichever reading worked. Each string then went to the real perl binary (5.26.1). An empty string didn’t count.

The paper admits that trying everything until something works is “profoundly unethical”, and that it’s at least more honest than calling it hyperparameter tuning.

What came out

93 of the 100 splatters produced a valid Perl program under at least one setting. The LSTM engine alone found one for 74% of the images, the legacy engine for 62%, and the combined engine for only 40%, which nobody can explain.

None of the programs do anything useful, but some of them evaluate to something:

  • 20 images read as plain numbers. One reads as 35, one as - 3 (−3, the smallest), one as 225252 (the largest).
  • Most of the rest are valid because Perl has barewords: a run of letters on its own counts as a string. A splatter that reads ME evaluates to "ME". Most other languages would throw a syntax error.
  • One reads as gggijgziifiiffif. Run it with -w and Perl warns that the word might clash with a future reserved word.
  • One reads as just ;, a statement that does nothing.
  • Others read as ;E,'__' (evaluates to E__) and -*? (evaluates to 0).

The seven that fail are the paper’s “rogue’s gallery”. For one of them, OCR came up with fifi;%:'i1i:, .%f:, & and i;%:';;:, and Perl rejected all four.

The full set is in the gallery: every splatter, what OCR read, and whether Perl accepted it.

The footnotes

I can really recommend you to read the footnotes as those are the best part.

The second author, “Tim Toady”, doesn’t exist: TIMTOWTDI, Perl’s motto “There Is More Than One Way To Do It”, is pronounced “Tim Toady”. The “unemployed person” paid to collect the images was the first author. And a splash image from Nintendo’s Splatoon site also turned out to be valid Perl, though the code it produced was too rude to print.

The paper ends with open questions: do paint smears behave differently from splatters, would a real toddler’s painting score lower than Pinterest-quality art, and are 2019’s swimwear trends also valid Perl? After the image search, Pinterest started recommending swimwear.

Check it yourself

So, as I came across the HN post, I thought: that seems like a fun project to recreate here.

That is what you can do on the canvas above: feel free to splatter paint around as much as you want. Every time you take a little break, it scans the image with Tesseract OCR, and passes the result to WebPerl to see if it’s valid Perl.

To do these two things, it needs to download both Tesseract and WebPerl, which comes in at around 30 MB.

We run both the new Tesseract models and the legacy models, and we work by consensus:

  • if more than half the models agree on the detected text, we use that result and pass it through WebPerl
  • often they do not all agree on what is detected, then we take the longest result. Because I don’t know what it is with paint, but some models see an ‘M’ in everything and that’s kinda boring.

If you’re on mobile data or don’t want to downlaod 30MB, you can still paint, and run the OCR and Perl validation yourself, like this:

tesseract paint-splatter.png reading --psm 7
perl -c reading.txt

syntax OK means your painting is a Perl program.

If you want to share your beautiful splatters, you can send them via email on hello@vandevliet.me or via X @itsgmjelle, and I’ll add them to the gallery below

The verdict

Counting the paintings…

I’ll write up what the wall has seen in a full post soon.

Galleries LaPerlette

Green paint spelling PERL; OCR reads peRL: valid Perl

Two lines of red handwriting dripping down the wall; OCR reads felt: valid Perl

Red, green and purple bucket splashes; OCR reads E13: valid Perl

A yellow zigzag stroke; OCR reads “V an”: valid Perl

Yellow, blue and purple paint smeared together; OCR reads “;;W”: valid Perl

A yellow smiley with black eyes and teeth; OCR reads “l..”: not valid Perl

Submit your painting to the Galleries

Submit your painting to the gallery: hit Result on the wall to save it, post it on X and tag me. I’ll add it to the gallery and credit you.

POST ON X