请输入您要查询的百科知识:

 

词条 Code golf
释义

  1. History

  2. Etymology

  3. Dedicated golfing languages

  4. Types of code golf

  5. See also

  6. References

  7. External links

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

History

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,[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. Today the term has grown to be applied to a wide variety of languages, which has even triggered the creation of dedicated golfing languages.

Etymology

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 are trying to minimize the number of club strokes needed to complete the course, code golfers are striving to reduce the number of key strokes necessary to write the program.

Dedicated golfing languages

Several new languages have been created specifically with code golfing in mind. Examples include GolfScript and Flogscript, which are Turing-complete languages which 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:

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 have users constantly creating new and unique golfing languages to win code golf challenges.

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.

See also

  • Data compression
  • Perl pastimes
  • Code poetry

References

1. ^{{cite newsgroup | author = Greg Bacon | title = Re: Incrementing a value in a slice |message-id= 7imnti$mjh$1@info2.uah.edu | newsgroup = comp.lang.perl.misc | date = 1999-05-28 | url = https://groups.google.com/group/comp.lang.perl.misc/msg/7b97c434492c8d20 | accessdate = 2011-07-12}}
2. ^{{cite web | url = http://www.cypherspace.org/rsa/pureperl.html | title = RSA in 5 lines of perl | accessdate = 2011-01-10 | last = Back | first = Adam}}

External links

  • [https://stackoverflow.com/questions/tagged/code-golf 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
  • [https://esolangs.org/wiki/Category:Golfing_language List of dedicated golfing languages]

1 : Programming contests

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/10 14:42:29