# Sandbox for Proposed Challenges

This "sandbox" is a place where Code Golf users can get feedback on prospective challenges they wish to post to main. This is useful because writing a clear and fully specified challenge on your first try can be difficult, and there is a much better chance of your challenge being well received if you post it in the sandbox first.

Sandbox FAQ

## Posting

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

## Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

• Parts of the challenge you found unclear
• Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

## Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

# Move arrows along a contour

Posted here

• I've edited in a question since it needs 2D for clarity.
Jul 26, 2019 at 8:48
• @Adám Only the arrows move. "+-|" always stay in place, or are "hidden" behind an arrow. So, you second example is correct (I deleted the first one) Jul 26, 2019 at 9:02
• Continuing @Adám's question: Are shapes always separated by at least one space, or can they be next to each other like ++++\n++++, and we have to determine if it's a ++++\n++++ or +--+\n+--+ based on the directions the arrows are facing? I.e. is this a possible/valid input, and are those outputs correct? Jul 26, 2019 at 11:26
• @GalenIvanov I didn't have anything but arrows move, and not it doesn't follow, because you couldn't tell what was behind the arrows, -s or +s which is what would make the two possible answers.
Jul 26, 2019 at 11:28
• @KevinCruijssen Example 2 has two adjacent shapes with no (vertical) spacing.
Jul 26, 2019 at 11:29
• @Adám Ah, you're right. As for your question however, you'd still know +<<+\n+>>+ is +--+\n+--+ due to the directions of the arrows in combination with the rule "when an arrow is on a corner, it keeps its current direction and changes it only after the turn is taken". See the pastebin in my previous comment for some test cases where you do know it's ++++\n++++ instead, because of the arrow directions. +^<+\n+>v+ will be two ++++\n++++ boxes, but +<<+\n+>>+ will be one +--+\n+--+ box. Jul 26, 2019 at 11:37
• @KevinCruijssen Good point, but OP actually never says that the input is an obtainable state, though it does make sense. I still have a feeling that there could be ambiguous cases.
Jul 26, 2019 at 11:41
• @KevinCruijssen The shapes will always be separated by at least one space, I'll add it to the description. Jul 26, 2019 at 11:44
• @GalenIvanov Probably better indeed to not have to deal with confusing ambiguous cases. In that case I would also have at least a newline separation, so test case 2 should be slightly modified. :) Jul 26, 2019 at 11:45
• @Adám Oh, I see - indeed I need to correct the second case to have a vertical space between the shapes. Jul 26, 2019 at 11:51
• Even single tracks can be incredibly difficult: [" ++ ","++++","++^+"," ++ "] only has one possible output: [" ++ ","++++","+++>"," ++ "]
Jul 26, 2019 at 11:55
• @AdámYes, this is the only output. Do you think a condition that sharp turns are forbidden will help? (this means no two + can be adjacent) Jul 26, 2019 at 12:21
• @GalenIvanov Maybe that's indeed better to reduce confusion and make the challenge someone more manageable. Although you can still deduct the solution in Adam's comment above, having no spaces inside the space makes it rather difficult to parse correct. Always having at least one |/- between two + will always give the shapes always spaces, making it easier to parse individual shapes. In which case Adam's one would become [" +-+ "," | | ","+-+ +-+","| |","+-+ ^-+"," | | "," +-+ "] -> [" +-+ "," | | ","+-+ +-+","| |","+-+ +>+"," | | "," +-+ "] Jul 26, 2019 at 13:55
• @KevinCruijssen Thanks, I added clarification. Jul 26, 2019 at 14:09
• @GalenIvanov Maybe also change the one Adam edited in, since it's still with ++ below one-another. :) Jul 26, 2019 at 15:08
• I found a lot of similar questions, but not quite the same. Would it be considered a duplicate? Aug 1, 2019 at 8:17
• we've had double factorial closed before as a dupe of the vanilla factorial question Aug 1, 2019 at 12:03
• @Giuseppe Thanks! I found that post, but I thought the variable factorial range might make it considerably different from the original challenge. Aug 1, 2019 at 12:12
• Can we take input as two integers?
Aug 1, 2019 at 12:49
• Can you give a definition for the multi-factorials above 2? Aug 2, 2019 at 4:55
• @Adám That makes the challenge somewhat easier, but I suppose it is fair. I added the other input option. Aug 2, 2019 at 7:04
• @MilkyWay90 Yes! Totally skipped that part, oops. Is it clear enough like this? Aug 2, 2019 at 7:05
• @KevinCruijssen Input numbers can be in any format, of course. I thought this was included in the default I/O rules, buy I will specify this in the challenge. Aug 2, 2019 at 12:39
• @KevinCruijssen In the input, at least one factorial sign is expected, i.e. a positive integer. I suppose the correct return value for a factorial number of zero would just be the base, but as the challenge is to calculate a factorial, this seems like an unreasonable restriction. The same goes for a factorial number lager than the base. If the factorial number is equal to the base, the base should be returned as per the generalized formula. I will add additional examples to clear this up. Thanks for the feedback! Aug 2, 2019 at 12:39
• @KevinCruijssen The range(start,stop,step) function in Python 3 returns a generator with an initial value of start (or 0 if not specified) and a final value of stop-1. For example, the list representation of range(1,4) is [1,2,3]. If this list is sliced as [1,2,3][::-1], the returned list is [3,2,1], which can also be achieved with range(3,0,-1). When the slicing operator is applied to the generator directly, a new generator is returned which generates the sliced list instead. Does that answer your question? Also, range(420,0,-30) would be a cleaner approach in this case. Aug 2, 2019 at 13:08
• @Jitse Ah ok, now it makes more sense. I indeed knew range(1,4) is [1,2,3]. And I also knew [::-1] reverses the order, since I see it used in answers every now and then. Seeing the range(1,4)[::-1] == range(3,0,-1) now I'm not sure why I didn't see it myself when I asked you the question. And yes, range(value,0,-n) would indeed be clearer than range(1,value+1)[::-n]. ;) Aug 2, 2019 at 13:24
• Seems good except maybe you should specify that $n!^{(k)} = n\underbrace{!\ldots!}{k}$ (n!^{(k)} = n\underbrace{!\ldots!}{k}) Aug 2, 2019 at 16:47

# Cliquish Program

Challenge: Write a program that accepts a character (or byte, see additional information) as input. Then:

1. If the character is contained within the source code, output a different character also in your source code.
2. If the character is not contained within the source code, output a different character also not in your source code.

This is a , so the shortest program (in bytes) wins.

• Your program must consist of at least 2 distinct characters.
• Your program must have at least 2 possible outputs.
• Your program does not have to be deterministic; it may output a character at random (with any distribution), so long as it conforms to the above criteria.
• Your program may optionally take a byte as input instead of characters. If you do, the code page the input is written in must contain at least each distinct byte in the source code, as well as at least two different bytes not in the source code.
• You may take input and give output in any reasonable way. For example, you may take input as a function parameter, a command-line argument, a line from STDIN, a triple-nested array containing a single character, etc. You could output via return value, STDOUT, exit code (if applicable), fax output, etc. The input and output formats must be consistent, however.
• Your output can only consist of the required character, optionally followed by one trailing newline. Prompt information (such as ans =) is exempt from this rule; such unpreventable output is acceptable.
• Slightly more interesting than most generalised quines. Have you checked quine for dupes? Aug 2, 2019 at 7:32
• @PeterTaylor related related related. I couldn't find any exact dupes. Aug 2, 2019 at 19:39
• What if your program contains all but one possible character? What encoding are the characters in? UTF-8? latin-1? ASCII? Aug 2, 2019 at 20:18
• @Beefster Hopefully I've addressed your first question. As per your second, I believe we have a standard consensus on what a character is Aug 11, 2019 at 18:13
• By induction the program must have 4 possible outputs. Inside/outside of the source × two included in each (if choose one, output the other). Btw I don't understand the title Aug 22, 2019 at 7:05

# Implement Brainfuck Algorithms

In order to make algorithms written in brainfuck more understandable, you can write them in a more abstract notation, where you give a given cell a name, and instead of lots of unreadable < and > instructions to move the pointer to a specific, you just write down the name of the cell. Let us see an example:

This algorithm doubles the value in cell x, and saves the result again in x. It needs an additional temporary cells t

t[-]          clear temporary variable
x[t+x-]       move the value from x to t
t[x++t-]      move twice as many units from t back to x


Now lets see what this would look like, if x was the cell with index 0, and t was the cell with index 2, assuming the poninter is in position 0 when the algorithm starts:

>>[-]
<<[>>+<<-]
>>[<<++>>-]


### Challenge

Given a string with a valid (see below) brainfuck algorithm, a list of strings containing the cell names and a list of integers containing the indices of each of the cell of the previous list, your program/function has to return an implementation of this algorithm in brainfuck.

### Details

• The pointer is assumed to be on a cell with index 0 when the implementation is executed.
• The two given lists can also be in a different reasonable format e.g. [cell1,index1,cell2,index2,...] or [[cell1,index1],[cell2,index2],... or as arguments of a function with a variable number of arguments etc.
• You can assume that in the given string representing the algorithm, there are only brainfuck instructions as well as cell names, but no other symbols (no line breaks, no spaces)
• The cell names consist of lower- and uppercase characters A-Z and a-z as well as digits 0-9
• The cell names in the string are always separated by at least one BF instruction symbol.
• You can assume that the pointer is the same index whenever it enters a loop as it exits the same loop.

### x=y:

String (remove line breaks):
temp0[-]
x[-]
y[x+temp0+y-]
temp0[y+temp0-]
List of variable names: [temp0,x,y]
List of indices:        [    2,0,1]
Output (remove line breaks):
>>[-]
<<[-]
>[<+>>+<-]
>>[<+>-]


### x=x*x

String (
temp0[-]
temp1[-]
temp2[-]
x[temp2+temp1+x-]
temp1[
temp2[x+temp0+temp2-]
temp0[temp2+temp0-]
temp1-
]
List of variable names: [x,temp0,temp1,temp2]
List of indices:        [0,    1,    2,    3]
Output (remove line breaks):
>[-]
>[-]
>[-]
<<<[>>>+<+<<-]
>>[
>[<<+>+>>-]
<<[>>+<<-]
>-
]


• Aah, I just noticed something when writeing that line (see meta section) but I do not have time right now to think through that. That's why this part was unfinished. Jun 20, 2016 at 15:14
• I think that this is undecidable. Consider a line of the form x[algorithm] where algorithm doesn't guarantee to leave the pointer where it started. For the subsequent line to move the pointer to the desired cell it needs to know whether x was zero going into that line or not. Jun 20, 2016 at 16:03
• I think the problem can be solved by requiring that there are no <> in the input. Although that would make the resulting language not Turing-complete (can only access finite amount of memory) May 2, 2018 at 9:51

# ASCII Maze Unrendering 3000

Posted

• Part of the wall for the current only test case seems a bit too narrow. Aug 28, 2019 at 2:37
• I think this could be considered a special case of this challenge, with slight differences in the voxel style. Aug 29, 2019 at 6:56
• @flawr You're right. As written, this is a duplicate. Do you know if the reverse has been done, taking the 3d version and returning the original? Aug 29, 2019 at 17:52
• I don't think the reverse has been done, but I'm not sure this would make a good challenge. I'm still thinking about how one could make this. I mean the 2d version you propose would make it a bit simpler. Aug 29, 2019 at 19:10
• Yes. The full 3d version would almost certainly be impossible, because most voxels would be completely blocked. Here, every block is visible, and a human can figure out where the walls are, so a computer should be able to do it too. Aug 29, 2019 at 19:17
• @Night2 Indeed, didn't notice that point, I fixed the samples in the rules to include AA-000-AA Sep 20, 2019 at 6:25
• Are the letters mandatory to be uppercased, or could we output in lowercase as well? Sep 20, 2019 at 9:51
• @KevinCruijssen Yes, letters are mandatory to be uppercase, also I feel like you ask that because of a builtin somewhere :P Sep 20, 2019 at 12:36
• Fine by me. I was mainly asking because it isn't a core-part of the challenge, and in some challenges lowercase/uppercase/mixed case is all allowed. But you're indeed right that lowercase would save a byte in my language of choice 05AB1E, where A is the lowercase alphabet builtin, and I'd need an additional u to uppercase it. ;p But since number plates are always uppercase, I can understand to keep the uppercase mandatory here as well. I had prepared a 24-byter, but will throw it away for now since I feel this can be done shorter.. Will try again later when it's posted to main. :) Sep 20, 2019 at 12:41
• Another question, or more recommendation: allowed both 0-based and 1-based indexing for answers. I see your test cases are 0-based, but some languages use 1-based indexing instead. Sep 20, 2019 at 12:44
• @KevinCruijssen Sure, no problem with 1-based indexing, going to fix the rules to add that. As I've never used such languages, I often forget about them Sep 20, 2019 at 13:19
• I would say if the format irl has to be in uppercase then following that would be better. I've got myself an 85-byte JS answer that conforms to the irl format though. Sep 21, 2019 at 1:06
• @ShieruAsakoto That's what I also advocate for, minus all the dumb real life rules that would just make it unfun to do. Anyway, going to post this Sep 23, 2019 at 18:41

# Almost Illegal Strings

Posted.

• Does the challenge need to have the robber code output "Well done!"? What if they could just submit any code with the substring that runs?
– xnor
Oct 24, 2020 at 10:24
• @xnor That's fair enough - I just struggle to define 'program that runs'. Would you consider zero exit code and no stderr output reasonable? Or are there some languages that output to stderr even in a valid program? Oct 24, 2020 at 12:00
• I think this is too similar to the original "illegal strings" question which basically turned into a cops-and-robbers anyway Oct 24, 2020 at 18:26
• @Sisyphus I was thinking you could just copy whatever condition Find an Illegal String uses. But it doesn't seem to be that rigorous, saying "The compiler/interpreter/runtime must give an error when given any source code that contains your string as a substring." I think requiring no output to STDERR is probably fine. Maybe though some languages give warnings to STDERR that golfers typically ignore? Note that defaults allow programs that print then crash, so just requiring output doesn't preclude a fatal error after.
– xnor
Oct 24, 2020 at 21:12
• Rule suggestion: commenting out the almost illegal string is not allowed Oct 28, 2020 at 15:33
• I think it's too thorny to define what comments are in a way that works across languages. One objective way to handle it would be to let cops specify a set of characters that are not in their code, where they might include their language's comment character(s) or quote literals.
– xnor
Oct 29, 2020 at 0:40
• @xnor Ok, I've rewritten the challenge to just require that the program does not error, and feel the rules are fairly straightforward and watertight. Nov 1, 2020 at 5:50
• @Beefster I considered this, and something like xnor's suggestion of banning characters. However, I think it ruins the purity of the challenge a bit, and for most languages it's very easy to avoid being in a comment (newline + end of comment block will do it). There are some languages which have 'inescapable comments', such as raw strings with specific delimiters, or something like Perl's __END__, but they're sacrifices I'm willing to make. Nov 1, 2020 at 5:52
• The problem with not banning comments (or including things within strings, for that matter) is that it's quite easy to cop out and write a hello world with the almost illegal string appended in a comment. That takes out all the challenge. xnor's suggestion solves that mostly, but that does end up limiting cops a little bit to make the robbers' job an actual challenge. Nov 2, 2020 at 16:25
• @Beefster Apologies, I have not been clear about my reasoning. My logic is that for the vast majority of languages, a cop can 'comment proof' their string trivially by adding a newline (to escape a single line comment) and an end of comment block (to end a multiline comment). For example, the string \nx"""x''' (with a literial newline) escapes all Python comments. You can do this in most languages - or am I missing something? Nov 3, 2020 at 3:12
• @Beefster It looks like you were right - it is too hard without allowing Cops to ban characters. I'd like to apologise for not taking your feedback more seriously while the question was in the sandbox. Nov 6, 2020 at 1:10

# Print random integers until 0

• Presumably, if the first number is zero, we just output zero and exit? Jan 16, 2021 at 18:57
• "integers may be separated by any non-digit, non-empty separator" can we output in zero-padded form (00 01 .. 98 99) so that a separator isn't necessary? What about codepoints/byte values (NULL - c)? Can it be a list-like object rather than a separated string? I think this would be better with more sequence-like IO rules Jan 16, 2021 at 18:59
• @pxeger Yes, if the first number is zero, you just output zero and exit. I don't think the standard is to output with zero-padding, so I'll say no on that. Byte values and list objects are both standard forms of outputting a bunch of numbers, so of course, those are allowed Jan 16, 2021 at 19:07
• Also, I assume it is not necessary that the program follows the indicated procedure (which would be unobservable anyway), as long as the output has the same statistical properties. So if a different procedure is used, perhaps the answer writer should justify it. (For example: generate a number K geometrically distributed with parameter 1/99, then output K nonzero numbers, then output a 0) Jan 16, 2021 at 19:07
• @LuisMendo Yeah, I'm pretty sure that "you don't have to follow the letter of the challenge so long as the behaviour is the same" is a standard rule, but in case not, I've edited in a sentence along with your example Jan 16, 2021 at 19:10
• I didn't fully define my example, sorry. You may want to change it to "then output K independent numbers with a uniform distribution on the set {1, 2, ..., 99}". That corresponds to the procedure you specify with a uniform distribution on {0, 1, ..., 99}. Jan 16, 2021 at 19:21
• @cairdCoinheringaahing are built-in functions for generating pseudo-random numbers forbidden? If not, is the challenge a very trivial one or am I missing something? Jan 27, 2021 at 23:17
• @Davide Trivial challenges are not necessarily bad, since it encourages participation in relatively hard-to-use or minimal esolangs. And I think this one is actually good because I smell many unexpected approaches to golf the problem. (Also, banning built-ins are considered bad.) Jan 28, 2021 at 0:26
• @Bubbler thank you so much for this train of information Jan 28, 2021 at 0:35
• @Davide Nope, all builtins are allowed. As Bubbler said, trivial challenges are only really bad if there’s no room for interesting solutions, which I don’t think is the case here Jan 28, 2021 at 10:06

# Remove Nth occurrences

• There is this but it got closed, Everything is clear, but can you replace, "the n" with "the integer n" in the last point of your assumptions list. For some reason that made me read the sentence multiple times. Feb 23, 2021 at 12:08
• Is there a reason for limiting the array values to 1-9? Feb 23, 2021 at 19:49
• @pxeger Because the values don't matter, so there's no reason to complicate it more. Plus, it can allow for some interesting string based approaches by taking $A$ as a single string Feb 23, 2021 at 19:52
• @pxeger It certainly helps that 0 cannot be part of the array, because then I can use it to erase values in APL. I'm sure other languages can take advantage of that too
– user
Feb 24, 2021 at 1:48

# To raise $$\ e \$$ to the power of a matrix code-golfmathmatrix

Posted

## Meta

• Is this clear enough?
• Is this a duplicate?
• Any other feedback?
• why not require exact calculation, it makes for a harder challenge but a more interesting one Apr 1, 2021 at 19:54
• @rak1507 it's irrational so an exact value can't be calculated Apr 1, 2021 at 19:55
• looked like there were methods on wikipedia but I could be wrong Apr 1, 2021 at 21:45
• Note that the exponential of a 9x9 matrix of 100's exceeds what floats can represent. You might want to lower the 100 bound or make allowances for that.
– xnor
Apr 2, 2021 at 6:30
• I think the precision convergence rule is too restrictive and too tied to that specific power series method, and some loose accuracy bound would allow more varied methods. For instance, one can approximate $e^M \approx (I+M/n)^n$ for large $n$.
– xnor
Apr 2, 2021 at 6:38
• @xnor I didn't read much into the matrix exponential (because I couldn't find the article on Wikipedia and was too busy watching the rest of the 3b1b video :P), so I hadn't not really realised there were other ways to compute it. What would you recommend? I still like the idea of requiring it to be observed to converge within floating point limits, because it adds an extra layer of challenge rather than just "repeat this step 100 times", but maybe that just isn't practical Apr 2, 2021 at 6:50
• I think convergence within floating point limits would unfortunately be hard and finicky here because of the nature of exponentials. The same way that $e^{100}$ and $e^{100.001}$ differ a lot, small errors in the computation can accumulate into huge ones. Also, the values in the output might be extremely small and become represented as zero. I'd have to think more about bounds, but maybe something like every entry within either 1% or 1e-4 of the true one should work.
– xnor
Apr 2, 2021 at 7:03
• My solution to floating-point errors is "the result should be within [insert error bound here] relative error for the given test cases". (The bolded part is VERY important. FP computation methods often have errors dependent on the magnitude of the input, so it is very hard to judge if an implementation is valid, even if the possible input range is specified. Explicitly giving the test cases makes it much easier to test submissions. Also, you need to craft the test cases carefully so that you don't accidentally ban a valid method or allow invalid methods.) Apr 4, 2021 at 23:28

# Non-quining infinite printer

Seems like the title could be better but I'm not sure what to do instead

I have heard that a monkey typing random keys on a typewriter, given infinite time, will eventually type out the entire works of Shakespeare, and in fact type out every possible string of characters of any length. This sounds to me like the basis for a profitable business venture in publishing. Unfortunately, however, as a result of previous failed business ventures, I am legally barred from possessing either monkeys or typewriters, so I'll instead need a program. I want this program to provably generate every possible string of characters, assuming infinite time and memory. Repetition is fine, as is overlap, as long as every possible string appears somewhere in the output. There's a catch, though. I imagine once my business gets off the ground and people realize the potential profits, they might want to get their hands on my program. The trouble is that since I'm outputting every possible string of text, in theory I'll eventually end up outputting the program itself, leaving it open to be stolen. To prevent this, I want the program never to output its own source code. It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of). Because my funds are currently very tight, I can't afford to pay for more bytes than are necessary, so I'm seeking the shortest possible program that does the job (This is a code-golf challenge, shortest answer in bytes wins). Is it communicated well enough what this challenge is asking for? Should I add a TL;DR and/or a more technical explanation of what's being looked for?

• I've had enough run-ins with the law in previous ventures, I'd like this one to go smoothly. So no abusing loopholes in the program, please.
• Given that this program is my financial plan for the next infinity years, I'd like some reassurance that it actually does what it's supposed to. Please provide at least a brief explanation of why your code works, since it can't exactly be tested.
• Any character encoding is fine, please specify though. The exception is that your source code must be printable in the encoding you use. Is this a reasonable way to handle this that is fair to all languages?
• No reading your own source, because that makes quine-related holes uncool, and uncoolness does not fit with my businesses' brand persona.
• How are the strings in the output separated? Some previous challenges about "print all possible strings" were closed as unclear because of this. Jun 7, 2021 at 1:06
• @Bubbler The strings don't have to be separated. What I mean is that every string should be a substring of the "main" output if that makes sense. Put another way, running a regex match on the output for any string of characters (other than the source) should return at least one result. Would adding something to that effect clear up that confusion? Jun 7, 2021 at 1:13
• It should still output every other possible string, just not itself (or, obviously, any strings which it is a substring of) Okay, the task makes sense now. I think you'll need to add that information somewhere before the sentence I quoted. Now I wonder if the task is actually possible... Jun 7, 2021 at 1:39
• @Bubbler Sure, it's possible. One approach is to store the program's source in a string, and then run some sort of code that generates every possible string, checking after each generation whether the generated string contains the source string, and only printing if it doesn't. There might be some trouble in making sure the source isn't present in a combination of two consecutively generated strings (i.e. if the source code is AB, then outputting XA and BX consecutively is an issue), but a simple solution to that is to insert a character not present in the source between each pair. Jun 7, 2021 at 8:02
• Here's an implementation in Python tio.run/… Jun 7, 2021 at 8:03
• @jeje An easily thought solution is just use an unused char as split, but that likely be longer
– l4m2
Jul 1, 2021 at 16:40
• What do mean by "all possible strings"? Is this restricted to all strings consisting of printable ASCII? The entire Unicode table? Jul 8, 2021 at 1:14

# Who Is Kevin Bacon?

• > I'm worried it will just be "string a load of combinatorial builtins together" and brute-force it That's a solution to pretty much anything Dec 30, 2021 at 5:12
• it looks interesting enough, I can't find anything similar with searches like "Erdos number" and such. It will inevitably get a trivial golflang answer, especially with felxible input methods. To control quality, maybe adding a restricted-time would help. Jan 2 at 7:49

# Output a random unary string

• Would printing an infinite stream of separators or xs be valid? It's an infinitesimally small chance that just, e.g., one x is ever printed for the rest of time, but does that count (I'd be inclined to say no)? Feb 22 at 20:43
• i have no idea what this challenge is about but +1 Feb 23 at 3:43
• Since most languages random number generator (RNG) only have finite state, The program won't output infinity number of different outputs. You may argue that we may consider (assume) RNG have infinity digits (precision). But then, someone would argue that repeat("x", floor(1/random_between_0_and_1())) is a valid submission as we can consider the output of random_between_0_and_1 have infinity precision. It is not very clear which is valid and which is not to me.
– tsh
Feb 23 at 10:32
• Looks like "the RNG in use has perfect random distribution" is a necessary assumption, but allowing the return value of RNG to be of infinite precision sounds a bit weird, as tsh pointed out. You may want to clarify these points in the challenge rules. (I'm not entirely against it though; in some langs the only source of randomness is a random real number in [0,1), which makes some compromises like "you can only use RNGs that return a finite number of integers" unsuitable) Feb 23 at 23:56
• @tsh @Bubbler Do you think the rule I just added is adequate? (I think tsh's suggested repeat("x", floor(1/random_between_0_and_1())) should be considered valid as long as it never causes a division by zero.) Feb 24 at 16:20
• @pxeger I cannot understand how random_between_0_and_1 output a "infinite precision" number in finite time (so program will halt with with probability 1). But regardless this, the rule seems clear to me.
– tsh
Feb 25 at 7:20
• @tsh Well obviously nothing can output an infinite precision number of any kind, but I'm allowing it as an assumption because I think it should be considered a valid possible solution. Feb 25 at 7:44
• Does "Every possible length of xs" includes 0 (empty output)?
– tsh
Feb 25 at 9:08
• @tsh "You may choose whether to include the empty string as a possible output" Feb 25 at 9:50
• Interesting idea. I think the challenge could be interesting if solutions were required to take in a size and output a spiked building of that size. Mar 9 at 8:20
• @ophact is it better now? Mar 9 at 23:37
• Why input 7 is one line taller than input 2?
– tsh
Mar 10 at 3:02
• @tsh its same height Mar 10 at 3:04

# Sort numbers in a ragged list

• Can the output be flattened? Mar 11 at 22:55
• @BgilMidol No, that defeats the point of it. Mar 11 at 22:56
• I think to avoid ambiguity it should be said something like "The shape of the output must be the same as the shape of the input". The spec is currently pretty sparse, relying mostly on an example.
– Wheat Wizard Mod
Mar 11 at 22:57

# King of the Holster (EXITING SANDBOX TOMORRROW)

I realized there hadn't been a King of the Hill in forever, so I wanted to create one.

## Before the Game

You will be given 10 points to distribute between HP, Dexterity, Armor, and Speed. You may distribute up to 10 points between these categories (integer amounts only). You do not have to put a point in each category.

• Your HP will equal 10 plus the number of points you put in HP.
• Your Dexterity (chance of dodging a hit) is equal to 0.04 times the number of points you put in Dexterity. For example, if you put 8 points in Dex, you would have a .32 chance of dodging a hit.
• Your Armor (chance of taking 1 less damage from a hit) is equal to .1 times the number of points you put into Armor.
• Your Speed is simply equal to the number of points you put in Speed.

## Gameplay

Agents will be ordered based on their speed, with ties being broken at random before the game begins. On their turn, each agent will be given their HP, all of their stats (max HP, Dexterity, Armor, and Speed), how much ammo they have, who they attacked most recently, and who attacked them most recently.

On each agent's turn, there are three possible moves:

• Heal: If not at maximum HP, gain 1 HP.
• Shoot: Choose another agent. They get a random real from 0 to 1. If that number is less than their dexterity, they dodge and take 0 damage. Otherwise, they take a random integer amount of damage from 1 to 4, then they generate another random real from 0 to 1. If that number is less than their armor, they take 1 less damage.

TLDR: Shooting does 0 damage if they dodge, 0 to 3 if they get armor but no dodge, 1 to 4 if none.

Once an agent's HP is less than 0, it is out and can no longer take actions. Last agent surviving wins the round.

## Scoring

Each round, if there were X agents, your agent receives X points for each agent below it. Therefore, in a 10 player game, the top agent would get 9 points, the second would get 8, and so on. I can currently run 5000 3-player modes in 10 or so seconds (probably much faster if I removed some of the printing for debugging), so as long as nobody's agent takes too long to run, I should be able to run thousands of score tests.

## I/O

Currently, submissions will create a class which extends PlayerClass. It will create a new class constructor that takes no inputs, which will call super() with the points it wants in each category. Additionally, you will redefine the makeMove function, which takes no inputs and calls move() with whatever arguments are required.

## Rules

Submissions in Java only. As long as the submission is simple enough, I might be able to translate from pseudocode/some other language to Java though.

No calling any methods of other entities using shenanigans. The biggest problem here is takeDamage(), which has to be public so it can be called when someone is shot. Other than that, there shouldn't be any public functions other than turn-order functions, which are probably fine to access.

No redefining any functions/variables of PlayerClass besides makeMove().

The subclass constructor must be of the form super(x,y,z,a); and cannot overwrite the requirements in the PlayerClass constructor.

You may define other methods within your class IF they are only called as part of generating your stats or deciding who to shoot and they follow the rules outlined above.

Don't make your code take forever. This KOTH is pretty lightweight, so there shouldn't be a need for complex algorithms.

The controller and four basic test agents can be found here: https://github.com/romanpwolfram/GunfightKoTH/tree/main

Challenge name by tjjfvi.

• What programming language? Apr 18 at 16:18
• Java right now, but it's simple enough that I can probably convert it to another language with a bit of work. Apr 18 at 16:31
• How much damage does getting shot do? Apr 18 at 16:33
• Random from 1 to 4, but random from 0 to 3 if they "win" their armor roll. Apr 18 at 16:34
• > I realized there hadn't been a King of the Hill in forever sad noises Apr 18 at 18:34
• That one looked like a good KoTH, and I have no idea why it failed. Reasonably complex strategy, but easy enough to code. Apr 18 at 18:36
• Watch out, a player can just do ammo = 10000 and get away with it. Might want to make em private and instead put getters. Apr 19 at 0:18
• Ok. I think I can change all of them since all the info you need should come from getInfo and getAlivenemies Apr 19 at 13:11

# Convert Alpha-3 to Alpha-2

• If that link goes down, or if the list changes for any reason (such as by adding a new country), it would invalidate existing answers. The usual way around this is to declare one unchanging list of every country/territory code that needs to be handled, even if the external resource changes. Since the full list looks too large to comfortably fit in a post, you could copy the list into a Pastebin or something. Apr 28 at 14:12
• Yep! I was planning on posting one to my website later today! Apr 28 at 14:13
• @Nitrodon done! Apr 28 at 16:22

# Shortest restricted superstring

• please don't enforce answers having to handle the empty set as either input but especially the first. It's just an annoying edge case. May 4 at 5:48

# ITEXTIN - Is This an EXTended Initialism?

Please write a program or function that, when given a list of words and proposed extended initialism, outputs whether it is valid.

Rules:

• The list will contain at least two words.
• The extended initialism will contain at least three letters.
• Each word in the phrase contributes a prefix to the extended initialism.
• This prefix must not be the whole word.
• In the case of the first and last words, the prefix must not be empty.
• The extended initialism is the concatenation of these prefixes.
• Inputs are alphabetic only, your choice of upper or lower case.
• Separators, if you want them, are any symbol or white space.

Examples (truthy):

laser=light amplification by the stimulated emission of radiation


Examples (falsy):

labyser=light amplification by the stimulated emission of radiation


This is , so the shortest program or function that breaks no standard loopholes wins!

• How should a function determine whether to exclude words such as by, the, of or and? May 26 at 1:21
• @jezza_99 By looking at which letters it needs.
– Neil
May 26 at 6:18
• Surely then labtseor is correct, not laser, by "Each word in the phrase contributes a prefix to the extended initialism." May 26 at 23:27
• @jezza_99 Empty prefixes are allowed except for the first and last words.
– Neil
May 26 at 23:27
• Can we assume the input initialism is always at least 2 characters long? If not, can we at least assume it's non-empty? May 28 at 11:41
• @pxeger Hmm, 2 characters is still a bit of an edge case, since it can only ever be the first character of the first and last words... maybe I should make it at least 3? What do you think?
– Neil
May 28 at 14:17
• @Neil I don't exactly see anything wrong with just >=2, but to completely minimise any problem you could go with >=3 to be safe. May 28 at 15:11
• @pxeger How about the list of words? I've gone with >=2 there for now.
– Neil
May 28 at 16:17

# Race some Robots

Based on RoboRally, but uses some different/simplified rules

In this KoTH, you will be coding a Python bot that attempts to race around a factory, reaching two specific places before the other bots, who are doing the same thing. The way you'll reach these places - the "checkpoints" - is by sending instructions to the bot, telling it where to move.

## The Factory

The factory is represented by a $$\13 \times 10\$$ 2D list, where each cell has a different component, each represented by a 2 character long string. The factory will be constant for the KoTH, and is the following 2D list (coordinates are shown around for reference):

    0     1     2     3     4     5     6     7     8     9    10    11    12
0 [['  ', '  ', '> ', '  ', 'vv', 'C2', '  ', '  ', '  ', '  ', '^^', '  ', ' ' ],
1  ['  ', '  ', '  ', '  ', 'vv', '  ', 'lv', '< ', 'l<', '  ', 'R^', '<<', '<<'],
2  ['  ', '  ', '  ', '<<', 'R<', '  ', 'v ', '  ', '^ ', '  ', '  ', '  ', '*v'],
3  ['  ', '  ', '  ', '  ', '  ', 'lv', 'r<', '  ', 'r^', '< ', '< ', 'l<', '  '],
4  ['PA', '  ', '  ', '  ', 'lv', 'r<', '  ', '  ', '  ', '  ', '  ', '^ ', '  '],
5  ['  ', '  ', '  ', '  ', 'v ', '  ', '  ', '  ', '  ', '  ', 'r>', 'l^', '  '],
6  ['  ', '  ', '  ', '  ', 'l>', '> ', '> ', 'rv', '  ', 'r>', 'l^', '  ', '  '],
7  ['  ', '  ', '  ', '  ', '  ', '  ', '  ', 'v ', '  ', '^ ', '  ', 'R>', '>>'],
8  ['  ', '  ', '  ', '>>', '>>', 'Rv', '  ', 'l>', '> ', 'r^', '  ', '^^', '  '],
9  ['  ', '  ', '> ', '  ', '  ', 'vv', '  ', '  ', '  ', '  ', 'C1', '^^', '  ']]


We will use compass directions in the explanations to refer to the direction a bot is facing, with "North" being the top of the factory (so $$\(0, 0)\$$ is the North-West corner).

This is fairly complicated, so we'll go over what each string means:

•  : This is just a blank square. Nothing special happens.

• C1/C2: Checkpoints 1 and 2. You must visit Checkpoint 1 first, then Checkpoint 2. The first bot to do both wins.

• > /< /v /^ : These are conveyer belts. At the end of each "register" (explained below), they move any robot on them one square in the corresponding direction.

• For example, if a bot is on $$\(5, 6)\$$ at the end of a register, it is moved to $$\(6, 6)\$$.
• r>/r</rv/r^/l>/l</lv/l^: These are corner conveyer belts. If pushed onto these squares by a conveyer belt, the bot is rotated 90 degrees clockwise (rX) or counter clockwise (lX). At the end of each register, any bot on them (not bots that were just moved onto them) is moved one square in the corresponding direction.

• For example, if a bot is moved from $$\(6, 6)\$$ to $$\(7, 6)\$$ while facing North, it is rotated 90$$\{}^\circ\$$ clockwise and now faces East.
• If this same bot then doesn't move during the next register, then it is pushed South to $$\(7, 7)\$$, facing East.
• >>/<</vv/^^: These are double conveyer belts. If a bot is on one of these at the end of a register, it is moved once in the corresponding direction, and the conveyer square it lands on then moves it a second time

• R>/R</Rv/R^: These are corner double conveyer belts, specifically right turn corners. As with normal right corner conveyer belts, they rotate a bot 90$$\{}^\circ\$$ clockwise when pushed on to, but they then immediately move the bot in the corresponding direction.

• For example, a bot facing South who ends a register on $$\(11, 1)\$$ would be pushed once to $$\(10, 1)\$$, rotated to face West, then pushed to $$\(10, 0)\$$.
• *v: This is the Reboot square. If a bot moves off the board, it is "rebooted": it receives 2 Spam cards, is placed on this square and all remaining instructions are ignored for this round. The bot is now facing South, and, if another bot is rebooted while a bot is on this square, the first bot is pushed one square to the South.

• PA: This is the Priority Antenna. It cannot be moved, you cannot move into the square, and is used to determine who acts first each round.

## Gameplay

Gameplay is very simple. The game is broken into rounds, and one round is structured as follows:

• First, play order is determined. Bots act in inverse order to their Manhattan distance to the Priority Antenna, with ties broken by the bot with the most "horizontal" (East-West) distance going first.
• Then, each bot is dealt 9 "programming cards" from their hand (initially 20, but it can grow). Each "programming card" contains a single instruction for the bot (e.g. Move 1, Left Turn, etc.). The bots then simultaneously* each choose 5 cards, discard the other 4, and order the 5 chosen from 1st to 5th.
• There are now 5 registers, one for each chosen card. A register proceeds as follows:
• The card for each robot for that register is revealed, and the instructions are executed in play order.
• Once all instructions are resolved, the conveyer belts all activate, potentially moving any bots.
• Then, each bot fires a laser, in a straight line in front of it, until it either hits another bot, a wall, the Priority Antenna or misses all other bots.
• If a bot is hit by a laser, it receives a Spam instruction, which is added to its "programming cards".
• If a bot is on Checkpoint 1, it is now able to visit Checkpoint 2 to win. If it is on Checkpoint 2, it wins.
• The next register begins, and the process is repeated.
• After all 5 registers are completed, and everything is resolved, each deck of programming cards are reshuffled with all programming cards, and the next round begins.

If a bot moves into the same square as another bot, that bot is pushed back one square in the direction the first bot is moving. For example, if Bot 1, facing East, moves from $$\(7, 4)\$$ to $$\(8, 4)\$$, and Bot 2 is already in $$\(8, 4)\$$, then Bot 2 is pushed to $$\(9, 4)\$$. Note that, if pushing a bot would push it into the space of another bot, both are pushed.

*: For the purposes of the KoTH, each bot will be given their cards, and will return their chosen instructions in some arbitrary order.

## Programming Cards

Each bot has a deck of programming cards, initially 20. The decks are all identical, and consist of:

• 3 Move 1 cards: the bot moves forward one square
• 2 Move 2 cards: the bot moves forward exactly two squares
• 2 Move 3 card: the bot moves forward exactly three squares
• 3 Right Turn cards: the bot stays in place, and rotates 90 degrees clockwise
• 3 Left Turn cards: the bot stays in place, and rotates 90 degrees counter clockwise
• 3 U-Turn cards: the bot stays in place and rotates 180 degrees
• 2 Move Back cards: the bot moves moves backwards one square, without rotating
• 2 Again cards: the bot repeats the previous instruction
• Note that these don't "stack": playing an instruction, followed by 2 Agains does the instruction a total of 3 times, not 4

Additionally, bots can increase the number of cards in their deck by taking damage from lasers, or by rebooting. In this case, they receive Spam cards, which are added to their deck:

• Spam cards: a random card from the bot's programming deck is chosen, and that is the instruction carried out this register. At the end of the round, the Spam card is removed from your programming deck.
• Note that this does stack: if the drawn card is a Spam card, you repeat until a non-Spam card is drawn. All drawn Spam cards are removed from your deck.

## Starting positions

Finally, we come to the start. At the very beginning of the game, the 6 players are placed on the 6 starting positions, in a random order. The positions are $$\(1, 1)\$$, $$\(0, 3)\$$, $$\(1, 4)\$$, $$\(1, 5)\$$, $$\(0, 6)\$$ and $$\(1, 8)\$$. Each bot may choose which direction they begin facing.

## Challenge

You are to write a function in Python 3 that takes the following arguments:

• round: an integer, beginning at 0, counting what round the game is on
• order: an integer from 1 to 6, indicating the bot's order of play, with 1 being first and 6 being last
• position: a 3-tuple (x, y, d) consisting of your zero-indexed coordinates in the factory, and a character, one of NESW, indicating the direction you're facing
• score: a boolean, indicating whether you have landed on Checkpoint 1 yet.
• cards: a list of 9 two character strings, indicating the cards you've been dealt
• M1/M2/M3/MB indicate Move 1, 2, 3 and Back respectively
• RT/LT/UT are Right, Left and U-Turn
• Ag/Sp are Again and Spam
• bots: a list of 3-tuples (x, y, d) of the coords and directions of all other bots
• factory: the factory matrix above.

It should then return the following:

• If round is 0, it should return one of N/E/S/W to indicate its starting direction
• Otherwise, it should return a list of up to 5 of the strings from cards, indicating its registers. Note that the first element of this list will be the first register, the second the second and so on. If you return fewer than 5 strings, the list will be filled with randomly drawn cards from your programming deck that weren't in cards until there are 5 elements.

Once the first bot finishes a register on Checkpoint 2, after its score is True, the game is finished, and the winner receives 1 point.

## Scoring

Every combination of 6 bots will play 3 games together. The winner of a game receives 1 point, and the bot with the most number of points after all the games wins.

## Example Bots

Sandbox note: once I've written the controller, I'll add in a couple basic example bots

### random_bot

A completely random bot, it shuffles the cards dealt and returns the first 5:

import random

def random_bot(round, order, position, score, cards, bots, factory):
if round == 0:
return random.choice('NESW')

random.shuffle(cards)
while cards[0] == 'Ag': random.shuffle(cards)
return cards[:5]


# Sandbox

• Thoughts?
• Is this clear enough?
• The original game of RoboRally is super dynamic. I worry that bots may not be able to handle that without being super complex. Thoughts?
• Is this a dupe?
• Tags are , , , and . Suggestions?
• Any further feedback?
• @cairdcoinheringaahing maybe add some examples? No need for an exampple bot, just an example round... Jun 4 at 2:04
• @cairdcoinheringaahing so the board isn't random but is that already? ok Jun 4 at 2:04
• @Nobody No, the board is not random, and stays fixed throughout the game. Bots are given access to it so that people don't have to code in what each square does to their bot. Yes, I can add an example round in a bit Jun 4 at 2:15
• Just to remind you again to add an example round and bot and controller function and stuff. I don't quite understand everything. Jun 7 at 5:33
• Just to remind you yet again to add an example round and bot and controller function and stuff. I don't quite understand everything. Jun 17 at 1:04
• Thoughts: Nothing except seriously add the example Clear enough: Probably, with an example Dupe: Probably not Tags: Good to go. I don't really think tag random is **needed**, but alas... Further feedback: Why a static board? Why the same board always? You can either resolve the edge cases or simply make it not happen; I think it is more interesting that way. Jun 17 at 1:12

Note: If you are seeing this first, you might want to sort by active.

## Unhappy numbers ascii art

Draw a square (or a rectangle as close to a square as possible) that represents the cycle of an unhappy number.

[ short description of unhappy numbers here + example ]

[ square formating rules ]

Unhappy integer.

ASCII art.

### Example

Input:
4
Output:
4 -  16 - 37
20         58
42 - 145 - 89

• The cycle of an unhappy number is a constant.
– J B
Mar 7, 2011 at 23:42
• @JB: thanks, I will rephrase the question. I didn't mean the 4 cycle. (Why did I chose 4 as an example? :/ ) Mar 8, 2011 at 4:56
• @Eelvex This is an nice challenge. Are you still interested in finishing it? Feb 7, 2016 at 19:06
• This challenge proposal has been inactive for over a month. I would like to take ownership of the challenge and make it ready for posting. Please let me know within the next 2 weeks if you have any objections and would still like to finish and post this challenge yourself. Feb 10, 2016 at 0:19
• @JAtkin, no objections. Feb 12, 2016 at 11:20
• If this was posted, can you please delete it? Aug 17, 2017 at 16:58

# Posted Here

• I suggest allowing a matrix of characters as output too (relevant meta). Maybe even allow a boolean matrix as output? May 29 at 17:22
• @pajonk Ah yeah, thanks! May 30 at 19:11
• Maybe Give Examples for intersecting lines or diagonal lines? May 31 at 0:25
• @Nobody finished! Jun 3 at 18:02
• The [6, 4, 2] example is unclear. If each movement draws 2 #s, why are there 7 total #s? I'm guessing that the board begins with 1 # already drawn, and instructions start from there, but this isn't made clear. In fact, if so, the image for the [6, 4, 2] explanation is wrong, as it says "start at the X", when the X is one space too far to the right. Also, I believe you have left and right mixed up with 2 and 6 in the explanation? Jun 4 at 18:01
• @cairdcoinheringaahing oh frick yeah, I'm gonna fix it later, thanks Jun 4 at 19:31

# Create Bernard from Desmos

• Might want to include this animation for understanding the algorithm as listed. However, that algorithm is a bit complicated because it describes the reason for the pattern forming; you could keep it at the end, but I'd suggest describing the result matrix in terms of rectangles: Quadrants 3 and 4 are filled with 1s, as well as quadrant 1.1 and 1.2, then recurse on quadrant 1.4. (where quadrant a.b is the bth quadrant of the ath quadrant, and quadrants are numbered counter-clockwise starting from 1=top right quadrant) Jun 16 at 7:15
• Please take a screenshot of bernard in case this specific manifestation of the bug is fixed or changed, for posterity Jun 17 at 3:43
• @thejonymyster OK will do Jun 20 at 7:02

# Extract the word containing this index

• can we take input as list of words? Jun 20 at 16:02
• @Steffan I didn't want to allow that, because it means there are indices that fall on the boundaries of words with no corresponding value, which I think would unnecessarily complicate the rules and confuse the challenge for little benefit. If you can make a good case for why it should be allowed, I'm all ears. Jun 20 at 16:03
• This is a delightful problem. It seems like it should be trivial, but it's not exactly. And I can think of multiple ways to do it that are competitive with each other in my chosen language. Jun 20 at 19:33
• @chunes Thank you! My favourite challenges are exactly those like this one: despicably simple, with numerous possible approaches. I find the best source of inspiration for these is problems I encounter in real-world programming. Jun 20 at 20:04

# Enumerate the Microwave Timer

• Now I wanna try this on my microwave :P Jun 19 at 1:25
• Can the output times be [second, minute]? Jun 20 at 15:54
• @steffan that's covered under the reasonable format rule Jun 21 at 0:56

## Verification of solutions to the 3 knishops problem

For the purposes of this question, a knishop is a fairy chess piece which can move to precisely those squares which are not an integer distance away. So knight moves (distance $\sqrt{5}$) are ok, as are bishop moves (non-zero multiples of $\sqrt(2)$) and many more besides.

The 3 knishops problem is to place 3 knishops on an infinite chessboard such that none of them attack each other, but every square other than the 3 they occupy is attacked by at least one of them. A more prosaic formulation is to find three lattice points which form an Erdős-Diophantine graph.

Your task is to write code (see below) which takes three co-ordinates as input and produces a truthy or falsy output: truthy if the co-ordinates are a solution to the 3 knishops problem, and falsy otherwise. The code must be able to handle each of the test cases below in no more than one minute on a reasonable desktop machine.

### The small print

"Write code" should be understood to permit one of the following:

• A program which takes input via stdin and gives output via stdout. The permitted input formats are 6 integers, delimited by your choice of a comma or whitespace, and optionally wrapped in one of parentheses (), curly brackets {}, or square brackets []; or three pairs, each pair similarly delimited and wrapped, and the pairs similarly delimited and wrapped. Examples:

0 0 3 4 12 13
(0,0,3,4,12,13)
{0,0},{3,4},{12,13}
{{0 0} {3 4} {12 13}}
[{0 0} {3 4} {12 13}]


Or using different whitespace for the two types of delimiter:

0 0
3 4
12 13

• A named function, verb, block, or equivalent which takes input as an array of six values, an array of three two-element arrays, three separate arrays of two-element arrays, or six separate parameters; and gives output as a return value.

You may assume that none of the input values or the unattacked points have coordinates outside the range $\pm 2^30$.

### Test cases

input                          output

(0 0) (0 0) (0 0)              false
(0 0) (3 4) (12 13)            false
(5 -5) (8 -1) (2 -9)           false
(0 0) (384 2030) (720 1653)    true


TODO More test cases.

NB I need to code up some naïve approaches and test whether the one-minute restriction is actually relevant. I'm hoping that MathJAX will be enabled; if not, the stuff in dollars will be replaced before posting.

# Write a Connect Four Bot

Your task is to write a Connect Four bot. Your submission must be less than 2000 bytes long. You may not save state. You may not use libraries or external resources that are, at my discretion, related to Connect Four.

Gameplay

Your submission will play against each other submission one hundred times. Each player will play first for exactly half of the matches. Each match flows like:

1. Player 1 drops a red token into a column.
2. If Player 1 has not won, then Player 2 drops a black token into a column.
3. If Player 2 has not won, repeat.

Tokens fall down a column until they collide with another token in the row beneath it or hit the bottom of the board. Your program will be terminated and called anew after each move. You win the match if you connect four tokens vertically, horizontally or diagonally.

The winner of the challenge is the submission with the most match wins at the end of a tournament.

Input

The first command line argument you will receive is the game board. Rows are ; delimited . Cells are , delimited. The first row is the top of the board. A cell contains 0 if unoccupied, 1 if occupied by Player 1, and 2 if occupied by Player 2. The board you receive will always be 7 columns by 6 row.

The second command line argument you will receive is your player number. That means 1 or 2.

Examples:

java ThatBot 0,0,0,0;0,0,0,0;0,2,1,0;0,1,2,1 1

Output

You will print the column for which you would like to move to STDOUT. Columns are zero indexed. The following earns an immediate loss:

• Dropping a token into a full column
• Dropping a token into a column that does not exist
• Failing to output anything to STDOUT within one second

Deliverables

You must submit the following:

• A program
• A unique name
• A method of calling your program via command line
• Any instructions I might need to compile your program. I'll try my best, but my best isn't always good enough.

• Oops, didn't see that, sorry :S I think there might be problems still, as several moves could be hard-coded in. (i.e. the first move(s) is always just the middle column) Feb 4, 2015 at 17:07
• @FryAmTheEggman I am totally fine with a few hard coded moves, but perhaps I should reintroduce the byte limit that I originally had in place. Do you think 500 characters is sufficient? I went ahead and added it back. I also added a restriction on external resources to prevent external hard coding. It's probably a loophole, but one worth covering I think. (I'm in chat btw if you want to discuss.) Feb 4, 2015 at 17:08
• 500 seems fine, but it might squeeze Java / C# entries. I'll see how long a pretty bad bot is over the weekend if you haven't posted yet ;p Feb 4, 2015 at 17:21
• @FryAmTheEggman It will be a little while. I haven't written the controller yet. Thanks for the feedback! Feb 4, 2015 at 17:25
• I took a program that claims to do perfect play and added some timing: the vast majority of its moves take less than 1ms; in about 1 game in 8 it has a single move which takes more than 1s. The longest I've seen was just short of 2s, so with a bit of optimisation and a more modern computer it might well come inside the 1s limit. The byte limit would hit it hard, though: its opening book is 12k. Feb 4, 2015 at 20:14
• @PeterTaylor Thank you for that. Knowing what you just found out, do you think that the 500 byte limit plus the timing restriction are enough to make the challenge interesting? If someone can solve Connect Four optimally under those restrictions, then at least PPCG has created something worth having, right? I'm just asking because nobody has upvoted the sandbox proposal, so I assume that maybe there are still some concerns about it. Feb 4, 2015 at 20:37
• I got distracted by looking for work on perfect play and didn't post the thoughts I had. I'm slightly confused about the input format: is \n a literal backslash followed by an n, or does it mean a newline character? The latter would be my assumption, but the example input makes it look literal (and wouldn't work if it were newline). I don't think you specify whether the output assumes 0-indexed or 1-indexed columns. I'm not sure whether the rule about external resources is intended to indicate that I can fetch stuff from the web without it counting towards the byte limit. Feb 4, 2015 at 21:18
• I feel that with a strict byte limit, you're most likely to see mainly versions of min/max or other "simple" algorithms. If you want more interesting or varied players, you may want to relax it. Banning extensive hard-coding is good, but I'd hate for it to come at the expense of creativity. Feb 4, 2015 at 21:19
• The byte limit and timing restriction between them may be too much: I can't see any approach which attempts a real analysis fitting into 500 bytes except in a golfing language which will struggle with the time limit. Maybe 2kB would be a better compromise. Feb 4, 2015 at 21:20
• @PeterTaylor 2000 bytes it shall be, then. I changed the row delimiter to ; to eliminate confusion. I added that columns are zero indexed. The rule about external resources was intended to allow you to fetch from existing resources, but to disallow you to fetch from resources that were created after the fact. In hindsight, this might open the door to abuse, so I've removed that allowance. I'm unsure if this leaves the challenge vulnerable or not, so I'll bring it up in chat. Feb 4, 2015 at 21:28
• Discussed in chat and made the change. I think I've addressed all comments up to now. Feb 4, 2015 at 21:38
• I didn't look very closely at that command line. It should be java MyBot (or maybe java -classpath c:\ MyBot, not java C:\MyBot.java. Other that that, looks good. Feb 4, 2015 at 22:40