The Mathematica One-Liner Competition at last year’s Wolfram Technology Conference was such a popular success that we did it again this year. As readers of this blog may recall, last year’s winning entry, submitted by Stephan Leibbrandt, was a complete, animated simulation of particles coalescing under gravitational and repulsive forces. This year’s winner takes advantage of the integration of Mathematica and Wolfram|Alpha that debuted in Version 8.

The rules were the same this year as last: produce the most stunning output you can with 140 or fewer input characters, typeset 2D expressions are allowed, and white space doesn’t count. The entries were once again all over the place, from anagrams and fractals to abstract graphics and astronomical charts.

Eighteen participants submitted 33 one-liner entries. Five of those merited Honorable Mentions. One got a Dishonorable Mention. And of course, prizes went to Third, Second, First-and-a-Half, and First Places.

First-and-a-Half Place?

After the competition deadline had passed and the usual First-, Second-, and Third-Place prizes had been awarded, one email entry arrived that had gotten stuck in the ether along the way. Because the entry was submitted before the competition deadline had passed, we asked the judges to review it after the conference ended. It consisted of three high-quality submissions, two of which the judges awarded First-and-a-Half Place. Regrettably, the author, Stephan Leibbrandt, didn’t receive the recognition he deserved at the conference awards ceremony. We hope the special mention here will make up for that. Check out his inspiring First-and-a-Half-Place “Shooter” and “Slow Motion” entries further down, as well as his Honorable Mention “Fractal” entry.

The first of the Honorable Mentions went to William Wu for “Anagram Bands”. At 134 characters, Wu’s code nearly generates adjective-noun pairs whose component words are anagrams of one another. How can you not like code that yields such beauties as “snub buns” and “supple peplus”? Alas, the judges had to supply two characters of missing code (“w =”) to make the submission work; thus, his entry was disqualified from winning a prize.

A second Honorable Mention went to Sascha Kratky for his “Desktop Search Engine”, a 140-character implementation of an interactive, full-text search of the files in a directory. Unfortunately, Sascha’s function required an additional 32 characters to invoke, which put it over the 140-character limit.

Chuck Ronco won an Honorable Mention for “The Music of π”, 128 characters that play a melody obtained by mapping the digits of π to a set of notes. His code makes clever use of ArrayRules to create the mapping and ToString to save quotation characters.

Play Audio



An Honorable Mention went to Stephan Leibbrandt for “Fractal”, a 130-character rendering of the Mandelbrot set that not only works, but uses Compile to make it efficient enough to work in practice. Perhaps a reader can figure out what in the world the hyperbolic tangent of a seventh root does.

We received the competition’s first 0-character submission from Dave Lawrence—his “World’s Smallest Mathematica Quine”—with the comment “See below. Don’t miss it.” Here it is in its entirety:

Those who are baffled might want to check out the Wikipedia definition of “quine”. For providing the judges with comic relief, Dave’s submission was awarded an Honorable Mention. Unfortunately, the judges couldn’t tell whether his submission was written in Mathematica or C.

This year’s Dishonorable Mention went to Zdeněk Buk for his 125-character “White Space Data”, which renders a stunning image of Stephen Wolfram. Amazing! Until you realize that Zdeněk’s submission includes 5,073 characters of white space—which don’t contribute to an entry’s character count—that encode the image. Nice try, Zdeněk! The judges didn’t buy it.

This year’s Third-Place prize went to William Wu, who paradoxically used Compress to increase the size of his submission from 75 to 137 characters. You realize why he used that strategy when you execute the code, which the judges said belongs in the “Heart Attack” category.

The Second-Place prize went to Yves Klett (last year’s Third-Place winner) for “Instant Recursive Art”. With 101 characters, Yves’s submission images the notebook in which it resides, applies Erosion to merge the image’s “ink” into larger regions (by eroding the white background), and then partitions the result into colored regions via WatershedComponents and Colorize . The operation can be executed multiple times to generate beautiful abstract recursive images.

The judges commented that Yves’ 101 characters could have been further reduced to a mere 71 by replacing the ImportString [ ExportString [...]] trick with Rasterize , which can be applied directly to Notebook objects:

First-And-a-Half prize goes to Stephan Leibbrandt (last year’s First-Place winner) for two equally impressive interactive submissions, “Shooter” and “Slow Motion”.

The 140-character “Shooter” implements a complete interactive shooting game. Stephan was so razor-close to exceeding the 140-character limit that he had to omit the usual semicolon following the first initialization line, but in this case, that doesn’t matter.

Stephan’s 130-character “Slow Motion” implements a surreal motion trail in real time from the images of a computer’s camera. It shows unusual mastery of functional programming constructs to achieve a beautiful graphic result.

This year’s First-Place prize goes to Zdeněk Buk, whose submissions were so compelling that the judges initially awarded him both First- and Second-Place prizes—with the judging being anonymous, they had no idea they were awarding both prizes to the same person. Zdeněk received this year’s Dishonorable Mention as well, an impressive accomplishment.

Zdeněk’s 140-character “Recursive Image Collage” recreates an image from scaled copies of the image itself, each adjusted in darkness to match the average brightness of the original in that area. Zdeněk’s entry shows clever use of Mathematica‘s functional programming constructs for nesting, replacement, and image operations.

Zdeněk’s second, 137-character submission, “Animated Sky Chart”, makes exemplary use of Wolfram|Alpha’s integration into Mathematica to gather 10 days’ worth of sky charts from Wolfram|Alpha via natural language queries that the code constructs. The resulting animated charts are useful as well as beautiful.

You can get a real education in Mathematica programming techniques by going through these concise examples step by step to understand how they function. To see just the winning entries or all of the Mathematica One-Liner submissions, download one of the notebooks below. Thanks to all who participated. You’ve inspired us with your creativity.

Download a notebook of the winning 2011 Mathematica One-Liner Competition submissions.

Download a notebook of all 2011 Mathematica One-Liner Competition submissions.