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
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:
Via browser for you to see working too.
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.
I’m wondering if the question better be here or at the finish line
– bfavaretto
Codewar that’s it.
– Guilherme Lautert