Create Valid Perl by Smearing Paint on the Wall Interactively

●6 MIN READ

Create Valid Perl by Smearing Paint on the Wall Interactively

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

 

The paper: 93% of Paint Splatters are Valid Perl Programs by Colin McMillen (SIGBOVIK 2019), with its gallery of splatters, after Jake Archibald’s question. In the wall: Tesseract.js running the Tesseract OCR engine (Apache 2.0), and WebPerl by Hauke Dämpfling (Perl compiled to WebAssembly; Artistic License / GPL). The paint is my own WebGL code, with ideas borrowed from Blender’s Dynamic Paint (wet paint that drips), Matthias Müller-Fischer’s height-field fluids, David Li’s Fluid Paint, MyPaint (brush loading and smudging) and Google’s LiquidFun Paint; the stretched drops use the impact-angle rule from bloodstain pattern analysis. Icons from Lucide. Cover photo by Mathias Reding on Unsplash (Paris, 2022).

More polaroids I want to share

CLICK OR DRAG THE TOP ONE ASIDE

You've reached the end of the shoebox. More polaroids and other posts live on my Instagram.

@GMJELLE →
Polaroid of a calm lake at dusk reflecting pink clouds and dark hills, at a wild campsite near Adana, Turkey
Polaroid of Josip Broz Tito's marble tomb seen through plant leaves in Belgrade, Serbia
Polaroid of a motorcycle parked at a Soviet-era bus stop decorated with a flower mosaic in Moldova
Polaroid of a large stone statue of a bearded man in a long coat on a hillside near Buzludzha, Bulgaria
Polaroid of the saucer-shaped Buzludzha Monument on a distant hilltop above the trees in Bulgaria
Polaroid of a man standing in front of the Buzludzha Monument and its tower in Bulgaria
Polaroid of a valley of pale, cone-shaped rock formations in Cappadocia, Turkey
Polaroid of hot air balloons silhouetted against the dawn sky in Cappadocia, Turkey
Polaroid of the brutalist Cosmos Hotel tower in Chisinau, Moldova
Polaroid of the Tomb of Cyrus the Great on its stepped stone base at Pasargadae, Iran
Polaroid of a close view of the Tomb of Cyrus the Great at Pasargadae, Iran
Polaroid of a converted red fire truck camper and a motorcycle at a campsite on the west coast of Turkey
Polaroid of a mosque minaret and domes silhouetted against a cloudy sky in Edirne, Turkey
Polaroid of the Mimar Sinan statue in front of the Selimiye Mosque in Edirne, Turkey
Polaroid of the courtyard of a historic house with a fountain and colored-glass windows in Isfahan, Iran
Polaroid of a man standing next to an Isfahan city emblem sign on a sidewalk in Isfahan, Iran
Polaroid of the tiled dome and entrance portal of the Sheikh Lotfollah Mosque in Isfahan, Iran
Polaroid of the tiled entrance portal and twin minarets of the Shah Mosque in Isfahan, Iran
Polaroid of a columned palace silhouetted at sunset behind a fountain pool on Naqsh-e Jahan Square, Isfahan, Iran
Polaroid of a dark interior lit through colorful stained-glass windows in a historic house in Isfahan, Iran
Polaroid of rocky ridges and rock formations under a cloudy sky near Goreme, Cappadocia, Turkey
Polaroid of a loaded motorcycle parked by a desert road with mountains behind it in Iran
Polaroid of a loaded motorcycle with a helmet on the mirror, parked on a coastal road near Izmir, Turkey
Polaroid of a Soviet-era mosaic of workers and a motorcyclist on a building wall in Lutsk, Ukraine
Polaroid of a Soviet-era mosaic of a crowned woman holding scales, framed by tree leaves in Lviv, Ukraine
Polaroid of the Lviv Opera House facade with a fountain in front in Lviv, Ukraine
Polaroid of a Soviet WWII memorial column with a stork's nest on top in northern Moldova
Polaroid of a large Soviet-era mural of figures on a wall beside a tree in Moldova
Polaroid of royal tombs carved into the cliff face at Naqsh-e Rustam near Persepolis, Iran
Polaroid of a stone relief of a Persian soldier holding a spear at Persepolis, Iran
Polaroid of the Gate of All Nations with its winged bull statues and columns at Persepolis, Iran
Polaroid of four men sharing dinner at a table in a traditional hostel in Shiraz, Iran
Polaroid of the tiled courtyard and reflecting pool of the Nasir al-Mulk (Pink) Mosque in Shiraz, Iran
Polaroid of two men smiling at a restaurant table in Tabriz, Iran
Polaroid of the mirrored hall of Golestan Palace lit by large chandeliers in Tehran, Iran
Polaroid of the bronze statue of Leonidas raising a spear at the Thermopylae monument, Greece
Polaroid of a man looking up at the wooden Trojan Horse from the Troy film in Canakkale, Turkey
Polaroid of a backgammon board on a table overlooking the sea at a campsite in Turkey
Polaroid of a Soviet-era mosaic of a woman in traditional dress under a Ukrainian coat of arms in Ukraine
Polaroid of a motorcycle parked at a bus stop with a mosaic of three knights in Ukraine
Polaroid of a man standing on a boardwalk in front of the stairway of the Ziggurat of Ur, Iraq
Polaroid looking up the brick stairway of the Ziggurat of Ur, Iraq
Polaroid of eroded mud-brick ruins with a small sign in front at Uruk, Iraq
Polaroid of a man and two boys crouching by a freshly slaughtered sheep on grass on the road to Van, Turkey
Polaroid looking up at the curved glass Zlota 44 skyscraper in Warsaw, Poland
Polaroid of the Palace of Culture and Science lit at dusk in Warsaw, Poland
Polaroid of the Zoroastrian Fire Temple with a round reflecting pool in Yazd, Iran