Code Golf and Perl Golf
Abstract
Code golf is the game of solving a programming problem in the fewest characters (or bytes) of source code. Like golf, the lowest score wins. It took its name from Perl in 1999, when Greg Bacon called the shortest-answer threads on comp.lang.perl.misc “Perl Golf”. Organised tournaments followed in 2000, a Stack Exchange site in 2011, and programming languages designed for nothing but winning. The habit is older than the name: a Danish coding manual from 1962 already warned that writing with the fewest possible instructions was “a time-consuming sport”. In 2019 cryptographers used golfed programs as evidence in an argument about a Russian cipher standard.
The Sport Before the Name
In September 1962 Regnecentralen in Copenhagen published the third edition of its textbook for the GIER computer, Lærebog i Kodning for GIER, by Christian Andersen and Christian Gram. On page 104, after showing three different programs for the same exercise, the authors explain that they only did it to show off different instructions. It was not, they write, to encourage the reader to rewrite programs “to save a couple of cells. It is a time-consuming sport to code with the least possible number of instructions.”
In the early 1960s memory was the scarce resource, and saving words of core had real value. The manual’s point was that past a certain point the saving costs more programmer time than it is worth. Code golf keeps the sport and drops the economics: it counts characters of source text, not machine words, and nobody pretends the result is useful.
The theoretical version of the game has its own branch of mathematics. The length of the shortest program that produces a given output is its Kolmogorov complexity, named after Andrey Kolmogorov. Kolmogorov complexity is uncomputable in general; a golfer only needs a shorter program than the other players.
Perl and the Name
Perl suited the game. Its syntax lets almost every punctuation character mean something, it has many ways to express the same thing, and it borrows default variables that let a program omit most of what other languages make explicit. Perl’s culture already rewarded cleverness. Randal Schwartz started the JAPH tradition around 1988: short, deliberately cryptic Perl programs that print “Just another Perl hacker,” used as Usenet signatures. The Perl Journal ran an Obfuscated Perl Contest from 1996 to 2000, one of whose categories was the best program that fit in a four-line signature. Andrew Savige, who compiled a history of this side of Perl in 2002, dated the playing of golf to Wall and Schwartz around 1990.
The best-known early short Perl program had a political payload. On 9 March 1995 Adam Back posted an implementation of RSA encryption in five lines of Perl (it called out to the Unix calculator dc for the big-number arithmetic). Under US export rules, strong cryptography counted as a munition, so the program was an export-controlled weapon small enough to use as an email signature. Other programmers shortened it to three lines, which went onto T-shirts and, according to Back’s page, into at least three tattoos, and then to two:
print pack"C*",split/\D+/,`echo "16iII*o\U@{$/=$z;[(pop,pop,unpack"H*",
)]}\EsMsKsN0[lN*1lK[d2%Sa2/d0<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<J]dsJxp"|dc`Law professor Peter Junger obtained a written statement from the Commerce Department that the program must not be exported. The story belongs to the cypherpunks and the crypto wars; for golf it established the page title Back gave the collected versions, “The quest for the most diminutive munitions program”.
The name came four years later. On 28 May 1999, in a comp.lang.perl.misc thread titled “Re: Incrementing a value in a slice”, Greg Bacon described the familiar threads in which each poster tried to beat the previous answer by a few characters as Perl Golf. The analogy stuck because it matched the scoring: fewest strokes wins.
Tournaments
On 7 July 2000 Uri Guttman announced the “First Annual Perl Golf Apocalypse” on the Fun With Perl mailing list, for the fourth Perl Conference in Monterey that month. Ten teams of up to three Perl programmers got one computer each and nine problems, called holes, with five to seven minutes per hole. A correct answer earned one point, the three shortest correct answers six, five and four more, and the three earliest correct answers three, two and one. After four holes the five lowest-scoring teams were cut, as in a real golf tournament. Execution speed did not count. A Perl script judged the entries, and Chip Salzenberg and Chris Nandor did live commentary.
The game moved to the Fun With Perl list and a dedicated golf list, where tournaments ran for days rather than minutes and anyone could enter by email. Savige kept a mock “Career Money Leaders” table in golf-tour style, awarding imaginary prize money by placing. His November 2002 update covered thirteen tournaments since December 2001 and put Ton Hospel first, ahead of Rick Klement and Eugene van der Pijll. In the tournament that month Klement and Stephen Turner tied on 54.559 points, the first shared win.
Servers and Stack Exchange
Mailing-list tournaments needed a referee to run every entry. Golf servers automated that: a player submits code, the server runs it against hidden test cases and ranks it by length. The longest-lived is Anarchy Golf (golf.shinh.org), started by the Japanese programmer Shinichiro Hamaji in 2007. As the name says, it is deliberately casual. Anyone may post a problem, joke problems are welcome, and after a deadline all solutions are published so players can learn each other’s tricks. When a Perl golfer recommended it on Fun With Perl in 2011, that disclosure was the feature he singled out. By September 2026 the server accepted 116 languages and had published more than 1,800 problems.
In January 2011 Stack Exchange opened a site for programming puzzles and code golf. Its first question, posted on 27 January 2011, asked for the most obscure Perl program printing “Just another Perl hacker”. The site left beta on 23 February 2016 and now runs under the name Code Golf. By 2026 it held about 14,600 questions and 219,000 answers.
A site where anyone can answer in any language needed rules on what counts. In February 2014 its meta site started a list of “loopholes that are forbidden by default”, which by 2026 had 50 entries and more than 400 votes. The top-voted entries ban reading the challenge too literally, fetching the answer from the internet (for example, by downloading the question page), and inventing a language whose single built-in command solves the challenge.
code.golf, an open-source site written in Go under the MIT licence, took the other route of competitive ranking. It scores solutions in bytes or characters on per-language and global leaderboards, and supports more than 90 languages.
Languages Built to Win
Once every language could compete, some players built languages for the purpose. GolfScript was released on 13 December 2007: a stack-based language on top of Ruby in which single characters stand for whole operations such as map, join or array size. It was added to Anarchy Golf the next day as the server’s 53rd language.
The Stack Exchange site produced the successors. In 2014 the user aditsu released CJam, which borrowed heavily from GolfScript, and isaacg developed Pyth, whose prefix syntax suited short programs. In December 2015 Dennis Mitchell started Jelly, which drew on APL, J and CJam and led many leaderboards for years. Stax (2017) introduced compressed string literals, which later golfing languages adopted.
Newer ones such as Vyxal use their own single-byte character sets, so every byte value is a printable command, and most commands are overloaded to do different things for numbers, strings and lists. The result is unreadable by design. code.golf keeps separate leaderboards per language, so a Python golfer competes with other Python golfers rather than with Jelly.
The size-limited intros of the demoscene are the machine-code cousin of the same instinct, and esoteric languages and the International Obfuscated C Code Contest share its audience and its humour.
Golf as Evidence
Two Russian cryptographic standards, the hash function Streebog and the block cipher Kuznyechik (standardised as GOST R 34.12-2015), use the same 256-byte substitution table, called π, whose designers said it had been generated at random. Alex Biryukov, Léo Perrin and Aleksei Udovenko showed in 2016 that it had a hidden algebraic structure instead.
To make the case in a form anyone could check, a challenge went up on the Code Golf site on 7 June 2019 titled “Proving that a Russian cryptographic standard is too structured”. The argument: a random permutation of 256 bytes needs about 1,684 bits to write down, so a program that reproduces π in far fewer bits is evidence that π is not random. Golfers responded with a 78-byte x86-64 machine-code answer, a 139-byte C answer and a 58-byte answer in Stax (464 bits). In a paper at ASIACRYPT 2019 with Xavier Bonnetain and Shizhu Tian, and on his web page, Perrin used short implementations to bound the probability that a random table would be as simple as π: below 2^-556 based on a 161-character C program, and below 2^-1219 based on the Stax answer from the Code Golf site.
📚 Sources
- Andersen, Christian & Gram, Christian: Lærebog i Kodning for GIER, vol. I, 3rd ed., Regnecentralen, Copenhagen, September 1962, p. 104 (scan, Danish Datamuseum)
- Code golf, Wikipedia
- Savige, Andrew: “The history of the lighter side of Perl culture”, perl.packrats list, 3 November 2002
- Just another Perl hacker, Wikipedia
- Back, Adam: “export-a-crypto-system sig” (RSA in Perl, with Junger’s Commerce Department ruling)
- Back, Adam: “The quest for the most diminutive munitions program” (versions from 9 March 1995)
- Bacon, Greg: “Re: Incrementing a value in a slice”, comp.lang.perl.misc, 28 May 1999 (as cited by Wikipedia)
- Guttman, Uri: “ANNC: Perl Golf Apocalypse”, Fun With Perl list, 7 July 2000
- Perl Golf Apocalypse, Wikipedia
- Savige, Andrew: “Career Money Leaders Update”, perl.golf list, 19 November 2002
- Anarchy Golf (golf.shinh.org)
- Fish, Shlomi: “New Golf Server - http://golf.shinh.org/”, Fun With Perl list, 26 December 2011
- Hamaji, Shinichiro: “Code Golf” (slides on Anarchy Golf)
- Code Golf Stack Exchange: first question, “Just Another Perl Hacker” (27 January 2011); site dates and totals from the Stack Exchange API (queried September 2026)
- “Congratulations, you’re graduating!”, Code Golf Meta, 23 February 2016
- “Loopholes that are forbidden by default”, Code Golf Meta, 22 February 2014
- code.golf: About
- GolfScript home page (release notes, December 2007)
- Timeline of golfing languages, Esolang wiki
- Mitchell, Dennis: Jelly (GitHub repository, created December 2015)
- Perrin, Léo: “Proving that a Russian cryptographic standard is too structured”, Code Golf Stack Exchange, 7 June 2019
- Perrin, Léo: “Disproving a Coincidence with Code Golf”
- Bonnetain, Xavier; Perrin, Léo & Tian, Shizhu: “Anomalies and Vector Space Search: Tools for S-Box Analysis”, ASIACRYPT 2019, LNCS, doi:10.1007/978-3-030-34578-5_8
- Biryukov, Alex; Perrin, Léo & Udovenko, Aleksei: “Reverse-Engineering the S-Box of Streebog, Kuznyechik and STRIBOBr1”, EUROCRYPT 2016 (IACR ePrint 2016/071)