fbpx
Wikipedia

Code golf

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem.[1][2] Code golf challenges and tournaments may also be named with the programming language used (for example, Perl golf).

Etymology edit

The term "code golf" is derived from the similarity of its goal 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 and game scoring systems. While conventional golf players try to minimize the number of club strokes needed to complete the course, code golfers strive to reduce the number of characters necessary to write the program.

History edit

The length of the shortest possible program that produces a given output (in any fixed programming language) is known as the Kolmogorov complexity of the output, and its mathematical study dates to the work of Andrey Kolmogorov in 1963. Code golf, however, can be more general than this, as it often specifies a general input-output transformation that must be performed rather than asking for a single output with no input.

Whilst the term "code golf" was apparently first used in 1999 with Perl,[3] and later popularised through the use of Perl to write a program that performed RSA encryption,[4] a similar informal competition is known to have been popular with earlier APL hackers. The challenging nature of aggressively optimizing for program size has itself long been recognized; for example, a 1962 coding manual for Regnecentralen's GIER computer notes that "it is a time-consuming sport to code with the least possible number of instructions" and recommends against it for practical programming.[5] Today the term has grown to cover a wide variety of languages, which has even triggered the creation of dedicated golfing languages.

Dedicated golfing languages edit

Several new languages have been created specifically with code golfing in mind. Examples include GolfScript, Flogscript, Stuck, and Vyxal, which are Turing-complete languages that provide constructs for concisely expressing ideas in code. Because golfing languages compete for extreme brevity, their design sacrifices readability, which is important for practical production environments, and therefore they are often esoteric. Sometimes, however, a language is designed for a practical purpose but turns out to be suitable for code golf.

An example of GolfScript code to print 1000 digits of pi:[6]

;'' 6666,-2%{2+.2/@*\/10.3??2*+}* `1000<~\; 

This prints a string starting with "3141592653" followed by 990 more digits of pi.

Code golf websites include novel golfing languages created by users to win code golf challenges. Other popular languages include 05AB1E, Husk, Pyth, CJam and Jelly.

Types of code golf edit

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.

See also edit

References edit

  1. ^ Code Golf Stack Exchange. About code-golf. Retrieved 2021-12-21.
  2. ^ "Introduction to Code-golf | ASSIST Software Romania". Retrieved 2023-03-23.
  3. ^ 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.
  4. ^ Back, Adam. "RSA in 5 lines of perl". Retrieved 2011-01-10.
  5. ^ Andersen, Christian; Gram, Christian (1962). Lærebog i Kodning for GIER (PDF). Vol. 1 (3 ed.). Copenhagen: Regnecentralen. p. 104. Retrieved 2020-05-16.
  6. ^ "GolfScript Examples". Retrieved 2023-03-23.

External links edit

  • CodeGolf.StackExchange.com: Questions and answers on programming puzzles and code golf
  • Golf on the esoteric programming languages wiki
  • List of dedicated golfing languages

code, golf, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, find, sources, news, newspapers, books, scholar, jstor, september, 2021. This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Code golf news newspapers books scholar JSTOR September 2021 Learn how and when to remove this template message Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that solves a certain problem 1 2 Code golf challenges and tournaments may also be named with the programming language used for example Perl golf Contents 1 Etymology 2 History 3 Dedicated golfing languages 4 Types of code golf 5 See also 6 References 7 External linksEtymology editThe term code golf is derived from the similarity of its goal 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 and game scoring systems While conventional golf players try to minimize the number of club strokes needed to complete the course code golfers strive to reduce the number of characters necessary to write the program History editThe length of the shortest possible program that produces a given output in any fixed programming language is known as the Kolmogorov complexity of the output and its mathematical study dates to the work of Andrey Kolmogorov in 1963 Code golf however can be more general than this as it often specifies a general input output transformation that must be performed rather than asking for a single output with no input Whilst the term code golf was apparently first used in 1999 with Perl 3 and later popularised through the use of Perl to write a program that performed RSA encryption 4 a similar informal competition is known to have been popular with earlier APL hackers The challenging nature of aggressively optimizing for program size has itself long been recognized for example a 1962 coding manual for Regnecentralen s GIER computer notes that it is a time consuming sport to code with the least possible number of instructions and recommends against it for practical programming 5 Today the term has grown to cover a wide variety of languages which has even triggered the creation of dedicated golfing languages Dedicated golfing languages editSeveral new languages have been created specifically with code golfing in mind Examples include GolfScript Flogscript Stuck and Vyxal which are Turing complete languages that provide constructs for concisely expressing ideas in code Because golfing languages compete for extreme brevity their design sacrifices readability which is important for practical production environments and therefore they are often esoteric Sometimes however a language is designed for a practical purpose but turns out to be suitable for code golf An example of GolfScript code to print 1000 digits of pi 6 6666 2 2 2 10 3 2 1000 lt This prints a string starting with 3141592653 followed by 990 more digits of pi Code golf websites include novel golfing languages created by users to win code golf challenges Other popular languages include 05AB1E Husk Pyth CJam and Jelly Types of code golf editSome 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 See also editCode poetry Data compression Minification programming Perl pastimes Kolmogorov complexity Kata programming References edit Code Golf Stack Exchange About code golf Retrieved 2021 12 21 Introduction to Code golf ASSIST Software Romania Retrieved 2023 03 23 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 Andersen Christian Gram Christian 1962 Laerebog i Kodning for GIER PDF Vol 1 3 ed Copenhagen Regnecentralen p 104 Retrieved 2020 05 16 GolfScript Examples Retrieved 2023 03 23 External links editCodeGolf StackExchange com Questions and answers on programming puzzles and code golf Golf on the esoteric programming languages wiki List of dedicated golfing languages Retrieved from https en wikipedia org w index php title Code golf amp oldid 1189701789, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.