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


To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

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.


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
  • Comments addressing specific points mentioned in the proposal
  • 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.


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!


3991 Answers 3991

35 36
38 39

Number of arrangements of half a Rubik's cube

From a corner-on view of a Rubik's cube calculate the number of arrangements of stickers that are out of view.

Your input will provide the state of a Rubik's cube when viewed like the below image:

enter image description here

This input will be an array, in any defined order†, grouping†, and nesting† that you choose, containing the colours‡ of the \$27\$stickers (A.K.A. facelets or tiles) on three sides of a 3x3 Rubik's cube that join at one corner, like you can see above.

The input may be assumed to be that of a solvable state where only face turns can return the cube to having six sides with a single colour on each (if it isn't then your code may do anything, short of summoning Cthulhu).

† The input may be a flat list of colour-labels or you may specify that these labels will already be grouped in any way you wish (it may be a ragged, nested list for example), but the content thereof should only consist of the sticker colour-labels.

‡ Since the centres of the cube are actually fixed relative to each other, and hence the hidden centres' colours are known, you may choose to leave any or all of the central stickers out of the expected input (it could be as short as \$24\$ sticker colour-labels) while using a labeling that identifes the colours as the top-centre, left-centre, right-centre, and their three opposite colours. For the record, the standard colour theme, as in the image above, has orange opposite red, white opposite yellow, and green opposite blue (hence orange is the hidden centre sticker on the bottom etc.).

You should output the number of possible arrangements of sticker colours of the \$27\$ stickers which are not in the input (i.e. those stickers which are out of view). Note that swapping two of those stickers of the same colour is considered to be the same arrangement.

Sandbox questions

  1. Does this need test cases? (I'm not even 100% sure what the output should be if the input looked like a solved cube from that perspective although I may be able to work it out without writing a program it's certainly more than one - e.g. U' L R2 D' M D2 M' D' L' R2 U or R2 U R2 F2 R2 U2 F2 R2 F2 U R2)

  2. Is the spec clear?

  • \$\begingroup\$ You should probably make it more explicit that the center colors of the opposite faces are known. (Also, I'm fairly sure that a "solved cube" input would have an output of 192, but that's just me doing quick math in my head, so I could be wrong.) \$\endgroup\$
    – Nitrodon
    Jan 14 at 15:18

Solve nonimplication-SAT

  • \$\begingroup\$ I don't think there is really one set of "standard decision-problem rules" (as there are for sequence); you could just say something like "output using any two distinct values representing true and false" \$\endgroup\$
    – pxeger
    Dec 31, 2021 at 23:26

Is this continuous terrain?

  • \$\begingroup\$ [Suggested Testcase](Try it online!) \$\endgroup\$
    – Fmbalbuena
    Jan 10 at 0:23
  • \$\begingroup\$ I am unsure if you should allow both ~ and -. Can one even freely mix them? \$\endgroup\$ Jan 10 at 12:33
  • \$\begingroup\$ @JonathanFrech as in you can choose to take input with overlines replaced with one of them \$\endgroup\$
    – emanresu A
    Jan 11 at 8:39
  • \$\begingroup\$ question name idea: "is this continuous terrain?" I have a feeling there is a dupe of this. \$\endgroup\$
    – Razetime
    Jan 14 at 4:05
  • \$\begingroup\$ @Razetime Good idea! \$\endgroup\$
    – emanresu A
    Jan 14 at 8:25

Sides of a polygon

  • \$\begingroup\$ Will the shape touch itself? Say, like this or this ? \$\endgroup\$
    – tsh
    Dec 27, 2021 at 5:40
  • \$\begingroup\$ @tsh No,it won't. \$\endgroup\$
    – emanresu A
    Dec 27, 2021 at 5:56
  • \$\begingroup\$ By your current examples, this is a valid shape although it looks very strange. \$\endgroup\$
    – tsh
    Dec 29, 2021 at 7:15
  • \$\begingroup\$ @tsh Yeah, I’ll just leave that since allowing those shapes doesn’t car assist any problems or ambiguousities. \$\endgroup\$
    – emanresu A
    Dec 29, 2021 at 8:18
  • \$\begingroup\$ I would like for the valid inputs to be more clearly defined. How many sides does @ths's "very strange" looking shape have? \$\endgroup\$ Jan 10 at 12:52

BCD to binary, with bitwise

In this challenge, you'll convert an 8-digit BCD (Binary Coded Decimal) number to a 32 bit (unsigned) integer in the fewest instructions possible, with only bitwise instructions available.


You'll be given a single positive integer as input, from 00000000 to 999999999. It will be represented using BCD, as a 4-byte unsigned integer, with each nibble being a decimal digit from 0000 (0) to 1010 (10). More significant nibbles will correspond to more significant digits of the decimal number.

Your output should be that same number, as an ordinary 32-bit integer.


This is atomic code golf, so you can only use the following instructions, the number of which is used for scoring:

and [r], [r|I]      Bitwise AND
or  [r], [r|I]      Bitwise OR
xor [r], [r|I]      Bitwise XOR

not [r]             Bitwise NOT

shr [r], [r|I]      Shift right (zero fill)
shl [r], [r|I]      Shift left

mov [r], [r|I]      Copy

All instructions will write their output to the first register listed, and for the second argument [r|I] indicates either a register or an immediate (any 32-bit constant) can be provided.

You have four registers to work with, all of which hold a single 4 byte unsigned integer: ra, rb, rc, and rd. Any instruction using only registers costs 1 byte, and any with an immediate cost a total of 4 (this isn't technically possible, since the immediates are 4 bytes on their own, but I don't want to make them too costly).

Input will be provided in ra, and the contents of ra when your program is finished will be used as output. All other registers will be initialized to 0.

Instructions Mk. 2:

This is atomic code golf, so you can only use the following instructions, the number of which is used for scoring:

and [r], [r|I]      Bitwise AND
or  [r], [r|I]      Bitwise OR
xor [r], [r|I]      Bitwise XOR

not [r]             Bitwise NOT

shr [r], [r|I]      Shift right (zero fill)
shl [r], [r|I]      Shift left

mov [r], [r|I]      Copy

goto [r|I]          Go to an instruction (`0` is the start of the program)
goif [r] [r|I]      Go to an instruction, if `r` is not all `0`s

All instructions (aside from goto and goif) will write their output to the first register listed, and for the second argument [r|I] indicates either a register or an immediate (any 32-bit constant) can be provided.

You have 8 registers to work with, all of which hold a single 4 byte unsigned integer: ra, rb, rc, rd, rk, rn, rp, and rs. Any instruction using only registers costs 1 score, and any with an immediate cost a total of 2.

Input will be provided in ra, and the contents of ra when your program is finished will be used as output. All other registers will be initialized to 0.


I don't actually know if this is an interesting challenge, or if more registers will be needed, or if there's already a well known solution. I'd try it myself but it's kinda late here so I'm too tired to, and if I don't post this now I'll forget about it lol

  • \$\begingroup\$ Maybe just give infinite amount of registers and don't call them "byte" but "score"? \$\endgroup\$
    – l4m2
    Jan 18 at 12:29

Compress and decompress

  • \$\begingroup\$ self-referential might be better than quine. But are you assuming normal quine rules? Are programs allowed to introspect their own source code? \$\endgroup\$
    – pxeger
    Jan 17 at 10:15
  • \$\begingroup\$ This challenge is fairly similar to Encode a Lenguage, but I think it's sufficiently open-ended that it's different in an interesting way. \$\endgroup\$
    – pxeger
    Jan 17 at 10:18
  • \$\begingroup\$ Personally I think this would be more interesting if you were allowed to read your source code, because otherwise it becomes too much of a quine variant where most of the code is taken up by encoding the program's source code, and not the interesting task (which is the compression). (Sorry, I probably should have given you this opinion before I asked you to decide whether quine rules applied) \$\endgroup\$
    – pxeger
    Jan 17 at 10:26
  • 1
    \$\begingroup\$ @pxeger I added the quine rules specifically to discourage solutions where you just swap your programs source code and a single input. The other (more interesting imo.) approach is to actually do compression and then make your source code compressible. \$\endgroup\$
    – AnttiP
    Jan 17 at 10:32

Prime Number Fibonacci

In this challenge, you will make a program that calculates the Fibonacci sequence with a twist. Instead of it starting with 0 and 1, it starts with the nth prime number determined by input by the user. The second number is the nth+1 prime number. The sequence should also stop after nth number iterations.


  1. Get a number from the input. We will call it n
  2. Calculate the n prime number and n+1 prime number
  3. Make a function that adds these numbers and calls itself with the result.
  4. Make the function stop once prime number with index n numbers are output





By the way, here is the JavaScript code I used for this example:

var primeNumber1 = prime(num);
var primeNumber2 = prime(num+1);
function fib(num1,num2,iterations,max){
if(iterations == max+1){
function prime(number){
var numPrime = 0;
for(var i = 0; i > -1; i++){
if(numPrime == number){
return i;
function isPrime(num) {
  for(var i = 2; i < num; i++)
    if(num % i === 0) return false;
  return num > 1;
  • \$\begingroup\$ I would define the task more clearly. Something along the lines of (if I understood correctly) "Let \$(p_k)_{k\geq 1}\$ denote the ordered sequence of all prime numbers. Given a natural number \$n\geq 1\$, output \$(a_1,\dots,a_{p_n+p_{n+1}})\$ where \$a_{-1}:=p_n\$, \$a_0:=p_{n+1}\$ and \$a_k:=a_{k-2}+a_{k-1}\$ for \$k\geq 1\$." \$\endgroup\$ Jan 19 at 9:28
  • \$\begingroup\$ @JonathanFrech I have no idea what those symbols mean except for greater than and I know := is used in statically typed programming language to infer the type of a variable. Could you explain what the math string means and how it would clarify my question? \$\endgroup\$ Jan 19 at 14:12
  • \$\begingroup\$ When you say "the nth prime number", is for you 2 the prime number with index \$0\$ or \$1\$? I guess the latter, so \$p_1=2\$. Then I understand your task to be printing \$p_n\$ integers which are defined as follows: the first number to be printed is \$a_1=p_n+p_{n+1}\$, the second is \$a_2=p_{n+1}+a_1\$, the third \$a_3=a_1+a_2\$ and so on up to \$a_{p_n+p_{n+1}}\$. I found it hard to read into your explanation and would like a more clear definition of the task -- be it with formulae or word descriptions. \$\endgroup\$ Jan 20 at 19:21
  • \$\begingroup\$ I guess my problem is that I have to infer from your example that the 2nd prime number is 3 and "Make a function that adds these numbers and calls itself with the result." requires thinking of Fibonacci to properly interpret. \$\endgroup\$ Jan 20 at 19:23

Mat Printing Matrix

  • \$\begingroup\$ er wats default I/O @adam \$\endgroup\$
    – DialFrost
    Jan 17 at 11:56
  • \$\begingroup\$ im sorry i dont understand @adam could u explain the defualt IO (i alr read the link doesnt rly help) or edit my post thx \$\endgroup\$
    – DialFrost
    Jan 17 at 12:02
  • \$\begingroup\$ like this? i changed it \$\endgroup\$
    – DialFrost
    Jan 17 at 12:08
  • \$\begingroup\$ Yeah, this looks great. Maybe put in the tags you plan on using. \$\endgroup\$
    – Adám
    Jan 17 at 12:55
  • \$\begingroup\$ @adam pls edit the tags if its wrong thx \$\endgroup\$
    – DialFrost
    Jan 17 at 13:24

Implement an argwhere function


  • \$\begingroup\$ Interesting. I'm guessing "no", but are langs without function definition allowed to participate? \$\endgroup\$ Jan 14 at 19:53
  • \$\begingroup\$ @thejonymyster I'm not too interested in making restrictions. If your language can accept code as input and run it to make decisions, I'd say that's good enough. But as with all functional-programming questions, some languages will inevitably be excluded. \$\endgroup\$
    – chunes
    Jan 15 at 5:47

Is this word in standard order?

  • \$\begingroup\$ IMO this would be better as an array challenge with arrays of [1,2,3] etc. \$\endgroup\$
    – emanresu A
    Dec 31, 2021 at 22:07
  • \$\begingroup\$ @emanresuA I considered that, but I thought using letters might create some interesting solutions using regular expressions and what-not. Do you think I should allow working over any set (e.g. the natural numbers), not just the alphabet? Or would that be too complex? \$\endgroup\$
    – pxeger
    Dec 31, 2021 at 22:14
  • \$\begingroup\$ And "some \$x\$"? \$\endgroup\$ Jan 10 at 12:35
  • \$\begingroup\$ @JonathanFrech What do you mean? \$\endgroup\$
    – pxeger
    Jan 18 at 8:28
  • \$\begingroup\$ @pxeger I edited in what I meant; feel free to revert. \$\endgroup\$ Jan 19 at 9:16
  • 1
    \$\begingroup\$ I thought on first looks that this is the same as Stackable sequences, but this allows things like aabcc, which I think would be a good test case. Perhaps another useful characterization is that if we take the first appearance of each letter, the resulting sequence counts up from a without gaps. \$\endgroup\$
    – xnor
    Jan 19 at 11:57

Move to Right and left

  • \$\begingroup\$ why are there X crossings? wouldn't they just combine right there? \$\endgroup\$ Jan 20 at 15:42
  • \$\begingroup\$ @thejonymyster this is cross. \$\endgroup\$
    – Fmbalbuena
    Jan 20 at 17:35

Crack the Caesar cipher

  • \$\begingroup\$ Can we not have to deal with capitalisation? \$\endgroup\$
    – emanresu A
    Jan 18 at 21:08
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Jan 21 at 21:59

Regex ordinals

Inspired by this xkcd comic, your job is to write an extremely meta regex.

Specifically, the depth of a regex is an ordinal defined as follows:

  1. regex golf has depth 0.
  2. meta-x has depth 1 greater than the depth of x.
  3. The depth of <regex> is the supremum of the depths of everything <regex> matches.

Of course, it's possible for a string not to have a depth. For example, /.*/ matches itself, so its depth would have to be greater than its depth, which is impossible.

Your challenge is to write a regex with depth \$\omega^2\$.

And this is code golf, so the shortest regex wins.

Examples of regex ordinals

  • meta-regex golf is depth 1.
  • meta-meta-regex golf is depth 2.
  • /(meta-)*regex golf/ is depth \$\omega\$.
  • /(meta-)*\/(meta-)\*regex golf\// is depth \$\omega 2\$.

Von Neumann Probe Battle ()

This is just an idea for now, placing it here as a draft and to collect feedback.

Basically, your goal would be to design a set of machines, including factories and spacecraft, which start on earth and spread outward into the universe. You'd be able to design these machines. Not just their code, but the parts that make them up.

For example, you could start on earth with a single factory, which would make a swarm of mining bots. These would bring ore to the surface, and the factory would switch to making spacecraft. Once the spacecraft are built, the factory could assemble all of the parts needed to make an identical factory, load them onto the spacecraft, and send them to the moon. Then, both factories would start the process over.

The ultimate goal would be to build "stamps", which cost a small amount of iron, and then vanish from existence. These are used for scoring.

This challenge might not be very practical, due to the issues involved in simulating a detailed and exponentially increasing swarm of robots in a vast universe.

  • \$\begingroup\$ stamps? you mean paperclips \$\endgroup\$
    – Ginger
    Jan 22 at 22:05
  • \$\begingroup\$ @GingerIndustries Maybe :p \$\endgroup\$ Jan 22 at 22:06

Pretty print my arrays

I like to pretty print multidimensional arrays, like this:

[ [ [1, 2, 3],
    [4, 5, 6] ],
  [ [7, 8, 9],
    [6, 4, 2] ] ]

But it's a pain to do by hand and it'd be nice to have a program that does this for me. Your challenge is to create a program that does this for me, taking a multidimensional array containing only numbers and prettyprinting it.

Specifically, an array of depth 1 is printed joined by , with [ prepended and ] appended:

[1, 2, 3]

An array of depth \$n+1\$, which contains at least one array of depth \$n\$, has its subarrays prettyprinted, joined by newlines and indented by two spaces. All but the last subarray have a comma appended, the last has ] appended, and the first has its first line indented with [ instead of two spaces:

enter image description here

Here's a reference implementation:

function recursivePrettyPrint(array){
  if(array.every(x => typeof x == "number")){
    return `[${array.join(', ')}]`;
  } else {
    return array.map((item, index) => {
      let result = recursivePrettyPrint(item) + ',';
      result = result.split`\n`;
      if(index == 0){
        result[0] = '[ ' + result[0];
      } else {
        result[0] = '  ' + result[0];
      for(let i = 1; i < result.length; i++){
        result[i] = '  ' + result[i]
      return result.join('\n');
    }).join('\n').slice(0,-1) + ' ]';

function change(){
  let array = JSON.parse(document.getElementById('input').value);
  let output = document.getElementById('output');
  output.innerText = recursivePrettyPrint(array);
<textarea id=input></textarea>

<button id=run onclick=change()>Pretty Print</button>

<pre id=output></pre>

Numbers may be multiple digits. The input will always be orthogonal/rectangular, and you may take its dimensions as well.


[[892, 759], [962, 251]] ->
[ [892, 759],
  [962, 251] ]

[118, 922, 619] ->
[118, 922, 619]

[[966, 639, 616, 255], [622, 483, 87, 241], [453, 870, 728, 725], [163, 936, 48, 967], [261, 833, 87, 200]] -> 
[ [966, 639, 616, 255],
  [622, 483, 87, 241],
  [453, 870, 728, 725],
  [163, 936, 48, 967],
  [261, 833, 87, 200] ]

[[[[[912, 547], [366, 754]], [[723, 536], [779, 238]]], [[[559, 392], [602, 709]], [[692, 915], [412, 302]]]], [[[[3, 504], [936, 83]], [[352, 442], [425, 375]]], [[[380, 440], [793, 762]], [[850, 321], [780, 457]]]]] ->
[ [ [ [ [912, 547],
        [366, 754] ],
      [ [723, 536],
        [779, 238] ] ],
    [ [ [559, 392],
        [602, 709] ],
      [ [692, 915],
        [412, 302] ] ] ],
  [ [ [ [3, 504],
        [936, 83] ],
      [ [352, 442],
        [425, 375] ] ],
    [ [ [380, 440],
        [793, 762] ],
      [ [850, 321],
        [780, 457] ] ] ] ]

[[[128, 910, 664, 658], [172, 238, 564, 492], [325, 384, 566, 90]], [[876, 819, 764, 105], [583, 528, 731, 839], [480, 126, 692, 875]], [[215, 84, 268, 504], [400, 674, 997, 526], [799, 692, 193, 296]], [[943, 185, 567, 188], [118, 200, 879, 409], [116, 493, 62, 343]]] -> 
[ [ [128, 910, 664, 658],
    [172, 238, 564, 492],
    [325, 384, 566, 90] ],
  [ [876, 819, 764, 105],
    [583, 528, 731, 839],
    [480, 126, 692, 875] ],
  [ [215, 84, 268, 504],
    [400, 674, 997, 526],
    [799, 692, 193, 296] ],
  [ [943, 185, 567, 188],
    [118, 200, 879, 409],
    [116, 493, 62, 343] ] ]
  • \$\begingroup\$ "Numbers may be multiple digits" but you should state that numbers will be the only atomic data to occur. \$\endgroup\$
    – Adám
    Jan 24 at 23:40
  • 2
    \$\begingroup\$ Fine challenge, but I hate this way of printing arrays :P \$\endgroup\$
    – Wheat Wizard Mod
    Jan 24 at 23:46
  • \$\begingroup\$ May I input the array as a string? If so, what formatting may I assume for the input array? For example, will there always be a space after each comma? \$\endgroup\$
    – tsh
    Jan 27 at 8:16

Trap the hero in a maze


Ragged list addition

Let's define the operator \$+\$ as follows, using wrapping list indexing:

\$ a+b=\begin{cases} a+b,\space\text{if }a\text{ and }b\text{ are integers (regular integer addition)}\\ [a+b[0], a+b[1], ...,a+b[len(b)-1]],\text{if }a\text{ is an integer and }b\text{ is a list}\\ [a[0]+b,a[1]+b,...,a[len(a)-1]+b],\text{if }b\text{ is a list and }\text{ is an integer}\\ [a[0]+b[0], a[1]+b[1], a[2]+b[2],...,\\a[\max(len(a),len(b))-1]+b[\max(len(a),len(b))-1]],\text{if }a\text{ and }b\text{ are lists} \end{cases} \$

That is huge wall of text, so let's look at an example: We want to add the arrays \$[1,2,[5,6,7]]\$ and \$[[1],2,3,10,0,[3,0],1]\$ together

Let's start


We are adding two arrays, so we add element by element, looping if neccesary:


Now, let's get all the additions that don't involve lists out of the way


Next, lets look at \$1+[1]\$ and \$[5,6,7]+3\$. Here we add an integer to an array, so we just distribute the addition like so:



Now we have \$[5,6,7]+[3,0]\$ left. Again, we interleave the arrays, looping if necessary:



Now there are no \$+\$ signs left. Thus \$[1,2,[5,6,7]]+[[1],2,3,10,0,[3,0],1]=[[2],4,[8,9,10],11,2,[8,6,10],2]\$

Note that ragged list addition is not commutative. So \$a+b\$ is not necessarily the same as \$b+a\$.

Your code takes two ragged lists and returns their sum. Shortest code wins.


Animate finding the middle (hypercube edition)

  • \$\begingroup\$ "All dimensions are the same" should probably be worded more like; "All dimensions are the same length". \$\endgroup\$
    – ATaco
    Jan 20 at 6:33
  • \$\begingroup\$ @Adám Added testcase \$\endgroup\$
    – emanresu A
    Jan 25 at 20:09
  • \$\begingroup\$ @emanresuA The last text case contradicts "until it has less than 3 elements left". \$\endgroup\$
    – Adám
    Jan 25 at 20:13
  • \$\begingroup\$ @Adám You asked for that testcase. But if it's invalid, I'll remove it. \$\endgroup\$
    – emanresu A
    Jan 25 at 20:15
  • \$\begingroup\$ @emanresuA It isn't invalid per se, but your spec is odd. Why not say "until the length of each dimension is less than 3"? \$\endgroup\$
    – Adám
    Jan 25 at 20:16

Play a chess-like game

Your task is to build a program that plays chess. However, it doesn't know how the pieces move before the game begins. In fact, each time it sits down at the board the pieces are different!

The game

This game is played on a 6x6 board, looking roughly like:


Each game has a time control of 1+1 (1 minute, plus 1 second per move). One piece (of 2345) is selected to be the king, and the game ends when any of the following occur:

  • A king is captured (a win for the capturing player)
  • 50 moves pass without a piece being captured or a pawn moving (a draw)
  • One player runs out of time or attempts an invalid move. (a loss for that player)

The pieces


Each player has 6 pawns. Pawns have at least one possible capturing move and at least one non-capturing move that moves it forward. If a pawn moves into a space on the last rank, it may promote into any non-king piece. I've listed white's moves; blacks are mirrored. Pawns may have any or all of the following:

Capturing or non-capturing

... x.x .x. ...
.p. .p. .p. xpx

Capturing only

.p. .p.
x.x .x.

In a game, pawns may be able to move to


And capture pieces in


Major Pieces

The major pieces are more varied, but all of their moves are symmetric. If a major piece can move to a space, it can also capture on that space. Possible moves include (not necessarily exhaustive):

.x. x.x
xPx .P.
.x. x.x

These moves may or may not include the ability to jump over pieces in between:

.x.x. x.x.x
x...x .....
..P.. x.P.x
x...x .....
.x.x. x.x.x

These moves extend across the whole board:

.x... x.x.. P....
xPxxx .P... ..x..
.x... x.x.. .x..x
.x... ...x. .....
.x... ....x ..x..

Each piece will have at least one of these (or others - no guarantees will be made that other movesets will not be included). A piece can have any number of these sets of moves. The two "1"s will have the same moves.

The controller

I haven't built this; I want to gauge interest first.

A potential spec for the controller (have to work out how it communicates):

// Return a list of possible moves in that game state
// If piece is passed (a 2-element array - [x,y]) then only moves which that piece can make are returned
getMoves(board, player, piece = null) => board[]

// Returns the number of milliseconds that player has remaining on their clock.
getTime(player) => float

// Move the piece at origin to destination
makeMove(origin, destination, promotion = null) => void

The tournament

There will be a round-robin tournament played, with as many rounds as possible. Each game will have its pieces randomized at the start, then the bots will play a game as white and a game as black (using the same pieces).


  • Does this sound like an interesting challenge (would it be more than just "fork stockfish")?
  • Would it be alright to restrict this to javascript?
  • 2
    \$\begingroup\$ If you restrict it to a single language, C++ doesn't seem like a very good choice. This KotH will already probably have a high barrier of entry, and a lot of people here probably won't know C++ well enough to bother trying to compete at all. \$\endgroup\$ Feb 2 at 21:40
  • \$\begingroup\$ @taRadvylfsriksushilani Fair point. Performance is a non-negligible factor here, so it's likely that if I don't restrict it to a single language, python or similar may not be able to compete. Restricting it to a single language would alleviate that risk. Python would be my next choice - and I might have to loosen the time control for that. \$\endgroup\$ Feb 2 at 21:47
  • 2
    \$\begingroup\$ Do you know JS? If so, that's a good middle-ground between C++ and Python in terms of performance and accessiblity, and it has the advantage of being able to port it to the browser so people can test bots more easily. \$\endgroup\$ Feb 2 at 22:01
  • \$\begingroup\$ @taRadvylfsriksushilani Interesting. I thought JS was considerably worse than python! Yeah, could do that, then. \$\endgroup\$ Feb 2 at 22:16

Retaining Water

  • 1
    \$\begingroup\$ I like this challenge but I think the string input is unnecessary. A 2D list of ints would be a better format in my opinion. \$\endgroup\$
    – Wheat Wizard Mod
    Feb 6 at 11:29
  • \$\begingroup\$ can i say "- You are allowed to take in the input as 2D list of integers " @WheatWizard? \$\endgroup\$
    – DialFrost
    Feb 7 at 0:52
  • 1
    \$\begingroup\$ I would just have the input be a 2D list of integers. I can hardly imagine it being more convenient to take the current format. \$\endgroup\$
    – Wheat Wizard Mod
    Feb 7 at 0:53
  • \$\begingroup\$ do i manually change the entire input, or just write The input is in the form of a 2D list of integers \$\endgroup\$
    – DialFrost
    Feb 7 at 0:58
  • \$\begingroup\$ @WheatWizard is my challenge now ok? \$\endgroup\$
    – DialFrost
    Feb 7 at 1:38

Can I wall glitch to there?



Slice the source code - Cops and Robbers

  • 1
    \$\begingroup\$ Try to clarify the robbers challenge and add a example \$\endgroup\$
    – Fmbalbuena
    Jan 27 at 16:07
  • \$\begingroup\$ Challenges should be self contained: i.e. copy the relevant info from the link onto the question \$\endgroup\$ Jan 27 at 16:11
  • \$\begingroup\$ @Fmbalbuena Added a example. \$\endgroup\$
    – Bgil Midol
    Jan 28 at 15:13
  • \$\begingroup\$ not bad although i never understand cops and robbers challenge +1 \$\endgroup\$
    – DialFrost
    Jan 31 at 5:34
  • \$\begingroup\$ Really love it. Can't wait for it to be posted! \$\endgroup\$
    – ophact
    Jan 31 at 12:45
  • \$\begingroup\$ @DLosc done.... \$\endgroup\$
    – Bgil Midol
    Feb 9 at 18:54
  • \$\begingroup\$ It would also be good to add examples for negative indices and a negative step value. If people haven't seen Python-style slicing before, they might be very confused about why [::-1] is "reverse the code." \$\endgroup\$
    – DLosc
    Feb 9 at 20:04

All sequences as substrings




Make me a k-NN classifier

The "machine-learning" tag will be created

The k Nearest Neighbors (k-NN) classifier is a simple machine learning classifier. Although k-NN also works for regression tasks, we will be focusing on classification tasks for this challenge.

The classifier can be customized in a number of different ways. For this challenge, the following can be customized:

  • k itself;
  • the distance metric; and
  • the aggregation function.

Main idea

As you can probably tell by its name, k-NN works using the concept of neighbors. First, we "train" classifiers by giving it (preferably a lot of) training data.

A training data point consists of two parts: its "features" and its target value. For instance, if predicting car brand, features might be maximum speed, size etc, and the target variable would be brand. We can also specify k, a distance metric, and/or an aggregation function, or let the classifier fine-tune these hyperparameters itself. For this challenge, the above hyperparameters will be given directly to the classifier.

When we give the classifier a list of features to be assigned a predicted target value, it takes the k train points closest to the test point, measured by distance metric via features, and runs their target values through its aggregation function to obtain its prediction.

The hyperparameters are explained below:


k is the neighbor count. If k is 5, for instance, the classifier will consider 5 neighbors when predicting.

Distance metric

The distance metric measures how far two data points are from each other, measured by their features. A standard distance metric is Euclidean distance, but many others can be used, such as the Manhattan distance.

Aggregation function

Once the classifier has found the k nearest neighbors, it calls its aggregation function using the target values of these neighbors. A standard aggregation function for classification is majority vote, but many others can be used.


The following are to be taken as input:

  • a list of train data points where each data point consists of:
    • a list of numbers, where the lengths of these lists are the same for all training data points; and
    • a target value;
  • k;
  • a distance metric which takes two data points' features and outputs a positive number; and
  • an aggregation function which takes k data points' target values and outputs a value that is one of the target values contained within the training data (this means that you can't just output some arbitrary number; it must be a target value for at least one of the train data points);

You may also take in the following:

  • a list of features of the same length as every list of features within the training data.


  • if an additional list of features was given, the prediction, found using the procedure described above, for that list of features;
  • if no such list was given, a function that takes in a list of features as described above and outputs the prediction for that list of features.

Input is flexible so long as it is within reason.

The distance metric and aggregation function are black-box functions.

This challenge is , so the shortest code, measured in bytes, wins.

Test case

Given in python.

k = 5
distance = lambda a, b: sum((b[i] - a[i]) ** 2 for i in range(5)) # Euclidean distance
aggregation = lambda a, b, c, d, e: max([a, b, c, d, e], key=lambda i: [a, b, c, d, e].count(i)) # output the one with the most occurrences
train = [
 [[1, 2, 3, 4, 5], 0],
 [[2, 3, 4, 5, 6], 1],
 [[3, 4, 5, 6, 7], 1],
 [[1, 4, 5, 6, 7], 0],
 [[1, 8, 9, 9, 9], 0],
 [[9, 0, 0, 0, 0], 1],
 [[2, 3, 4, 1, 1], 1]

classifier_func = knn_classifier(train, k, distance, aggregation) # function output

print(classifier_func([1, 0, 0, 0, 0])) # outputs 1

Do we have any feedback? Duplicate? Clarification needed? Wrong terminology? Wrong test case?

  • \$\begingroup\$ Maybe you should include algorithm the knn classifier used. And how should answers handle random numbers if any randomness is involved in the algorithm. \$\endgroup\$
    – tsh
    Feb 20 at 12:37
  • \$\begingroup\$ @tsh The functions given as input are black-box functions. And I'm not sure what you mean by "including the algorithm the knn classifier used". You mean add the code for the classifier? \$\endgroup\$
    – ophact
    Feb 20 at 14:36

Simulating Bombs


Golf the prime numbers in Shue

  • \$\begingroup\$ how are you this smart to create such a challenge? \$\endgroup\$
    – DialFrost
    Feb 15 at 2:45
  • \$\begingroup\$ I'm not sure I entirely understand the language. What does b!c mean? What is =| (without anything before it on a line)? \$\endgroup\$
    – ophact
    Feb 15 at 8:33
  • \$\begingroup\$ @ophact so the only characters with special meaning are =, \ and the newline. b!c is just a string like any other. I could have used T instead of !, it's just an arbitrary character that is used as a separator. =| means that you can replace the empty string with |, meaning that for example, if we had the string Hello, we could transform it to H|ello or |Hello| or |H|e|l|l||||||||||o| and so on. \$\endgroup\$
    – AnttiP
    Feb 15 at 10:01
  • \$\begingroup\$ @l4m2 If you mean a character or string that matches the beginning of the string, the answer is no. \$\endgroup\$
    – AnttiP
    Feb 15 at 15:29
  • \$\begingroup\$ Output mean it need whole match? \$\endgroup\$
    – l4m2
    Feb 15 at 15:44
  • \$\begingroup\$ @l4m2 Yes, otherwise it wouldn't be turing complete. \$\endgroup\$
    – AnttiP
    Feb 15 at 15:45
  • \$\begingroup\$ Why not ab => a|b => | => L| => no? \$\endgroup\$
    – l4m2
    Feb 15 at 15:49
  • \$\begingroup\$ but ab match "a"*x+"b"*x \$\endgroup\$
    – l4m2
    Feb 15 at 15:52
  • \$\begingroup\$ @l4m2 Yes, that's right, I'll fix it \$\endgroup\$
    – AnttiP
    Feb 15 at 15:52

Golf the colors of a rug


The challenge is based on this rug:


Its colors seem very regular, but the pattern isn't obvious. However, it becomes visible when we move vertical stripes of the rug up and down:

Rug strips

All stripes are colored in the same way, but each stripe is offset by some height, except for a few irregularities. Also, the stripes have different widths.

First, we need to list all colors:

0: blue-ish white
1: lighter blue
2: darker blue
3: darkest blue
4: green-ish white (the color between the middle orange rows)
5: middle green
6: dark green
7: orange
8: light red
9: dark red

Now, we can lay a grid of cells of equal color over this image. I found that using a cell size of 73.5x129 pixels seems to be a good compromise between precision and compactness. This results in a 42x32 grid, which looks like this when overlayed over the rug:

Rug grid

Correcting for some perspective errors, we now can approximate the colors of this rug like this:

Rug simplified

The color scheme shared by all stripes consists, from top to bottom, of these 42 colors: [3, 3, 2, 3, 3, 2, 2, 0, 2, 2, 1, 1, 3, 1, 1, 5, 5, 6, 5, 5, 6, 6, 7, 6, 6, 7, 7, 4, 7, 7, 8, 8, 7, 8, 8, 9, 9, 8, 9, 9, 9, 9]. (This already contains the information that some rows have different heights, by having multiple entries of the same color in a row.)

There are 18 stripes with widthes [2, 3, 3, 3, 1, 1, 4, 2, 1, 6, 1, 1, 2, 2, 2, 3, 2, 3]. Their vertical offsets are [3, 4, 3, 4, 2, 0, 2, 4, 7, 9, 10, 9, 5, 3, 5, 3, 4, 5], which means the first stripe starts at the color at index 3 in the common scheme, the second stripe at index 4 and so on. Starting from the respective start index, the next 32 colors are used; remaining colors (if any) are unused.

There are some irregularities in the rug. I didn't find a better way of expressing them except for listing their X and Y coordinates in the grid together with their colors:

X     [8,  9, 10, 19, 19, 12,  0,  1,  2,  3,  4,  2,  3,  4,  2,  3,  4,  5, 13, 14, 15, 16, 17, 18, 34]
Y     [18, 18, 18, 23, 24, 27, 31, 31, 29, 29, 29, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31]
Color [5,  5,  5,  0,  0,  8,  9,  9,  9,  9,  9,  9,  9,  9,  8,  8,  8,  9,  9,  9,  9,  9,  8,  8,  9]

They are included in this challenge to better reflect the rug and to increase difficulty a bit.


Output this 42x32 grid of numbers from 0-9, each corresponding to the color of one cell of the rug:



  • The program should not take input.
  • Formatting doesn't matter.
  • This is , so shortest answer (in bytes) wins.

Sandbox Questions

  • Why doesn't the box with irregularities align?
  • Would the challenge be more fun with or without having to include irregularities? I guess allowing both variants is not a good idea because solutions aren't comparable anymore.

Smallest maximal rectangle in a skyline

  • \$\begingroup\$ u can say that this is like version 2 of the previous challenge u posted similar to this \$\endgroup\$
    – DialFrost
    Feb 17 at 10:32

Chess Board Analyzer

  • 1
    \$\begingroup\$ I really like this \$\endgroup\$ Feb 17 at 11:12
35 36
38 39

You must log in to answer this question.

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