What is code golf?

Asked

Viewed 614 times

7

Looking at the tags on the site, I come across the tag , I read the brief explanation:

code-golf
Use this tag when only when the question has a relation irrefutable to Code Golf Code Competition. Take great care to use this tag as this is an easy theme to have questions of very low quality. Code Golf is a recreational competition of programming in order to solve a specific problem in the smallest number of bytes, characters or with some kind of code restriction source.
Source: /tags/code-golf/info

And I’d like to know:

  • What is this competition?
  • What a competition problem it would be Code Golf?
  • Example of a problem resolution Code Golf?
  • 5

    I’m wondering if the question better be here or at the finish line

  • 5

    Codewar that’s it.

2 answers

6


Definition of

Code Golf is a competition to solve a specific problem in the smallest number of bytes or lines of code.

The term code golf is derived from the similarity of its objective with that of conventional golf, where participants seek to achieve the lowest possible score... While conventional golfers are trying to minimize the amount of strokes needed to complete the match, the code golfers are striving to reduce the number of bytes of their algorithms.1

Programming puzzles (problems) need to be solved (usually) with some restriction or special condition. In this competition you can use any available tool, as long as it does not go against the rules said in the post.


Examples

Build a digital clock in Conway’s Game of Life

See a prelude to the post:

Your task is to build a Game of Life simulation that represents a digital clock:

Objectives

  • The clock displays the hours and minutes in decimal (12:00, 3:59, 7:24)
  • The standard is periodic, and the state is accompanied without any external interaction.
  • The minutes update is at regular intervals
  • The digits are visible and clearly distinguishable.
  • The digits update is in place and should appear next to each other

Scoring

Your program will be scored on the following things in order (with lower criteria acting as tiebreakers for higher criteria):

  • Size of the bookbinding box
  • Speedier execution
  • Initial count of living cells
  • First to post

Final result:

Result

Via browser for you to see working too.


It was just a bug

Another golf code, a little different, the goal was to be able to develop an algorithm that printbake on the screen, exactly like the text below:

1        2        3        4        5        6        7        8        9        0
1       2       3       4       5       6       7       8       9       0
1      2      3      4      5      6      7      8      9      0
1     2     3     4     5     6     7     8     9     0
1    2    3    4    5    6    7    8    9    0
1   2   3   4   5   6   7   8   9   0
1  2  3  4  5  6  7  8  9  0
1 2 3 4 5 6 7 8 9 0
1234567890
1 2 3 4 5 6 7 8 9 0
1  2  3  4  5  6  7  8  9  0
1   2   3   4   5   6   7   8   9   0
1    2    3    4    5    6    7    8    9    0
1     2     3     4     5     6     7     8     9     0
1      2      3      4      5      6      7      8      9      0
1       2       3       4       5       6       7       8       9       0
1        2        3        4        5        6        7        8        9        0

The accepted answer was given using a specific language for code golf stack-based. It was this one below, using only 13 bytes:

17F9ÝÀN8αð×ý,

Simple and in very few lines has been solved. You can see how the result here.

Explanation below:

17F            # para N em [0 ... 16] faça
   9Ý          # empurre de [0 ... 9]
     À         # virar esquerda
      N8α      # computa diferença absoluta entre N e 8
         ð×    # empurre esse tanto de espaços
           ý   # mescla a lista de dígitos com a seqüência de espaço como separador
            ,  # print

All these and many others code golf may be found in the specific community of the SE in Programming Puzzles & Code Golf.

-4

Follow the answer:

"Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that implements a given algorithm. Golf code should not be confused with sizecoding, a contest to achieve the lowest binary executable code. The golf playback code is known as "golf scripting". Code golf tournaments can also be named with the programming language used (e.g., Perl golf)"

Source: wikipedia
Example: www.code-golf.com/

  • 3

    This link may be a good suggestion, but your reply will not be valid if one day the link crashes. In addition, it is important for the community to have content right here on the site. It would be better to include more details in your response. A summary of the content of the link would be helpful enough! Learn more about it in this item of our Community FAQ: We want answers that contain only links?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.