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


4560 Answers 4560

39 40
42 43

When's my weekend finally here?


Reverse RegEx

Take a regex a as input, output a regex b such that, for each string x, x matches a iff x.reverse matches b.

Here, regex need to support such symbols:

  • .(any character expect \n)
  • [abc](any character in abc)
  • [^abc](any character not in abc)
  • x?(appears 0-1 times), x*(appears any amount of times), x+(appears any positive amount of times)
  • x{n,m}(appears n to m times, m can be omitted to mean infinite)
  • (abc) (?:abc)(group block, () can be referred while (?:) can't)
  • \n(refer to the latest match of n-th group)
  • ^(begin of string), $(end of string) (or begin/end of line, see flags/m)
  • |(or, choose one in some choices)
  • Letters, \n(this n is char rather than variable, line-feed)

You need to handle flags i(ignore upper/lower case) and m(multiline, ^ and $ match begin/end of lines rather than string). You can also just pipe the flags and make the containment of regex work for all possible flags, aka. you can treat pipe free. (They refuse to allow or disallow)

Sample Input    Sample Output
/abcd/          /dcba/
/[abc]/         /a|c|b/
/[^abc]/        /[^abc]/
/(.)abc\1$/     /^(.)cba\1/
/$1/            /10% of $10/

Shortest code win

  • 2
    \$\begingroup\$ What's the regex flavor/set of allowed features/inputs? Is it for a full or partial match? \$\endgroup\$
    – feersum
    May 10, 2019 at 9:07
  • \$\begingroup\$ @feersum Allowed features need discuss. To be a full match ^ and $ can be added \$\endgroup\$
    – l4m2
    May 10, 2019 at 9:21
  • \$\begingroup\$ Why is test case /[^abc]/ there twice? Or is it to give two different example outputs? Since just outputting /[^abc]/ for input /[^abc]/ would be fine. Also, I'm not too familiar with this Regex syntax, but how does /$1/ work, since $ is the end of the match? And why is it /10% of $10/ reversed? \$\endgroup\$ May 10, 2019 at 9:27
  • \$\begingroup\$ @KevinCruijssen twice to show that same input may lead to different output. /$1/ and /10% of $10/ both match nothing \$\endgroup\$
    – l4m2
    May 10, 2019 at 9:32
  • \$\begingroup\$ "both match nothing" Ah ok.. I falsely assumed the regex would match something. So incorrect (but still valid) regexes are also allowed as input. Maybe it's a good idea to add some comments to the sample outputs, like /10% of $10/ can be anything as long as it doesn't match anything (and maybe put the /(?!a)[^bc]/ or /[^abc]/ for the same input on one line. \$\endgroup\$ May 10, 2019 at 9:37
  • 2
    \$\begingroup\$ You should more rigorously explain what x.reverse means, from the examples it looks like you mean the order of letters is reversed, but some people might be confused. \$\endgroup\$ May 11, 2019 at 21:28
  • \$\begingroup\$ 1) I think x|y is missing in the list of symbols. 2) The behavior of each symbol is underspecified in so many ways. What does [a-z], [[\]], (ab+)*\1, or (((((((((((x)))))))))))\11 do? Do we need to handle any backslash escapes other than newline? 3) Are you sure this is possible? Can you reverse (a(bx*){0,2}c)*\2\1? \$\endgroup\$
    – Bubbler
    Jun 22, 2021 at 23:38
  • \$\begingroup\$ 4) Using such a complex flavor of regex is a parsing hell, which I don't recommend with the same reasons as parsing arithmetic. Good challenges about manipulating regexes include this and this. \$\endgroup\$
    – Bubbler
    Jun 22, 2021 at 23:41
  • \$\begingroup\$ @Bubbler I'll just don't care [[\]] and assume input only contain letters and \n. (a(bx*){2}c)+\2\1 reverses into (c(x*b)(?:x*b)a)\2\1(c(x*b)(?:x*b)a)*(Handcode, maybe wrong; need some OR to fit your original one) \$\endgroup\$
    – l4m2
    Jun 23, 2021 at 0:53
  • \$\begingroup\$ I'll ask differently: 1) Should we support range notation [a-z] or not? I assume it's not a set of three chars a-z since - is not a letter. 2) I think you have the knowledge that (x)* only captures the last iteration and \1 fails if it is not actually captured. You need to include it in the post. 3) Should we support multi-digit backreference (like \11 being the eleventh)? \$\endgroup\$
    – Bubbler
    Jun 23, 2021 at 2:06
  • \$\begingroup\$ A note for the future: a regex with backreferences is no longer a regular expression in the CS sense, and any kind of manipulation on it can easily fall into an uncomputable problem. \$\endgroup\$
    – Bubbler
    Jun 23, 2021 at 2:20
  • \$\begingroup\$ Also, about the "pipe free" thing: you didn't define the term "pipe" anywhere, so it only makes the challenge more unclear. "They refuse to allow or disallow" seems like a misunderstanding on your side; see Jo King's comment there. Basically an I/O method is allowed only when the language or the answer format (function or full program) supports it. And regardless of what site policy says, you can allow anything you want as long as you make it explicit (you already did here, so no need to mention the meta post). \$\endgroup\$
    – Bubbler
    Jun 23, 2021 at 3:41
  • \$\begingroup\$ I'm pretty sure that the algorithm you have in mind does not handle ((x)|(y))+\2\3 (though it is reversible). I suspect it can be made irreversible if I replace x and y with something more dynamic. \$\endgroup\$
    – Bubbler
    Jun 23, 2021 at 4:09

The Great Betting Game


Play Thud

Thud is a game described by Terry Pratchett in his novel, Thud!.

The game simulates a battle between the Dwarfs (in blue) and the Trolls (in green) on an octagonal board with the Thudstone (an impassable space) in the centre of the board.

Thud board

I have created an environment to play the game and develop game playing code at: https://ajfaraday.github.io/Thud/dist/index.html

The challenge is to write the most successful dwarf or troll player of this game (these will be two separate challenges).


Starting with the Dwarfs, players take it in turns to move.

Dwarf Movement

On the Dwarf player's turn, they can move one dwarf piece either as a walk or a hurl.

Walk: Dwarfs can move as far as they like in any direction until they hit an obstacle (another dwarf, the edge of the board, or a troll). They can only kill a troll by walking if they are only one space away.

Hurl: If two or more dwarfs are in a line (horizontal, vertical or diagonal), they can hurl the dwarf on the end of the line, by the length of the line (e.g. in a line of 3, the dwarf on the end can be hurled 3 spaces). If a dwarf is hurled into a troll, the troll is killed, reducing the trolls score by 4 points.

Troll Movement

On the Troll player's turn they can move one troll piece, either as a walk or a shove.

Walk: Trolls can move one space in any direction, unless a troll, dwarf or the edge of the board is in the way. Whenever a troll moves, it kills all dwarfs adjacent to it's destination space.

Shove: If two or more trolls are in a line (horizontal, vertical or diagonal) they can shove the troll at the end of the line that number of spaces away, but only if any of the target space's immediate
neighbours contain a dwarf. When a troll is shoved, it kills all dwarfs on or adjacent to it's destination space.

It is not permitted for a troll to land directly on a dwarf by either walk or shove moves.

Each dwarf killed reduces the dwarfs score by 1 point.


The score is calculated thus:

  • The dwarf player has one point for every dwarf remaining on the board.
  • The troll player has four points for every troll remaining on the board.
  • The key figure is the difference between these two. This will be used to calculate players' scores in the tournament.

Ending the game

The game ends when any of these conditions is met:

  • There are no dwarfs on the board.
  • There are no trolls on the board.
  • Both players have declared the game over.
  • The game has reached it's cut-off length of 500 moves.

How to manually play a game

  • Go to https://ajfaraday.github.io/Thud/dist/index.html
  • Hover the mouse over a piece to see it's available moves.
    • Safe moves are outlined in green.
    • Dangerous moves (which can be killed the next turn) are outlined in orange.
    • Killing moves are highlighted in red when the mouse hovers over them.
  • Click a piece to select it for the current move.
  • Click one of the available moves to move the piece.
  • (You can click the relevant 'Make Peace' button to declare the game over according to that player, during their turn)

How to set up a local instance of the game

You don't have to clone the repository and use it locally to to create an entry, but it helps.

  • git clone [email protected]:AJFaraday/Thud.git
  • cd Thud
  • npm install
  • You can then run ./get_answers.sh to get the latest entries from Stack Exchange

If you prefer, you can use the github pages instance at https://ajfaraday.github.io/Thud/dist/index.html

How to customize a game

  • Open /dist/index.html in your browser
  • Click 'Customize'
  • Select troll and dwarf clients (manual allows direct control)
  • Select a turn time in milliseconds (only relevant to non-manual players)
  • Click 'Run Game' to see or play the game.
  • (Clicking 'Close' will not enact any changes)


The game is played by clients, which represent either a troll or a dwarf player. Each is a JavaScript class which must have these three functions:

  • constructor(controller) - controller is an object which acts as your interface with the game (see below).
  • turn() - This is called whenever it is your players turn to move.
  • end_turn() - This is called after your player's turn is over. It can not move pieces, but can make decisions on whether or not to declare the game over.


The controller object is your client's interface with the game itself. You can find full documentation for the controller class here: https://github.com/AJFaraday/Thud/blob/main/docs/controller_interface.md

It provides these methods to interrogate the state of the game:

  • turn() - Current turn of the game

  • scores() - The current score

  • spaces() - Every space, and what's in it

  • space_info(x, y) - Detailed information on any space on the board.

  • dwarves() - The location of every dwarf

  • trolls() - The location of every troll

  • pieces() - All pieces belonging to the current player (equivalent of dwarves() or trolls())

  • indexed_dwarves() - The location of every dwarf with a fixed index

  • indexed_trolls() - The location of every troll with a fixed index

  • previous_move() - What got moved to where last turn

  • killing_moves() - All moves which can kill one or more opponent

  • current_space - Currently selected space (not a function)

  • clear_space() - Empties currently selected space These methods are used to actually make your move:

  • check_space(x, y)- Find out what moves are available from a given space

  • select_space(x, y) - The player decides to move a piece at space.

  • check_move(x, y) - Find out what will happen if you move to a place

  • move(x, y) - The player moves the current piece to the selected space.

These are concerned with ending the game:

  • declare(game_over) - Say whether or not your player thinks the game is over.
  • opponent_declared() - Has the opponent declared the game over?

How to write a client

Warning: There is an issue with the project on Firefox (https://github.com/AJFaraday/Thud/issues/3) which prevents editing the code in the browser. This has been confirmed to work in Chrome.

  • Open 'dist/index.html' in your browser.
  • Click 'Customize'.
  • Select 'dwarf/template' as the Dwarf player (or use another client as a starting point).
  • Click 'Edit' beside the Dwarf player select.
  • Write your client code in the text box provided.
  • The Validate button will change colour based on whether or not the client is passes validations (see below).
  • When you're happy with it, click 'Apply' (This can be done before it passes validation, but it may not actually work).
  • Select a worthy opponent and click 'Run Game' to see the game.


In order for a client to work, and therefore be enterable in the challenge, it has to pass these validations:

  • It must evaluate as Javascript code.
  • The code must return a class, with a constructor which accepts one argument.
  • Instances of this class should have functions named turn() and end_turn()
  • The client must play a game until it is over (i.e. it must call a valid move during every turn call). The validator will run games against default opponents to determine if this happens.
  • Does not have any forbidden terms ** game. - Only interact with the game via controller ** Math.random - Please keep it deterministic ** setTimeout or setInterval - Keep it sequential
    ** eval, require or import - Just don't

You can open the developer console (F12) to see more detailed information on your client's validation process.

How to save a client

If you have cloned the git repository, you can save your entry for future tinkering. This step is not required for entry in the challenge, but it may be helpful.

  • Edit a client, as above.
  • When you're happy with it (preferably if it's passing validation, too), click 'Copy' from the edit interface.
  • Create a .js file in /src/clients/dwarf/entry with the name of your entry e.g. /src/clients/dwarf/entrygreat_dwarf_player.js. (This folder will not be wiped by get_clients.js)
  • Run node script/get_clients.js from the Thud directory to make your entry available from the Dwarf player select. You only need to do this once to make it avilable.
  • npm run build - this will keep watching for changes in your entry and updating the package.

How to enter your client in the competition

  • Decide on the name of your client, your client_name must only have alpha characters and underscores.
  • Answer this question with your entry
    • The first line of your answer should be your client's name as a title (with = characters under it on the second line)
    • There should be a code block containing the class for your entry (with or without the preceeding module.exports =)
    • After that please include a brief explanation of your client's behaviour, and any other information you'd like to include.

Once this is in place, anyone running ./get_answers.sh will see your client available under your username.

The GitHub Pages instance will also be updated periodically. So by making an entry, your code will be added to the repo.

Tournament rules

The tournament will pit every available dwarf client (in /src/clients/dwarf/) against every available troll client (in /src/clients/troll/), and each pairing will play exactly one game.

The difference between the two players' scores will then update a running total for each client. The winner will gain the difference, and the loser will lose the difference.

There are two winners in the tournament, the most successful troll player and the most successful dwarf player.

According to the rules, after playing a game, the players swap sides, so please also write an entry on the Troll challenge.

This is now nearly complete (apart from some UI improvments and presenting the tournament results a bit more nicely). There's a working example of the code importer working against these two meta questions:

I could really use someone to attempt an end-to-end run at creating a client and adding it to one of these to check that my instructions are clear and everything works.

  • \$\begingroup\$ Very well described challenge. Seems nice! \$\endgroup\$
    – user100752
    Jun 20, 2021 at 14:17
  • \$\begingroup\$ @EliteDaMyth Thank you for taking a look. Glad it looks complete. \$\endgroup\$
    – AJFaraday
    Jun 20, 2021 at 22:43
  • \$\begingroup\$ Two rule questions: 1. in which direction can be hurled/shoved? 2. It is not permitted for a troll to land directly on a dwarf by either walk or shove moves. but both troll moves have lines like kills dwarfs on … destination/…only if the target space … contains a dwarf. \$\endgroup\$
    – xash
    Jul 2, 2021 at 14:17
  • 1
    \$\begingroup\$ @xash Good questions, I'll update to be clear. The answer is always 8 directions vertical, horizontal and diagonal. Also, I learned about the rule that trolls can't land on anything after writing the rules. I should have updated the steps too \$\endgroup\$
    – AJFaraday
    Jul 2, 2021 at 14:31

Print this sequence I just made up

  • \$\begingroup\$ Your test cases are correct. (Confirmed with an ungolfed integer implementation.) \$\endgroup\$
    – Arnauld
    Jun 27, 2021 at 0:05
  • \$\begingroup\$ Your code must not fail due to floating point errors. If the language used doesn't have arbitrary-precision integers, an integer implementation may fail because of integer overflow before a floating point implementation fails. :-/ \$\endgroup\$
    – Arnauld
    Jun 27, 2021 at 0:13
  • \$\begingroup\$ @Arnauld Thanks for confirming my testcases. Would saying that you cannot use floats work? \$\endgroup\$
    – emanresu A
    Jun 27, 2021 at 0:34
  • \$\begingroup\$ I think the current wording is fine. It's just weird that prohibiting floating point errors is likely to lead to integer implementations that are actually worse. \$\endgroup\$
    – Arnauld
    Jun 27, 2021 at 0:41
  • \$\begingroup\$ @Arnauld Oh well. \$\endgroup\$
    – emanresu A
    Jun 27, 2021 at 0:44

Generate off-by-one regex for a string

Given an alphanumeric string as input, generate JS-flavored regex in order to match any off-by-one errors for that string. In stricter terms, your resulting regex must match any single deletions, single replacements, or single additions like in the below examples.


"hi" -> "(h|i|.i|h.|.hi|h.i|hi.)"
"golf" -> "(olf|glf|gof|gol|.olf|g.lf|go.f|gol.|.golf|g.olf|go.lf|gol.f|golf.)"

Here is a program for generating the results.

Note: The order of the regex does not need to matter (ie, "hi" could be "(h|h.|hi.| . . .")) so long as all patterns are in the regex.

This is , so shortest program in bytes wins.

  • \$\begingroup\$ Which flavor of regex will be used? \$\endgroup\$
    – user
    Jul 4, 2021 at 16:13
  • 1
    \$\begingroup\$ @user Lets go with JS to make it consistent, it shouldn't really matter though as the regex will share the exact same format as the example cases, with only the order possibly changed. However, i've now updated the post for clarity. \$\endgroup\$
    – Underslash
    Jul 4, 2021 at 17:23
  • \$\begingroup\$ May string contains special characters like `.[]$^(?!)\`? \$\endgroup\$
    – tsh
    Jul 5, 2021 at 1:36
  • 1
    \$\begingroup\$ Your regexp for input hi also match hi itself, which is not off-by-one. Is this designed behavior? \$\endgroup\$
    – tsh
    Jul 5, 2021 at 1:37
  • \$\begingroup\$ @tsh for question 1, ill specify alphanumeric, and for question 2, ill keep it as intended just so it doesn't needlessly complicate the question, but if you have a simple way to implement it, be my guest \$\endgroup\$
    – Underslash
    Jul 5, 2021 at 9:18

Are you a probabilist or a physicist?

  • \$\begingroup\$ Is it fine to be a function in one language and a full program in another? \$\endgroup\$
    – Bubbler
    Jul 23, 2021 at 2:13
  • \$\begingroup\$ "Your programs should be true polynomials" - did you mean polyglots? \$\endgroup\$
    – pxeger
    Jul 23, 2021 at 7:50
  • \$\begingroup\$ @Bubbler Yep, that's fine \$\endgroup\$ Jul 23, 2021 at 11:35
  • 1
    \$\begingroup\$ @pxeger No, clearly you should code mathematical functions involving powers, multiplications and additions to solve this ;) Typo fixed \$\endgroup\$ Jul 23, 2021 at 11:36

Calculate the integer square root of a matrix

  • 1
    \$\begingroup\$ Should really be "Calculate the integer square root of a matrix", because there acan be multiple square roots. E.g. [[18, 63], [14, 67]] also has as square root, the given solution divided by 11. \$\endgroup\$
    – Adám
    Jul 31, 2021 at 23:16
  • \$\begingroup\$ I think it should be "Calculate an integer square root of a matrix", since "the integer square root" is the language you would use if there were only one. If you find combining "Calculate" with "an" a bit awkward, you could substitute "Determine" or "Find". \$\endgroup\$
    – theorist
    Aug 4, 2021 at 2:22

Pinpoint the typo!


Write a program that finds the location of an error in its own code!

The program itself must output either nothing or an empty string (or an appropriate equivalent in your language).

Let n be the length of the program in bytes, which must be at least 2. For an integer k with 1<=k<=n, if the kth byte of the source code is deleted, then the resulting program should output the integer k (and nothing else), in as many cases as possible.

Outputs may be 0-indexed if preferred, so that omitting the kth byte outputs k-1, but the choice of indexing must be consistent across all k.

Error messages do not count as valid output unless they are of exactly the required form.

Your score is the number of integers k for which the above condition is satisfied, divided by n. Highest score wins, with ties broken by smallest n.


Consider the program blob() in a fictitious language. Suppose that:

blob() outputs nothing (this is a requirement)

lob() outputs 1 (right)

bob() outputs 2 (right)

blb() outputs 3 (right)

blo() outputs 4 (right)

blob) outputs nothing (wrong)

blob( outputs 6: Syntax error (wrong)

Then the score would be 4/6 = 0.66666667

  • 1
    \$\begingroup\$ This might be abused by simply making a very long answer. \$\endgroup\$
    – user
    Aug 5, 2021 at 20:06
  • 1
    \$\begingroup\$ Related. Related. Related \$\endgroup\$ Aug 5, 2021 at 20:11
  • \$\begingroup\$ @user Yes, I did wonder about that, although such answers might still be interesting. Ideas for a better scoring system? Number of 'wrong' answers is not great, because of very short answers.... \$\endgroup\$
    – aeh5040
    Aug 5, 2021 at 20:12
  • 1
    \$\begingroup\$ What I did with my 'Quantum quine' question, which is similar, is for the scoring system count the number of chars that it doesn't work for. \$\endgroup\$
    – emanresu A
    Aug 6, 2021 at 11:23
  • \$\begingroup\$ @emanresu A The problem I see with that is that very short programs would get an unreasonable advantage. E.g. any 4-byte program that does nothing gets 4 without even trying to accomplish the task... \$\endgroup\$
    – aeh5040
    Aug 6, 2021 at 13:24
  • \$\begingroup\$ Perhaps it would be better if the unaltered program must output Hello World or something... \$\endgroup\$
    – aeh5040
    Aug 6, 2021 at 13:27
  • \$\begingroup\$ @aeh5040 I also ruled that each answer had to have at least one functional result... Then again, quines do have to be at least a certain size. Your choice. \$\endgroup\$
    – emanresu A
    Aug 7, 2021 at 10:45

IATA Airport Codes

Out of 17576 alphabetical triplets, to this day, 9144 are used as IATA airport codes.

Given a 3-letter string, tell whether it appears in the list.

  • The input string is mixed-case by default, but you can restrict it to non-mixed-case or lower-case or upper-case

  • To output the affirmative/negative outcome you should use:

    • truthy/falsy according to your language's convention (swapping is allowed), or
    • one consistent value as either affirmative or negative, and any other value as the other
  • This is

The list was scraped from iata.org on 2021-08-07


  • Is there something that needs to be specified/clarified?
  • 1
    \$\begingroup\$ What is uniform case? Add the kolmogorov-complexity tag since there's a limited input domain? GitHub Gist is an alternative that's well-trusted by this community, I'd say \$\endgroup\$
    – pxeger
    Aug 8, 2021 at 17:05
  • \$\begingroup\$ @pxeger I want to say a string where all the letters are uppercase or lowercase, contrary to mixed-case \$\endgroup\$
    – Domenico
    Aug 8, 2021 at 17:07
  • \$\begingroup\$ @pxeger maybe non-mixed-case would be more direct? \$\endgroup\$
    – Domenico
    Aug 8, 2021 at 17:25

Sum of 3 Vectors


Given 3 vectors a, b, c

Find integer (n, m, r) where a*n+b*m+c*r = 0 and n,m,r are all not equal to 0.

your answer group (n, m, r) must be the closest valid group to 0, calculate by adding abs value together: |n|+|m|+|r|

You can assume that 3 vectors do not parallel

Test case

work in progress


  • no Standard loopholes
  • any I/O case allowed, as long as it's clear and mostly understandable.


  • Lowest byte count per language wins!


any extra tag?


Rename question?

  • \$\begingroup\$ this looks like a 3d linear equation solving problem. \$\endgroup\$
    – Razetime
    Aug 19, 2021 at 4:02
  • \$\begingroup\$ Are the vectors 2-dimensional with integer components? \$\endgroup\$
    – Nitrodon
    Aug 27, 2021 at 14:53
  • \$\begingroup\$ @Nitrodon those are 2D vectors currently. \$\endgroup\$
    – okie
    Sep 1, 2021 at 1:33

Distances between keys on a QWERTY keyboard

  • \$\begingroup\$ fro kolmogorov i suggest keeping everything in the same unit. \$\endgroup\$
    – Razetime
    Aug 19, 2021 at 3:58
  • \$\begingroup\$ All jokes aside, this is a well specified challenge. \$\endgroup\$ Aug 19, 2021 at 14:05
  • \$\begingroup\$ Why radiation-hardening? This is the opposite, isn't it? \$\endgroup\$
    – pxeger
    Aug 21, 2021 at 14:21

Unfudge my terminal!


Today I fiddled around with termios for a program. The only thing I managed to do so far is fundging my terminal... can you help me out?


Given a terminal input that contains fudged special chars, output the string that should be displayed if the terminal worked correctly. Here's a list of the broken special chars:

^B -> Backspace
^J -> (Fwd-) Delete
^W -> Discard
^D -> Cursor left
^C -> Cursor right
^F -> End
^H -> Start

How the special characters work

  • Backspace deletes the character behind the cursor and moves it one step back. Has no effect on the start of the string.
  • Delete deletes the character in front of the cursor. Has no effect on the end of the string.
  • Discard deletes the string typed up to this point.
  • Cursor left/right moves the cursor to the left/right by one. Has no effect on the end/start of the string.
  • End/Start move the cursor to the end/start of the string.

Undefined special characters are to be removed.


  • Any represetation of a string/list of characters
  • Single lines only
  • The special characters may be either all capitalized or all not capitalized
  • The input will not contain a sequence that will result in a ^ in the output, nor will it contain a single ^ at the end.


  • The unfudged input.
  • No leading/trailing whitespace that isn't part of the string.


abcd^B^B^B --> a

abcd^We^Af^Lgh --> efgh

 gof^D^D^D^Dcode^C^C^Cl --> code golf

ocde gol^H^J^Jco^Ff --> code golf

edgecase^H^D^B^J^F^C^J^B --> dgecas


  • This is , shortest answer wins
  • Standard loopholes are not allowed
  • A submissiom may be a program/function/link/lambda/chain/etc.


Sandbox things

  • Is anything unclear?
  • Should any special char be added or removed?
  • Is there an edge case not covered by the examples?
  • Are the rules and I/O restrictions fine or should I change anything?

Snap (card game)


Display a number in Toki Pona

  • 2
    \$\begingroup\$ Welcome to Code Golf and nice first question! Thank you for using the Sandbox first :) I've done some minor edits to add capitalisation and formatting. Tags wise, [integer-partitions] and [natural-language] both apply. This is a similar challenge, but that uses US coins \$\endgroup\$ Aug 12, 2021 at 22:49

Khinchin's constant bad estimate


Unicode Calendar Generator


Your program will receive a valid date in the format relevant to your language (date object or three int for year, month, day or whatever) and should returns a fancy unicode calendar as such (note that the title is right/left aligned):

Given Y-M-D as 2021-10-13

║ October ░░░░░ 2021 ║

Given Y-M-D as 2021-11-13

║ November ░░░░ 2021 ║

Given Y-M-D as 2021-06-15

║ June ░░░░░░░░ 2021 ║

This is , so you the shortest bytes of each language will be the winner.

Inspired by qwerty.dev

  • 1
    \$\begingroup\$ What does it need the day for? If you want to include the selection of the given day, perhaps you should include that in the challenge post in an example, to keep it self contained. also is the 00 intentional? \$\endgroup\$ Oct 13, 2021 at 20:29
  • \$\begingroup\$ @thejonymyster fixed. And the 00 was a mistake. Thank you :) \$\endgroup\$
    – aloisdg
    Oct 13, 2021 at 20:32
  • \$\begingroup\$ Are the month/year always to be left/right aligned, like ` May ░░░░░░░░░ 2021 `? What input formats (string, 3 integers, list, built-in date object, ...) are allowed? \$\endgroup\$
    – Dingus
    Oct 13, 2021 at 22:04
  • \$\begingroup\$ month year should be left/right aligned. For the inputs formats, what would be the most popular? \$\endgroup\$
    – aloisdg
    Oct 14, 2021 at 6:37
  • 1
    \$\begingroup\$ I'd recommend allowing any sensible input format (because the challenge is more about producing the calendar than parsing dates). You should explain the alignment rules in the post. Maybe it would be enough to swap one of the examples for a month with a shorter name, but probably better to be explicit. \$\endgroup\$
    – Dingus
    Oct 15, 2021 at 1:03
  • 2
    \$\begingroup\$ What date range is required to support? 1970~2038? Or maybe larger? \$\endgroup\$
    – tsh
    Oct 18, 2021 at 3:54
  • \$\begingroup\$ @Dingus lets use any sensible input format \$\endgroup\$
    – aloisdg
    Oct 18, 2021 at 12:31
  • \$\begingroup\$ @tsh I dont have a strong opinion about that. \$\endgroup\$
    – aloisdg
    Oct 18, 2021 at 12:32
  • \$\begingroup\$ tsh's question needs a definite answer because the date range could influence the input method and/or implementation. You should also mention that the Gregorian calendar is used. \$\endgroup\$
    – Dingus
    Oct 21, 2021 at 23:57
  • \$\begingroup\$ Name suggestion: Wheatian group :) \$\endgroup\$
    – Bubbler
    Oct 15, 2021 at 6:01

Pretty print a grid of polyominoes

  • \$\begingroup\$ For challenges which require Unicode, it's generally a good idea to let people count those characters as a single byte each. Aside from that, looks good! \$\endgroup\$
    – emanresu A
    Oct 24, 2021 at 23:04
  • \$\begingroup\$ @emanresuA Thank you very much for your feedback! Is there an easy way to make TIO count like that? Or perhaps as a workaround allow defining the special characters as constants in the header? \$\endgroup\$
    – loopy walt
    Oct 25, 2021 at 0:17
  • \$\begingroup\$ You just generally get people to count, I think. Or you could allow people to use any set of distinct characters instead of the box-drawing characters, or allow both. \$\endgroup\$
    – emanresu A
    Oct 25, 2021 at 0:28

Fast Matrix Multiplicator Evaluator


Find the k-th order summary of a number


  • \$\begingroup\$ very similar: codegolf.stackexchange.com/questions/70837/say-what-you-see \$\endgroup\$
    – Razetime
    Nov 4, 2021 at 2:15
  • \$\begingroup\$ @Razetime, yes they are quite similar, but the look and say operation is a bit different from the summary operation; for example look_and_say(112211) = 21 22 21 whereas summary(112211) = 41 22 \$\endgroup\$ Nov 4, 2021 at 5:51

Consider all arrays of \$\ell\$ non-negative integers in the range \$0,\dots,m\$. Consider all such arrays whose sum is exactly \$s\$. We can list those in lexicographic order and assign an integer to each one which is simply its rank in the list.

For example, take \$\ell=7, s=5, m=4\$, the list could look like:

(0, 0, 0, 0, 0, 1, 4)  rank 1
(0, 0, 0, 0, 0, 2, 3)  rank 2
(0, 0, 0, 0, 0, 3, 2)  rank 3
(0, 0, 0, 0, 0, 4, 1)  rank 4
(0, 0, 0, 0, 1, 0, 4)  rank 5
(0, 0, 0, 0, 1, 1, 3)  rank 6
(0, 0, 0, 0, 1, 2, 2)  rank 7
(0, 0, 0, 0, 1, 3, 1)  rank 8
(0, 0, 0, 0, 1, 4, 0)  rank 9
(3, 2, 0, 0, 0, 0, 0) rank 449
(4, 0, 0, 0, 0, 0, 1) rank 450
(4, 0, 0, 0, 0, 1, 0) rank 451
(4, 0, 0, 0, 1, 0, 0) rank 452
(4, 0, 0, 1, 0, 0, 0) rank 453
(4, 0, 1, 0, 0, 0, 0) rank 454
(4, 1, 0, 0, 0, 0, 0) rank 455

This challenge requires you to produce two pieces of code/functions.

  • Given a rank, compute the corresponding array directly. Call this function unrank()
  • Given an array, compute its rank. Call this function rank()

Your code should run in polynomial time. That is it shouldn't be brute force and more specifically it should take \$O(\ell^a s^b m^c)\$ time for fixed non-negative integers \$a, b, c\$. Any non-brute force method is likely to satisfy this requirement.


unrank((7, 5, 4), 9) = (0, 0, 0, 0, 1, 4, 0)
rank((7, 5, 4), (4, 0, 0, 0, 0, 1, 0)) = 451
unrank((14,10, 8), 100000)  = (0, 0, 0, 1, 0, 0, 1, 3, 1, 2, 0, 0, 2, 0)
rank((14, 10, 8), (2, 0, 1, 1, 2, 0, 0, 0, 2, 1, 1, 0, 0, 0)) = 1000000

Your score will be the total size for your code


Convert codepoint to UTF-9

  • 5
    \$\begingroup\$ For clarity, I'd start octal constants with 0o. Also, an explanation of how UTF-9 works should probably be included here. \$\endgroup\$ Jun 19, 2021 at 1:39
  • 2
    \$\begingroup\$ Could you include the basic algorithm to encode UTF-9 in your post instead of require an external resource? So this question can be made self contained. \$\endgroup\$
    – tsh
    Oct 12, 2021 at 6:27
  • \$\begingroup\$ @tsh Should I do with actual program source or in pseudo code? \$\endgroup\$
    – user100411
    Oct 12, 2021 at 12:26
  • \$\begingroup\$ first challenge that made me LOL \$\endgroup\$
    – don bright
    Oct 18, 2021 at 3:12

Lexigolf: Is this number a prime?

Write a program that, given a strictly positive integer n as input, determines whether n is prime and prints a truthy or falsy value accordingly.

For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.


Competing programs are compared lexicographically. The program that is lexicographically less than all other programs is the winner.

If a program begins with a prefix that may be removed without altering the program's behavior, it is disqualified. This is to discourage adding meaningless whitespace or comments to change the first character (consider int main(){} or /**/int main(){}).

For example,

abc < def
aa < ba
aaaaaaa < aba
aa < aaaa
Zzz < aaa
012 < AAA


This is essentially an earlier classic code-golf challenge, Is this number a prime?, except with a different goal, which I propose is called lexigolf.

I'm not sure whether lexicographic order should entirely be based on UTF-8 (for languages that can be expressed in bytes). It seems to massively favor weird esolangs that rely on characters with small ASCII codes. There is also a loophole in prefixing the program with noop characters, e.g. placing a arbitrary amount of whitespace before a C program: int main() {} > int main(int, char**) {} > int main(int argc, char **argv) {} (fixed? probably still a loophole somewhere)

  • 1
    \$\begingroup\$ For the scoring favoring weird esolangs that rely on certain characters, the scoring here is typically a per-language comptition, so Java and GolfScript wouldn't be competing. The null byte prefixing is a bit of an issue, so you might want to require that you can't take any number of characters off the left side of the program without making it stop working (so prefixing a null byte wouldn't be allowed unless it actually affected how the program ran). Also, primality testing might not be the best challenge for this idea, since many golfing languages have it as one or two byte built-ins. \$\endgroup\$ Nov 16, 2021 at 17:42
  • \$\begingroup\$ @Fmbalbuena The < are to indicate which is lexicographically smaller, not which is winning \$\endgroup\$ Nov 16, 2021 at 17:43
  • 2
    \$\begingroup\$ You might want to allow language with SBCSs (custom code pages, instead of UTF-8 or ASCII) like Jelly to use those for the lexicographic order instead, since that would make it more interesting to try to find the lexicographically smallest program in those languages. \$\endgroup\$ Nov 16, 2021 at 17:46
  • \$\begingroup\$ @RedwolfPrograms, I've updated the post \$\endgroup\$
    Nov 16, 2021 at 17:51
  • 1
    \$\begingroup\$ In some languages (for example, Befunge) you could probably detect whether the leading spaces were removed... \$\endgroup\$
    – Maya
    Nov 16, 2021 at 22:19
  • 3
    \$\begingroup\$ Removing only prefixes isn't enough: I could add a test at the end to check whether that prefix is present. Maybe you should require the code to be irreducible instead? \$\endgroup\$
    – Dingus
    Nov 16, 2021 at 22:55
  • 4
    \$\begingroup\$ It seems like this challenge is entirely about finding the lexicographically smallest prefix that can be extended arbitrarily far in a way that removing a prefix of it will be invalid syntax or fail. The prime-finding task doesn't really matter -- any code is equivalent if put after arbitrarily much prefix padding. \$\endgroup\$
    – xnor
    Nov 17, 2021 at 2:12

Will one-cell brainfuck halt?

  • 3
    \$\begingroup\$ Do you really want use - for increment while + for decrement? Or maybe a typo? \$\endgroup\$
    – tsh
    Nov 10, 2021 at 10:17
  • \$\begingroup\$ @tsh Oops. Fixed. \$\endgroup\$
    – emanresu A
    Nov 14, 2021 at 1:01

Construct a Heptagon avoiding compass use

A while back I asked you to construct a pentagon avoiding compass use. Now flawr suggested:

Next time you should ask people to draw a heptagon, which would be slightly more challenging:)

This is of course a joke, because if you didn't already know it is not possible to construct a Heptagon using a ruler and compass ...

... in finite steps.

In this challenge answers will construct equilateral polygon of 7 sides, using a ruler and a compass.

We will begin with some standard ruler and compass operations:

  • Draw a line that passes through two non-identical points. (Ruler)

  • Draw a circle centered at one point such that another point lies on the circle. (Compass)

  • Place a point at an intersection of two non-identical objects (a circle and a line, a line and a line or a circle and a circle)

Normally a construction must be finished after some finite number of operations. However we will allow you to take any ordinal number of steps. Meaning you can perform an infinite number of steps and then perform more.

To go with this you are given one more operation:

  • Choose converging sequence of already drawn points and place a point at their limit. (limiting)

This operation is only meaningfully useful if you have already performed an infinite number of steps, but is crucial to constructing a heptagon.


In this challenge you will start with two arbitrarily placed (but non-equal) points on an infinite plane. You must then describe some sequence of steps to arrive at a regular Heptagon. Here a regular heptagon simply being 7 points which form the vertices of a heptagon, they do not need to be in any particular position relative to the starting points.

Your score will be the number of compass operations used in the entire proof with lower being better. Since many answers may end up using an infinite number of compass steps we will break ties by the strict supremum of ordinals representing steps you have used a compass.

For example if two answers both use an infinite number of compass operations, their primary score is \$\infty\$. If one of them uses all of their compasses at finite numbered their secondary score is \$\omega\$, which would beat the other answer if it uses the compass at any time \$\omega\$ and after.

  • 1
    \$\begingroup\$ The theoretical optimal score is likely 2. It is known that a circle and its center (with a couple other known points, because we can't create arbitrary point) plus straightedge operations equals general compass + straightedge in terms of constructibility. It must be possible to construct a sequence of constructible points that converges to a heptagon-related point. The actual challenge is coming up with a constructive solution. \$\endgroup\$
    – Bubbler
    Dec 6, 2021 at 2:01

How long will my microwave run for?

  • \$\begingroup\$ I'd recommend getting rid of the bonuses, they're pretty strongly discouraged \$\endgroup\$ Dec 3, 2021 at 17:32
  • \$\begingroup\$ @RedwolfPrograms I do like the bonus challenge, however I'm not sure what to do with it. \$\endgroup\$
    – Ginger
    Dec 3, 2021 at 17:33
  • 1
    \$\begingroup\$ You could just turn the bonus challenge into a separate question \$\endgroup\$
    – pxeger
    Dec 3, 2021 at 17:41
  • \$\begingroup\$ @pxeger I'll make it a seperate question and post it later. \$\endgroup\$
    – Ginger
    Dec 3, 2021 at 17:49

Operator precedence is dead

Calculate the result of some math expressions using the following constraints:

  • Numbers will be between 0 and 9
  • Operators are + - / *
  • Expressions will always have the format Number operator number operator number...
  • Parenthesis have the highest precedence
  • The order of reading goes Left Left Right Right Left Left Right Right etc.
  • Division by 0 never happen

For example:

1       = 1   ; Start calculating using the left most number
 +    9 = 10  ; Add 9
  3  *  = 30  ; Multiply by 3
   -4   = 26  ; subtract 4

Using this method 1+3-4*9 = 26

Input / Output


  • string OR list of characters OR list of numbers and characters
  • Can be reversed if specified in the answer

Output: a number


Floating point errors are OK.

More examples and test cases:

2*9 = 18
1       = 1
 +    9 = 10
  3  *  = 30
   -4   = 26
8               = 8
 -            4 = 4
  5          *  = 20
   *        3   = 60
    0      +    = 60
     /    2     = 30
      9  /      = 3.33333...
       +8       = 11.33333...
Knowing that 1+3-4*9 is 26

8                       = 8
 -                    4 = 4
  5                  *  = 20
   *        (1+3-4*9)   = 520
    0      +            = 520
     /    2             = 260
      9  /              = 28.8888...
       +8               = 36.8888...
8         = 8
 -      2 = 6
  2    /  = 3
   +  6   = 9
    4*    = 36

First group:
 +  7 = 8
  2*  = 16

Second group:
 *  3 = 6
  2+  = 8

(1+2*7)             = 16
       *    (2*2+3) = 128
        6  +        = 134
         +3         = 137
Nested group:
6     = 6
 +  2 = 8
  1*  = 8

6           = 6
 +        2 = 8
  (6+1*2)/  = 1

Full expression:
1                 = 1
 +              4 = 5
  (6+(6+1*2)/2)/  = 5


This is , so the answer with the least amount of bytes wins.

  • 1
    \$\begingroup\$ "Division by 0 should not return a valid number." What do you mean by "a valid number"? I'd suggest just saying answers can assume division by zero will never occur \$\endgroup\$
    – pxeger
    Dec 17, 2021 at 3:05
  • 1
    \$\begingroup\$ Thanks for your feedback @pxeger ! I'm removing errors handling \$\endgroup\$
    – Julian
    Dec 17, 2021 at 3:20

Subdivide the Bezier Curve


A Bezier curve is a type of curve that has a lot of applications in all sorts of places, but most commonly, in computer graphics. It has a very simple algorithm and yet can represent a wide variety of shapes with just one common formula. If you've ever used pen tools in drawing software, you're probably already familiar with the general idea behind Bezier curves.

Given an ordered list of control points, we set some parameter \$t\$ in the range \$[0, 1]\$. Then, for each \$t\$, we draw a line between each consecutive pair of control points and select a point that is \$t\$ from the starting point. For example, if we have three control points and \$t\$ is \$\frac13\$:

enter image description here

The purple point is \$\frac13\$ of the way from the red point to the blue point, and the black point is \$\frac13\$ of the way from the blue point to the green point. You can change the ratio and move the points around here to try it out.

Now, we have one fewer point than we initially had control points. Let these be the new control points, and do this again with the same \$t\$:

enter image description here

(Desmos link). Now, we finally have a single point, so that is the point we obtain for this value of our parameter \$t\$. The Bezier curve is obtained from all final points for each \$0\leq t\leq 1\$. For more points, we just repeat this for more steps. Here's what a Bezier curve with four control points looks like:

enter image description here

(Desmos link)


Given a list of control points for a Bezier curve and a positive integer \$n\$, subdivide the Bezier curve into \$n\$ segments and return the points. More precisely, return the output points for \$t=0,\frac1n,\frac2n,\cdots,\frac{n-1}n,1\$.

You may do I/O in any reasonable format; for example, a list of pairs or a pair of x and y coordinates for input, and a pair of numbers for output. Floating point errors are acceptable but your outputs should have an accuracy of at least \$10^{-3}\$ relative or absolute, whichever is larger.

There will be at least one point and \$n\$ will be a positive integer.


Given input \$\{(0,0),(1,3),(4,2),(5,1)\}\$ and \$3\$ subdivisions:

For \$t=0\$, we just have \$(0,0)\$, and for \$t=1\$ we just have \$(5,1)\$.

For \$t=\frac13\$, we first go \$\frac13\$ of the way from each control point to the next to get \$\{(\frac13,1),(2,\frac83),(\frac{13}3,\frac53)\}\$. Repeating that once more gives us \$\{(\frac89,\frac{14}9),(\frac{25}9,\frac73)\}\$. Finally, if we do it once more, we get the single point \$(\frac{41}{27},\frac{49}{27})\$.

For \$t=\frac23\$, we first get \$\{(\frac23,2),(3,\frac73),(\frac{14}3,\frac43)\}\$, then \$\{(\frac{20}9,\frac{20}9),(\frac{37}9,\frac53)\}\$, and finally, \$(\frac{94}{27},\frac{50}{27})\$. And just for a sanity check, the points are indeed on the curve:

enter image description here

Note that these points do not evenly subdivide the Bezier curve by arclength. The arclength of a Bezier curve actually cannot be calculated exactly and subdividing like that would have to be done via approximations.

Test case generator

Credit to Wezl for the original idea.

  • \$\begingroup\$ love the interactive parts \$\endgroup\$
    – Wezl
    Dec 18, 2021 at 17:28
  • \$\begingroup\$ When reading this I didn't expect it to be you having posted it lol \$\endgroup\$
    – emanresu A
    Dec 23, 2021 at 7:55
39 40
42 43

You must log in to answer this question.

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