Unlike most Stack Exchange sites, answers here are typically easier to write than questions. However, there are a few things that every answer needs to include, and a couple of criteria they should meet.
We have a standard format for answers, which you can get hold of in 2 main ways.
If your language is on Try it online!, you can write up your solution in the Code section on Try it online! (commonly referred to as TIO), click the "Link" button at the top of the page and Copy-Paste the test in the "Code Golf submission (Stack Exchange)" field.
Alternatively, the standard formats are, in Markdown:
For [tag:code-golf] challenges:
# [<Language Name>][1], <length> bytes
```
<code>
```
[Try it here!][2]
<explanation>
[1]: <link to language page>
[2]: <link to an online testing environment>
For other challenges:
# [<Language Name>][1], <score>
```
<code>
```
[Try it here!][2]
<explanation>
[1]: <link to language page>
[2]: <link to an online testing environment>
Your answer should, at the bare minimum, include the following:
- The language name
- Your score, as defined by the challenge
- The code you are submitting
Your answer should not include:
- Promotions or links unrelated to the challenge
- Spam
- Language such as "Hi", "Thanks for the challenge" or other chatty language
Your code should:
- Make a serious effort at winning. This doesn't mean that you have to have the shortest code in a [tag:code-golf] challenge to participate, but it does mean you shouldn't post code with long variable names, unnecessary whitespace and more
- Complete the task in the question. If the question asks you to print
Hello, World!
and your code does anything other than printHello, World!
, it is not a valid answer. Make sure that you handle all the test cases included in the question. - Not break any of the standard loopholes
We allow any languages to be used on the site, so long as you can provide a working interpreter. A lot of people decide to create their own languages specifically designed for code golf, leading to the rise of languages such as Golfscript, CJam, Jelly and others.
Don't worry about these. If you prefer to golf in a language you're more familiar with, please, use that language, and don't care about how long it is. Languages such as Java are generally going to be more competitive with similar languages (e.g. C#) rather than with golfing languages, and so we prefer to consider [tag:code-golf] challenges as competitions within languages. So 05AB1E answers try to compete with other 05AB1E answers and other golfing languages, while Java answers try to compete with other Java answers and with languages comparable to i.
Some languages use characters outside of the standard ASCII range. Often, these use custom code pages to encode their answers instead of the standard Unicode table. If you have any doubts or concerns, don't hesitate to leave a comment or check out our https://codegolf.meta.stackexchange.com/questions/10145/how-to-count-bytes-faq
The easiest way to get started is to just start! Head over to the challenges page and choose one you like the look of. Fire up your favourite code editor/IDE/whatever you use to code, and start working on a solution to the challenge. Once you've got a working program, post it as an answer. Some things to help you:
- If the challenge includes a bunch of test cases, setting up a testing environment where you can quickly check that your code still works for each input after any changes is a smart way to keep your answer valid
- The https://codegolf.meta.stackexchange.com/questions/11924/new-users-guides-to-golfing-rules-in-specific-languages is likely to contain specific examples, rules and details for competing in [tag:code-golf] challenges for your favourite language.
- [tag:tips] pages will likely have ways you can golf down your answer. Almost every language under the sun has a "Tips for golfing in language" page, so searching for it (add your language name after the "in" in the search bar) will most likely help you save some bytes.
- Avoid the standard loopholes. They were funny in 2011, but the site now strives towards good quality answers.
- The standard Input and Output methods list various different ways you can take input and output
- Note that inputting via a variable ("The input is in variable
s
") is not a permissible method of input
- Note that inputting via a variable ("The input is in variable
- Programs must be full programs or functions, not snippets
- Don't worry about not being the shortest answer there. Other users are more than willing to suggest golfing opportunities and ways you can improve your solution
For more questions about answering, check out the "How to Answer" help pages or browse the [meta-tag:answers] tag on Meta.
- https://codegolf.meta.stackexchange.com/questions/202/where-to-find-an-online-testing-environment-for-specific-programming-languages
- https://codegolf.meta.stackexchange.com/questions/10145/how-to-count-bytes-faq
- https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default
- https://codegolf.meta.stackexchange.com/questions/11924/new-users-guides-to-golfing-rules-in-specific-language
- https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods
- https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet
- Try it online!
- "How to Answer" help pages