## The *Mathematica* One-Liner Competition

December 17, 2010 — Christopher Carlson, Senior User Interface Developer, User Interfaces

Your assignment:

Write a simulation of spherical particles coalescing under gravitational attraction. Limit the approach distance by a secondary repulsive force that acts over short distances. Produce an animation of the dynamic system starting with 15 particles in randomized positions.

Formulate your solution in 140 characters or less.

Sound challenging? A 138-character solution was Stephan Leibbrandt’s winning entry in the *Mathematica* One-Liner Competition that was a part of this year’s Wolfram Technology Conference.

The goal of the competition was to find the most astounding outputs that attendees could produce from the shortest inputs—not just physics simulations, but any applications attendees could dream up. The competition was intended to highlight how much can be accomplished with a few keystrokes in *Mathematica*. And it was intended to give conference attendees an opportunity to entertain and amaze each other with their creativity. Which they did.

Our first task in designing the competition was to nail down what a “one-liner” is. The concept is not as clearly defined today as it was in the punched-card era, particularly with *Mathematica*‘s two-dimensional typesetting. We settled arbitrarily on a modern unit of information—the Tweet, or 140 characters—as the size limit of a one-liner, and permitted full use of two-dimensional typeset structures. Special consideration was given to entries that came in at 80 characters or less.

Predictably, the submissions showed great creativity and conniving in finding tricks to reduce character counts to absolute minimums. And satisfyingly, the topics of the submissions were all over the place, from esoteric mathematics to works of art, astronomy to origami.

Four submissions merited Honorable Mentions, and one a Dishonorable Mention. Zdenek Buk won an Honorable Mention with this 140-character expression that produces a graph that shows which countries—indicated by their flags—share borders (click the figure for a magnified view).

A second Honorable Mention went to Stephan Leibbrandt for his “Tubular Bells”, a meditative multimedia experience implemented in just 140 characters.

Paul Abbott had characters to spare with this surprising 112-character plot of a deceptively simple function in spherical coordinates—another Honorable Mention.

In the category of Useful Stuff, Sal Mangano’s 116-character expression yields a complete table of functions and their derivatives and integrals—the last of the Honorable Mentions.

A Dishonorable Mention went to Yves Papegay, who submitted this 80-character expression with the comment, “If only I had a better machine.”

This input selects from all 200696776371546515671027031705365217492618488

1582832600210755762096900905036350233077746752088222272458708782885

444148423180502637853488332240652972952399993950 possible expressions of 80 characters or less those that are syntactically valid *Mathematica* inputs. That number is so unimaginably large that descriptions in terms of the number of particles in the universe, or nanoseconds since the dawn of time, are woefully inadequate to describe it.

While this expression is a disaster practically, it has a certain conceptual appeal that made up for it hanging the judges’ machines. It expresses all one-liners of 80 or fewer characters. The expression itself is a member of the set that it describes.

Prizes were awarded for First-, Second-, and Third -Place entries. Third Place went to Yves Klett for this animation of a unit cell of the Miura map fold, an origamic structure originally proposed for deploying solar panels on satellites. The judges were particularly impressed with Yves’ cunning use of 2D typesetting and replacement rules to achieve a count of 137 characters.

Chris Ladroue took Second Place with this 136-character expression that assembles collages from random images pulled from *Mathematica*‘s built-in `ExampleData`. The judges liked Chris’ apt use of *Mathematica* constructs; the appealing visual output; and the fact that the expression, when applied to your favorite collection of images, could actually be useful in practice.

Which brings me to Stephan Leibbrandt’s elegant simulation of gravitational attraction, the First-Place winner of the One-Liner Competition. Animated output, simulation of a physical phenomenon, and clever use of a variable (*d*) to conserve characters impressed the judges. Stephan’s code reveals a deep familiarity with *Mathematica*‘s programming constructs, which enabled him to pack a complete physics simulation into just 138 characters.

There are yet more intriguing one-liner entries that space does not permit me to share. You can see all of them by downloading the Computable Document Format (CDF) file below. If you’re inspired to write your own one-liners, send them to one-liner@wolfram.com, and if interesting submissions come in, I’ll share the best of them in a future post.

Download the CDF file of all One-Liner Competition submissions.

## 5 Comments

I enjoyed the onelines really, they will become learning material in tthe next semester, thank you! A fwremarks:

11 should be turned around to see the duck.

12,21 does not seem to work

15,16, 21 Need Combinatorica

18 is dangerous, keeps speaking after quitting

25-27 are dangerous

Turning to the server makes a program rather slow

Thanks for posting, Chris. This has to rank as the best-ever Mathematica contest….

Inspirational! Though it would be interesting to see a companion category comprising a succinct explanation of how the code works — I suspect the character count there would average at least a factor of 10 higher :-)

15 and 16 miss tree with depth n-1.

17 miss some graphs.

Why don’t use the number of nodes in the expression (LeafCount) instead of the number of characters (StringLength)?

To Math: It is not true that 15 misses certain trees. You should interpret the results as ordinary trees, not rooted trees. By Cayley’s formula, there are n^(n-2) of them, and the code finds them all. The same remark applies to 16 and 17.