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
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.
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 .