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!


4273 Answers 4273

7 8
10 11

Programming Puzzle or Code Golf?

(A judging books by covers question)

^Might need a better title.

This question is based off the "Let's Judge Some Books By Their Covers" question.

Browsing the site, I see that 1859 of our 2692 questions (69%) are tagged . My question is: what's the difference?

Your goal is to write a program (or function) to predict, given only the title of a question, whether or not that question is tagged code-golf. Your program will receive a title as input and should output either a truthy (if it's code golf) or falsey (it it's not) value.

Additionally, your program should contain no more than 1000 bytes.


The test data will be all of the questions on this website, excluding closed/migrated/deleted questions. Your score will be the Phi coefficient calculated by comparing the results of your program with the actual data. Higher values (closer to 1) are considered better.

The Phi coefficient is calculated via the following formula:

guess      puzzle  golf  total
  puzzle   A       B     Y
  golf     C       D     Z
  total    W       X

Phi = (AD - CB) / sqrt(WXYZ)

The benefit of this scoring method is that any form of random guessing (output not affected by input) results in an average score of zero.

The exact data set is yet to be generated.


I believe this challenge is an improvement over the previous challenge due to a few reasons:

  • The question title probably has a much stronger relationship to its tags than to votes, so there's hopefully more room for improvement and competition.
  • Although there will be special-casing (for words like "short") it won't be for single questions. There's no massive outliers in the data.
  • \$\begingroup\$ You might want to force the program to be deterministic to prevent return rand<.69 \$\endgroup\$ Nov 11, 2014 at 15:59
  • 2
    \$\begingroup\$ Please don't change the title, it's perfect :P \$\endgroup\$ Nov 11, 2014 at 16:36
  • \$\begingroup\$ This has the issue of hardcoding. A near-perfect program can probably be written by compressing the 2692 bits needed into a 337-bytes magic string and using a hash table with enough expansion to make collisions rare. Ideally, you'd have a secret test set that's separate from the training set, but I don't know how to restrict that here except for "honor system" given that the data is public. \$\endgroup\$
    – xnor
    Nov 14, 2014 at 10:22

Find a Diagonal

Given a (possibly concave) polygon of n ≥ 4 sides, output a valid diagonal, a line segment joining two distinct vertices which, aside from the endpoints, is completely contained within the interior of the polygon.

For example, for the polygon

[(0, 0), (3, 0), (1, 1), (0, 4)]

a valid diagonal (in fact, the only possible diagonal) is:

[(0, 0), (1, 1)]


Some invalid diagonals are:

[(3, 0), (0, 4)]     Lies outside the polygon
[(0, 0), (3, 0)]     Is an edge of the polygon - the interior of the line is not inside
[(0, 0), (0, 0)]     Two identical vertices


Input will be n pairs of integers representing the vertices of the polygon in order. There is no fixed orientation for the input — it could be clockwise or anticlockwise. You may write either a function or a full program for this challenge, and assume any clear (all integers distinguishable) and convenient list/string format for the input.

You may assume that no three consecutive vertices of the polygon are collinear, i.e. there are no 180 degree angles. You may also assume that all coordinates are between 0 and 255 inclusive.

Output will be 2 pairs of integers representing a diagonal, which may also be in any clear and convenient list/string format.


  • You must work in the integers or rationals. In particular, you cannot use floating point integers, due to imprecision.

  • You may not use any polygon-related builtins.

  • This is code-golf, so the program in the fewest bytes wins.

Test cases

For each case, the first line is the input polygon, and the second line is all possible edges which are a valid diagonal. You only need to output one valid diagonal, and the vertices may be in either order.

Vertical diagonal
[(0, 0), (1, 1), (2, 0), (1, 3)]
[(1, 1), (1, 3)]

Horizontal diagonal
[(5, 0), (3, 4), (8, 8), (6, 4)]
[(3, 4), (6, 4)]

The relevant images are given below, in test case order (click the thumbnails to view).

Test 1 Test 2

(More cases to be added)

  • 2
    \$\begingroup\$ Your first example of a valid diagonal has one end-point which isn't actually a vertex of the polygon. The example would benefit from an image. Since you're restricting people to exact arithmetic, you should specify a bound on the vertex coordinate values so that people can work out whether they're at risk of overflow. \$\endgroup\$ Mar 17, 2015 at 8:00

The Predator of my Predator is my Prey

(Three Team KotH)

Three teams: Red, Green, Blue

  • Red kills Green
  • Green kills Blue
  • Blue kills Red

As in Red vs Blue, each entrant is assigned a colour based on their userid. Your objective is to ensure your team has the most surviving members at the end of the game.

The rules are simple but the dynamics may not be obvious. For example, wiping out your prey colour early on seems like success, but it leaves your predator colour with no predators of their own, and free to wipe you out. This means early on it may be better to herd your prey rather than kill them, but this could back-fire if your team leaves it too late...

Possible game styles

Whatever the style, when a Red bot touches a Green bot, the Green bot becomes a Red bot (the bot's code is replaced by its attacker's code). The total number of bots is therefore constant throughout the game. There are a number of settings in which such a game could be played:

  • pixels in an open arena (like Red vs Blue)

  • pixels in an arena with obstacles/walls/mazes

  • bots in a continuous arena (no grid), free to turn smoothly through 360 degrees

I like the idea of a continuous arena, and bots only seeing a small radius semi-disc ahead of them. With no vision behind them they would have to either turn regularly, or coordinate with their team mates to get more information on their surroundings. Bots would be able to write messages and read the messages of other bots on the same team.

Sandbox questions

  • Stack Snippet / full multi-language KotH?

  • which of the game styles suggested would be most interesting?


ASCII Art of the Day Series

My new found love for ASCII art has lead me to a lot of good (trivial and non-trivial) ideas for ASCII ART challenges. Here are the ideas :

1. Double Knot

2. Flow Snakes

3. Chinese Shrine

4. Zodiac Signs

6. Snow Flakes

Its time for another ASCII Art of the Day. This time, we are going back to the winters and drawing Snow Flakes (not to be mixed up with Flow Snakes ;) ). The snow flakes are generative based on random walk so each run should give a different pretty snow flake ASCII.


Given an input integer N, draw an ASCII snow flake of radius N using the construction instructions provided below.


The Snow Flake will have 6-fold rotational symmetry and 3-fold reflection symmetry. You will ideally only generate 1 out of the 12 wedges in a snow flake and then rotate/mirror them to get the other wedges.

Lets consider the following snow flake for N = 5:

     \__    __/
     /_/ /\ \_\
    __ \ \/ / __
  \/ __/_/\_\__ \/
    /_/ /\/\ \_\
     __/ /\ \__
     \_\ \/ /_/
     /        \

Lets name its wedges as:

       4      3
     5\__    __/2
      /_/ /\ \_\
     __ \ \/ / __
7  \/ __/_/\_\__ \/  12
     /_/ /\/\ \_\
      __/ /\ \__
      \_\ \/ /_/
     8/        \11
       9     10

For creating the above snow flake, all we need is to first construct a single wedge (say 1) and fit others in place based on wedge 1.

Wedge Construction

Lets consider the wedges 1 and 2 from the above example and shade all the blocks which belong to wedge 1 with x.

    /2       x
   _\     xxx
  / __ xxxxx

We can see that exactly 25 x belong to wedge 1 in a 50 block trapezium of wedge 1 and 2. The height of the trapezium corresponds to the input integer N and the base length of the trapezium is 2N.

To construct the wedge 1, follow these instructions:

  • Use only the area marked for your wedge (For example, the x area in the above image for wedge 1)
  • Use uni-directional random walk to fill up the x using the characters /, _ and \
  • There should be at least 1 path in the random walk which connects the left most x with any one of the right most x of each row.

A few examples of valid random walks for wedge 1 are:


Random Ants

This is still a bit hazy but the challenge would involve making random ants out of the following ants:







Fish Aquarium

         .               `         /
                          .    ,../...       .
          .                .  /       `\  /  .
     \    .        o         < '  )     =<
     /\  .                    \ \      /  \   .  __
   >=)'>                       `'\'"'"'         /o \/
     \/ .    /         o              /,        \__/\    .:/
     /   .  /--\ /         /         <')=<     .      ,,///;,   ,;/
           <o)  =<      . / \         \`         .   o:::::::;;///
            \__/ \       <')_=<                     >::::::::;;\\\
             \            \_/            .            ''\\\\\'' ';\
    (                      \              .   __
     )                                       <'_><          (
    (          (                ,/..          `              )
     )     (    )             <')   `=<                )    (
    (       )  (               ``\```                 (      )
  • 1
    \$\begingroup\$ I like (1) and (2) more than (3) and (4) because they are more structured, so more can be done with algorithms rather than compression. \$\endgroup\$
    – xnor
    May 21, 2015 at 5:20
  • \$\begingroup\$ @xnor 3 is not finalized yet, so I may do 4 before 3. But 3 would have more structure to it once done. I agree that 4 does not have much similarity, but there still is scope for reuse in 4. \$\endgroup\$
    – Optimizer
    May 21, 2015 at 5:49

Sandbox note : Big change in specs, mainly for balancing issues (thanks to @trichoplax for your sugeestions :))

Major changes : Starting, Turn deroulement (2 phases from now), tie-break, Cloning. Merging may be removed due to the new specs (rendered pretty useless).

With the current specs, 1000 turn migh be WAAAAAAY to much, as you could easily go up to the 17 range... well, you could reach it in 3 turns, and with 3 turns more you could wipe everything with an explode.... Will fix that

Summoner war

tags :

You're a Summoner controlling Demons. Regulary, some tournament are done to dertermine who will be the king. And the king is always the strongest !

As it is a turn-based game, each Summoner will play twice against each opponent. So, for each pair of submission, they will all fight while playing first AND playing last.

A fight is limited to 1000 turns. A turn is the cumulated actions of both Masters.

The winner of a fight is the one who totally destroyed all the demons of the opponent. The number of Demons you killed will be used as tie-breaker

The winner of the tournament is the Summoner who won the most fights. The same tie-breaker as for fights is used, except it is the cumulated amount of kill :).

The Grid

The grid is 9*17 and the cells are placed as above :


The numbers indicates the position of the starting Demons. Each Summoner will see itself as the left Summoner. Demons can move and attack on horizontal lines, vertical lines and diagonals.


You will chose up to 6 Demons to summon, determining their stats and their capacities. You can give a maximum of 12 stat point distributed among your Demons Each Demon you summon (at this moment) will cost you 2 points.

Summoning 6 demons will cost 6*2=12 points

Summoning 3 demons will cost you 3*2=6 points, leaving you 6 points to increase their statistics.


Demons have 4 statistics :

    Hp = 2+Life
    If the hp of your Demon reach 0, it dies.
    Determine the damages you deal/heal
    Reduct all incoming damages by defense/2 rounded to superior. 
    You can't take less than 1 (except if you're attacked for 0 hit points)
    Determine the range of your attacks

Basic Moves

There's 3 moves that every Demons can do :

    The Demons will move by one unit.
    Deal damages to the Demon in an adjacent cell.
    Damages: attack+1
    Destroy the Demon and deal damages to it's surrounding.
    It only can be used if your Demon have more than 40% hp.
    It does raw damages (defense doesn't influence it).
    Damages: attack/2 (raw)
    Radius : 1+sqrt(range)  (square shaped, truncated)


Each Demon will have one capacity in the following list:

    Allows a Demon to absorb an other adding their stats 
    During the merge process, you chose if you want to keep Merge as a capacity, 
    or if you want to take the other Demon's capacity.
    After merging, a Demon won't be able to clone again.
    Heal nearby Demons but not self.
    Heal: attack/2  rounded to superior
    Radius : range+1(square)
    Deal damages on all lines or diagonals around your Demon
    It will damages on lines if the direction you specify is
    Otherwise, it will damages on the diagonals.
    Damages : attack
    Radius : range+1(lines or diagonals)
    Steal some stats if it kills the target
    The target must be on an adjacent cell.
    Damages : attack
    Stat stolen : range (maximum)
                The stat stolen will be distributed randomly between the stats
                of your Demon. It cannot steal more point that the opponent 
                Demon have.


You may give an optional name for your Demons. This name will only be known by you, and could be useful if you want to remember the role you gave to your Demons. This name could be changed at anytime.

Turn deroulement

Each player's turn has 2 steps : the enhance phase and the battle phase.

A turn is derouling as following :

player 1's enhancing phase
player 2's enhancing phase
player 1's battle phase
player 2's battle phaes

Enhance phase

Each turn, you will be given 6+nbTurn/50 stats points.

On turn 1, you will have 6 points.
On turn 50, 7 points. 
On turn 1000, 26 points. 

Those points will stack upon time if you don't use them.

On turn 1, I had 6 points, I used 4 remain :2
Turn 2, I gain 6 points more, I can use 8.
etc ...

Those points can either be used to increase the stats of your Demons (1 point = 1 life||attack||defense||range) or to clone them.

To clone a Demon, you must use 2+life+attack+defense+range points. In result, the origin demon will have his points halved, and a clone with the other half will spawn.

Let's say I want to clone the following demon :
He has 2+2+5+0 = 9 statistics points, so I would need 2+9=11 points.
The resulting Demons would both be :
 defense=3 (yes, stats are rounded to superior :))

Battle phase At the start of the battle phase, you will be given :

  • The current tableboard
  • A list containing your Demons and all the information about them
  • A list containing the stats and position of your opponent's Demons

You will return the actions of all your Demons.

you have up to x ms to return this list (not decided yet)

Once you've chosen your actions, the following will happen :

  • Every Demons which had to move, will move. If two Demons try to move to the same location, they will both stay still.
  • All the actions which change the hp(heal/damages) will happens at the same time.
  • Finally, your turn end, and your opponent's will decide his actions.


Each submission will be written in Java. You can't interact with other players nor the controller in any way you could imagine.

You must extend the following class :

Class not yet developped

A github link will be provided, for the controller etc.

Sandbox notes

I'm aware that there's plenty typos and errors, I will correct them before the final version. Some text and clarification might be added. As it can be complicated (lot of options), 4 demonstration Summoner will be provided (and will be in the pool), each of them using only some functionnality (prooving that you don't have to use every single thing).

I'm not done yet with all the sources for the controller/field etc. An API will be provided for extracting/using informations easily. Once it will be complete, I will put a time limit for the execution of one turn. If I have time, I will provide an interface to see the fights with colors etc.

Questions :

  • Is this too complex? I'd like to know if to much options are given, and if it's confusing (ie, if you don't know where to start).
  • Is there some points of the ruleset that are obviously dangerous for the good health of this contest.
  • Any suggestion?

Thanks for reading :)

  • \$\begingroup\$ I've removed all <code></code> tags and instead selected the code and pressed ctrl-K (which adds 4 spaces before the code). This formats as a code block, instead of a series of code lines with white gaps between. I find this much easier to read so I've edited it in for you to see, but feel free to rollback to the previous edit (I thought it would be easier to edit and show, rather than try to describe). \$\endgroup\$ Jun 5, 2015 at 11:02
  • \$\begingroup\$ Ho, thank you, did not know the K^ thing ! I didn't think it was hard to read with it, that's why I did put <code> instead of spaces. Anyway, thanks :). \$\endgroup\$
    – Katenkyo
    Jun 5, 2015 at 11:11
  • \$\begingroup\$ You're welcome :) \$\endgroup\$ Jun 5, 2015 at 11:37
  • \$\begingroup\$ @Katenkyo I'm not certain but wouldn't it be possible just to fill the whole grid by cloning? Which would make it quite hard to develop an effective strategy (because clone leaves two demon with potentially full health- it might work if it shares the health between the clones)- or is that the idea (make a massive army of demons and then fight? \$\endgroup\$
    – euanjt
    Jun 5, 2015 at 14:14
  • \$\begingroup\$ @TheE I think the AoE could compensate this point. One Demon with a good attack stat (via merging/eating) could one-shot a big number of your Demon/turn. I want the "fill with clones" strategy to be possible, but with a little more thinking to be competitive. I don't know yet if it is owerpowered. Anyway, it have to be tested ! Thanks for the case, didn't think of it. Will test it as soon as the controller is up. \$\endgroup\$
    – Katenkyo
    Jun 5, 2015 at 14:29
  • \$\begingroup\$ Minor point: the list of standard moves still refers to 4 instead of 3 moves. \$\endgroup\$ Jun 22, 2015 at 14:09
  • \$\begingroup\$ Explode affects a radius of 1 + sqrt(range). Is this a square range or some other shape (Euclidean to give an approximate circle?). Is the sqrt rounded up or down? \$\endgroup\$ Jun 22, 2015 at 14:11
  • \$\begingroup\$ square range, round down (so 16 range will effectively add 4 points) I did that because you'd only need 17 range to wipe out the entire map with raw damages... No you still can have a good range, but it's harder \$\endgroup\$
    – Katenkyo
    Jun 22, 2015 at 14:13
  • \$\begingroup\$ What if the cross affected both players (so you need to get into the right position or else accept that some of your own demons will be hit too)? Would that be interesting or just awkward? How would it affect the balance of the different capacities? \$\endgroup\$ Jun 22, 2015 at 18:35
  • \$\begingroup\$ What if explode and heal also affected both players (all demons in range)? \$\endgroup\$ Jun 22, 2015 at 18:36
  • \$\begingroup\$ @trichoplax I'm thinking about it since the beginning, but I am not able to make my mind about it... I mean, sure it is interesting, and all but... Isn't it too much? You already have to manage lots of demons, to buff/clone them, be aware of your opponents. So I don't know, I can't know, if that would be too difficult to handle... \$\endgroup\$
    – Katenkyo
    Jun 22, 2015 at 18:48
  • \$\begingroup\$ I was thinking less about how complicated it is and more about whether it would make the capacities more balanced. I think the main problem would be if one of the capacities is too strong and everyone chooses nothing else. \$\endgroup\$ Jun 22, 2015 at 21:55
  • \$\begingroup\$ @trichoplax sounds logic. I'll look at a way to implement it :) \$\endgroup\$
    – Katenkyo
    Jun 23, 2015 at 5:32

Ironclad Tactics KoTH

This KoTH is inspired by the Ironclad Tactics paper version from Zachtronics.

The game is played on a 9x4 grid split into three areas: the North, the South, and No-Man's-Land (the center). To make things easier for you, it will always appear that you are the North (the left).


Each battle, each player starts with 10 Action Points (AP). In a battle, there are 4 phases: Selection, Placement, Upgrading, then Attacking.


During selection, players start by each simultaneously choosing an upgrade to ban, and then choosing 5 of the 8 or 9 remaining upgrades they wish to use. The chosen upgrades are not revealed to their opponent.


During placement, players simultaneously place an Ironclad until they decide to drop out of the phase or they have used all of their AP. Each placement costs 1AP, and Ironclads can only be placed on the player's respective side and No-Man's-Land.


During upgrading, players simultaneously upgrade one of their Ironclads using their remaining AP until they decide to drop out of the phase or they have used all of their AP. Each upgrade costs 2+(# of times you previously used the upgrade)-(# of times your opponent previously used the upgrade), with a minimum cost of 0.

There are 10 possible upgrades:


The stars represent Ironclads, and each circle represents the squares the Ironclad will attack. The arrow represents the Saboteur upgrade, which will give the player 2 additional victory points, and the diamond represents the Heavy Chassis upgrade, which requires 2 hits to be destroyed.

Upgrades can be given to any of your unupgraded Ironclads, even if the squares it would attack fall off of the board. Upgrades do not need to be given to all Ironclads.


During attacking, all Ironclads simultaneously attack. Any Ironclad in the square of attack (even if the attack is friendly) is destroyed (unless the tank has the Heavy Chassis upgrade, in which case it must be attacked by two different tanks.

Any remaining tanks give 1 (or 3, if the tank has the *Saboteur upgrade) victory point(s) if they have a horizontal line of sight to the opposite end unobstructed by undestroyed enemy tanks.


You will implement a Java class. more info

Additional Info

  • You will have 10 battles against each opponent.
  • The price for upgrades resets after each opponent.
  • You beat an opponent by having more victory points than them after the 10 battles. You win this challenge by beating the most opponents.
  • If both players attempt to place in the same spot at the same time, that location becomes unplaceable for the rest of the battle, and players must place again.
  • -


You are the proud maintainer of one of the smartest robots in the world. Well, it used to be. Now its speakers and microphones have been broken and the darn thing only seems to read Brainfuck. To make matters worse, it would appear most of its RAM... disappeared? This will be tough to explain to the boss. No matter. It seems to have figured out how to draw on a whiteboard to supplement its now-shoddy memory, and you have bigger problems on your hands.

You need to know how to fit things in cubes.

The Task

Lately, your biggest problems (aside from the embarrassing conversation with your boss later) have to do with volume. Cubing things is hard. That's why you'll get the robot to do it for you! Your goal in this challenge is to write a Brainfuck program that computes the cube of a given number. However, the robot's whiteboard isn't very big. The less memory your Brainfuck program requires, the better.


You will receive a single integer as input, x.

  • You may choose to accept input in any integer base greater than 0 and less than or equal to 36, so long as this base does not vary from input to input. (e.g. binary, hexadecimal, decimal)

  • You may assume that x is in the range 0 <= x <= 2^16 - 1

  • You should take input as a string of characters, not bytes. For example, if x = 33 and my program accepts input in binary, I should receive the string "100001" (bytes: 49 48 48 48 48 49) not simply bytes containing 100001.


  • Your Brainfuck program must output the value of x^3 in the same base that input was received in.

  • As it is for input, your program should output a string of ASCII characters, not a sequence of bytes.

  • The program must terminate, and should not print anything except for its numerical output.

Rules and Scoring

Your score in this challenge is defined in the following manner: Let the tape of the Brainfuck memory be described as having a 1st element at the left-most position, and then with potentially infinite cells to the right, indexed by increasing integers n.

Let N(x) denote the right-most (highest n) cell that the program ever sends the tape pointer to (not necessarily modified) for a given input x. Your score for this challenge is then sum (x = 0, 1, 2, ... 100) N(x) (modification pending)

In order to verify score, you may use [this] (soon) modified interpreter.

  • Your program must be written entirely in Brainfuck.
  • Assume the highest value a cell can hold is 255 before wrapping to 0, and that moving left off of the tape will cause the robot to suddenly and violently crash.
  • Your program should not exceed 10k bytes, nor should it take more than 10 minutes to compute x^3 for any x <= 2^16 - 1 on a relatively modern machine.
  • Standard loopholes are disallowed.


What do you think of BF memory-optimization as a basis for a challenge?

I chose cubing x as a challenge that is not so trivial as to allow for different approaches, but still within the grasp of BF (if different bases are allowed). Any other ideas?

  • 1
    \$\begingroup\$ How is the base determined? For example, if the input is 2, how is it determined if that's base-10 (and so output 8) or base-8 (and so output 10)? \$\endgroup\$ Nov 5, 2015 at 20:50
  • \$\begingroup\$ My thought was along the same lines as TimmyD: the obvious cheat is to just read the digit, write it, and then write 00 and claim that the input was in base x. \$\endgroup\$ Nov 5, 2015 at 21:48
  • \$\begingroup\$ @TimmyD Ack! My post is unclear. I meant that you, as the programmer, may choose what base you expect your input/output to be in. e.g. I can write a BF program that accepts input in base 16 and outputs in base 16, or use ternary if I think it'll help me use less memory. I didn't mean that the base changes from input to input. Thank you for the feedback, I'll certainly try to clear that up! \$\endgroup\$
    – BrainSteel
    Nov 6, 2015 at 1:48
  • \$\begingroup\$ What is the largest allowed input base? Also, the maximum input needs to be bigger: the current rules probably allow hardcoding of all the outputs. \$\endgroup\$
    – feersum
    Nov 6, 2015 at 2:08
  • \$\begingroup\$ @feersum Good points. I'll cap it at 36 to avoid the general silliness of trying to figure out what symbols to use. I understand your concern, but I want to keep the upper limit fairly small. I think 2^16 - 1 should do the trick? \$\endgroup\$
    – BrainSteel
    Nov 6, 2015 at 2:27
  • \$\begingroup\$ @BrainSteel That should be good enough, as long as there are some test cases throughout the range. \$\endgroup\$
    – feersum
    Nov 6, 2015 at 2:31

Pi, continued

The task: generate an arbitrarily precise rational approximation to pi by using a continued fraction.

One way to calculate pi is by using this continued fraction (from Wikipedia):

enter image description here

The first few approximations can be calculated as follows:

enter image description here

enter image description here

enter image description here

enter image description here

You may not use this particular continued fraction. The reason is that in order to calculate this sequence to arbitrary precision, you have to already know pi to arbitrary precision. The series [3,7,15,1,292,...] does not repeat, like pi's own digits.

However, there are continued fractions that have a regular structure. You may use any of these you wish (like these on Wikipedia) in your program.

The rules

  • Input: a single, non-negative integer n.
  • Output: the nth (improper) fraction in your chosen continued fraction series, in lowest terms.
  • Output may be in any form, provided that these conditions are met: 1) the same base is used for numerator and denominator (and for all fractions), 2) the numerator and denominator are clearly distinguishable, and 3) the numerator comes first.
  • Your program must use a continued fraction. It may not use any summation series like the approximation formulae here on Wikipedia.


  • I feel like some of this may be confusing. What can I clear up, and how?
  • Is it misleading to introduce continued fractions by using an unpredictable series when I want users to use ones that have a regular structure?
  • \$\begingroup\$ It looks good to me. As long as you don't mind the example being valid for use in an answer, yes it does seem to make sense to use one of the regular structured ones for the example. That way someone who doesn't read it properly can just use the example without realising there are other options, and you get fewer annoying questions... \$\endgroup\$ Nov 18, 2015 at 2:20
  • 2
    \$\begingroup\$ Yes, it is misleading to start with the unpredictable series. Are you ruling out approximating pi with a built-in or other limit (that is not a summation), then computing the continued fraction from that? The examples you link are generalized continued fractions, which can have numerators other than 1 and summands that are not whole -- I take it those are allowed? \$\endgroup\$
    – xnor
    Nov 18, 2015 at 9:24
  • 1
    \$\begingroup\$ The nth term in a continued fraction series is well defined modulo possible out-by-one disagreements in the indexing. But for generalised continued fractions, there are three competing definitions: if the gcf is x = b_0 + a_1 / (b_1 + a_2 / (b_2 + ... )) is the sequence b_0, b_0 + a_1, b_0 + a_1 / b_1, b_0 + a_1 / (b_1 + a_2), b_0 + a_1 / (b_1 + a_2 / b_2), ...; or is it b_0, b_0 + a_1 / b_1, b_0 + a_1 / (b_1 + a_2 / b_2), ...; or is it b_0 + a_1, b_0 + a_1 / (b_1 + a_2), b_0 + a_1 / (b_1 + a_2 / (b_2 + a_3)), ...? \$\endgroup\$ Nov 18, 2015 at 19:44
  • \$\begingroup\$ Regarding the competing definitions, I think the cleanest resolution would be to allow any pattern that adds one layer at a time in a consistent fashion, which allows any of the examples as well as off-by-one disagreements. \$\endgroup\$
    – xnor
    Nov 18, 2015 at 22:09

Rotate / Flip a Unicode Box Drawing

Given a Unicode box drawing, followed by a series of rotate and/or flip commands, output the result of those operations on the drawing. For clarification, a box drawing can be made from the following characters:

─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼
═ ║ ╔ ╗ ╚ ╝ ╠ ╣ ╦ ╩ ╬
    ╒ ╕ ╘ ╛ ╞ ╡ ╤ ╧ ╪
    ╓ ╖ ╙ ╜ ╟ ╢ ╥ ╨ ╫

The rotate and flip commands are also presented using Unicode symbols:

↔  Flip the drawing horizontally
↕  Flip the drawing vertically
↷ Rotate the drawing 90° clockwise
↶ Rotate the drawing 90° counter-clockwise
↯  Convert all single lines to double and vice versa (Optional - 10% bonus)

All other characters should remain unchanged, but moved to fit where they would be in the modified drawing. For example, if given the inputs:

Input   Output          Input   Output
 ┌┴╖     ╓┴┐             ┌┴╖     ╔═╕
 │A║     ║A│             │E║     ╣E├
 ╘╦╝     ╚╦╛             ╘╦╝     ╙─┘
 ↔                       ↔↷

 ┌┴╖     ╒╩╗             ┌┴╖     ┌─╖
 │B║     │B║             │F║     ┤F╠
 ╘╦╝     └┬╜             ╘╦╝     ╘═╝
 ↕                       ↷↔

 ┌┴╖     ╓─┐             ┌┴╖     ╔╩╕
 │C║     ╣C├             │G║     ║G│
 ╘╦╝     ╚═╛             ╘╦╝     ╙┬┘
 ↷                      ↶↶

 ┌┴╖     ╒═╗             ┌┴╖     ╔╩╕
 │D║     ┤D╠             │H║     ║H│
 ╘╦╝     └─╜             ╘╦╝     ╙┬┘
 ↶                      ↔↕

The drawing may be of any size (let's say anywhere from 1×1 to 50×50), and not necessarily square.

The flip and rotate commands will always occur after any drawing to be flipped, and by themselves on one single line. They should be executed from left to right. (Note that order matters - the E and F examples use the same two commands but in reverse order, and produce different results.)

There may be an arbitrary number of flips and rotates, but you'll note that there are only 8 possible end-states for the final drawing. The G and H examples show two different sets of commands that produce the same result (other than the letter in the middle). It is possible that a series of commands will result in simply returning to the original drawing.

Input may be supplied via command line, user input, file I/O, or any other means you see fit. (Though it should obviously support multiple lines of input. You may use \n to represent line breaks if your input mode only supports a single line.) Likewise, output may be to the screen or a file at your discretion.

This is code-golf, so shortest code wins.

Some more complicated examples:

Input    Output        Input    Output
          ┌─┐                    ┌─┐
          │A│                    │B│
┌─╥─┐     ╞═╡          ┌─╥─┐     ╞═╡
│A║B│     │B│          │A║B│     │A│
└─╨─┘     └─┘          └─╨─┘     └─┘
↷                     ↶

   Input           Output
┌─┐╔═╗╒══╓──    ──╖══╕╔═╗┌─┐
├─┘╠═╝│  ║ ╖    ╓ ║  │╚═╣└─┤
│  ║  ╘══╙─╜    ╙─╜══╛  ║  │

┌─┐╔═╗╒══╓──    ╔═╗┌─┐╓──╒══
├─┘╠═╝│  ║ ╖    ╠═╝├─┘║  │ ╕
│  ║  ╘══╙─╜    ║  │  ╙──╘═╛

┌─┐╔═╗╒══╓──    ┌─┐╔═╗╒══╓──
├─┘╠═╝│  ║ ╖    ├─┘╠═╝│  ║ ╖
│  ║  ╘══╙─╜    │  ║  ╘══╙─╜
  • \$\begingroup\$ You should have examples where characters other than the box move, the box is a different size and with more than one box, if that is allowed. This looks like a good challenge, but one that is likely to be rife with ambiguity. \$\endgroup\$ Dec 9, 2015 at 14:46
  • \$\begingroup\$ @FryAmTheEggman - I chose one starting box which is asymmetrical just as a simple example. I could add a couple more complicated shapes - I was thinking this could be applied to any shape using the box-drawing symbols, not just a simple box. \$\endgroup\$ Dec 9, 2015 at 18:55

Create a spiraling image




Given an image, output the image with a spiraling effect.


This is a , so the submission with the highest number of votes wins!

Test cases

Note that your program should work for images with any size. The output should be a 512×512px image. Also, note that the test cases are examples, you may use any algorithm to produce these images and do not have to match the images below. Use your creativity!

Test case 1

enter image description here


enter image description here

Test case 2

enter image description here


enter image description here

Test case 3

enter image description here


enter image description here

Test case 4

enter image description here


enter image description here

Test case 5

enter image description here


enter image description here


The full size images:

  • \$\begingroup\$ What counts as the Droste effect does not appear to be clearly defined here, and some of the example outputs are hard to justify as exhibiting the effect. The chat image in particular doesn't seem to have any repetition of the image within itself, only distortion of the scale. \$\endgroup\$ Feb 13, 2016 at 23:23
  • \$\begingroup\$ @trichoplax Oh, you're right. That isn't even a Droste image. I should probably remove the "Droste" thing and make something else out of it. Maybe define it as a "spiral" image. \$\endgroup\$
    – Adnan
    Feb 13, 2016 at 23:30
  • \$\begingroup\$ Either way it sounds like the too-broad end of the popularity contest spectrum. For a Droste image challenge you could probably make it well defined enough to not need to be a pop con if you also have a template as input, defining one or more places where the image needs to reappear recursively. So for each hole in the template, the image will reappear, including the holes in the template for repeatedly smaller images. \$\endgroup\$ Feb 13, 2016 at 23:33
  • 2
    \$\begingroup\$ @trichoplax Hmmm, okay. I should give this a lot of thought then. I do think that with the amount of possible ways to approach this problem, this should be a popularity contest. But it's definitely too broad at this stage. \$\endgroup\$
    – Adnan
    Feb 13, 2016 at 23:41

Random Physics Golf #1: Net Gravitational Force

Introduction to the Series

Every week or so I will be posting a physics challenge. My goal here is to design challenges that in the end, teach some people some physics. Overall, the challenges will be very basic with little information. All of these challenges will have the minimal information necessary to solve them, and the goal is for users like you to do some research, watch some videos, and understand how these concepts work to teach you how to approach these types of physics problems and explain how they work. Of course, I will also give two optional hints per challenge, which are there if you do not have the time or determination to do the research, or you cannot figure out how to do the problem after researching. The two hints will be "necessary equations for this challenge" and "process to solve the problem". The hints are completely optional to use and it is encourages to not use them, but as stated above to learn the information for yourself. The series will have one main leaderboard. Whoever has the least combined byte count for all of the challenges gets a to be determined prize. Each challenge will range in difficulty, with an upwards trend of difficulty. I wish you all luck and I hope you learn a thing or two!

Challenge #1: Net Gravitational Force

Note 1: this challenge highly requires knowledge of the mathematical vector quantity, if you do not know what that is, I suggest reading this and this before attempting this challenge.

Note 2: this challenge considers gravity in CLASSICAL MECHANICS. Disregard general relativity for this challenge.

Lets start with the definition of a force. A force is a vector quantity, a number with both direction and magnitude. Simply put, force is mass times acceleration. Many mathematicians will know the name of this formula as Newton's Second Law. Now, that is a well known formula, but here is something less known: all forces are classified in one of four categories: weak nuclear, strong nuclear, electromagnetic, and gravitational. These four are called the four fundamental forces of the universe. We will be focusing on the gravitational force in this called.

The gravitational force is then classified as a field force. This means that the force acts on all objects in a certain radius around another object. In this case, gravity pulls down on objects from anywhere in a radius around them. However, I still have not defined where gravity comes from. Well, the simple answer is from mass. An object with more mass has a bigger gravitational pull on objects around it. In case you are wondering, the earth has a gravitational pull of -9.81 m/s^2 (an object will gain 9.8 m/s of downward velocity every second). But here is where it gets fun: because gravity comes from mass, every object with mass has a gravitational pull. This is where you come in. I want you to calculate the net gravitational pull of all the objects surrounding another object. Here is a better explanation:

You will receive co-ordinates and masses of objects in space for input. So an example input could be visualized as this: enter image description here You can easily see each force being applied on the target object by the three larger objects. Objects will smaller masses have a smaller gravitational field (as shown by the orange force arrow). Your job in this challenge is to find the net gravitational force being acted on the target object. To do this, it is a simple vector addition problem with the forces from the other objects. So, the resultant vector (net force), may look something like this: enter image description here This is all of the information that I will give you. It is now your job to find the equations, and research how this all works.

Challenge Specs

  • Input will be several lists of numbers consisting of the x co-ordinate, y co-ordinate, and mass of each object. The numbers could be either integers or decimals. You may take this in any convienent format ([[1 2 3][4 5 6][7 8 9], [(1,2,3),(4,5,6),(7,8,9)] and 1,2,3|4,5,6|7,8,9 are all acceptable. The first list of inputs will always be the target object (red in the pictures above), and the other lists will be the other objects. All inputs will have at least two objects. No objects will have the same co-ordinates.
  • Output will be two numbers, in any human-readable format, in any order. One will be the magnitude of the net force, using your desired unit system (SI, Planck units, Imperial units, etc.) and the other will be the direction in radians OR degrees of the net force. Output must be precise to the least number of significant figures in the input (Input: 2, 3.5, 6.1 -> Output: 200 (232.34 before rounding), note this is not an actual test case). Output may or may not be in scientific notation, its up to you.
  • You may assume input will not cause any error during execution, and you may assume all inputs will be valid.

META NOTE: Help me decide the precision of the output: http://strawpoll.me/6825341

Test Cases

Meta Note: WIP


These hints are for those who do not want to put in the time and effort of research, or those who could not find a solution. So, here are the two hints:

Hint 1: Equations:

You need the following equations for this challenge:

enter image description here

You will also need the standard vector equations for this challenge:

enter image description here

Hint 2: Sample Solution Process:

It would take up too much space to fit it all here, so I made this to aid you for this hint.


Meta Note: blah blah blah, working leaderboard will eventually go here! This leaderboard will contain and combine scores for all of the weekly challenges. It will only be visible on this question, though.

  • 1
    \$\begingroup\$ The input format currently is cumbersome, requiring string parsing. I would recommend loosening it to allow input as a list of 3-tuples (or similar representations). You should also specify whether the inputs will be integers or decimals. \$\endgroup\$
    – user45941
    Feb 5, 2016 at 3:45
  • \$\begingroup\$ @Mego I took your recommendations. Does that look good? \$\endgroup\$
    – GamrCorps
    Feb 5, 2016 at 21:55
  • 1
    \$\begingroup\$ "Output must be precise to at least three decimal places" would get a rebuke from every physics teacher I ever had. Surely it should be to a number of significant figures which depends on the s.f. of the input? \$\endgroup\$ Feb 6, 2016 at 13:45
  • 1
    \$\begingroup\$ @PeterTaylor Well, this is a programming challenge, and sig-fig calculations would (IMO) overly complicate the answers. (If your comment was a joke/sarcasm sorry ;) \$\endgroup\$
    – J Atkin
    Feb 13, 2016 at 19:56

Temperature in a line of rooms

You have a line of rooms that are different temperatures.

      1       2       3  
 1.2  |  3.5  |  4.0  |  3.7

The doors between adjacent rooms start out closed. When you open a door, the now-connected rooms average out their temperatures. For example, opening door 2 gives

      1       2       3   
 1.2  |  3.75 _  3.75  |  3.7

Then, opening door 1 equalizes the first three rooms to their average (1.2+3.75+3.75)/3 = 2.9

      1       2       3   
 2.9  _  2.9 _  2.9  |  3.7

Finally, if we close door 2 and then open door 3, the last two rooms will average out without affecting the other rooms.

      1       2       3   
 2.9  _  2.9 |  3.3  _  3.3

You can think of the instructions to open and close doors as a sequence of toggles that switch between open and closed, here 2, 1, 2, 3, with the doors starting closed. Given the initial temperatures of the rooms and the sequence of door toggles, output the final temperatures. Fewest bytes wins.


  • A list of initial room temperatures, which are positive reals. There will be at least two rooms.
  • (Optional) The number of rooms n.
  • A list of doors to toggle in order, which range from 1 to n-1. Optionally, these may be zero-indexed.

Output: The list of final room temperatures to some reasonable precision.

TODO: Test cases.


Senior Prank

We're graduating to a full site soon, and there's only one thing left to do before graduation: pull a senior prank! I think we should do a variation on the classic "fill a hallway with cups of water" gag.


Your program will read in text and output that text, covered in upside-down cups of water. An upside-down cup of water looks like this: /~\
These cups can only be placed in whitespace in the input, and can only be placed so that all three characters of the cup are directly above a non-whitespace character (otherwise the water would spill out!). Cups cannot be stacked on top of other cups. Cups must be placed in every available opening, and it is assumed that every input is surrounded by an infinite field of whitespace.
We need to pull the prank off quickly and without anyone noticing, so fewest bytes in each language wins.

Test Cases


    /   ___    /   ___    /   ______/   ________/
   /   /__/   /   /__/   /   /     /   /_______
  /   _______/   _______/   /     /   //__    /
 /   /      /   /      /   /_____/   /___/   /
/___/      /___/      /_________/___________/


    /   ___    /   ___    /   ______/   ________/
   /   /__//~\/   /__//~\/   /     /   /_______
  /   _______/   _______/   //~\  /   //__    /
 //~\/      //~\/      //~\/_____//~\/___//~\/
/___/      /___/      /_________/___________/


 L\\        ____I____
    ========    |  |[\


 L   /~\/~\/~\/~\/~\/~\/~\
 L\\/~\/~\  ____I____
    ========/~\ |  |[\
  • \$\begingroup\$ @TimmyD Initially that gap was two wide. I must have added the space after making the output. \$\endgroup\$ Mar 3, 2016 at 18:19
  • \$\begingroup\$ @FryAmTheEggman Yeah, that's a typo. I should really double check when I edit on my phone. \$\endgroup\$ Mar 4, 2016 at 4:39

City Life

A cellular automation war game.

In this game, each player will control group of cites on a grid. Each city takes up one cell, and all cells with no city are "wilderness", and have no owner. The game will consist of a series of rounds, called "generations". Play continues until a player gets 1000 points, or 200 rounds, whichever happens first.


The board will start with one city controlled by each player. It will be square with sides length ceil(sqrt(25*n)) for an n player game. Cities will be placed randomly in such a way that no two cities will see each other the first round.

Phase 1: give orders

At the start of each generation, each city gets n actions where n = # of adjacent wilderness spaces + 2. So a city surrounded by wilderness gets 10 actions while a city surrounded by cites gets only 2. The Actions will be divided into these three categories:

Attack/Spread : used to Attack Cites or spread into the wilderness.

  • Takes a direction as a parameter. Will add one "Attacker" to that cell, even if the cell is a city with the same owner. (See resolve attacks)

Defend : used to protect your city.

  • Will add one to the defender count of the city performing this action. (If no defend actions are used, the city will become wilderness.)

Score : used to win.

  • Adds one to the score the cites owner.

Phase 2: resolve attacks

After all cites have put in orders, all cells are checked for takeover.

  • A wilderness cell will become a city if at least three attackers are there. The new city's owner will be determined randomly from among the attackers.(for example, if player A sent 2 attackers and player B sent 3, than A has a 2/5 chance of owning the new city)

  • A city will become wilderness if the number of attackers is equal to the number of defenders (even if both are 0).

  • A city is taken over if their are more attackers than defenders. The city's new owner is determined randomly from among the attackers, as above.

After the round is complete, all attackers and defenders are reset.

To enter the competition, you must create a bot to perform the "give orders" step. All bots will be written in JavaScript.


You will provide a character to represent your city and a function that takes as parameters:

  1. Your vision. each city can see a 5x5 square with the city as its center. It will be represented as an array of arrays of characters, " " representing wilderness, and each players character to represent their cites.


if you have a map like This ("Y" represents you)

|AA  B|    N
|A    |    ▲
|  YY | W< O >E
|C   C|    V
|   C |    S

Your sight parameter will be:

[["A","A"," "," ","B"],["A"," "," "," "," "],[" "," ","Y","Y"," "],["C"," "," "," ","C"],[" "," "," ","C"," "]]`
  1. The number of actions you can perform this turn. (which can be calculated, but I will give it to you as most bots will need it.)

You must return an array of strings, each string representing an order.

"N" - Attack North

"NE"- Attack North east

"W" - Attack West


"D" - Defend

"$" - Score

If you return more moves than you have actions allotted, the moves at the end of the array will be ignored. If you have less, extra moves will be set to "D".

I have made a controller that is reasonable, although I would like add to it and finalize the rules before publishing. If you have any advice or criticism, please comment below.

Example Answer:

Random Bot [?]

function(map, moveCount){
    var allMoves = ["N","S","E","W","NE","NW","SE","SW","D","$"];
    var orders = [];
    while(orders.length < moveCount){
    return orders;

This bot will just assign a random move for each action. Its cites are represented by ?.

  • \$\begingroup\$ I think you left off a row in the map. You should also clarify whether attackers and defenders are persistent or must be re-assigned each turn. \$\endgroup\$
    – ballesta25
    Jan 18, 2016 at 20:15
  • \$\begingroup\$ "A city can become wilderness if the number of attackers is equal to the number of defenders" implies to me that there's a random element. Is that so? If not, I suggest replacing can with will. \$\endgroup\$ Jan 23, 2016 at 19:08
  • \$\begingroup\$ @PeterTaylor Thank you, fixed. \$\endgroup\$
    – MegaTom
    Jan 23, 2016 at 20:52
  • \$\begingroup\$ I've been thinking more. It would be good to state the initial density (or, in other words, how the size of the world varies with the number of players). In the interests of fairness, probably also worth guaranteeing that the initial cities will have a certain buffer region (and in particular, that two of them won't start next to each other and a third in a nice open space); and that the topology will be toroidal (so the board wraps both horizontally and vertically). Finally, I would make it explicit that you can attack your own city, but not "support" it (i.e. lend it defenders). \$\endgroup\$ Jan 23, 2016 at 22:25

Super Smash Bots

This is an idea for a KOTH based off of the Super Smash Bros video game series by Nintendo.

The basic mechanics of this KOTH would be an every-man-for-himself battle between a large number of players simultaneously. Players can execute a variety of moves, like short/medium/long-ranged attacks or blocking. As opposed to most combat-based games, players do not have a health bar, but rather die when knocked off of the stage (the arena). When an attack hits a player, it deals damage to that player but also causes knockback. The amount of knockback a player experiences is proportional to the total amount of damage he's received so far in the game.

The Arena

The game takes place on a vertical stage with gravity. There will be several fixed platforms surrounded by empty space. A player too far from a platform is killed. More ideas about the design of the stage are covered in the Stage Design section.

Character Selection?

The actual game offers players the selection of different characters, each of which have different abilities, strengths, and weaknesses. If I am to include character selection, that will be a way for players to pick the strategy they think works best and choose a bot that has those strengths. Another KOTH which had this feature was the Pokemon-themed KOTH (citation needed).

On the other hand, balancing stuff can be hard.


  • Move. Simple as that. Well, not exactly. I think this could make a very good contender for a continuous-surface (not a grid) area. On a surface, the character would walk, while airborne, the character's movement doesn't respond as quickly.
  • Jump. Is like a move, but vertical. More specifically, this gives the player an upward velocity. Double jumping might be possible.
  • Short Range. This deals damage to an immediately adjacent player.
  • Medium Range. This deals damage to players within a certain range. It would likely involve your player physically moving as well.
  • Long Range. This creates a projectile, which can deal damage to a player in the specified direction, no matter the distance.
  • Area of Effect. All players within a given range take a little damage.


Is is often typical that players have three lives, and thus must be killed three times to be eliminated. By respawning players, the variance of each match outcome should be reduced.

Game Ticks

If I'm doing a continuous-field, then I would want something the emulates continuous movement. In order to give fair processing time, I can't really have all of the entrant programs running at once in an asynchronous fashion. Some possible solutions are as follows.

  1. Priority Queue
    • Each action taken creates a certain time delay before the player can move again. Standing still is shortest delay, moving is second-shortest, and long-ranged attacks have the longest delay.
    • Turn order is determined by a priority queue. From the list of players, the player with the least delay is selected. Then, the game's physics are simulated for that amount of time ("virtual" time, not "true" time) and that much time is subtracted from everyone's delay. The selected player picks an action, and he is put back into the queue with that move's delay.
    • This creates a period of vulnerability after an attack which may be game-mechanically interesting.
  2. Random Time-Steps
    • Play occurs in a semi-random order, with random, non-uniform time-steps between moves. This makes it so that the player cannot predict exactly what the world will be like in the future, or guarantee the exact timings of any moves.
    • After each player has taken a single move, the order of players would be scrambled.
    • Time-step duration would be approximately constant with a random variation of +/-20% or something like that.


This would be really cool to watch, but I don't think I could possibly animate this by myself.

Stage Design

Stage design will be important, because a large chunk of the entrant programs will be tailored the stage. I don't really have any clue what I'm doing here.

One idea I've had is to crowd-source the stage design.

Maybe something with a few ledges, like this? (scaled down for ASCII-artability)


I could add some more features like so:


The slants represent ramps that the player could walk up.

Player Navigation

I foresee one of the most difficult things for entrants to do is to navigate the stage. Each player would definitely receive a copy of the current stage and players as input every turn (or as arguments/parameters, more details on that below).

I may choose to offload a bunch of pathfinding stuff onto the controller so that entrants, if they so desire, can give the destination and have their character move there. Given that the stage would be constant, this should not be difficult for the controller to do. On the other hand, the continuous-field design can make pathfinding more complicated.

One thing to consider during stage design is the ease of pathfinding.

Vertical or Horizontal?

Pretty much the whole proposal has been assuming a vertical map. I could change this to horizontal to allow a larger number of people to fight in one match.

Classes or Full Programs, and Language?

Personally, I think this would be easiest to do as a Java KOTH with classes. It will run quick(-er than several other methods) and I could give entrants access to a variety of methods that give information about the stage.


Literally no work has been done yet.


Golf all the 16 logic gates with 2 inputs and 1 output!

This question asked for 16 independent functions. I would like the opposite: a single function that takes an additional parameter that specifies which of the 16 logic gates is required using an integer from 0 to 15. If you don't want to use a 0-based index of the list in the linked question then you should specify which integers map to which logic gate (but they should still be 0 to 15).


 0,0,0  falsey
 1,0,1  falsey
 2,1,0  truthy
 3,1,1  truthy
 4,1,1  falsey
 5,0,1  truthy
 6,1,0  truthy
 7,0,0  falsey
 8,0,0  truthy
 9,0,1  falsey
10,1,0  truthy
11,1,1  truthy
12,1,1  falsey
13,0,1  truthy
14,1,0  truthy
15,0,0  truthy

This is , so the shortest answer in bytes wins.

  • \$\begingroup\$ Here you go \$\endgroup\$ Jun 15, 2016 at 10:37
  • 2
    \$\begingroup\$ @PeterTaylor That one is a kolmogorov-complexity. \$\endgroup\$
    – Leaky Nun
    Jun 15, 2016 at 10:47
  • \$\begingroup\$ @Mego How is generating 0101010101010101\n0011001100110011\n0000111100001111\n0000000011111111 the same as golfing 16 logic gates? \$\endgroup\$
    – Leaky Nun
    Jun 21, 2016 at 9:48
  • \$\begingroup\$ You may want to ban builtins. J has a two-byte solution, b. \$\endgroup\$ Jun 25, 2016 at 22:18
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ How do I go about looking up what b. means? \$\endgroup\$
    – Neil
    Jun 25, 2016 at 23:53
  • \$\begingroup\$ @Neil Voila \$\endgroup\$ Jun 25, 2016 at 23:54
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Thanks, I can see that excluding builtins will be necessary. (Strictly speaking, I asked how to look it up, rather than for a direct link, which wouldn't help me look up any other J code should I need to for any reason.) \$\endgroup\$
    – Neil
    Jun 26, 2016 at 0:03
  • 1
    \$\begingroup\$ @Neil J is a hard language reverse. I would postix your search on google with site:jsoftware.com \$\endgroup\$ Jun 26, 2016 at 0:05


Make me some fireworks !
And since we are super-late for the 4th make them as quick (read short) as possible !

2 integer, the fuse (any value equal or bigger than 5) and the radius (1 - 2 - 3).

The fuse define the lenght of the tail, the last character of the tail is the center of the explosion. The tail must be centered with the explosion.
The radius define the explosion.

No need for exception handling, the input will be a valid one.
You may or may not padd your firework, the choice is up to you.
Input, Output and the choice beetwen full program or function is, once again, up To you and your lenguage of choice.
Standard loophole rules apply.
Hopefully no built-in (i'm looking at you mathematica) exist.


fuse 5, radius 1  
     * *    
    * * *

fuse 10, radius 3  

   *     *
    *   *
     * *    
* * * * * * *
    * | *
   *  |  *

while stretching the fuse is not a big deal, ence no limit to it, I found interesting see if it's gonna be cheaper to have hardcoded the strings for the part where the firework cross the fuse or is gonna be cheaper some fancy algorithm, ence I' ve set a limited number of alternative for the radius.

I'm really sorry if my english is bad, I usually can get my idea trought but more than often i stumble with some verbs.

  • 1
    \$\begingroup\$ Welcome to PPCG and thanks for using the sandbox! "Number" isn't very descriptive, I assume that the fuse and radius should be positive integers (i.e. not including zero)? What happens if the radius is larger than the fuse? \$\endgroup\$ Jul 13, 2016 at 17:00
  • \$\begingroup\$ thanks for the welcome, i'm actually lurking since a bit, but never had something new \ better golfed to add. anyway 2 time my bad :/ . First with the number (i'm used to deal alot with database where number make sense) and then i must have forgot about min and max value while rewriting my question. edited ! \$\endgroup\$
    – Jackyz
    Jul 13, 2016 at 17:29

Peter Piper and the Peck of Pickled Peppers


Without an introduction, output the following tongue twister:

Peter Piper picked a peck of pickled peppers.
A peck of pickled peppers Peter Piper picked.
If Peter Piper picked a peck of pickled peppers,
Where's the peck of pickled peppers Peter Piper picked?

with or without a trailing newline.

This is , so shortest code wins.

  • \$\begingroup\$ I did some searching for duplicates, I came up with: this and this. There were a couple others that were also rather similar (slim shady and old macdonald), but they had a source restriction or some input as well. I'm not sure if any of them are duplicates, but these seem awfully close. \$\endgroup\$ Jul 26, 2016 at 21:05
  • 3
    \$\begingroup\$ I wish the words didn't come in the same chunks. The substrings "Peter Piper picked" and "peck of pickled peppers" are most of the text, and the rest has little structure: X a Y. A Y X. If X a Y, Where's the Y X? Is there another tongue-twister where the words are permuted more? \$\endgroup\$
    – xnor
    Jul 27, 2016 at 1:21

Transpose a Ragged Array

Given an array of arrays of integers where the rows may not be of equal length, pad those rows with nulls, and transpose the array.


  • Use any sane input for the array.
  • Specify which null(s) you are using for this function.
  • The output should be a transposed array, printed in whatever way is sane for your language.
  • This is code golf. Aim for the shortest code possible.

Test cases

I: [[1, 2], [3], [4, 5]]          # Padding with nil here
O: [[1, 3, 4], [2, nil, 5]]

I: [[1], [2, 3], [4, 5]]
O: [[1, 2, 4], [nil, 3, 5]]

I: [[1, 4, 5], [8, 3, 2], [1, 7, 9, 6]]
O: [[1, 8, 1], [4, 3, 7], [5, 2, 9], [nil, nil, 6]]

I: [[1], [2]]
O: [[1, 2]]

I: [[1, 2]]
O: [[1], [2]]

I: [[4, 5, 6, 7], [8, 9]]                  # Padding with spaces here
O: [[4, 8], [5, 9], [6, ' '], [7, ' ']]    # as an example of a different null

As always, if the problem is unclear, please let me know. Good luck and good golfing!

  • \$\begingroup\$ Having arrays that contain both integers and strings seems odd (and unrelated to the challenge) to me. \$\endgroup\$ Aug 19, 2016 at 6:29
  • \$\begingroup\$ @NathanMerrill In my head, I was trying to allow as many nulls as possible by restricting what data the arrays would have. You're right, though, and I have removed the reference to numbers and strings. \$\endgroup\$
    – Sherlock9
    Aug 19, 2016 at 6:32
  • \$\begingroup\$ There's still a test case with it :) \$\endgroup\$ Aug 19, 2016 at 13:54
  • \$\begingroup\$ @NathanMerrill That's because I still want arrays that can contain any data. \$\endgroup\$
    – Sherlock9
    Aug 19, 2016 at 13:59
  • \$\begingroup\$ @NathanMerrill Alright I rewrote the test case \$\endgroup\$
    – Sherlock9
    Aug 19, 2016 at 17:00
  • \$\begingroup\$ Perhaps "ragged" is a better term for "uneven" \$\endgroup\$ Sep 10, 2016 at 15:54
  • \$\begingroup\$ Does the "null" have to be constant or can it depend on the input? \$\endgroup\$
    – Dennis
    Sep 16, 2016 at 6:20
  • \$\begingroup\$ @Dennis, I think the nulls should be constant for all inputs. \$\endgroup\$
    – Sherlock9
    Sep 16, 2016 at 10:01

Play a 1D chess variant

in this challenge, you must create a bot that plays a 1d variant I created, featuring all leaper pieces, and a 15 long board.

Esolangs are encouraged to participate

Game Rules


To capture the opponents royal (king/queen).


The board is 15 squares long

Player _______________________________ Player
 one   |_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|   two
       player1 side       player2 side

Each player has their side of the board. (note that while playing, you will always be on the left side of the board). You have six squares that belong to you, the opponent has six of their squares, and three squares in the middle are unowned.

Setting up

At the start of the game, you will place your pieces into a configuration of your choice. The pieces will be set independently of each other; this game does not have perfect information. When setting up, you will pick where to place your four pieces, and whether they will be reversed (see next section). You may only place your pieces in your owned squares.


There are 4 / 8 pieces; there are 4 distinct pieces, which you can have reversed, and unreversed. I have given them distinct names. Their movements are detailed here.


reversed means that all the moves of these pieces are reversed in their direction; 2 forward becomes 2 back, three back becomes three forward.

Capture means to move to a space occupied by an enemy piece, and remove that piece from the game. Move means to move to a space occupied by no pieces.

Ascii "diagrams" have been provided. P denotes the piece being showed, $ denotes a space the piece can move to, X a place the piece can capture on, # a piece can move and capture on. Diagrams are the same for both pieces in a pair, because one simply executes the moves backwards.

You must have exactly 4 pieces on the board, and have exactly one from each of the pairs below.

Footman (f)/Coward (c)

The footman may move to an empty space one (1) forward, and capture two (2) forward.

The coward may move to an empty space one (1) backward, and capture two (2) backward.

Horse (h)/spider (s)

The horse may move to an empty space two (2) or three (3) forward, and move or capture one (1) backward.

The spider may move to an empty space two (2) or three (3) backward, and move or capture one (1) forward.

#P $$
Archer (a)/Trickster (t)

(I doubt anyone will use trickster unironically)

The archer may move two (2) squares backward, one (1) forward, and may capture four (4) steps forward

The trickster may move two (2) squares forward, one (1) backward, and may capture four (4) steps backward

I have included some black and white squares for clarity in distance

# # # #
$ P$  X
King (k)/Queen (q)

Both Royal pieces will end the game when captured.

The king may move or capture one (1) backward

The queen may move or capture one (1) forward



Check does not exist: Royal pieces may be left en prise, capture of them results in a win for the capturing side.

There is no (pawn) promotion of any kind

A piece may not attempt to move of the board; the board is a fixed size and does not wrap.


Programs will take input. When they take input of "0", or a specific input of your choosing, they will output a setup for the game. when they take input "1", or a specific input of your choosing, they will then receive input of the board, and output a move. (the program will be run multiple times)


To move, you will output the square that the piece is currently on, and the space where you wish to move the piece to, or have the piece capture on. The format is as so (in regex):


The board is zero indexed, a piece on the first square is on square 0.

There should be exactly 2 non-newline characters in the output


when it is your turn to move, you will receive input. The input you receive will represent the pieces in the playing field. The input will fit the regex here:

[fFcChHsSaAtTkKqQ ]{15}

Caps represent enemy pieces, lowercase represent your pieces.

when you receive the board positions, you will always have the perspective of player one

WIP, will do more later


What should happen if bots enter an infinite loop? I could just make a draw on a time limit, but that seems not so great, since it is hard for bots to know when they are doing this.

Also just other feedback in general

  • \$\begingroup\$ Maybe put the ASCII characters used to represent the pieces next to each description so we know what each piece is? It looks pretty vague right now. Also, the king and queen together seems redundant - maybe have it one or the other? \$\endgroup\$
    – clismique
    Oct 4, 2016 at 5:47
  • \$\begingroup\$ 1. The solution to infinite loops would seem to be automatic draw on three-fold repetition. 2. Is the Nash equilibrium pure or mixed? \$\endgroup\$ Oct 4, 2016 at 7:33
  • \$\begingroup\$ @PeterTaylor 1. Three-fold repetition== one repetition of position (if bots have no RNG/are determistic, and I don't want non-RNG bots to suffer), and the bots don't know when they are repeating, because they have no memory. I was kind of thinking of maybe removing a square or something, but that would kind of mess up some stuff... I kind of want to introduce some aspects that will change the position, like adding a piece or something. 2. I imagine you are talking about the starting positions, given perfect play. I have no idea, but it's probably an intricate Rock Paper Scissors cycle \$\endgroup\$ Oct 4, 2016 at 7:47
  • \$\begingroup\$ When I asked about the Nash equilibrium I'd calculated that the number of starting positions is only a bit over 5000 each, so I thought it would be practical to brute-force. But the number of board positions is quite a bit higher, so it's probably not very practical without spending a lot of money. I'm not going to try writing a game tree searcher tonight to verify that. Re repetition: normally in koth you want to use persistent processes where possible, because otherwise the overhead of launching the program for every single move makes it really slow to score. \$\endgroup\$ Oct 4, 2016 at 20:57
  • \$\begingroup\$ I was also thinking that maybe I would make the time it takes to win factor into the score, so that riskier strategies can do as well as a perfectly planned program might; It would make a more diverse series of strategies \$\endgroup\$ Oct 4, 2016 at 22:46
  • \$\begingroup\$ Is there a limit on how long a turn can take? IMO the obvious solution is a minimax tree, so we'd need to know about how many turns we can look ahead. \$\endgroup\$
    – Riley
    Oct 12, 2016 at 15:40

(-: Emotional Programming ;-)

Write the most emotional program you can, i.e. which consists of emoticons as much as possible.

The program should receive a word and print an appropriate emoticon.

Scoring - I'm really not sure about this, and the question will be worthless without a good scoring algorithm. I want to:
1. Avoid giving an advantage to very short programs (e.g. (-:, is 100% emotional).
2. Avoid a meaningless help of emoticons - print '(-:' #(-:(-:(-: and such.
3. Prefer a variety of different emoticons.

1. Count characters of code.
2. For each emoticon in the code, reduce a character. 2. For N different emoticons used, reduce further 2*N^2 characters.

What's an emoticon? Anything that somewhat resembles a face, or a closed list?

And should I ban Emoticon?

  • \$\begingroup\$ My suggestion to fix scoring would be to add restrictions to the submissions' output, and have scoring be a function of their code and their output. \$\endgroup\$
    – jwrush
    Aug 31, 2013 at 16:32
  • \$\begingroup\$ Thanks @jwrush, Scoring based on output seems to complicate things, and I'm already unclear about my scoring. I changed the required behavior to something more closed. Still, I don't feel the question is good enough. \$\endgroup\$
    – ugoren
    Sep 1, 2013 at 4:45
  • 2
    \$\begingroup\$ This seems to have a strong bias towards GolfScript, which produces lots of emoticons naturally. It also seems hard to tighten to an objective spec. \$\endgroup\$ Sep 1, 2013 at 18:43
  • \$\begingroup\$ @PeterTaylor, I don't like a bias towards GolfScript, but if that was a reason not to post questions, this site would be much smaller. The requirement can be very tight - I can provide a list of words and emoticons, and require translation between them. I'm not sure I want to tighten this way though. \$\endgroup\$
    – ugoren
    Sep 2, 2013 at 4:27
  • \$\begingroup\$ I disagree on the first point. I see a difference between GS having an advantage in code golf because it's designed to be terse, and GS having an advantage in a challenge because the challenge actively rewards a property which GS has as a side-effect of its design. Also note that I probably wouldn't be the loudest protestor against a pro-GS bias, but I think it's fair to warn you that other people might protest ;) \$\endgroup\$ Sep 2, 2013 at 10:53
  • \$\begingroup\$ @PeterTaylor, I wish that was the problem. I don't really how to make this a question that triggers interesting solutions, so it looks like it stays in the sandbox. \$\endgroup\$
    – ugoren
    Sep 8, 2013 at 6:54
  • \$\begingroup\$ Might want to forbid comments? \$\endgroup\$
    – Justin
    Nov 28, 2013 at 22:22
  • \$\begingroup\$ I think this would only work as a popcon \$\endgroup\$ Nov 3, 2016 at 10:19

Create an Autostereogram (Optical Illusion w/ Hidden 3D Shape)

An autostereogram is a type of optical illusion requiring the viewer to, simply put, change distance at which your eyes are trying to view the image. In order to see the hidden image rather than just a nonsensical two-dimensional image, the viewer must either focus their eyes in front of the image (cross-eyed), or behind the image (wall-eyed). Depending on its type, autostereograms may be viewed either way, only cross-eyed, or only wall-eyed. Wall-eyed are the most common.

The illusion below taken from the linked Wikipedia article may only be viewed successfully using the wall-eyed technique. Viewing the full-sized image may help.


The hidden image is:

A shark

I didn't know they were called autostereograms until today, but I always liked this type of optical illusion, since I found the hidden image easy to spot using the wall-eyed technique.

Your goal is to take a depth map and either:

  1. Take in an image to modify with the map, then return/display the resulting image
  2. Create a random dot autostereogram

The quality of the image must be such that the image is hidden and can be viewed using one of the techniques listed above.

  • \$\begingroup\$ I've also seen reddit.com/r/crossview which is a similar idea but uses 2 images next to each other to make it look 3d. \$\endgroup\$ Apr 7, 2016 at 14:42
  • \$\begingroup\$ I'd like input on whether people would prefer a [popularity-contest] or [code-golf] for this. I'm not sure if answers would be unique enough for a popularity contest. How much quality will users drop for saving bytes? \$\endgroup\$
    – mbomb007
    Apr 7, 2016 at 15:11
  • 1
    \$\begingroup\$ I would clearly go for code-golf and restrict it to random dot autostereogram (which e.g. also needs e.g. the number of points as input). This can be defined quite well. (In a popularity contest people would probably just vote what they can see easily. Furthermore the there would be the question about a validity criterion.) I totally like the idea! \$\endgroup\$
    – flawr
    Apr 11, 2016 at 20:19
  • \$\begingroup\$ @flawr The thing is, I actually think random dot ones are much harder when trying to view the hidden image. \$\endgroup\$
    – mbomb007
    Apr 11, 2016 at 20:55
  • 1
    \$\begingroup\$ @mbomb007 Harder to view or harder to produce? (PS: tx.technion.ac.il/~yonie/stereogram.txt) What do you think about ASCII stereograms? It would be quite a bit easier to make a validity criterion. \$\endgroup\$
    – flawr
    Apr 11, 2016 at 21:01
  • \$\begingroup\$ From chat, it seems like the consensus is that this question should be narrowed. This could potentially become 3 different questions about autostereograms: using random dots, using an image, and using ASCII. I think I'd like to start with using an image, since its output is easily viewable. \$\endgroup\$
    – mbomb007
    Apr 12, 2016 at 13:49
  • \$\begingroup\$ @flawr Do you think other languages would be able to do what Mathematica can? mathematica.stackexchange.com/a/57108/35531 \$\endgroup\$
    – mbomb007
    Nov 2, 2016 at 16:35
  • \$\begingroup\$ Probably, but the mathemtica version is already quite long, and most other languages will probably need way more code to do the same, which, so I'm afraid, could deter many people from participating. \$\endgroup\$
    – flawr
    Nov 2, 2016 at 21:31
  • \$\begingroup\$ @flawr Well, it's not golfed yet. \$\endgroup\$
    – mbomb007
    Nov 2, 2016 at 21:34

Generate a Call Tree

Given a C program, generate a graphical call tree.

A call tree is a tree where the nodes represent stack frames, and the connections represent nested function calls. For example, here is a simple C program and its call tree:

#include <stdio.h>

int foo() {
    return 4;

int bar(int a) {
    return a + 2;

int baz(int a, int b) {
    return a + foo() + bar(a)*bar(b);

int main() {
    int a = baz(1, 2);
    printf("%d\n", a);
    return 0;

call tree


The layout of a call tree is as follows:

  • The top function is always main().
  • On the next level below are all of the functions that main calls, in order of calling (top-to-bottom, left-to-right).
  • On the next level are all of the functions that those functions call, and so on.
  • The leaves of the tree are functions which do not call other functions, or are standard library functions (which are treated as black boxes).
  • Each function (with its argument list) is in a rectangle, large enough that the function name and argument list isn't touching the rectangle's borders.
  • Rectangles must not touch other rectangles.
  • The lines drawn between the rectangles must not touch or cross any line or rectangle other than the two rectangles they are connecting.
  • The text must be a monospaced 14-point font.
  • The colors of the text, rectangles, lines, and background are not important, so long as all text is one color, all rectangles are one color, all lines are one color, the background is a single color, and everything can be clearly distinguished from the background.

Note that the example image above does not perfectly follow these rules.


  • You may assume that the C program is a valid, standalone program (all functions called are either defined in the input source code or exist in an #included header, and no input is taken from any source).
  • Any functions not defined in the input source code are assumed to not call any other functions (this is not the case in reality, but it allows for simplification of the call trees, namely by avoiding implementation-specific details)
  • All function calls in the call tree must include the arguments passed.
  • main is assumed to not have any arguments.
  • There will be no function pointers, gotos, setjmp/jonglmp calls, dynamic memory allocation/deallocation (so no malloc, calloc, realloc or free), or preprocessor macros in the input source code.
  • There will be no infinite loops or infinite recursion (all programs are guaranteed to terminate and thus have a finite call tree).
  • All arguments will be ints (to simplify matters, since the types don't really matter for this challenge). This means that the example program above would not be a valid input, because of the printf call.
  • All functions will either return an int or will be void (non-returning) functions.
  • \$\begingroup\$ What about recursion? Do we have to support the full complexity of the C grammar? \$\endgroup\$
    – orlp
    Dec 1, 2016 at 7:07
  • \$\begingroup\$ @orlp Clarified on recursion as well as loops. Are there any parts of the C grammar that would be problematic, in your opinion? \$\endgroup\$
    – user45941
    Dec 1, 2016 at 7:09
  • \$\begingroup\$ Mainly that the actual grammar is quite large. \$\endgroup\$
    – orlp
    Dec 1, 2016 at 7:21
  • \$\begingroup\$ @orlp For the most part, a lot of it can be ignored, because it won't have anything to do with function calls. Solutions will still be larger than typical code golf solutions, but that's fine - not every code golf challenge needs a 10-or-less-bytes solution. \$\endgroup\$
    – user45941
    Dec 1, 2016 at 7:24
  • \$\begingroup\$ It is implied that the text in the nodes should include a representation of the arguments, but what should that representation be when they aren't "nice" ones like integers or strings? Obvious nasty cases are structs, unions, and pointers. \$\endgroup\$ Dec 1, 2016 at 8:27
  • \$\begingroup\$ @PeterTaylor Good point. I'll restrict it to ints. \$\endgroup\$
    – user45941
    Dec 1, 2016 at 8:29
  • \$\begingroup\$ Is it possible that the source will contain function declarations (as opposed to function definitions)? Those can look a lot like function calls (especially if they appear inside functions, which is legal in C). \$\endgroup\$
    – user62131
    Dec 1, 2016 at 10:59
  • \$\begingroup\$ @ais523 Yes, they are allowed. They don't look that similar to function calls - function calls don't have a type signature prefixed (foo(); versus int foo();). \$\endgroup\$
    – user45941
    Dec 1, 2016 at 22:35
  • \$\begingroup\$ What about code of the form a * foo();? That's either a function call or a function declaration depending on whether a is a type or a variable. (You could probably get around this by banning pointers full stop, not just function pointers.) \$\endgroup\$
    – user62131
    Dec 1, 2016 at 22:40
  • \$\begingroup\$ @ais523 I clarified that all functions will either return int or void, so that won't be an issue. Besides, you can't declare a variable that has the same name as a type, so that situation could be deterministically resolved without the restriction. \$\endgroup\$
    – user45941
    Dec 1, 2016 at 22:42
  • \$\begingroup\$ I like the idea of the challenge a lot, but I'm not convince that the "graphical output" part adds something... I think just printing it one call per line, and increasing the indentation level would be enough. \$\endgroup\$
    – Dada
    Dec 3, 2016 at 16:04
  • \$\begingroup\$ Also, what about if there is a function call like f(f(n)) ? Should we consider that a call to f(1) is done first, then a call to f(result of f(1))? (maybe adding a line about it would be nice) \$\endgroup\$
    – Dada
    Dec 3, 2016 at 16:06
  • \$\begingroup\$ @Dada Re: graphical-output: it's a lot harder to have an unambiguous, readable tree in text format versus graphical format. RE; nested calls, yes, nested calls are evaluated left-to-right, starting with the innermost nest and working outwards. For example, int main() { f(a(), b(c())); return 0;} would be main [ a, c, b, f ] (see what I mean about unambiguous and readble format for text?). \$\endgroup\$
    – user45941
    Dec 5, 2016 at 7:42
  • \$\begingroup\$ @Mego If you ask for a text format version based on indentation, I don't think there can be any ambiguity. But if you prefer graphical-output, why not (I just think that most of the code will be about formatting the graphical output, while I find the "genrate the call tree" part more interesting, but that's only my personal opinion, I like the challenge either way). \$\endgroup\$
    – Dada
    Dec 12, 2016 at 17:33

Regex Golf Generators



The cops must post a 150 byte or less program in any language that outputs between 20 and 200 strings of printable ASCII (this excludes newlines), half of them "match" strings and half "don't match" strings. You can't output an odd number of strings -- there must be one don't match for each match.

The strings can be output as two lists of strings, or one list with a fixed delimiter between the "match" and "don't match" sections. The "match" and "don't match" lists can come in any order.

The following special characters are not allowed in the strings: ()[]*+?.\|^$.

Note that the program must be deterministic, and the language must be revealed.


The robbers must pick a cop answer and submit a regex in any flavor that matches the "match" strings but does not match the "don't match" strings.

The regex must be shorter than min(<length of all the match strings> + <number of match strings>-1 + 4, <length of all the don't match strings> + <number of don't match strings>-1 + 10), as this is the length of the regex that simply hardcodes it: ^(<match string 1>|<match string 2>|...)$ or ^(?!(<don't match string 1>|<don't match string 2>|...)$).*.

The shortest regex posted for that submission wins (note that there can and should be multiple competing cracks for one submission).


The robber's score is simply their number of wins (posted the shortest regex for a given submission) -- higher is better.

The cop's score is max(byte count of winning regex - byte count of submission - 4*(number of match strings - 10) for each submission) -- again, higher is better (you should be maximizing the length of the cracks and minimizing the length of your code). The byte count of the winning regex for an uncracked submission is the length of the hardcoded regex. Self cracks are permitted but must be marked as non-competing and will not count toward your cop or robber score.

The winning cop and robber will be announced 2 weeks after the posting of this challenge. Submissions will be allowed after that, but will not count towards your score.

  • \$\begingroup\$ Can they be a list of lists, i.e. [['string1',truthy],['string2',falsy]...]? With truthy/falsy being match/don't match. \$\endgroup\$
    – Riker
    Feb 15, 2017 at 17:41
  • 2
    \$\begingroup\$ I've said this in chat, but I'm listing it here for reference: 1. No need to have a fixed number of match strings. 2. No need to remove regex special characters. Everybody has the same benefit of using them. 3. No need to have a maximum regex length. It's like having a maximum bytes on a code-golf. 4. I don't see why you want to aggregate the cops' scores. Simply make it a standard maximum-score-wins. Otherwise, a person who posted the best scoring submission may lose to another who only posted a single decent submission. 5. Disallow self-cracks. It's too abusive for robbers. \$\endgroup\$ Feb 16, 2017 at 1:42
  • 2
    \$\begingroup\$ What's the point of allowing a "Retina flavor" of regex? Wouldn't that be identical to .NET? \$\endgroup\$
    – feersum
    Feb 16, 2017 at 8:23

Machines learning arithmetic

Note: Feel free to take and use this challenge, either the entire challenge as is, or just parts of it.

I've made a complete rewrite of this question. I figured the original version was more complex than it had to be. The task is essentially the same. The original challenge text had 4 upvotes and can be found in the edit history.

You will receive 30 lists of integers. Those lists are the result of a polynomial expression y = p(x) = a*x^4 + b*x^3 + c*x^2 + d*x + e, for x in the inclusive range [-1e5, 1e5]. Let's call those lists L1, L2 ....

I reserve the right to make changes to the lists by changing constants and the order if solutions seem to be custom made for those 30 lists.


Your task is to figure out what the constants a, b, c, d, e are for each of those 30 lists.

You will write a code that pulls numbers from each list (one list at a time). It must ask for the y-values for individual x-values, as many as you want, but one at a time. When you think you have enough information, you'll attempt to guess the value of the constants.

You'll do this for all 30 lists.


The lowest score wins!

  • You get 1 point for every number you pull from the list
  • You get 10 points for every attempt to crack the code (guess a, b, c, d, e)
  • The scores for all lists will be added up.

If no submission cracks all lists successfully then the one that cracked the most will win. Tie breaker #1 will be fewest points, tie breaker #2 will be time of submission.

Rules and clarifications:

You can assume all constants to be integers

The lists will be formatted in this way (suppose the expression for L1 is: 2*x). I'm using MATLAB/Octave syntax for a cell array. You can change this to fit your needs (language).

L1 = {[-200000, -199998, -199996, ... -4, -2, 0, 2, 4, ... 199996, 199998, 200000], [0 0 0 2 0]};

You can change the format to fit your needs, but you must not mix the list and the values for a, b, c, d, e.


You ask for y for four different input values, and get the results:

L1(0) = 0
L1(1) = 0
L1(2) = 2
L1(3) = 12

Your function guesses (for some reason) that this is x^3-2x^2+1, and attempts to crack it:

L1([0, 1, -2, 0, 1]

You have tried 4 values, and attempted to crack it once. This gives you 4 + 10 = 14 points.

You try a few more values:

L1(-9) = 6480
L1(-7) = 2352
L1(7)  = 2352
L1(9)  = 6480
L1(100)= 99990000

You're now confident that this has to be: x^4-x^2, and attempt to crack it again:

f([1 0 -1 0 0])

You have successfully guessed the constants a, b, c, d, e, and get a score of `14 + (5 + 10) = 29 points.

You have 29 functions left.

  • I'll have to post the lists on some suitable place (where)?
  • Can I ban builtin interpolation functions somehow without risking the "unobservable requirements", "x without y" pitfalls?
  • Anything else?
  • \$\begingroup\$ This isn't yet 100% clear to me, but I've upvoted because it looks like an interesting idea that will make a great challenge once fine tuned. \$\endgroup\$ Jan 18, 2017 at 10:58
  • \$\begingroup\$ :) Anything in particular that isn't clear, or everything in general? \$\endgroup\$ Jan 18, 2017 at 11:00
  • \$\begingroup\$ I've edited... It was never intentional to have the number of bytes mixed in here... I'm probably just so used to writing it that I didn't even notice it :P \$\endgroup\$ Jan 18, 2017 at 11:03
  • \$\begingroup\$ Will it be done like: 1. "start writing your function" 2. "end of function writing period" 3. "release black box function for scoring submissions"? To avoid learning the expressions and tuning the functions to fit. \$\endgroup\$
    – Emigna
    Jan 18, 2017 at 11:04
  • \$\begingroup\$ I guess you could have a controller that generates new random test cases each time to allow the competition to be open ended, but rescoring the old entries might reorder them in some cases. Might need to average over a number of different sets of test cases. \$\endgroup\$ Jan 18, 2017 at 11:07
  • \$\begingroup\$ The given example of h(x) = ((3*x*x*x)/(x+1))+1 is incompatible with "You can assume the functions will give integer results back". But basically it's a case of guessing and verifying a rational function of some bounded degree? \$\endgroup\$ Jan 18, 2017 at 11:09
  • \$\begingroup\$ If you want a variety of languages to be able to compete without having to implement arbitrary size integer arithmetic, you could use modular arithmetic. For example, everything is mod 256, or 65536. \$\endgroup\$ Jan 18, 2017 at 11:10
  • \$\begingroup\$ @Emigna, good question :) One solution could be: Provide x number of functions on a certain format. After the submission is posted it will be tested against the "real" cases that are of similar difficulty, but different. I think I can have some fairly easy, and some quite hard. But it's a really good question, so I'm not sure... I'm open for ideas :) \$\endgroup\$ Jan 18, 2017 at 11:11
  • \$\begingroup\$ @PeterTaylor, I made a blooper when making the examples. Using rational functions with input arguments and 8/10(?) significant figures in the output is probably a good idea. I think 10 is low enough that rounding shouldn't be an issue as long as you have the correct function..? And it can be restricted to 3/4/5..9th degree polynomials. \$\endgroup\$ Jan 18, 2017 at 11:15
  • \$\begingroup\$ Peter's comment also makes me wonder what happens for division by zero. Will this be avoided somehow or will we be informed that a particular input causes an error? Will the error be specifically "division by zero" or just "error"? \$\endgroup\$ Jan 18, 2017 at 11:16
  • \$\begingroup\$ First comment @trichoplax: You have a point, but it will also make it harder, since it will no longer be a continuous function. Second comment: I think an error message / warning of some sort would suffice. Handling that error should be very simple, since this isn't code golf. It will probably be 1-3 lines of code. Giving inf for divison by zero, and error for 0/0 could also be a solution (that's the default solution in MATLAB). \$\endgroup\$ Jan 18, 2017 at 11:21
  • \$\begingroup\$ Note that if you want continuous functions you would need to avoid rational functions, but it sounds like you're happy with piecewise continuous if you don't mind "inf" and "error" in some places? \$\endgroup\$ Jan 18, 2017 at 11:34
  • \$\begingroup\$ @trichoplax, What do you think? Is modular arithmetic a good idea? Should I skip division (impossible to avoid division by zero if not)? \$\endgroup\$ Jan 18, 2017 at 11:51
  • \$\begingroup\$ I really don't know. I'm just suggesting possibilities. Someone more mathematical would probably be useful for assessing whether modular and rational functions would be interesting to crack. Are you aiming for a situation where most people can write code that cracks all 10, but getting a low score is challenging, or where most people can only crack a proportion of the 10? \$\endgroup\$ Jan 18, 2017 at 11:59
  • 1
    \$\begingroup\$ Parentheses should be removed since it makes this challenge much more difficult... and it is already really difficult without them \$\endgroup\$ Jan 19, 2017 at 0:44

This message is open for anyone to adopt and post to main. For more details, see the chat room or meta post.

Ping an IP address continually and report the dropped to returned ratio

Create a console program that pings an IP address at most once per second and reports the ratio of dropped to returned packets to the screen in real time.

The IP address will be provided on the command line in standard IPv4 notation. (eg.

The 'ping' method should be ICMP echo (See here for a summary of ICMP packet structure) with a packet size of at least 32 bytes.

Your program must be "standalone" and cannot rely on external programs, libraries, or resources.

This is so let the shortest answer win

  • \$\begingroup\$ ping isn't enough? \$\endgroup\$
    – TheDoctor
    Apr 7, 2014 at 19:31
  • \$\begingroup\$ ping works great, except you have to tell it when to stop to get the final tally \$\endgroup\$ Apr 7, 2014 at 19:32
  • \$\begingroup\$ I think you're assuming that everyone will interpret this as sending the same ICMP control packet that ping sends, but it would be an improvement to the question both to make this explicit and to link to some documentation about ICMP. \$\endgroup\$ Apr 7, 2014 at 22:46
  • \$\begingroup\$ Actually I left it ambiguous. Any IP request that elicits a response can be considered a ping. \$\endgroup\$ Apr 8, 2014 at 1:00
  • \$\begingroup\$ Alright, lets make it easier and say ICMP specifically... \$\endgroup\$ Apr 8, 2014 at 12:16
  • \$\begingroup\$ Well this doesn't have enough upvotes...I'll leave it in the sandbox, but likely it will not be posted \$\endgroup\$ Apr 9, 2014 at 12:17
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$
    – user58826
    Jun 9, 2017 at 16:34
  • \$\begingroup\$ @programmer5000 be my guest :) \$\endgroup\$ Jun 9, 2017 at 16:40

Me, Me, Me!

Edit: changed success when the input matches the source code to when the input is any permutation of the source.

Your code is clearly superior to all other code. In fact, your code is so great that it prints itself when the opportunity arises (but not when any other, inferior code is around.)


Write a program or function that takes a string as input. If the string is equal to some permutation of the characters in your source code, then output the entire source code. Otherwise, output Gross.

If your language uses a non-ascii encoding, "character" is defined as whatever a character in your source looks like. If it's unreasonable to take input in that format, you can treat the bytes of your source as their respective extended ascii codes.


Takes a string using whatever input mechanism your programming language provides.


Prints either the entire source of your program or the word Gross. No additional output is permitted.


  • You can take input using any reasonable method. (Stdin, function parameter, etc.)
  • A string a is a permutation of a string b iff each character in the alphabet appears the same number of times in a and b.
  • This is Shortest code (in bytes) wins.
  • \$\begingroup\$ quine? -- \$\endgroup\$
    – MD XF
    Jun 7, 2017 at 21:32
  • \$\begingroup\$ @MDXF it will have the quine tag, of course – but it's not strictly a quine unless it gets the right input! I just didn't see how to add tags in the answer... \$\endgroup\$ Jun 7, 2017 at 21:34
  • 1
    \$\begingroup\$ Use [tag:quine] in the header. And yes, we accept the quine tag for quine variants :-) \$\endgroup\$
    – MD XF
    Jun 7, 2017 at 21:34
  • 2
    \$\begingroup\$ trivial extension of this challenge \$\endgroup\$ Jun 7, 2017 at 23:14
  • \$\begingroup\$ aw shucks. I figured something like this existed already, just didn't know what to search for. \$\endgroup\$ Jun 8, 2017 at 14:36
  • \$\begingroup\$ actually, @DestructibleLemon I could be missing something obvious but I don't think the extension is trivial. Printing its own source code is, I would say, significantly harder than printing "true" as long as I add the usual restriction that it can't read its own source. \$\endgroup\$ Jun 8, 2017 at 14:38
  • \$\begingroup\$ @rogaos If the test on the input passes, printing its source code is as simple as printing the input string. \$\endgroup\$ Jun 8, 2017 at 15:33
  • \$\begingroup\$ @NonlinearFruit true of course, but adding the print statement may make the quine harder to construct in the first place. (Except in languages like javascript, which are basically reading their own source anyway.) Maybe the challenge would be improved by transforming the input string in some way, or crashing on "correct" input? \$\endgroup\$ Jun 8, 2017 at 15:38
  • \$\begingroup\$ @rogaos it is the difference between printing true and printing the input \$\endgroup\$ Jun 8, 2017 at 23:29
  • \$\begingroup\$ modified to use permutations of the input rather than the input itself \$\endgroup\$ Jun 19, 2017 at 18:21

What is your Operating System?

I can't believe we haven't had this one before

To avoid any doubts about what constitutes a separate OS, you must return an index into your chosen subset (containing minimum two) of the following OS families. You may order your set as you like, so include your ordered set, and state if you use zero or one based indexing. You may also bunch together families you cannot distinguish between.

  Windows, Minix, Linux, macOS, BSD, HP-UX, AIX, Solaris, Unix, Z/OS, OS/2, QNX

Your score is your byte count divided by the square of the number of indices your code can return – given that it is run on the appropriate OSs, of course.

You do not have to account for virtual machines, emulation layers etc., e.g. WSL and Wine.


Your code can detect Windows, macOS, AIX, and Linux. It returns 0 for Windows, 1 for macOS, 2 for AIX, and 3 for Linux. Your score is a sixteenths of your byte count.

Your code can distinguish between Z/OS, OS/2, and UNIX/Linux/AIX. It returns 1 for Z/OS, 2 for OS/2, and 3 for any UNIX-like OS. Your score is a ninth of your byte count.

  • \$\begingroup\$ 2 is definitely better than 1. After that I think it may just be your preference for the kinds of answers you want. I think 3 will promote more answers that reach, while 2 will promote more 2 answers. However, if you really want to reach maybe make the denominator grow as a square? These scoring mechanisms are unfortunately very important to these kinds of challenges as well as very hard to figure out beforehand. I'd ask around and see what other people think! \$\endgroup\$ Jun 15, 2017 at 0:37
  • \$\begingroup\$ @FryAmTheEggman Thanks. \$\endgroup\$
    – Adám
    Jun 15, 2017 at 0:39
  • \$\begingroup\$ Are not macOS, BSD, and Linux Unix? Is OSX considered the same as macOS? \$\endgroup\$
    – Wheat Wizard Mod
    Jun 21, 2017 at 14:53
  • \$\begingroup\$ The I/O requirements are rather strict, could you not just print/return the name of the OS? \$\endgroup\$ Jun 21, 2017 at 14:56
  • \$\begingroup\$ @WheatWizard Yes, but you may pick whichever many you want from that list, so you can bunch all Unixes together or keep them separate, or you can detect specific flavors while also detecting vanilla Unix. \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:02
  • \$\begingroup\$ @musicman523 I'd rather have comparable output from all solutions. \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:03
  • 3
    \$\begingroup\$ It seems like people with access to proprietary OSs will have an advantage in this problem. For example, to ensure my code runs on Windows I have to buy windows, because I don't own it. I happen to own a copy of OSX, but other users might not given me an advantage. I feel like this is problematic. (also is OSX considered the same macOS?) \$\endgroup\$
    – Wheat Wizard Mod
    Jun 21, 2017 at 15:09
  • \$\begingroup\$ @WheatWizard You're right, but that will be problematic in detection of OSs no matter what the challenge is. And yes, good luck testing your solution on Z/OS… \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:34
  • \$\begingroup\$ It's not just that. If I claim to detect Windows, which versions of Windows do I have to test it on? And what can I assume about e.g. the C header files that are available? \$\endgroup\$ Jun 21, 2017 at 15:35
  • \$\begingroup\$ @WheatWizard Oh, and yes, OSX and macOS are the same (I don't expect anyone to submit an answer that will run on MacOS 9-) \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:35
  • \$\begingroup\$ @PeterTaylor Good point. Any ideas how to fix this or is it doomed? \$\endgroup\$
    – Adám
    Jun 21, 2017 at 15:36
  • 1
    \$\begingroup\$ I suspect that the difficulties around specification and testing might explain why this hasn't been asked already. \$\endgroup\$ Jun 21, 2017 at 15:44
  • \$\begingroup\$ Why numbers only? Why not just outputs? \$\endgroup\$ Jun 21, 2017 at 16:00
  • 1
    \$\begingroup\$ Is the set of OSes listed there exhaustive? (I've done some programming on SunOS in the past, for example, although I don't have access to it right now.) Also, "Unix" seems a bit strange to have in the list; many of the listed OSes (e.g. BSD and Solaris) are flavours of Unix. It's also worth being aware of cases like WSL and Wine; which OS should they count as? \$\endgroup\$
    – user62131
    Jun 22, 2017 at 10:28
  • \$\begingroup\$ @ais523 "Unix " allows submissions to bunch together various flavors as one, and also allows differentiating the other Unixy OSs from vanilla Unix. I'll add a note about virtual machines etc. \$\endgroup\$
    – Adám
    Jun 22, 2017 at 14:54

One OEIS after another

  • 1
    \$\begingroup\$ This sounds fun! \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 22:32
  • \$\begingroup\$ Awesome frickin' idea. You might wanna add what to do when one answer reaches 289,585 bytes ('cause obscure esolangs). ;) \$\endgroup\$ Jul 19, 2017 at 22:41
  • 1
    \$\begingroup\$ @totallyhuman I would've thought that that score is about right for Java, so I'll address that \$\endgroup\$ Jul 19, 2017 at 22:59
  • \$\begingroup\$ A possible problem is that many languages have "add 1" and "subtract 1" or similar functions that are inverses of each other. So you could add any even amount of bytes. For example, sequence A005843 (the even integers) in CJam can be ri2* or ri2*()()()()()()()() \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 23:07
  • \$\begingroup\$ Ah, no, the rule is that removing any subset of the characters must give wrong output. That rule is enough to invalidate the above \$\endgroup\$
    – Luis Mendo
    Jul 19, 2017 at 23:08
  • \$\begingroup\$ I think the rule about the program having to be pristine is bad for this challenge. It makes writing answers incredibly difficult in most languages. Why do you care if people change the length of their post? All they can do is control which sequence appears next. \$\endgroup\$ Jul 19, 2017 at 23:19
  • \$\begingroup\$ You might want to bold or otherwise emphasize unused language, as I missed it the first couple times I read through (or just remove that restriction, because it would be more fun if we had to go through all sequences instead of all languages ;) ). Also, what to do about very short sequences, such as the busy beaver sequence? \$\endgroup\$
    – Stephen
    Jul 21, 2017 at 13:01

Invisible Ink, Easy

In the physical world, invisible ink usually becomes invisible when it dries, and is then is readable if it is exposed to heat or chemicals of some kind. The invisible ink in this challenge will be readable when exposed to highlighting.

Create a full program or function that takes in text from the console (using a prompt) and outputs it the console so it cannot be seen unless highlighted.

enter image description here

enter image description here


  • Assume that the console is a solid color (black, white, green, etc.).
7 8
10 11

You must log in to answer this question.

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