There are a number of standard loopholes which experienced question-setters seek to explicitly close. However, inexperienced question-setters may unintentionally leave them open, or respondents may try to argue for contorted interpretations of the question in order to side-step attempts to close them.

The purpose of this question is to provide a repository of standard loopholes which may be assumed to be closed without the question-setter having to explicitly close them. The intention is that each answer shall contain one and only one loophole (to allow independent voting); and that the loophole described in any answer which is at +5 or above and has at least twice as many upvotes as downvotes may be taken to be deemed to be unacceptable to the community. A link to that answer may be provided in a comment to accompany a downvote and a flag.

Return to FAQ index

  • 105
    \$\begingroup\$ Loopholes are part of what makes the game interesting. Even common ones can be funny or clever, depending on context. If you find a loophole in an answer disinteresting, don’t vote for it, or vote against it. I don’t think we need a canonical list of fun things that you can’t do. (With the exception of Interpreting the challenge too literally below. That’s always boring. ;)) \$\endgroup\$ – Ry- Feb 27 '14 at 18:16
  • 12
    \$\begingroup\$ @minitech: And the countless variations of curl -L http://bit.ly/012foobar aren't? \$\endgroup\$ – Ilmari Karonen Mar 2 '14 at 14:59
  • 7
    \$\begingroup\$ @IlmariKaronen: Depends whether it’s actually clever. If you don’t find it clever, vote appropriately. As always. \$\endgroup\$ – Ry- Mar 2 '14 at 15:57
  • 3
    \$\begingroup\$ @minitech, there seems to be a strong consensus that the appropriate vote is "Low quality, delete". \$\endgroup\$ – Peter Taylor Mar 2 '14 at 22:56
  • 37
    \$\begingroup\$ "at least twice as many upvotes as downvotes" ... You can't see that until you have at least 750 rep on the site. Seems like the rules should be visible to everyone. \$\endgroup\$ – derobert Apr 14 '14 at 16:05
  • 5
    \$\begingroup\$ @derobert, I don't want to be seen to claim that a 105 vs 100 voting situation represents a clear community consensus, and I think that looking for a supermajority is the best way to avoid that. It's unfortunate that the score breakdown isn't visible to everyone, but I don't generally expect many low-rep users to visit meta. FWIW, the only current answer which doesn't have a supermajority is "Using comments to circumvent character requirements/restrictions" on +11/-6. \$\endgroup\$ – Peter Taylor Apr 14 '14 at 16:31
  • \$\begingroup\$ @PeterTaylor Ah. I'm surprised "Using the program name to store data" isn't one of them, considering the +26 comment on it. \$\endgroup\$ – derobert Apr 14 '14 at 16:51
  • \$\begingroup\$ @derobert, it's at +28/-4. Very puzzling. My best guess is that most of the people upvoting the answer agreed with the part of the comment which says that the filename should be counted towards the length of the program. \$\endgroup\$ – Peter Taylor Apr 14 '14 at 16:57
  • 2
    \$\begingroup\$ The condition for whether the loophole applies should probably be changed to +10 or +15. All of the answers are currently above the +5 mark due to the surge in popularity of this post. Perhaps it could be a moving window (all answers with a score of average of all answer scores / 2 or the score of the highest voted answer / 5 or something), but that would be pretty complicated. \$\endgroup\$ – Doorknob Apr 27 '14 at 21:24
  • 1
    \$\begingroup\$ It's nice that this is in the FAQ, but I can find no obvious way to get to the FAQ so that new users can see it. I don't think we should be downvoting users for breaking a rule they don't know about. The FAQ needs to be easily available to new users who get her via any means. \$\endgroup\$ – trlkly Jun 29 '14 at 12:34
  • \$\begingroup\$ When I say it is "no obvious way to get to the FAQ", I am referring to the fact that it does not seem to be linked in the Help dropdown itself nor mentioned in the Tour or Help Center pages. I know I only found out about this page after I saw a question that downvoted because of it. (And because it was mentioned explicitly in some questions, but those keep being removed.) \$\endgroup\$ – trlkly Jun 29 '14 at 12:46
  • \$\begingroup\$ While I agree with the intention of a list of standard loopholes, I think I have shown here that even the answers below are not clear cut \$\endgroup\$ – Alchymist Sep 9 '14 at 14:18

46 Answers 46


Generating a random stream of output when a specific output is required

For example, if a challenge requires you to output 4, you can't output an infinite stream of random digits, and say "4 is in there somewhere!" You must output 4, and no other number.

This is similar to this other loophole.

  • 23
    \$\begingroup\$ I would not consider this as a loophole. This just does not meet the specifications of the corresponding challenge and is therefore invalid. Why do you want to explicitly add this as a loophole? \$\endgroup\$ – flawr Jun 27 '16 at 8:23
  • \$\begingroup\$ +1, but it's essentially covered by meta.codegolf.stackexchange.com/q/8379/8478 if you consider the RNG's seed as part of the program's input. \$\endgroup\$ – Martin Ender Jun 27 '16 at 8:25
  • \$\begingroup\$ @MartinEnder Good point, I didn't think about that meta post. I don't think it hurts to have it explicitly stated here as well as on that post. \$\endgroup\$ – Mego Jun 27 '16 at 8:26
  • 1
    \$\begingroup\$ @Mego I think what is allowed or isn't should always be clear from the challenge itself. Can you provide an example where we need this loophole rule? (Where this is not alredy clear from the challenge itself?) Otherwise I think this is a tautology, which does not make any sense adding here. We could write a ton of others such as "loophole: if the output must be true you cannot output false" The challenge requiring you to output 4 does exactly imply that you cannot output any other number. \$\endgroup\$ – flawr Jun 27 '16 at 8:31
  • 3
    \$\begingroup\$ @flawr here, before I added the word "deterministically". \$\endgroup\$ – Leaky Nun Jun 27 '16 at 8:33
  • \$\begingroup\$ If you do not add deterministically your challenge really asks for the infinite monkeys solutions, which would be perfectly fine under these challenge rules. I can imagine that the loophole as it is now would restrain certain solutions for code-challenges or popularity-contests. I suggest rephrasing it, as it does not really catch the problem of LeakyNun's challenge. My suggestions: "Generating a random sream of output when specific output is required" with "For example, if a challenge requires you to output 4, you cannot output and infinite stream of random digits.". \$\endgroup\$ – flawr Jun 27 '16 at 8:42
  • \$\begingroup\$ @flawr I agree with your improved wording and have made the edit. \$\endgroup\$ – Mego Jun 27 '16 at 10:15
  • 4
    \$\begingroup\$ I still think that if the challenge requires you to output 4 and you output something like 8 7 1 2 4 3 5 6 you simply don't meet the specs \$\endgroup\$ – Luis Mendo Jun 27 '16 at 11:57
  • \$\begingroup\$ @LeakyNun, if this is really a problem with that question (and I agree with those who are saying that it isn't) then adding the word "deterministically" doesn't fix anything. If finding the desired output somewhere in the middle of a stream of junk meets spec then the stream can be generated deterministically for fewer characters than required to generate it randomly. \$\endgroup\$ – Peter Taylor Jun 27 '16 at 16:01
  • \$\begingroup\$ @LuisMendo Right, this is all in all quite similar to this loophole, so they could probably be merged? \$\endgroup\$ – flawr Jun 27 '16 at 17:42
  • 4
    \$\begingroup\$ @flawr I'd say it's not even a loophole, it's an answer that doesn't meet the specs \$\endgroup\$ – Luis Mendo Jun 27 '16 at 18:02
  • \$\begingroup\$ @LuisMendo I wouldn't agree with that, since you could argue that the program has a chance to get the correct result (and not "chance" as in "clearly invalid program produces correct output because cosmic rays cause a bit to be flipped at the right time"). Often there is a very reasonable likelihood of getting the right output by chance, so you'll see a lot of programs on the Anarchy Golf server using randomness, although usually to select a canned output (which AFAIK is already a loophole here). \$\endgroup\$ – Desty Jun 28 '16 at 15:20
  • 1
    \$\begingroup\$ I think this loophole description is too narrow. I suspect you also want something like 1. to be an invalid entry. It's a program which deterministically prints Graham's number in unary. It's followed by additional digits, but it's not simply a case of "Graham's number is in there somewhere": Graham's number appears right at the start, with nothing in between, and extra output at the end is generally considered to be valid. (Or should I post that as an answer? (: ) \$\endgroup\$ – hvd Jun 28 '16 at 20:47
  • \$\begingroup\$ @hvd I believe that is already covered by another loophole. I'd drop a link, but navigating this post on mobile is a nightmare. Look for "abusing number systems". \$\endgroup\$ – Mego Jun 28 '16 at 20:58
  • \$\begingroup\$ @Mego That doesn't appear anywhere on either of the two pages of answers here, and I cannot find that using Google either. Could it be a answer somewhere that has since been deleted? Or are you mixing it with "Abusing native number types to trivialize a problem"? That doesn't cover my idea. \$\endgroup\$ – hvd Jun 28 '16 at 21:06

Empty / Bare Output

Not sure on the best title but hopefully the examples show what I mean. Mainly targeting where the score is determined by the output. This results in very boring, but valid, answers which tend to get upvoted especially on pop-cons with no other answers.

An example: if the goal was to output the Mona Lisa as close as possible. Outputting a blank image should be considered a loophole.

Another Example: In a such as this one where score is determined by the most correct output. Always outputting false and claiming a score of 0 should count as a loophole.

  • \$\begingroup\$ This is already forbidden by our rules. Answers must make a serious attempt at competing. \$\endgroup\$ – Mego Jan 31 '16 at 4:58
  • 5
    \$\begingroup\$ Already mentioned in the help center. \$\endgroup\$ – Doorknob Jan 31 '16 at 4:59
  • \$\begingroup\$ I didn't think the "serious attempts" fully covered it because many of these types of answers can be considered "serious" attempts and still violate this loophole. I've reworded \$\endgroup\$ – Downgoat Jan 31 '16 at 5:00
  • 2
    \$\begingroup\$ Your edits so far only describe what is already forbidden by the serious attempt rule. \$\endgroup\$ – Mego Feb 2 '16 at 2:14
  • \$\begingroup\$ I think that if the empty output actually gives a good score, then it should not be considered a loophole. If it was actually a serious attempt (which means that it would actually give a good score), then that means that it's a flaw in the challenge, not the answer \$\endgroup\$ – MilkyWay90 Mar 17 '19 at 18:41

Outputting Unicode characters in challenges

If a challenge requires an image to be output, outputting a Unicode character instead is not acceptable. In challenges, the output should always be an image.

  • 7
    \$\begingroup\$ Disagree. If you're outputting say HTML+CSS, it seems just as valid to use a Unicode character as to use SVG, CSS or any other method to draw a circle, for instance. Of course, individual challenges can still ban unicode chars if they want. \$\endgroup\$ – Steve Bennett Jun 5 '17 at 5:46
  • \$\begingroup\$ @SteveBennett In challenges which say "output an image" (which is all graphical-output challenges), an output consisting of one or more Unicode characters is not acceptable because it is not an image (excepting those obvious exceptions where it is a textual encoding of an image). \$\endgroup\$ – Mego Jun 5 '17 at 5:48
  • 11
    \$\begingroup\$ Based on what definition of "image"? Is SVG an "image"? Is HTML? What about SVG that contains unicode characters? \$\endgroup\$ – Steve Bennett Jun 5 '17 at 5:53
  • 1
    \$\begingroup\$ @SteveBennett Now you're just splitting hairs. \$\endgroup\$ – Mego Jun 5 '17 at 5:54
  • 1
    \$\begingroup\$ No, I think you are. I'm saying all these things qualify as outputting an image, and you're (implicitly) saying that some of them don't - so I'm asking you where you're drawing that line. \$\endgroup\$ – Steve Bennett Jun 5 '17 at 5:55
  • \$\begingroup\$ @SteveBennett Here's a simple (but not perfect) test: if display (from the ImageMagick toolkit) can display it, it's an image. If not, then it's not. \$\endgroup\$ – Mego Jun 5 '17 at 5:57
  • \$\begingroup\$ That's a definition of an image file. \$\endgroup\$ – Steve Bennett Jun 5 '17 at 6:44
  • \$\begingroup\$ Also, from the documentation, a directory of image files would qualify, so...yeah imperfect. :) \$\endgroup\$ – Steve Bennett Jun 5 '17 at 6:45
  • 2
    \$\begingroup\$ It sounds like you really want to impose some kind of minimum resolution requirement. Are you trying to rule out programs that generate ascii-art graphics? Some video players (like mplayer/mpv) have ASCII-art video-output drivers, as well as the usual opengl, vdpau, X11, and so on. e.g. archive.oreilly.com/pub/h/4441. \$\endgroup\$ – Peter Cordes Jul 20 '17 at 17:39
  • 4
    \$\begingroup\$ Or are you really trying to rule out using just a couple characters, effectively taking major advantage of font glyphs instead of drawing pixels directly or with image-library functions? \$\endgroup\$ – Peter Cordes Jul 20 '17 at 17:41

Storing information in platform specifications

We often allow people to require certain qualities of the machine their answer is run on, (for example Operating System). However we should disallow requiring the program to be run on a certain specification to store information used for the challenge.

For example the language Nullary only has zero length programs instead deriving its source from the time since epoch. Similar languages could be created to exploit things such as monitor/terminal size, screen brightness, volume or even Operating System.

These types of answers should be disallowed.

  • \$\begingroup\$ I'm not sure about this one. For example, there could be languages where its interpreter only works properly on one operating system. \$\endgroup\$ – Okx May 3 '17 at 17:07
  • 3
    \$\begingroup\$ @Okx Its not forbidding specifing the platform, only drawing information from the platform to circumvent having to put it in the program. \$\endgroup\$ – Post Rock Garf Hunter May 3 '17 at 17:08
  • 1
    \$\begingroup\$ What I mean is, that the interpreter could act slightly differently on different operating systems (as, for example, it may not have some operating system specific function) therefore breaking answers. But about storing information that, I totally agree. \$\endgroup\$ – Okx May 4 '17 at 10:01
  • \$\begingroup\$ I think this would be better rephrased as creating an environment, and it goes together with having the output pre-stored in a file already (unless you actually have an os that has that stuff stored there by default) \$\endgroup\$ – Destructible Lemon May 8 '17 at 5:45
  • 2
    \$\begingroup\$ Hmm. There was a Bash answer to the "output any string as long as the program" that ran arch, which outputs i386 on the appropriate hardware. I found that pretty creative - not cheaty at all. \$\endgroup\$ – Steve Bennett Jun 5 '17 at 5:45

Exactly duplicating another answer

This specifically came up for me in a contest. In particular, this contest had a random component, so replicating a submission could allow one to win by luck.

In general, duplicate submissions are uninteresting, and do not add anything to any sort of contest, king of the hill, code golf or otherwise.

Importantly, even if the posters came up with the answers separately, duplicate answers should still be banned.

  • \$\begingroup\$ I don't think this really needs to be stated. It seems like in your challenge the duplicate poster was just unaware of the basic bots you had posted. \$\endgroup\$ – Chris May 7 '18 at 8:27
  • 2
    \$\begingroup\$ @Chris I'm not thinking of the situation that game up in my contest. I'm thinking of the potential exploit where someone just copy-pastes the leading answer. This is obviously not allowed, and so goes here, on the list of stuff that's obviously not allowed. \$\endgroup\$ – isaacg May 7 '18 at 8:38
  • 2
    \$\begingroup\$ Well, that's already on here ;) \$\endgroup\$ – Chris May 7 '18 at 8:59
  • \$\begingroup\$ @Chris The implication of that question seems to be that it's about copying a solution from another source, e.g. not stack exchange. But more importantly, I'm saying they should be banned even if they were invented separately, as can happen in KotH challenges. \$\endgroup\$ – isaacg May 7 '18 at 9:02
  • 5
    \$\begingroup\$ The current consensus actually allows duplicate answers. \$\endgroup\$ – Laikoni May 7 '18 at 10:05
  • \$\begingroup\$ @Laikoni That answer isn't specific to KotH \$\endgroup\$ – isaacg Aug 28 '18 at 21:37

Features added to a pre-existing language, after the challenge was posted

See Covfefify a string. This might been solved in 45 bytes using:

select covfefify(:a) from dual@datadictionary

This isn't the same as these pre-existing loopholes:

  • Using a made-up language specifically designed for the challenge: it is not a made-up language; it is a programming language in use.
  • Using prior knowledge to circumvent other loopholes: it is not made up.
  • Creating a new compiler for a language after a challenge was posted: it is not creating a new compiler, but extending an existing grammar.

None of these covers the scenario where an existing language is extended by a new function.

  • 6
    \$\begingroup\$ It's the same as creating a new compiler. It's not a compiler, but it's still adding a feature after the challenge. \$\endgroup\$ – Rɪᴋᴇʀ Jun 4 '17 at 15:05
  • \$\begingroup\$ And was this what you meant? I tried to clarify a bit. \$\endgroup\$ – Rɪᴋᴇʀ Jun 4 '17 at 15:07
  • \$\begingroup\$ Hi @Riker, yes, this covers the loophole I think. I now find it impossible to perform fraud using this loophole. \$\endgroup\$ – Guido Leenders Jun 4 '17 at 17:13
  • 1
    \$\begingroup\$ I would argue that the bytes added or changed in adding a language feature are part of your byte count for the challenge. While it is unlikely to be small, maybe someone has written a golfing language in a golfing language. \$\endgroup\$ – David G. Jan 8 at 12:58

Using non-programming languages (irrelevant to "golfing" languages)

Not to be confused with golfing languages. This loophole definitely has nothing to do with golfing languages.

A purported programming language should be accepted as such if and only if it is capable of addition of natural numbers and primality testing of natural numbers.

Follow the link for a more complete definition.

Related meta post: Do submissions have to be answered with a programming language?

That is, to use something that was not considered a programming language in our criteria. I don't think this was really forbidden before. So here is something everybody can vote.

If this is forbidden, you cannot use languages such as HQ9+ or Text in any challenges. You have to use the less familiar Help, WarDoq! or /// instead, in most cases, or simply cannot compete if your code involves some more creative features that nobody invented a rule-compliant counterpart of the language having them. In this way we could possibly encourage users to program, not to find something "creative" or obscure.

If not, you can use any language as long as the person who created a compiler or interpreter calls it a language, unless forbidden by other per site or per question rules. If there is a good reason to add this restriction (such as in some cops-and-robbers questions), you should specify that explicitly. If the term "programming language" is mentioned somewhere, by default, it refers to languages satisfying our criteria.

  • 5
    \$\begingroup\$ This was always forbidden (at least as long as we had criteria for what constitutes a programming language), but it doesn't hurt to have it restated here IMO. \$\endgroup\$ – Mego Jan 13 '16 at 14:48
  • \$\begingroup\$ I once saw an answer that was an Excel formula. Would this invalidate that answer? \$\endgroup\$ – micsthepick May 16 '16 at 6:47
  • \$\begingroup\$ @micsthepick No. Added the definition to this post. \$\endgroup\$ – jimmy23013 May 16 '16 at 7:38
  • \$\begingroup\$ Thank you for the clarification. \$\endgroup\$ – micsthepick May 16 '16 at 7:49
  • \$\begingroup\$ Why? Http is not programming language, but do ypu think this answer is bad? \$\endgroup\$ – Qwertiy May 17 '16 at 12:58
  • 1
    \$\begingroup\$ @Qwertiy I personally don't like banning this. But before this post people were already assuming they were forbidden. \$\endgroup\$ – jimmy23013 May 17 '16 at 15:07
  • 3
    \$\begingroup\$ @Qwertiy, yes. This is a site for programming contests. Answers should be programs, not data. Answering with HTTP headers on the basis that you can view the output in Firefox makes no more sense than answering with a Word document on the basis that you can view the output in Word. \$\endgroup\$ – Peter Taylor Jun 28 '16 at 11:21
  • \$\begingroup\$ I think answers which use things like HQ9+ should be allowed but not compete. \$\endgroup\$ – Mega Man Sep 11 '16 at 11:14
  • 2
    \$\begingroup\$ HTML+CSS would fail this definition, but they often make interesting solutions to challenges. \$\endgroup\$ – Steve Bennett Jun 5 '17 at 5:48
  • \$\begingroup\$ There should be a mention here that the linked meta post entirely supersedes this. \$\endgroup\$ – Ørjan Johansen May 31 '18 at 0:11
  • \$\begingroup\$ I don't think that meta post supersedes this. The score (+35/-25) is not high enough to be considered consensus, but if this were to get 15 more upvotes I don't see why that wouldn't mean that the community has changed its mind about whether to allow solutions in non-programming languages. \$\endgroup\$ – pppery Sep 22 '19 at 2:14

Empty answers to questions requiring an interpreter

If a question asks for an implementation of a language or a machine, the language/machine itself is a terribly boring answer. In particular:

  1. "Simulating" a machine on that machine by accepting the initial state as its own initial state and producing the final state as its own final state.

  2. "Interpreting" a language using an empty program that "accepts input" as the rest (i.e., all) of what's fed to the interpreter.


Using inconsistent I/O formats

For example, for a hypothetical challenge where the output could only ever be two or eleven, submitting the python program

lambda x:print"11"

and claiming that it outputs in unary for certain inputs and in decimal for other inputs should not be allowed, even though outputting in either of these bases is usually allowed.

Likewise, for a challenge, submitting the python function

lambda i:type(i)is str

and claiming it takes input as a singleton list for inputs that match the challenge's criteria and as a string otherwise shouldn't be allowed, even though taking input as a singleton list is usually allowed.

  • 5
    \$\begingroup\$ Is this an issue which has actually come up, or a pre-emptive strike against a hypothetical answer? \$\endgroup\$ – Peter Taylor Oct 14 '19 at 8:16
  • 3
    \$\begingroup\$ It hasn't been a problem as far as I know, but I figured it might be best to have it written down either way. Maybe it would have been better to wait until it actually was a problem, but this feels like the kind of rules lawyering that someone would come up with soon enough and that wouldn't be all that interesting even the first time. \$\endgroup\$ – Sara J Oct 14 '19 at 10:36

Precomputing data (including compile-time computation) to achieve lower runtime in challenges

Consider a challenge where solutions must print out as many Fibonacci numbers as possible within a certain time limit. A C++ solution might look like this:

#include <iostream>
using namespace std;
int main() {
    int a = 1, b = 1, c = 0;
    while(true) {
        cout << b << endl;
        c = b;
        b = a+b;
        a = c;
    return 0;

This is a perfectly valid solution. All of the computation is done at runtime, and its score can be determined fairly.

Now, consider the following solution (adapted from this SO answer):

#include <iostream>
#include <cstdint>
using namespace std;
template<uintmax_t N>
struct fibonacci : integral_constant<uintmax_t, fibonacci<N-1>{} + fibonacci<N-2>{}> {};

template<> struct fibonacci<1> : integral_constant<uintmax_t,1> {};
template<> struct fibonacci<0> : integral_constant<uintmax_t,0> {};

int main() {
    const uintmax_t max = 10000ull;
    cout << fibonacci<1>() << endl;
    cout << fibonacci<2>() << endl;
    cout << fibonacci<3>() << endl;
    // ...
    cout << fibonacci<10000>() << endl;
    return 0;

This program (compiled with g++ -o template_fib template_fib.cpp -std=c++14 -ftemplate-depth=12257) shifts the burden of computing the 10000 Fibonacci numbers to the compiler. At runtime, it's simply outputting 10000 constant values.

Such solutions which attempt to cheat the scoring system by doing all of the computation during a time where the clock is not running should either not be allowed, or be required to count their compilation time into their score.

  • \$\begingroup\$ Looks like a bad question to me. In most cases you could just also count the compile time for all submissions. But in your example, someone could just post a PHP or /// answer with the required output in it. \$\endgroup\$ – jimmy23013 Oct 22 '16 at 9:59
  • \$\begingroup\$ @jimmy23013 But there could be a legitimate solution that does all the work during runtime, but the compiler is woefully slow. We wouldn't want to penalize such a solution. \$\endgroup\$ – Mego Oct 22 '16 at 10:01
  • \$\begingroup\$ Do you have any examples of such a compiler? \$\endgroup\$ – jimmy23013 Oct 22 '16 at 10:04
  • \$\begingroup\$ I know that C++ itself could be slow if you use some libraries. But there are a lot of things that could be abused there. For example someone can write a compiler that automatically convert something like your first code to the second, and technically it could be just an optimization, without changing the semantics of the language. I'm thinking about something like limiting the size of the source code (if counting compile time) or the compiled code (if not counting compile time). Some questions already do, but I'm not sure it works for all cases. \$\endgroup\$ – jimmy23013 Oct 22 '16 at 10:23
  • 10
    \$\begingroup\$ Sorry, but I felt that I had to downvote this. As has already been mentioned, a compiler could easily do this optimisation itself, with the required flags of course. But in the example you've shown, it's just manually hard-coding the input using some syntactic sugar, and so it's barely different to printf("1\n1\n2\n3\n5...");. \$\endgroup\$ – wizzwizz4 Oct 22 '16 at 10:59
  • 3
    \$\begingroup\$ It doesn't matter if its code or a compiler flag doing the storage. Fundamentally, nearly all fastest-code challenges can be precompiled (if it takes input, you could simply precompile all possible input). This is a loophole, and one we often have to say "don't do" in all fastest-code challenges. \$\endgroup\$ – Nathan Merrill Oct 22 '16 at 12:30
  • 4
    \$\begingroup\$ This is an interesting point. Hard-coding manually is one thing, but actually having the real work done at compile-time is another. In the latter case, maybe you should count compile-time as part of the total run-time of the program. This is mostly an issue with C++ template "metaprogramming". Since C++ compilers use memoization instead of redoing recursive work every time, a dumb recursive algorithm implemented with template args can run much faster at compile time than the run-time performance of the same algo implemented in plain C. \$\endgroup\$ – Peter Cordes Jul 20 '17 at 17:49
  • \$\begingroup\$ In the case of large data, the size of a stripped binary executable (or at least its text+data segments) is a useful measure. Getting the compiler to make a big table for you at compile-time has a run-time cost, but repeated runs (with the executable's pages hot in memory instead of cold on disk) doesn't reflect that. Still, pre-computing (especially from compact and maintainable source) is a valid option for real programs. Depending on the task, doing it at program-startup instead of compile-time is more appropriate, though, for a long-running program. \$\endgroup\$ – Peter Cordes Jul 20 '17 at 17:53
  • \$\begingroup\$ Also, sequential Fibonacci numbers is a poor example, unless you were showing a stupid recursive implementation. Both of those will run at near-identical speeds, totally dominated by the cout << function calls. If anything, the loop might run faster on a modern x86 because it stays hot in the uop cache and branch predictors, instead of having to decode new mov and call instructions. (Even unconditional direct branches like call need branch prediction to run efficiently.) \$\endgroup\$ – Peter Cordes Jul 20 '17 at 17:58
  • \$\begingroup\$ If you really wanted to optimize, you'd write code that turned into a string of multiple numbers and newlines at compile time. That could really run fast, not requiring any integer->string conversions and only one I/O function call for a big block of data, and might actually have the run-time dominated by a write() system call, and/or soft page-faults reading the giant string. Either way, printing '\n' instead of std::endl is probably faster (since it forces an extra flush), but printing multiple newlines at once is way faster on a line-buffered stream. \$\endgroup\$ – Peter Cordes Jul 20 '17 at 18:00
  • 4
    \$\begingroup\$ TL:DR, the first version probably runs faster! Fully unrolling a loop that long is bad, especially with no loop-condition. \$\endgroup\$ – Peter Cordes Jul 20 '17 at 18:02
  • \$\begingroup\$ @PeterCordes The specific example isn't very important. The point is, fastest code challenges are timed based on runtime, which excludes compile time for compiled languages. Thus, solving the problem at compile time to get an extremely low run time is loophole abuse. \$\endgroup\$ – Mego Jul 21 '17 at 2:37
  • \$\begingroup\$ @Mego: I guess I'd agree with that, even if template metaprogramming to achieve that would be the right solution in a real program for that case. The problem is that it's hard to state the rule in a way that blocks everything we want to block, but allows everything we want to allow. (Analyzing the specific example was an interesting side-track, but ultimately irrelevant. Still, since I don't think we can do much better than just knowing it when we see it, having the at-compile-time example do some string concatenating to beat the run-time version would be good.) \$\endgroup\$ – Peter Cordes Jul 21 '17 at 2:53
  • \$\begingroup\$ As other people have pointed out, pre-computing some quick things as part of a bigger algorithm is realistic. It's only fully pre-computing the final answer that we probably must always disallow. So the headline wording of this answer should be more specific. \$\endgroup\$ – Peter Cordes Jul 21 '17 at 2:54
  • \$\begingroup\$ So? Just count the compilation + execution time together. Problem solved. If a program solves exactly one instance of one problem, the compile time should be included. Why we don't care about what happens at compile time is that, usually, software is run many times for different problem instances, after being built once: compiling is a fixed cost. \$\endgroup\$ – Kaz Aug 1 '17 at 4:43

Infinite output programs that wouldn't give all output given infinite resources

Example, loophole-violating code to output all integers:

bigint i = 0;
for(;;) bigint_print(i++);

This would never output negative numbers, even given unlimited resources, so it does not fulfil the challenge's requirements. A program that does fulfil the requirements would be:

bigint i = 0;
for(;;) {

Using comments to circumvent character requirements/restrictions

It's cute and makes you laugh once, but when you see it several times over several challenges, it just becomes facetious and contrary to the spirit of the game.

Example: https://codegolf.stackexchange.com/a/12370/5358

  • 59
    \$\begingroup\$ I think that's actually a good answer for that question \$\endgroup\$ – SztupY Feb 25 '14 at 14:15
  • \$\begingroup\$ @SztupY It's clever, and I laughed about it and upvoted it. But it is against the "spirit" of the question, and this kind of thing is done in lots of places. \$\endgroup\$ – asteri Feb 25 '14 at 14:26
  • 4
    \$\begingroup\$ It's funny once. But I agree, if you post something like that challenge, you should forbid comments. (If someone does not, leave a link to this answer). \$\endgroup\$ – Johannes Kuhn Mar 13 '14 at 15:17
  • 4
    \$\begingroup\$ @JeffGohlke Actually, for that particular question, it's completely fair game - but sadly it's not the shortest by a long shot. \$\endgroup\$ – Joe Z. Mar 24 '14 at 22:28
  • \$\begingroup\$ @JohannesKuhn I don't think comments was a big concern with that question, since the comments don't make it trivial. You still need to be printing characters without using them. \$\endgroup\$ – Cruncher May 14 '14 at 20:34
  • \$\begingroup\$ Perhaps "don't submit a program without any code" is what you mean \$\endgroup\$ – Supuhstar Oct 17 '14 at 3:53
  • 2
    \$\begingroup\$ As I told in some comment, my answer should be the worst possible answer. And funnily some people even posted longer answers. \$\endgroup\$ – Johannes Kuhn Oct 17 '14 at 14:36
  • 2
    \$\begingroup\$ I am strongly against this; this means that there is something wrong with the question, not the answer. \$\endgroup\$ – MilkyWay90 Apr 13 '19 at 3:16

A script invoking itself as a form of looping/recursion, where the filename has to be a specific name

e.g. I answered a question with PowerShell which included sleep 1;t where the script had to be called t.ps1 and saved in the PATH, so it would call itself.

I considered it maybe reasonable because running programs is part of what shell scripts do, and there's no reference to it in this meta topic as a standard loophole. The closest is about hiding information in the filename, e.g. a file called "hello world".

People commented to say relying on the filename is frowned upon, so I'm submitting it here so it can be voted on and be on record as approved/denied in future. Is it a loophole, or is it valid in the same way as an answer might say "requires version 3 or above" or "only works in a particular interpreter"?

  • 4
    \$\begingroup\$ I don't think requiring a specific filename is a problem in general, unless this is abused to hide code or store information in the filename. For example, every full Java program requires a specific filename for compilation. \$\endgroup\$ – Dennis Dec 16 '15 at 17:46
  • \$\begingroup\$ @Dennis But that is also a requirement of the language - using it explicitly for purposes other than compiling seems a bit loophole-y. \$\endgroup\$ – Addison Crump Dec 16 '15 at 18:25
  • 2
    \$\begingroup\$ If it is not considered a loophole, then the filename should also be counted in the byte count. \$\endgroup\$ – Addison Crump Dec 16 '15 at 18:29
  • \$\begingroup\$ The filename is counted, t in the script is the filename. if you had a bash script which called sed would you count sed as 3 more characters as well as it appearing in the script? It's also relying on a particular program with a particular filename being in the PATH. \$\endgroup\$ – TessellatingHeckler Dec 16 '15 at 18:48
  • \$\begingroup\$ Then you'd need to count the t in the code and the t.ps1 in the filename - if you changed either of these, it wouldn't function, would it? \$\endgroup\$ – Addison Crump Dec 16 '15 at 18:53
  • 7
    \$\begingroup\$ @FlagAsSpam I fail to see why we would count t.ps1 as 5 bytes, yet t.java as 0 bytes, especially since this seems to be the most natural form of recursion for PowerShell. \$\endgroup\$ – Dennis Dec 16 '15 at 18:55
  • 1
    \$\begingroup\$ @Dennis You need to call it in Java, because that's how the language works. Recursion can be called via other methods in PowerShell, as shown by another answer in the same question. \$\endgroup\$ – Addison Crump Dec 16 '15 at 18:57
  • \$\begingroup\$ @FlagAsSpam If we're talking about the same answer, it uses a for loop, not recursion. In any case, I could get behind a convention that counts t.ps1 as one byte (for the t), since the rest is just the typical PowerShell extension. \$\endgroup\$ – Dennis Dec 16 '15 at 19:04
  • 2
    \$\begingroup\$ For a sed script which requires a flag, the flag must be counted in the byte count because it's a required extra to make the answer work. But it's not possible to save a script with no filename, so I'm not mandating extra information, so why would it count extra? You always need a filename ending in .ps1 for a PS script, constraining what the filename can be doesn't add any extra bytes. (@Dennis, I partly deleted my answer because it would eventually overflow - but I also wonder about that - usable answers which would eventually hit real world limits are sometimes allowed). \$\endgroup\$ – TessellatingHeckler Dec 16 '15 at 19:06
  • \$\begingroup\$ @TessellatingHeckler I don't think we have a default for that. The best option is to ask the OP in a comment. (Note that exec $0 in Bash should not have the same limitation, since exec replaces the current shell with another one.) \$\endgroup\$ – Dennis Dec 16 '15 at 22:18

Sending error messages to the null device

... instead of avoiding them.

This should either be forbidden or add to the byte count, as setting options to suppress messages do.


  • 8
    \$\begingroup\$ I don't think this is a loophole. Since STDERR is ignored by default, the example provided looks to just be a way to prettify the output. \$\endgroup\$ – AdmBorkBork Sep 29 '16 at 18:23
  • \$\begingroup\$ @TimmyD That I didn´t know until now. Hey and I wasted tons of bytes to code around warnings. :D I still find it ... confusing that error messages are allowed; but if those are the rules: so be it. \$\endgroup\$ – Titus Sep 29 '16 at 22:09
  • 3
    \$\begingroup\$ Nitpick: Warnings aren't error messages. \$\endgroup\$ – Dennis Sep 30 '16 at 4:05

Compressing your source code

Some language provide builtin facilities to compress data and execute the result as source code. I consider this to be a standard loophole, especially when the challenge is counted in characters instead of bytes.

  • \$\begingroup\$ This can be argued and extended to many other built-ins. Like Mathemetica's built in MandelbrotSetPlot to plot a mandelbrot set. I think the practice of questions themselves explicitly disallowing such compressions is the most favorable scenario and holds true for any such built-in, not just code compression ones \$\endgroup\$ – Optimizer Apr 13 '15 at 14:25
  • 27
    \$\begingroup\$ I do not think that this is a loophole. The default scoring is in bytes for good reason. If a challenge author deviates, then I'd assume they have a good reason for doing so. \$\endgroup\$ – Rainbolt Apr 13 '15 at 14:27
  • \$\begingroup\$ In addition, if you're doing a kolmogorov-complexity challenge in a language like ///, the only way to be competitive whatsoever is to compress the source code. If you can find a way to encode and then eval your code so that it's shorter than the normal algorithm, than good for you. \$\endgroup\$ – Esolanging Fruit Mar 8 '17 at 6:14

Using built-in functions to do the work

Mathematica is a big one for this, with Fibonacci[n] to calculate the n'th Fibonacci number.... I have no objection to these being posted as a side note within the main answer though - that is interesting and helps me learn different languages capabilities.

Another one that encounters this more often than most is with Assembly, especially with questions requiring bitwise-related operations, such as ARM's rbit reversing the bits in place or Haswell's pext to extract bits according to a mask.

  • 11
    \$\begingroup\$ Or using CellularAutomaton to implement a Game of Life \$\endgroup\$ – AShelly Feb 24 '14 at 1:59
  • 5
    \$\begingroup\$ I think this only applies when the main part of the question is for the function. \$\endgroup\$ – Justin Feb 24 '14 at 2:56
  • \$\begingroup\$ @Quincunx Yes, I know. Still... \$\endgroup\$ – user10766 Feb 24 '14 at 3:24
  • 65
    \$\begingroup\$ Perhaps if it were qualified with "lion's share of the work". Fibonacci[n] to solve a Fibonacci problem is bad form, but there are also plenty of instances of high-level stats/graphics/maths functions in R, Processing, Mathematica, etc. being used in the context of good answers. It's hard to define objectively the line between good answer playing to the language's strengths and lazy answer plastering over the answerer's weakness. But you generally know it when you see it. \$\endgroup\$ – Jonathan Van Matre Feb 24 '14 at 6:28
  • 14
    \$\begingroup\$ If we were all limited to the same set of built-in functions, every contest would be won by APL or Golfscript because their command names are the shortest. \$\endgroup\$ – Michael Stern Feb 28 '14 at 16:01
  • 5
    \$\begingroup\$ @MichaelStern I mean that if the challenge is to implement a function, we shouldn't just give a function that was already implemented into the source of your language. \$\endgroup\$ – user10766 Feb 28 '14 at 16:22
  • \$\begingroup\$ I believe one purpose of code golf is to display features, especially obscure ones, of a language, but I still agree they should be disallowed. \$\endgroup\$ – Ming-Tang Apr 15 '14 at 21:06
  • 108
    \$\begingroup\$ Contrarily, I think using built-in functions is good. It highlights the benefits of different languages. \$\endgroup\$ – daviewales Apr 19 '14 at 9:51
  • \$\begingroup\$ I made an edit to include the increasing prevalence of assembly built-ins under the same umbrella here. \$\endgroup\$ – Isiah Meadows Sep 2 '14 at 0:07
  • 3
    \$\begingroup\$ What if, in a certain language, there's no work to be done to solve a problem? For example, for a snippet, by receiving the input the result is already calculated? That's what I ran into for my AVR answer \$\endgroup\$ – rsaxvc Jan 4 '15 at 19:06
  • \$\begingroup\$ @rsaxvc I do not know. You will have to ask a question about this. \$\endgroup\$ – user10766 Jan 5 '15 at 1:45
  • 6
    \$\begingroup\$ Isn't that the whole point of built in functions, though? I mean I thought the whole idea behind programming was to not reinvent the wheel. \$\endgroup\$ – tfitzger Apr 15 '15 at 18:12
  • 8
    \$\begingroup\$ @Hosch250 Then it should be up to the poster to determine what level of function answers can contain. Technically, most of the answers on this site rely on functions, routines, subroutines, etc to get their answer. Some can just do it in one or two instead of twelve of fifteen. I've seen posts limit the use of min or max functions, use of inherent random functions, use of mod, etc. There, the person asking the question was responsible for deciding the level of function that was allowed. \$\endgroup\$ – tfitzger Apr 15 '15 at 18:35
  • 1
    \$\begingroup\$ There was a question that required the computation of the Kolmogorov—Smirnov statistic. It is a built-in in R that requires no extra packages, so why should I re-invent the wheel? Forcing to re-implement the intrinsic features of a language in the same language seems futile to me. \$\endgroup\$ – Andreï Kostyrka Aug 31 '16 at 23:05
  • 2
    \$\begingroup\$ Banning built-ins is like banning golfing languages; it is done out of annoyance and there is no formal definition of a builtin \$\endgroup\$ – MilkyWay90 Mar 17 '19 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .