Wolfram Blog
Christopher Carlson

The 2011 Mathematica One-Liner Competition

December 1, 2011 — Christopher Carlson, Senior User Interface Developer, User Interfaces

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.

Mathematica One-Liner Competition

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.

Code generating adjective-noun pairs whose component words are anagrams of one another


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.

Code building an interactive, full-text search of the files in a directory

DS[$InstallationDirectory, "*.m"]

File directory showing files that match "*.m"

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.

Mapping the digits of π to a set of notes

To hear this audio, you must have Adobe Flash Player 10.0 or higher installed and JavaScript enabled. You can download the latest version of Adobe Flash Player here.

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.

Building a 130-character rendering of the Mandelbrot set

Mandelbrot set

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.

Using white space data to render an image

Image of Stephen Wolfram built from white space data

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.

Third-Place prize entry

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.

Colorful recursive image

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:

Colorize@WatershedComponents[Erosion[Rasterize@EvaluationNotebook[], 1]]

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.

Building a complete interactive shooting game

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.

Building a surreal kind of slow-motion motion trail in real time from the images of a computer's camera

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.

Recreating an image from scaled copies of the image itself

Image from scaled copies of the image itself

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.

Using Wolfram|Alpha in Mathematica to gather 10 days' worth of sky charts

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.

Posted in: Wolfram News
Leave a Comment



I really enjoy these one-liners

Posted by Kees    December 1, 2011 at 5:15 pm

Impressive! Congratulations to the winners.

Posted by igo    December 1, 2011 at 5:22 pm
Lucile Lichtblau

I thought Mandelbrot was a kind of Jewish cookie. Who knew?

Posted by Lucile Lichtblau    December 1, 2011 at 7:14 pm

The Tanh[] function is just a smooth switch function that rescales the escape times to lie in (0,1), which Image[] interprets as grayscale. The 7th root is chosen to give a good contrast in the image. (I actually prefer the 4th root…). See http://pastebin.com/gZSzPkFB

Posted by Simon    December 1, 2011 at 8:54 pm
Stefan Salanski

I believe the Tanh[(i/9^2)^(1/7)] is simply his way of defining the grayscale gradient to make the image. It converts the integer values of i (ranging from 1 to 9^3) into real values from 0 to .76 (might have looked nicer if it was from 0 to 1).
Also, I liked the musical pi one-liner, interesting tune and clever use of ArrayRules.

Posted by Stefan Salanski    December 2, 2011 at 10:22 pm
Barrett Leslie

Great Mathematica coding and very useful as well.

Posted by Barrett Leslie    December 3, 2011 at 1:47 pm

Great Mathematica coding and very useful as well.

Posted by mirc    December 6, 2011 at 3:43 pm

Leave a comment


Or continue as a guest (your comment will be held for moderation):