Code golf
Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible interpreted code (not to be confused with binary Sizecoding) that implements a certain algorithm. Such tournaments may also be named with the programming language used (for example Perl golf).
History
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. A fully featured wiki has been implemented in 1287 characters of PHP.[3] Today the term has grown to be applied to a wide variety of languages, which has even triggered the creation of dedicated golfing languages. More systematic practical use of terse code is known as Spartan Programming.[4]
Etymology
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 include GolfScript, Flogscript, Pyth, and CJam which are all Turing-complete languages which provide powerful constructs for concisely expressing ideas in code. Golfing languages 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[citation needed]. 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:
;''
6666,-2%{2+.2/@*\/10.3??2*+}*
`50<~\; #truncate for webpage purposes
-> 3141592653589793238462643383279502884197169399375
An example of a Pyth program that calculates the nth Fibonacci number, where n is an inputted number:
eu,eGsGQU2
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
- A+, Ada, Arc, Asymptote, Awk, Bash, BASIC, bc, Befunge, Brainfuck, Burlesque, C, C#, C++, Clojure, COBOL, Common Lisp, Curry, Cyan, D, dc, DOS, Erlang, FerNANDo, fish, FlogScript, Forth, Fortran, GNU Assembler, Go, GolfScript, GolfScript2, goruby, Grass, Groovy, Haskell, Io, J, Java, Javascript, JVM, Kite, Lazy-K, GNU LilyPond, LMNtal, Logo, Lua, GNU m4, Maxima, Mind, Minus, MNNBFSL, Nemerle, Objective-C, Pascal, Pefunge, Perl, Perl 6, PHP, PostScript, Prolog, Python, QCL, R, REBOL, Ruby, Scala, Scheme, sed, Smalltalk, Tcl, Universal Lambda, Unlambda, VHDL, vi, wake, Whirl, Whitespace, x86, Xtal, Z80, zsh
- Ongoing
- Anarchy Golf (online)[5]
- JAGC (online)[6]
- Shortening codes at SPOJ (online)[7]
- Ongoing
- Clojure
- Ongoing
- 4clojure.com (online)[8]
- Ongoing
- K
- Ongoing
- Kona code golf (online)
- Ongoing
- PHP
- Ongoing
- phpGolf (online)
- Ongoing
- Perl
- Historical
- 2000, July: Perl Golf Apocalypse at Perl Conference 4.0, Monterey California.
- Historical
- Perl, PHP, Ruby and Python
- Ongoing
- CodeGolf (online)
- Ongoing
- Vim
- Ongoing
See also
External links
- StackOverflow.com: Questions tagged with 'code-golf'
- CodeGolf.StackExchange.com: Questions and answers on programming puzzles and code golf
- regular expression golfing: a fun variant to code golf
- ShortestWikiContest
References
- ^ Greg Bacon (1999-05-28). "Re: Incrementing a value in a slice". Newsgroup: comp.lang.perl.misc. Usenet: 7imnti$mjh$1@info2.uah.edu. Retrieved 2011-07-12.
- ^ Back, Adam. "RSA in 5 lines of perl". Retrieved 2011-01-10.
- ^ "Wik Wiki A Wiki in 1287 characters of PHP".
- ^ Spartan Programming, Jeff Atwood, Coding Horror, 08 Jul 2008
- ^ "Anarchy Golf".
- ^ "Just Another Golf Coding".
- ^ "Shortening codes".
- ^ "4clojure League". Retrieved 2011-07-24.
While the primary purpose of 4clojure.com 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.