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".

  • \$\begingroup\$ What if I posted on the sandbox a long time ago and get no response? \$\endgroup\$
    – None1
    Commented May 15 at 14:05
  • \$\begingroup\$ @None1 If you don't get feedback for a while you can ask in the nineteenth byte \$\endgroup\$
    – mousetail
    Commented May 29 at 13:27

4705 Answers 4705

87 88
90 91

Aircraft registration numbers

Write a program that takes a United States aircraft registration number and returns a 24-bit ICAO hex code corresponding to that registration and vice-versa.

An aircraft registration number always begins with an N and is followed by 1 to 5 characters: 1 to 5 digits and then 0 to 2 letters. That is, one of the following three patterns:

  • N plus 1 to 5 digits
  • N plus 1 to 4 digits then one letter
  • N plus 1 to 3 digits then two letters

The first digit cannot be 0 and the letters I and O are not used. The letters always follow the digits.

ICAO hex codes assigned to the US are numbers from A00001 to ADF7C7 (in hexadecimal). They are assigned in alphanumeric order: A00001 corresponds to N1, A00002 corresponds to N1A, A00003 to N1AA, A00004 to N1AB, etc., up to ADF7C7 for N99999.

Some test cases:

Registration ICAO code (hex) ICAO code (decimal)
N17CA A11707 10557191
N1PP A00155 10486101
N959ZP AD5863 11360355
N999ZZ ADF669 11400809

You can assume no invalid inputs will be given.

  • \$\begingroup\$ s/numbers/digits/ \$\endgroup\$
    – Philippos
    Commented Jan 15 at 15:43

Validate a codice fiscale


The TAK function


This is my first challenge here, and I know I'm not supposed to start with a KotH. But I had this idea and I think it is simple enough while allowing more advanced strategies, so here it is:

Tank Game

There are two tanks on a 16×16 toroidal grid (wrapping in both directions), one starting at (0, 0) and its opponent starting at (8, 8). The objective is to occupy the enemy base (starting point) without getting shot. Some grid cells are walls, which tanks can't move, shoot or see through. Each submission includes 2 separate programs that form a team, a commander and a tank driver. Direct communication between them is not allowed, but actions of the commanders are visible to the drivers, allowing you to encode some information that way.

The commander

  • Sees the entire map and the positions of the tanks.
  • Can build or destroy walls.

The tank

  • Has very limited vision but knows its position.
  • Sees the actions of both the friendly and the enemy commander.
  • Can move in a straight line up to 3 cells.
  • Can shoot in a straight line.

Details of the game

The tanks and commanders take turns in the following order:

  1. Commander of 1st submission
  2. Tank driver of 2nd submission
  3. Commander of 2nd submission
  4. Tank driver of 1st submission

Although from an outside perspective your tank may start at either (0, 0) or (8, 8), the map and all other coordinates provided to your programs (including enemy actions) will be translated by the controller to make it look like your tank started at (0, 0) and has to go to (8, 8). This is done so your program doesn't have to check where it started from.

The starting position looks like this:

      | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15 <--- Coordinates observed by Tank 1
      | 8| 9|10|11|12|13|14|15| 0| 1| 2| 3| 4| 5| 6| 7 <--- Coordinates observed by Tank 2
 0  8 |T1|  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 1  9 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 2 10 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 3 11 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 4 12 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 5 13 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 6 14 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 7 15 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
 8  0 |  |  |  |  |  |  |  |  |T2|  |  |  |  |  |  |
 9  1 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
10  2 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
11  3 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
12  4 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
13  5 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
14  6 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
15  7 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |
^^ ^^
|| ++---- Coordinates observed by Tank 2
++---- Coordinates observed by Tank 1

T1: Starting position of Tank 1, target of Tank 2
T2: Starting position of Tank 2, target of Tank 1

The commander receives two arguments, map and enemyAction:

  • map: (x: number, y: number) => Cell:

    • A Cell is one of the following:

      • ' ' (space): empty cell
      • '#': wall
      • 'F': friendly tank
      • 'E': enemy tank
    • x and y wrap around (mod 16).

    • You can't directly modify the map

  • enemyAction: Action

    • type Action = { action: 'B'|'D', x: number, y: number } | null
    • The last action of the enemy commander.
    • Given only for convenience, it could be computed from the map.

And must return one of the following actions:

  • { action: 'B', x: number, y: number }:

    • Builds a wall.
    • Walls can not be built on the two bases ((0,0) and (8,8)) and on cells with tanks. Attempting to do so is an error.
  • { action: 'D', x: number, y: number }:

    • Destroys a wall.
    • Attempting to destroy a non-existing wall is an error.
  • null:

    • Does nothing.

The tank driver receives four arguments:

  • x: number, y: number: position of your tank
  • friendlyAction: Action, enemyAction: Action: the last actions of the friendly and enemy commanders.

And must return one of the following actions:

  • { action: 'M', direction: Direction, distance: number }

    • Move the tank (up to 3 cells in a straight line, instantly).
    • Direction is one of the following:
      • 'U': negative y direction (up)
      • 'L': negative x direction (left)
      • 'D': positive y direction (down)
      • 'R': positive x direction (right)
    • 1 <= distance <= 3
    • If the tank can't move distance cells because a wall or the enemy tank is in the way, it stops moving before colliding with that (it will not move at all if the obstacle is directly in front of it).
  • { action: 'S', direction: Direction }

    • Shoot.
    • The bullet travels in a straight line until it hits a wall or a tank, instantly.
    • If you hit the enemy tank, you immediately win the round 2-0.
    • You can't shoot yourself.
  • { action: 'L', callback: (Result) => void }

    • Look around (in straight lines in all 4 directions).
    • type Result = { U: number, L: number, D: number, R: number, enemyDirection: Direction | null }
      • U, L, D and R are the lengths of empty cells in the respective directions.
      • enemyDirection is the relative direction of the enemy tank, if visible. If there are no walls in the row/column, it will be the direction which the enemy is closer in.


  • Reaching (8,8) and surviving until your next turn: win 3-0
  • Shooting down the enemy tank: win 2-0
  • Reaching turn number 40 without a winner: draw 1-1
  • Throwing an error or returning invalid action: lose 0-3

Technical details

The submissions must consist of two separate programs written in . The programs may not use any APIs that aren't part of the language itself (i.e. browser or Node.js APIs) and may not introduce globally observable changes (including but not limited to prototype pollution and mutating built-in objects). The programs may not run code asynchronously.

To keep the game reproducable, Math.random() will be replaced with a seeded PRNG, which you can use for randomness, but please don't introduce any other non-determinism.

The commander must be a script with a function commander in the top-level scope. Likewise, the tank driver has to have a function named tankDriver. You may create helper functions and variables for storing state (state will be reset after each game).

Each submission will be run against every other submission in pairs, 2×5 times for each pair (each submission starting 5 times). The maps will be randomly generated. The submission reaching the highest total score wins the challenge.

The controller is not yet done, I want to get feedback about the challenge first.

Besides the ones listed above, standard loopholes also apply.

I reserve my right to disqualify entries that violate the above rules or ones that I deem to be cheating. I will always notify the author in advance and allow them to fix the problems.

  • \$\begingroup\$ If all tanks start at (0, 0), does that mean multiple tanks can be on the same tile? And also, what do the numbers in C1 T2 C2 T1 mean? \$\endgroup\$ Commented Jan 25 at 14:25
  • \$\begingroup\$ @AlanBreadel From an outside perspective, one tank starts at (0,0) and the other at (8,8) as mentioned in the introduction. But both tanks see the world as if the tile they started on is (0,0), so they don't have to use conditional logic to decide if they should go to (0,0) or (8,8). I'll try to clarify this. Also, I can easily remove this rule if it's too confusing. C1 T2 C2 T1 means "commander of first player; tank of second player; controller of second player; driver of first player" \$\endgroup\$
    – FZs
    Commented Jan 25 at 15:15
  • \$\begingroup\$ Ah, so each tank is paired up with one other tank. Is that other tank with another submission or something else? \$\endgroup\$ Commented Jan 25 at 15:20
  • \$\begingroup\$ Yeah, 2 tanks at a time. One submission consists of one team of a commander and a driver, controlling one tank and editing the map. \$\endgroup\$
    – FZs
    Commented Jan 25 at 15:22
  • \$\begingroup\$ I'm pretty sure king of the hills are supposed to put all submissions against each other, but this is probably also fine. Maybe a swiss format? (e. g. one tank and commander against every other tank and commander team.) \$\endgroup\$ Commented Jan 25 at 15:24
  • \$\begingroup\$ Also, (0, 0) and (8, 8) imply a 9x9 grid (assuming those are the edges. I'm a bit confused because it specifies 16x16.) It should be (0, 0) and (7, 7) with 0-based indexing, or (1, 1) and (8, 8) with 1-based indexing. \$\endgroup\$ Commented Jan 25 at 15:25
  • \$\begingroup\$ This is described near the end, "Each submission will be run against every other submission [...]". Also, I have seen KotH's on this format on CGCC \$\endgroup\$
    – FZs
    Commented Jan 25 at 15:27
  • \$\begingroup\$ The map is 16×16, and toroidal (meaning wrapping around). This means (0,0) and (8,8) are the furthest cells (because to get to (15,15) you could just wrap around from 0 to 15 in two steps). \$\endgroup\$
    – FZs
    Commented Jan 25 at 15:30
  • \$\begingroup\$ If a tank moves right say, 5 squares, is that instant or does it take 5 turns with 1 square per turn? \$\endgroup\$ Commented Jan 25 at 15:39
  • \$\begingroup\$ I'll have to clarify that. Tanks can move up to 3 cells instantly. They can move longer than 3 cells in multiple turns \$\endgroup\$
    – FZs
    Commented Jan 25 at 15:44
  • \$\begingroup\$ So for example I try to move 7 tiles, I'll move 3 in one turn, 3 in the next, and 1 in the turn after that, right? But then I decide I want to do something else on the second or third turn. Can I stop the movement and do something else or does it override everything? \$\endgroup\$ Commented Jan 25 at 17:05
  • \$\begingroup\$ I already edited my post, see the edit. You can't return "move 7 tiles", that is an error. You'd have to go "move 3", "move 3", "move 1" to move 7 in effect. \$\endgroup\$
    – FZs
    Commented Jan 25 at 19:18

Demonstrate that 1³+2³+...+n³ = (1+2+...+n)²

The following image is a proof without words that \$\sum_{i=1}^{n}i^3=\left(\sum_{i=1}^{n}i\right)^2\$, or in other words, the sum of the first n cubes equals the square of the sum of the first n positive integers.

enter image description here

The image contains (the equivalent of) 1 square with side length 1, 2 squares with side length 2, etc up to 5 squares with side length 5. The 1x1 squares have a total area of 1x1x1 = 1³, the 2x2 squares have a total area of 2x2x2=2³, and the 5x5 squares have a total area of 5x5x5=5³. Overall, the total area of all the squares is 1³ + 2³ + 3³ + 4³ + 5³.

But, the larger square has a side length of 1+2+3+4+5, and an area of (1+2+3+4+5)². And, since all the small squares take up the same space as the large square, they must have the same total area, so 1³+2³+3³+4³+5³ = (1+2+3+4+5)². This can be shown to work for all positive integers.

The above can also be represented as the following integer matrix:

[[1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5]
 [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
 [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
 [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
 [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
 [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]

This matrix can be thought of as a series of "bands", where each band #n contains all points at coordinates (x, y) where max(x, y) = n. Every point in the first band, containing the point at coordinates [1, 1], contains 1; the second, containing [[1, 2], [2, 2], [2, 1]], and the third, containing [[1,3],[2,3],[3,3],[3,2],[3,1]], contain only 2s, the next 3 bands contain only 3s, and so on up to 5.

Your challenge is to, given a positive integer n, output the corresponding integer matrix for n. The above matrix should be output when 5 is input.

This is , shortest wins!

  • \$\begingroup\$ Can I print this matrix infinitely? Or take i,j and output the element in those coordinates? \$\endgroup\$ Commented Jan 29 at 3:55
  • \$\begingroup\$ @CommandMaster I'm gonna say no to that, I don't really see the point of the first and the second oversimplifies things. \$\endgroup\$
    – emanresu A
    Commented Jan 29 at 6:34
  • \$\begingroup\$ Looks similar to the one that output \$\begin{matrix}1&2&3&4\\2&2&3&4\\3&3&3&4\\4&4&4&4\end{matrix}\$ \$\endgroup\$
    – l4m2
    Commented Jan 29 at 6:41

Possible moves in Othello/Reversi

  • \$\begingroup\$ This actually seems interesting, commenting since it's late and otherwise you wouldn't see \$\endgroup\$
    – mousetail
    Commented Jan 25 at 14:30

Remove falsy rows and columns


Is it a coordinate-sum list?

In this challenge, we define a coordinate-sum list as a ragged list of positive integers where each value is the sum of its 0-indexed-coordinates in the array. For example, the following ragged list is a coordinate-sum list:

[[[0, 1],
  [1, 2, 3],
  [2, 3, 4],

In this array, the 4 is the third item of the second item of the second item of the list, or arr[1][1][2] (0-indexing), which gives it the coordinate [1, 1, 2], which sums to 4. Likewise, the 0 is arr[0][0][0] and has the coordinate [0, 0, 0] which sums to 0, and this is true for all items in the list.

This, however, is not a coordinate-sum list:

[[0, 1, 2],
 [1, 2, 3, 4],
 [2, 3, 6, 5],

Although all the other entries are the sums of their coordinates, the 6 at the third item of the third row has coordinate [2, 2], which sums to 4, but its value is 6, so this is not a coordinate-sum list.

Your challenge is to, given a nonempty ragged list of positive integers containing no empty lists at any level, determine whether it is a coordinate-sum list. You may instead validate the input via 1-indexing (i.e. [[2, 3], [3, 4, 5], 2] would be valid).

This is , shortest wins!


All of these use 0-indexing. If your answer uses 1-indexing, add to each value its depth in the list.


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


[[1, 2], [2, 3, 4]]
[[0, 1], [2, 3]]
[[[1, 2, 3], 4, [3, 4, 5]], [[2, 3, 4], [3, 4, 5], [4, 5, 6]], [[3, 4, 5], [4, 5, 6], [5, 6, 7, 8], [6, [7, 8], 8]]]
[4, 3, 2, 1, 0]
[[4, 3, 2], [3, 2, 1], [2, 1, 0]]
  • \$\begingroup\$ Why does it matter that the array is othogonal? \$\endgroup\$
    – pajonk
    Commented Feb 12 at 7:12
  • \$\begingroup\$ @pajonk It doesn't, it was mostly because I didn't want to make things unnecessarily hard for langs like C and haskell which don't (natively) have ragged lists. You're right that almost all approaches would work for ragged lists, and I'm just going to change it to that. (sorry for the late reply) \$\endgroup\$
    – emanresu A
    Commented Feb 15 at 20:38
  • \$\begingroup\$ Ah, sorry for the confusion. We have different definitions of orthogonal and array - for me an array is simply a non-ragged list and orthogonal is a specific property related to arrangement of columns in the array. That said, I personally would prefer non-ragged lists (arrays) in this challenge, as this would be easier for languages supporting matrices (and higher dimension generalisations) like R or Octave. \$\endgroup\$
    – pajonk
    Commented Feb 16 at 5:44

Search the deepest depths of an array

  • \$\begingroup\$ "multidimensional array" is a bit of a confusing term here, it's really a ragged list/array. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Feb 24 at 0:51

Print the largest hidden double

Given a sting of space delimited words, find the longest word such that, when that word is replaced with spaces, it is still a subsequence of the remaining string. Then, replace everything, except for one such subsequence, with spaces. Print the result



that was esoteric and awesome man dope

longest applicable word: awesome


a w eso m e

Extra rules / Clarifications

  • You may always assume a solution
  • Input will only be ascii letters a-z and spaces
  • Input will be either all uppercase or all lowercase, whichever is most convenient for the solver
  • You must output leading spaces unless that is absolutely impossible for your language in general, but trailing spaces may be removed


i havent written a challenge in so long - how much of this is salvageable and how much can i clear up haha

  • 1
    \$\begingroup\$ Will there always be a valid solution? Eg. a dog jumps has no answer \$\endgroup\$
    – ATaco
    Commented Mar 6 at 2:39
  • \$\begingroup\$ @ATaco oh yea good question! I think these are better if you can always assume a solution so I'll add that, thank you \$\endgroup\$ Commented Mar 7 at 6:04

Lattice points visible from the origin


Magical BF: BF code that works in two ways


  • This is basically a resurrection of this closed challenge but with different scoring. It was closed based on the policy about multipart challenges. I believe the most problematic part (copying parts of solutions) is solved by competing for each task separately. I also believe that this challenge is better served as one than five separate challenges, since there are some general techniques that transfer well across tasks (trust me, I solved all five tasks before posting this) and posting five of these would look spammy and unoriginal. Please leave comments if you think this version is off-topic.
  • \$\begingroup\$ Where does tape head start? \$\endgroup\$
    – l4m2
    Commented Mar 7 at 8:34
  • \$\begingroup\$ Tape head (data pointer) starts at the leftmost cell. \$\endgroup\$
    – Bubbler
    Commented Mar 7 at 8:37
  • \$\begingroup\$ Is "Author" you or the source? \$\endgroup\$
    – l4m2
    Commented Mar 7 at 8:38
  • \$\begingroup\$ Those are my best scores. \$\endgroup\$
    – Bubbler
    Commented Mar 7 at 8:40

Can I Clear The Grid?

  • \$\begingroup\$ Suggest case RGRG in case someone click on non-empty cell \$\endgroup\$
    – l4m2
    Commented Mar 18 at 8:37
  • \$\begingroup\$ Provide link to english version instead? \$\endgroup\$ Commented Mar 18 at 13:29
  • \$\begingroup\$ @Mukundan314 didn't realize there was one; thanks \$\endgroup\$
    – hyper-neutrino Mod
    Commented Mar 18 at 13:57
  • \$\begingroup\$ @l4m2 good suggestion, added \$\endgroup\$
    – hyper-neutrino Mod
    Commented Mar 18 at 13:59

Swingin' Four Operations!

Before, I found this song which has no meaning other than to combine all the consonants and vowels in the English alphabet. This challenge is similar, however, instead of outputting the song, your programs should output a modification which is basically addition, subtraction, multiplication and division tables of small integers up to 12, but presented in a format similar to the song.

Your challenge is to write a program that takes no input and outputs the four operation tables, where the operation inputs (first input from 1 to 10, second input from 1 to 12, both inclusive, 1 omitted for both inputs in the tables for multiplication and division) and output are seperated by spaces, the columns are seperated by commas followed by spaces and the rows are separated by dots followed by new lines. For division, non-integer outputs are rounded off to two decimal places. Each table is separated by two newlines.

The last two columns (11 and 12) don't contain the first parameter of the modification and are only separated by spaces. The required output is in this pastebin.


  • You are not allowed to use external resources, such as the internet.
  • You cannot use compression algorithms, such as gzip or bzip2, unless you include the full algorithm in your code.
  • Use any language, shortest code in bytes wins.

  • \$\begingroup\$ Great challenge for writing reusable code and formatting numbers. I've got a few questions: 1) You say that it should output the tables for small integers up to 12. Why are the matrices in the pastebin link 10 by 12? 2) Does 'You are not allowed to use external resources, such as the internet' mean you may not do research (which would be a little weird for answering an online question) or you may not use an API (which is generally not allowed for codegolf)? \$\endgroup\$
    – Cactusroot
    Commented Mar 29 at 18:41
  • \$\begingroup\$ @Cactusroot It does not specify that all of the small integer pairs are outputted. Also, 'You are not allowed to use external resources, such as the internet' means you may not use an API. \$\endgroup\$ Commented Mar 29 at 18:49
  • \$\begingroup\$ Sorry, I added the question. Now I got it, but 'the text in this pastebin' may be a little ambiguous. I believe you can define it precisely as "Any of the four modification tables, where the modification inputs and output are separated by spaces, the columns are separated by commas followed by spaces and the rows are separated by dots followed by new lines, with a trailing separation. The last two columns (11 and 12) don't contain the first parameter of the modification and are only separated by spaces" \$\endgroup\$
    – Cactusroot
    Commented Mar 29 at 18:51
  • \$\begingroup\$ @Cactusroot Edited. \$\endgroup\$ Commented Mar 29 at 18:54

Rotation by triple skewing

You can rotate a two-dimensional array by an angle by sampling or some other mechanism to approximate the resulting value at a specific point. However this is not very effective for a small array, such as an ASCII-art picture. Instead, we can approximate the rotation by a triple skew.

The first skew shifts the rows of the array by an amount proportional to the distance above or below the centre of rotation. This value is an input which I shall call \$ t \$.

The second skew shifts the columns of the array by an amount \$ \frac{-2t}{1+t^2} \$ multiplied by the distance to the left or right of the centre of rotation.

The third skew is a copy of the first skew.

The shift amounts should be one of rounded, floored or ceilinged so that each row or column is shifted by an integer amount.

The array should be considered to be cyclic so that elements shifted will wrap around to the other side.

Given an input array, a centre of rotation, and \$ t \$, output the resulting rotated array.

The array may be any convenient data type such as bytes, characters or integers. If the array is of characters then you may also represent it as a list of strings.

Example of the three skews for \$t=0.475\$:

  012       012          27DE      27DE 
 34567     34567        16CJK     16CJK 
89ABCDE    89ABCDE     05BIQR     05BIQR
FGH IJK -> FGH IJK -> 34A PVW -> 34A PVW
 STUVW       STUVW    FGNTY       FGNTY 
  XYZ         XYZ     LMSX        LMSX  

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

8-bit AVR integer division

Impatience got the better of me


Complement of a set of ranges

Consider a shop that exists for a given range of time. At certain times during the shop's existence items can go on sale. These items will be on sale for at least one unit of time.


Given such a shop, and the times it has items for sale, find the mutually-exclusive ranges of time when the shop is not selling anything.

Your inputs will be: a two-length array that represents the range of time the shop exists for. An array, where each element is a two-length array that represents a range of time that an item was on sale for.

your output will be: An array, where each element is a two-length array that represents a range of time that no item was on sale for. Where no element's range should overlap another's range.

All values defining a time range will consist of positive integers (or zero).


A shop exists for the time range [0, 10].

An item is put up for sale during the time range [5, 8]. Another item is put up for sale during the time range [2, 3]. Another item is put up for sale during the time range [4, 6].

Thus the shop is selling nothing from time 0 to 2, 3 to 4, and 8 to 10.

Inputs: [0, 10] and [[5, 8], [2, 3], [4, 6]]

Output: [[0, 2], [3, 4], [8, 10]]

Extra info

You may assume that the input time ranges overlap on a common boundary. i.e. items on sale for [1, 3] and [3, 4] is effectively a sale for [1, 4].

No time range (input or output) should span less than one unit of time: i.e. [1, 1] or [7, 7] is not permitted.

In case this seems ambiguous, the input time ranges can be thought of as closed intervals. Whilst the output time ranges can be thought of as open intervals. All the values used are whole numbers, however the ranges they represent are continuous. i.e. the open interval '[1, 2]' which does not contain any integers, still represents a continuous span of time between '1' and '2' (non inclusive on both sides).

Test cases (first array is the time for which the shop exists, second is the times for which items were on sale)

[0, 100] [[3, 7], [2, 5], [17, 54], [99, 100]] -> [[0, 2], [7, 17], [54, 99]]

[7, 20] [[8, 17], [12, 13], [14, 17], [9, 16], [18, 19]] -> [[7, 8], [17, 18], [19, 20]]

[1, 2] [[1, 2]] -> []

  • \$\begingroup\$ “You have written this well” is a compliment. The title should read complement. \$\endgroup\$ Commented Apr 1 at 14:10
  • \$\begingroup\$ @KaiBurghardt Thanks. That explains why I'm always spelling implement incorrectly (impliment). \$\endgroup\$ Commented Apr 2 at 13:45
  • 1
    \$\begingroup\$ Maybe add test cases with the words title-cased? And even with mOrE eRrAtIc CaPs, unless it's more to the point to guarantee that the input will always be either all-lower, all-upper, or title. \$\endgroup\$ Commented Mar 29 at 19:31
  • 1
    \$\begingroup\$ @UnrelatedString I am not going to do title case. I've considered it and I think it adds to much complexity, plus there are a bunch of cases where I don't even know what's proper, (m'Ubh, M'ubh, or M'Ubh?) And I definitely am not doing erratic caps. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Mar 31 at 19:01
  • \$\begingroup\$ I had assumed that title casing was expected to be handled from the verbiage about matching the case of the second character, but agree that the added complexity would be out of proportion. \$\endgroup\$ Commented Apr 1 at 0:06

Emulate Jelly's tie-scan


Bitwise and on 2-adic number

TODO: Explain 2-adic number

E.g. 0b...001001001 * 0b111 = 0b...1111111 = -1, so 0b...001001001 = -1/7.

Given two 2-adic numbers in fraction form, output their bitand result.

Test cases:

1 & 2 => 0
1/3 & 2/3 => 2

  • Should I require decimal support (1/2 = 0b0.1)?

You're to create a file using a hex editor. Unluckily most of keys on your keyboard are broken. You can:

  • Add a byte you can press at the end of file
  • Add a byte such that, the upper 4 bits hex is a character you can press, and lower 4 bits hex is 0
  • Modify upper/lower 4 bits of a byte hex to a character you can press.

Here, character 0x30-0x39 map char 0-9, and 0x41-0x46, 0x61-0x66 map A-F for hex edit purpose.

Given the set of characters you can press, return all chars you can type in. IO can be integers or chars, and all in [0,255].

Test Cases

  • 3 (space and three) => #03
  • 8A => 8:AHJ\x81\x88\x8A\xA1\xA8\xAA
  • \xBA => \xBA
  • 1
    \$\begingroup\$ I think it would be helpful to have "Given the set of characters you can press, return all chars you can type in." closer to the top, with the "rules" below that. The rules are a bit confusing otherwise until I get further down. \$\endgroup\$
    – mbomb007
    Commented Apr 10 at 18:30

Compose Two Polynomials


Given two polynomials \$p\$ and \$q\$ with integer coefficients (and with one indeterminate), output their composition \$p \circ q\$.

I/O format


It is assumed that the inputted polynomials have no leading zero coefficients, and the outputted polynomial shall have no leading zero coefficients, either.


Here, the polynomials are represented as lists of coefficients in descending degree of terms.

p(x), q(x), p(q(x))

[], [2,1], []
[1,2], [], []
[1], [1], [1]
[1], [2], [1]
[4,1], [1], [5]
[2,0], [1,2], [2,4]
[1,2], [2,0], [2,2]
[1,0], [3,3,3,-2], [3,3,3,-2]
[1,0,-1], [1,0,-1], [1,0,-2,0,0]
  • \$\begingroup\$ Duplicate? \$\endgroup\$
    – xnor
    Commented Apr 19 at 22:32
  • \$\begingroup\$ @xnor Nevermind; though that question is poorly titled. \$\endgroup\$ Commented Apr 20 at 0:12

Numbers with variable repeating digits

The number \${4...4}1\$ can be written as the expression \$\frac{4 \times 10^{a+1} - 13}{9}\$, where the variable \$a\$ represents the number of \$4\$s. Given such a number, output its corresponding expression.


  • The term doesn't have to be in the simplest form
  • The expression has to be in standard mathematical infix notation, you can replace the operators by a constant set of characters
  • You can take the variables via input or use lowercase/uppercase letters (you can assume the number of repeated groups is max. 26)
  • The number is strictly positive


[In]: [[4, "n"], 1]
[Out]: [[4, "*", [[10, "^", ["n", "+", 1]], "-", 13]], "/", 9]

[In]: [[6, "variable"], [2, "constant"], [53, "variable"]]
[Out]: "(10^(2*b)*(660*10^a-409)-53)/99"

  • \$\begingroup\$ Can each variable only be used once? \$\endgroup\$
    – l4m2
    Commented Apr 29 at 0:45
  • \$\begingroup\$ @l4m2 Good question, I’d say no. (To confirm, the challenge wouldn’t be too trivial then, right?) \$\endgroup\$
    – math scat
    Commented Apr 29 at 5:29
  • \$\begingroup\$ I'm not sure if I am missing something, but your formula seems to work for 4...43 rather than 4...41. I think if you change -13 to -31 it will be correct. I don't think you have enough of a requirement on the output as it is. I presume you want the answer to be divided by some multiple of 9 and 11, but without requiring it one could certainly come up with some other representation that would also work. \$\endgroup\$ Commented Apr 30 at 22:13
  • \$\begingroup\$ @FryAmTheEggman Thanks. About the output requirement, you’re saying it’s better to restrict it to expression without any divisions / multiple of 9 and 11? \$\endgroup\$
    – math scat
    Commented May 1 at 5:37
  • \$\begingroup\$ I was saying that was how I interpreted what you wanted the output to be. As is, a submission could produce some other valid expression, which may be very different from what you have here. If you don't actually care about that then you can leave it as it is. \$\endgroup\$ Commented May 1 at 15:10

3-Dimensional Minesweeper

I've been on a minesweeper kick for a while, but all the questions are for 2 dimensions (or that one in 1D). But 2D is 2 easy!


Write the shortest code possible to fill in the clues for a 3-dimensional minesweeper grid.


The board dimensions, taken in any order and reasonable format, and the mines as a list of 3-dimensional coordinates in any reasonable format and order.


A 3-D list resembling a 2-D list of columns (consistent order) or a list of 2-D slices (in order, any perspective) to form the final 3-D board. The number of adjacent mine can either be a number 1-26 or the corresponding letter a-z, unless it is empty and then it is 0. Mines can be any character/string that is not a number 0-26, and not a letter a-z if those are used instead.

test cases

Board: 3x3x3
Mines: [1,1,1]
  • \$\begingroup\$ Since the clues are going to be numbers, not just single digits, it would be convenient if the mines could be represented by numbers as well (optionally). I would suggest allowing answers to choose any number that can't be a clue to represent a mine. \$\endgroup\$
    – DLosc
    Commented Apr 29 at 18:43
  • \$\begingroup\$ so the surrounding mines can be up to 26, if you want to take the mines as a number greater than that i guess you can? \$\endgroup\$
    – pacman256
    Commented Apr 29 at 19:04
  • \$\begingroup\$ should i also allow a-z to represent adjacent mines \$\endgroup\$
    – pacman256
    Commented Apr 29 at 19:05
  • 1
    \$\begingroup\$ Sure, why not? It's a fun coincidence that there are 26 letters, and maybe someone will find it helpful. (In the realm of numbers, I was thinking mines might be usefully represented by either 27 or -1.) \$\endgroup\$
    – DLosc
    Commented Apr 29 at 19:10

Interpret Gray Snail

Gray Snail is a small Turing-complete string-based language that I've had fun using lately. Let's write an interpreter for it!

Note: there are several differences between the language spec on Esolangs, the behavior of the official implementation, and the spec for this challenge. These differences are noted in a section below.

Language overview

Gray Snail is an imperative language in which programs consist of a series of commands. Commands are executed one after another (unless the instruction pointer is changed by a GOTO statement). When the instruction pointer reaches the end of the program, execution halts.


Each line of code represents one command. A command consists of one or more words (see below) separated by spaces. Examples of commands:

POP first rest hello
OUTPUT [first]
GOTO "exit string reversal loop" "" "[original string]"

You may assume the code will not contain any blank lines.

There are five types of commands: POP, GOTO, INPUT, OUTPUT, and labels. See the section on Commands for a full description.


A word is composed of printable ASCII characters. It is either A) two double-quote characters surrounding a run of zero or more non-quote characters, or B) a run of one or more characters that do not include spaces or double quotes (in regex: ".*?"|[^\s"]+).

Examples of words:

"Hello, World!"
"  "

Quotes are only used for parsing and are not considered part of the word. For example, abc and "abc" are the same word, just written differently. There is no method of escaping quotes; words cannot include a literal " character. You do not have to handle unmatched quotes or quotes in the middle of a word.

The empty string is a valid word. You may assume that an empty word will always be wrapped in quotes ("").

No two words will occur next to each other; they will always be separated by spaces. The only way for spaces to be part of a word is if the word is wrapped in quotes. Outside of a word, you may assume there will never be multiple spaces in a row.


The only data type in Gray Snail is the unlimited-length string. Strings can be stored in variables, concatenated, and decomposed by the POP command (see below). Strings can be empty.

In contexts that expect a string, any word that does not contain square brackets is treated as a string literal. Anything wrapped in square brackets is a variable reference.


A variable has a name and a value, both of which are strings. Variables can be set by the POP or INPUT commands.

In contexts that expect a string, the value of a variable can be inserted by enclosing the variable's name in square brackets: for example, if the variable var is set to hello, OUTPUT var outputs the literal string var, but OUTPUT [var] outputs hello.

In contexts that expect a variable, the variable's name is not enclosed in square brackets: for example, INPUT var sets var to a string read from input.

Variable references can be concatenated to each other and to literal strings: if variable a contains code and variable b contains golf, [a]a[b] evaluates to codeagolf.

You may assume that variable names will be non-empty and will not contain square brackets.

Variable names may be wrapped in quotes and may contain spaces. Due to the syntax rules above, the quotes will always be on the outside of the word; thus, a variable named "some var" will be written as "[some var]" when retrieving its value.

Dereferencing a variable more than once (i.e. nesting square brackets) is undefined behavior: your interpreter will never need to handle something like [[a]]. You do not have to handle unmatched square brackets.

You may assume that variables will not be referenced before they are assigned.


There are five types of command in Gray Snail. Each consists of a fixed number of words, separated by single spaces. Four of them start with a specific word (POP, GOTO, INPUT, and OUTPUT).


POP var1 var2 string takes two variable names and a string. It separates the string's first character (in this example, s) from the rest (tring). It then stores the first character in the variable named var1 and the rest in the variable named var2.

  • If the third argument has only one character, that character is stored in var1 and the empty string is stored in var2.
  • If the third argument is empty, the empty string is stored in both var1 and var2.
  • The third argument is not modified by POP, even if it is a variable reference.


A single word on a line by itself is a label. Labels do nothing; they serve as targets for GOTO instructions.

  • You may assume that the other commands' names (POP, GOTO, INPUT, or OUTPUT) will not be used as labels. Labels are case-sensitive, though, so pop or Pop could be used.
  • You may assume that labels will be non-empty and will not contain square brackets.
  • Labels may be wrapped in quotes and may contain spaces.


GOTO label string1 string2 takes three strings and compares string1 and string2. If they are equal, the program jumps to the label named label and execution continues from there. Otherwise, execution continues with the next statement as normal.

  • A goto target label may contain variable references: for example, GOTO L[a] x x will jump to label L1 if a is 1 and L2 if a is 2.
  • You may assume that the evaluated label name will be a valid label that occurs once and only once in the program. In particular, variables that are referenced in target labels will not contain quotes or square brackets.


INPUT var takes a variable name. It reads a line of input and stores it in the variable named var.

  • Input may contain any printable ASCII character, including space, ", and [].
  • You may assume the program will not run out of input.


OUTPUT string takes a string. It writes out string with a trailing newline.

Differences from the official language

The language specified here is materially the same as the official definition of Gray Snail, but it has been simplified a bit. Here are the ways in which the official implementation differs from this spec:

  • Words can contain any Unicode character. Words can also contain newlines if they are wrapped in quotes.
  • Quotes can wrap any part of the word; for example, ["some var"] is equivalent to "[some var]", and "string w"ith" "spac"e"s is equivalent to "string with spaces".
  • The empty string does not have to be wrapped in quotes. It can be used as a variable name and also as a label.
  • All variables are initialized to undefined.
  • The official spec has some input/output quirks because it's designed for a webpage rather than command-line.
  • The official implementation allows unconditional gotos without comparison strings, such as GOTO x. As far as I can tell, this is contrary to the official spec. One of the example programs on Esolangs uses GOTO x a a for an unconditional goto, which is also what we'll be doing for this challenge.

More details

TODO: stuff about full program vs function, limitations on size of strings, etc.

Example programs


This is ; the goal is to minimize the size of your code, measured in bytes.

  • \$\begingroup\$ Can the label argument of the GOTO command be a variable? The official interpreter supports this functionality. Also how should something like OUTPUT ][x][ be handled? \$\endgroup\$ Commented Apr 30 at 0:59
  • \$\begingroup\$ Your regex for words doesn't seem to do what you describe in any flavour, as far as I can tell. You also say "even spaces" but it isn't clear if things like newlines should count as part of a word or if that is not supposed to appear in the input. \$\endgroup\$ Commented Apr 30 at 21:59
  • \$\begingroup\$ @FryAmTheEggman Oops. I often get \s and \w mixed up by thinking that \w stands for Whitespace. :P Regex updated and verified working in Notepad++. Re: newlines in words, the answer is implied to be "no" by the statement that each line of code is a command and that each command is composed of words; it's also stated explicitly that "words will only contain printable ASCII characters." ...Although the official interpreter does allow newlines in words if they are quoted, and I allow answers to imitate that behavior. But the default is not to. \$\endgroup\$
    – DLosc
    Commented Apr 30 at 22:13
  • \$\begingroup\$ Ah, I had missed the printable ASCII part. You may want to move it up to the explanation part, as it seems rather important. \$\endgroup\$ Commented Apr 30 at 22:18
  • \$\begingroup\$ I'm starting to think that all the lines of "the official interpreter does this, but you don't have to, but you can if you want to" are cluttering things up. I will probably move them to their own section. \$\endgroup\$
    – DLosc
    Commented Apr 30 at 22:30
  • \$\begingroup\$ @Mukundan314 1) Didn't think of it before, but yes; 2) undefined behavior. I clarified both points. \$\endgroup\$
    – DLosc
    Commented Apr 30 at 22:31

Flip a coin in Lost


Anti Tic-Tac-Toe

The rule of Anti Tic-Tac-Toe is like Tic-Tac-Toe.

The rules are:

  • There is a 3*3 grid, the squares in the grid are labeled 1 to 9:
  • X goes first.
  • The most important rule: If there's a line, a column or a diagonal with all squares non-blank and the squares are not all the same, the player with more squares in the line, column or diagonal wins. For example, if the grid is like this (. stands for empty cells):

Then X wins.

If there are more than one lines like this and their winners are different, the game will stop and the state of the game will be bad.

For example:


Is a bad game.

Your task is to input a list of integers from 1 to 9, each integer represents the cell the current player plays. The integers are guaranteed to be different from each other. You have to output the state of the game: X if X wins, O if O wins, . if the game hasn't stopped yet, ! if the game is bad.

Obviously, ties can't occur because if all the squares are taken, there will always be at least one row, column or diagonal that satisfies the winning condition.

You can use any forms of I/O, such as standard I/O, file I/O or function.


1 -> .
123 -> X
1539 -> O
214379 -> O
294371 -> !

This is , so code in the fewest bytes


Ultra-modular representative of rational numbers


Given a rational number, output the representative in the corresponding coset in the additive (abelian) quotient group \$\mathbb{Q} / \mathbb{Z}[1/2]\$. \$\mathbb{Q}\$ is the additive group of rational numbers, and \$\mathbb{Z}[1/2]\$ is the additive group of rational numbers whose denominator is power of 2, identified as an adjoint ring with multiplicative structure forgotten.


Being a quotient group, \$\mathbb{Q} / \mathbb{Z}[1/2]\$ consists of cosets. Each coset has exactly one rational number such that:

  • is \$0\$, or
  • is a positive proper fraction with positive odd denominator.

And this number is the representative of the said coset.

I/O format

The I/Oed rational numbers shall be a reduced fraction. That is, the numerator and the denominator shall be coprime, and the denominator shall be positive.


Input -> Output

0/1 -> 0/1
1/1 -> 0/1
2/1 -> 0/1
1/2 -> 0/1
3/2 -> 0/1
1/3 -> 1/3
2/3 -> 2/3
1/6 -> 2/3
5/6 -> 1/3
1/8 -> 0/1
1/10 -> 3/5
3/10 -> 4/5
7/10 -> 1/5
-1/1 -> 0/1
-1/6 -> 1/3
-1/12 -> 2/3

Meta Question

How would this challenge be presented in laymen's terms?


Convert base-10 to base-0.1.

Test cases:

12.34 <=> 432.1 12 <=> 2.1 3.0 <=> 3.00

Hint: Actually 0 can behave same as other digits, as long as you map 3.0 to 3.0 rather than 3 or 3.00.

Anything more I should say?


Is this a solvable Numberlink?

  • \$\begingroup\$ Your solution example looks like it's required to fill each empty cell with a number s.t. every number connected, which seems not intended \$\endgroup\$
    – l4m2
    Commented May 14 at 22:20
  • \$\begingroup\$ or if allowing to leave some empty cell, then both are equivalent \$\endgroup\$
    – l4m2
    Commented May 14 at 22:22
  • \$\begingroup\$ @l4m2 well you can leave some blank space, just that it has a path \$\endgroup\$
    – badatgolf
    Commented May 15 at 1:37
  • \$\begingroup\$ Many may also know this puzzle as Flow Free. See also But how hard is Flow? (YouTube) which talks about the computational complexity of solving Flow puzzles. Solving these puzzles is NP-complete, but I'm not sure if checking their solvability is. \$\endgroup\$ Commented May 21 at 22:31
  • \$\begingroup\$ @noodleman yeah the video inspired me to make this challenge actually, I wonder if there is a way to check in polynomial time, and is it more golfed than the brute-force solution. \$\endgroup\$
    – badatgolf
    Commented May 22 at 13:38
  • \$\begingroup\$ I think you should allow input either as that coordinate-y structure or as a matrix. I have edited in the code to make the images smaller, please check the Markdown diff: for stack exchange image uploads, adding m before the file ending makes the size medium, s makes the size small, l probably makes them large though I haven’t tried that. \$\endgroup\$ Commented May 22 at 14:34
  • \$\begingroup\$ For true test cases I suppose you could borrow from Flow’s levels. If you have a solution to the problem already, you could use that to find unsolvable ones. \$\endgroup\$ Commented May 22 at 14:38
87 88
90 91

You must log in to answer this question.

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