What is golf?

6

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

  

code-golf
  Use this tag when only when the question has a relation   irrefutable to the Code Golf code competition. Be very careful when   use this tag, as this is an easy topic to have   very low quality. Code Golf is a recreational   programming with the intention of solving a specific problem in the smallest   number of bytes, characters or with some kind of code restriction   Source: link

And I would like to know:

  • What is this competition?
  • What would a Golf Code Competition be?
  • Example of a problem resolution Code Golf ?
asked by anonymous 20.07.2017 / 19:55

2 answers

5

Definition of

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

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

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

Examples

Building 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 pattern is periodic, and the state is tracked without any external interaction.
  •   
  • 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
  •   

Score

     

Your program will be punctuated in the following things, in order (with lower criteria acting as tie breakers for higher criteria):

     
  • Binding box size
  •   
  • Faster execution
  •   
  • Initial live cell count
  •   
  • First to post
  •   

Final result:

Via browser for you to see working as well.

It was just a bug

Another code golf, a little different, the goal was to develop an algorithm that print on the screen, just 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 response was given using a specific language for golf stack-based. It was this below, using only 13 bytes:

17F9ÝÀN8αð×ý,

Simple and very few lines have been solved. You can see how the result here is.

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 several other golf codes can be found in the specific SE community in Programming Puzzles & Code Golf .

    
20.07.2017 / 20:24
-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 smaller binary code executable.The golf breeding code is known as "golf scripting." Golf golf tournaments can also be named with the programming language used (eg Perl golf) "

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

    
20.07.2017 / 20:16