World Library  
Flag as Inappropriate
Email this Article

Code golf

Article Id: WHEBN0018891728
Reproduction Date:

Title: Code golf  
Author: World Heritage Encyclopedia
Language: English
Subject: Golf (1984 video game), Perl
Publisher: World Heritage Encyclopedia

Code golf

An example round of code golf running on, showing the problem expressed as a series of unit tests, special requirements for the round's problem, and a results graph (the "league") with a personal score.

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible code that implements a certain algorithm. Such tournaments may also be named with the programming language used (for example Perl golf).


Whilst the term was apparently first used in 1999 with Perl,[1] and later popularised through the use of Perl to write a program that performed RSA encryption,[2] similar informal competition was known to have been popular with earlier APL hackers and probably others. Today the term has grown to be applied to a wide variety of languages, which has even triggered the creation of dedicated golfing languages.


The term 'Code Golf' is derived from the similarity of its scoring system with that of conventional golf, where participants seek to achieve the lowest possible score, rather than the highest as is the standard in most sports & game scoring systems.

Dedicated golfing languages

Several new languages have been created specifically with code golfing in mind. The most well-known examples are GolfScript and Flogscript, both stack-based Turing-complete languages which provide powerful constructs for concisely expressing ideas in code. Golfing languages like GolfScript and Flogscript are generally considered to be esoteric, as useful applications other than for code golfing are very limited due to their limitations on overall speed, readability and function. Binary Lambda Calculus was designed to make Algorithmic Information Theory more concrete, but ends up serving the same purpose.

An example of GolfScript code to print 1000 digits of Pi:

`50<~\; #truncate for webpage purposes
 -> 3141592653589793238462643383279502884197169399375

Types of code golf

Some code golf questions, such as those posed on general programming sites, may not require implementation in a specific programming language. However, this limits the style of problems that it is possible for the problem designers to pose (for example, by limiting the use of certain language features). In addition, the creation of such 'open' questions has resulted in the design of code golf specific programming language dialects such as REBMU (a dialect of REBOL). Both online and live competitions may also include time limits.

Tournaments by language

See also

External links

  • Questions tagged with 'code-golf'
  • Questions and answers on programming puzzles and code golf
  • regular expression golfing: a fun variant to code golf


  1. ^ Greg Bacon (1999-05-28). "Re: Incrementing a value in a slice".  
  2. ^ Back, Adam. "RSA in 5 lines of perl". Retrieved 2011-01-10. 
  3. ^ "Anarchy Golf". 
  4. ^ "Just Another Golf Coding". 
  5. ^ "Shortening codes". 
  6. ^ "4clojure League". Retrieved 2011-07-24. While the primary purpose of is to teach Clojure "by doing", you may also choose to compete for the shortest solution. This is affectionately known as code golf: the lower your score the better, get it? If you choose to participate, we'll score your correct solutions based on the number of non-whitespace characters (and some more metrics in the future). We'll also provide a chart showing how you stack up compared to everyone else on the site. 
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.