Hot answers tagged

423

Interpreting the challenge too literally That is, if the challenge says "write a function that, given a number n, returns the n-th prime", posting something equivalent to: function f($n) { return "the $n-th prime"; }


350

Fetching the desired output from an external source This includes doing an HTTP request to fetch the page with the question and extracting a solution from that page. This was mildly amusing back in 2011, but now is derivative and uninteresting.


300

Using a made-up language specifically designed for the challenge This includes any language with commands that "do whatever I choose them to do". Claiming that your answer is written in "MyOwnLanguage", where the command x means "read a sequence of numbers, split them into groups of three, and print the last numbers of those groups where the second number ...


219

Using lots of spaces to "hide" code out of bounds, especially in underhanded questions. This isn't very clever or tricky, in my opinion, and yet wins all too often. Example: #include <stdio.h> #include <time.h> #include <stdlib.h> int main() { srand(time(NULL)); // Make sure to seed rand so it's VERY random, we want to make super ...


163

Outsourcing the real answer I still did not see people using this thing here in serious answers (just in some jokes ones), but already saw it being used seriously elsewhere. To circumvent restrictions and rules in the question (normally size), the answerer writes a small program that downloads the real program from elsewhere and then compiles and runs it. A ...


159

Using the program name to store data without counting those bytes Example - this bash script prints Hello World! echo $0 Must be saved in a file called Hello World\! When using the filename to store data, add them as extra bytes to your solution similarly to any non-standard parameter. For example the correct byte count for the above is 7 (echo $0) + 13 ...


139

Hard-coding the output Unless the question is an obvious exception (the primary exception being those tagged kolmogorov-complexity), your program is expected to do work, not just print a pre-calculated result. If the question doesn't require input and so a solution which just prints the answer would seem to meet the spec, downvote the question rather than ...


136

Functions may output via their return value(s)


133

Fake random numbers Pretty much any underhanded challenge involving random numbers will have someone post this one: int getRandomNumber() { return 4; //chosen by fair dice roll. //guaranteed to be random. } It was funny when Randall Munroe did it 7 years ago, not anymore. It has been used in many challenges, some even multiple times in ...


124

Copying an (unimproved) answer from elsewhere If it's not your own work, and you can't even try enough to golf or improve it, then it's not yours to post.


119

Adding input or rules which weren't explicitly mentioned in the challenge There was recently a case where an answerer claimed Nowhere does it say the program can't (also) ask the user what the [result] is. Adding additional input or new rules, because they haven't been explicitly forbidden, can considerably simplify the challenge or make it trivial. ...


118

Zero-length quines Considering an empty program a quine was original in the 1994 IOCCC. Over two decades later, if you can answer a question with an empty program and that question is scored by length (e.g., code-golf) and is tagged as quine, source-layout or restricted-source, just notify the OP.


115

Functions may take input via function arguments


113

Consider the following pseudocode: if (x) { print "x is truthy"; } else { print "x is falsy"; } If it results in a runtime or a compile-time error then x is neither truthy nor falsy.


110

Cumbersome I/O formats Generally, allow flexible input and output formats. People want to write code to do your task of, say, composing permutations, not reading/writing numbers in a particular semicolon-separated format, or from a file, or with input validation. For code golf, it's annoying when most of your byte count is boilerplate, especially when other ...


100

Using a different name for something that's prohibited The title is not very clear, I know, but this is what it means: if a specific function is prohibited, someone can use a language where another term than "function" is used (for example "subroutine"), and then that user can claim that their submission is valid because they aren't using a function but a ...


93

Programs may take input via GUI prompts (This is for languages, for which this is the closest alternative to STDIN, like JavaScript's prompt(), Mathematica's Input[] or InputString[], Matlab's input() and VBScript's InputBox().)


91

Identical functions with different names For example, if + is forbidden, using num3 = num1.add(num2) or num3 = num1 num3 += num2 or num1++ or (GolfScript) ) etc.


89

Programs may output by displaying it on screen. This makes it possible to use languages like Vim script that can't print output directly to stdout. Example from this challenge: $ echo "This is a test line!" | vim - -c 'nm Q vEUWvEuWQ|norm Q' Will display: THIS is A test LINE! ~ ~ ~ ~ ~ Within a Vim session. I think that this way of displaying the ...


86

Using prior knowledge to circumvent other loopholes In particular, gaining an unfair advantage by inventing new languages for future challenges that are being sandboxed, discussed in chat, are your own, etc. For example, creating a language that solves a task specified in a sandboxed post with a one-character built-in (or even a zero-byte solution) should ...


84

Using a non-free language on a Cops and Robbers challenge Most (currently all) cops and robbers challenges consist of two parts: A cop submission, where a user posts some secret property of a program, such as its output, a scrambled version of the code, etc. Then, other users, the robbers, try to deduce the original program, or another program with the ...


82

Programs may output using their exit code... Exit codes are basically a return value for programs. If functions can output using their return values, it makes sense that programs should be able to do the same. Examples: Java exit codes C and C++ exit codes


80

Programs may take input via command-line arguments


77

Using MetaGolfScript MetaGolfScript is a family of programming languages. For example, the empty program in MetaGolfScript-209180605381204854470575573749277224 prints "Hello, World!". It is similar to using extra command line arguments, where they should also count as characters. And using the standard interpreter is likely using the program name to store ...


77

Functions may take multiple arguments via currying For some functional programming languages like Haskell this is actually necessary, because only single-argument functions exist and functions with multiple arguments are (somewhat transparently) implemented as curried functions. (The alternative would be to take a list or tuple of the values, but that is ...


76

Posting a code snippet instead of a complete answer Note: There is now a separate question covering this loophole in more detail. This is a issue mainly for code-golf, code-challenge and variants. Only in very few cases this seriously affects popularity-contest. The issue is when someone post a function, a method, an instruction or a code-snippet ...


76

Rules inferred from test cases Test cases are examples for people to check their understanding of the spec and the correctness of their code. They should not replace an explanation of how the output must relate to the input. (There are rare exceptions where it's straightforward, like a scaling ASCII art pattern.) Don't leave readers guessing as to what the ...


72

Explicitly disallowing or disadvantaging arbitrary (classes of) languages This has become much rarer recently, but the occasional challenge by a new user still includes it, so here as an answer to point them to. Disallowing arbitrary languages (or classes of languages, primarily things like "no golfing languages allowed") is not in the spirit of this ...


Only top voted, non community-wiki answers of a minimum length are eligible