What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, 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. 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, replace the post here with a link to the challenge and delete it.

See the Sandbox FAQ for more information on how to use the Sandbox.

The Sandbox works best if you sort posts by "active".

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]

| |

2972 Answers 2972

79 80
82 83

Write a negadecimal number in words.

Negadecimal is a numeral system with digits \$0\$ to \$9\$ but is base \$-10\$ instead of \$10\$. Here are some examples (the left side is decimal numeral, and the right side is a negadecimal numeral):

$$ \begin{array}{rcrl} 0 & \to & 0 & \\ 1 & \to & 1 & \\ 9 & \to & 9 & \\ 10 & \to & 190 & \bigl(1 \cdot 100 + 9 \cdot (-10) + 0 \cdot 1 \bigr) \\ 11 & \to & 191 & \\ 20 & \to & 180 & \\ 99 & \to & 119 & \\ 100 & \to & 100 & \\ -1 & \to & 19 & \\ -9 & \to & 11 & \\ -10 & \to & 10 & \\ -11 & \to & 29 & \bigl(2 \cdot (-10) + 9 \cdot 1 \bigr) \end{array} $$

Basically, the carry rule (for both addition and subtraction) is that if you add one to nine, it wraps around to zero and you subtract one from the digit to the left, and if you subtract one from zero, it wraps around to nine, and you add one to the digit to the left. Also note that you can add or remove leading zeros from a number without changing its value. (In particular, the empty string represents the empty sum, i.e. zero.)


Anyways, for the actual challenge, you will take an integer as input and convert it to negadecimal. Then you will convert that to words. What do I mean by that?

The digits \$0\$ to \$9\$ have their regulars names (i.e. zero, one, ..., nine). The negadecimal numbers \$10\$ through \$90\$ (i.e. negative ten through negative ninety) have the following names:

onetao, twotao, threetao, fourtao, fivetao, sixtao, seventao, eighttao, ninetao

The negadecimal numbers \$100\$ to \$900\$ have their regular names (i.e. one hundred, two hundred, ..., nine hundred).

Numbers that are a digit followed by three or more zeros are created by combining the above names. For example, negadecimal \$2000\$ is twotao hundred, \$40000\$ is four hundred hundred, \$300000\$ is threetao hundred hundred, etc.

All other numbers are named by writing it in expanded notation, naming each summand (which will be one of the above), and conjuncting them. For example, negadecimal \$5402=5000 + 400 + 0 + 2\$ is fivetao hundred, four hundred, and two.

Zero summands are a special case. If the whole number is zero, you just write zero. Otherwise, you omit all zero summands.


Here are some examples (the left side is a decimal numeral, and the right side is a negadecimal numeral noun):

0 → "zero"
10 → "one hundred and ninetao"
11 → "one hundred, ninetao, and one"
-11 → "twotao and nine"
-10 → "onetao"
-9 → "onetao and one"
101 → "one hundred and one"
999999997 → "ninetao hundred hundred hundred hundred, nine hundred hundred hundred hundred, ninetao hundred hundred hundred, nine hundred hundred hundred, ninetao hundred hundred, nine hundred hundred, ninetao hundred, nine hundred, ninetao, and seven."

This is , so the shortest code wins!

| |
  • 4
    \$\begingroup\$ Rather subjective: Interesting challenge, until I read "Then you will convert that to words" :( \$\endgroup\$ – ბიმო Jan 21 '19 at 16:21
  • \$\begingroup\$ The challenge is well explained, but it could be improved a lot with some minor formatting. Eg. use MathJax, make some paragraphs (intro,actual description, i/o rules, examples or the like). As it stands it's not very easy to read. Also by conjuncting do you mean join with , except for the last two with and? What about spaces, are they important? \$\endgroup\$ – ბიმო Jan 21 '19 at 16:21
  • \$\begingroup\$ @BMO What do you mean subjective? I specify exactly what I mean by convert to words later in the post. \$\endgroup\$ – PyRulez Jan 21 '19 at 18:26
  • \$\begingroup\$ @BMO Conjuncting means to join with commas, and then to insert and between the last and second to last item. If there are only two items, you omit the comma. If there is only one item, you omit the and. \$\endgroup\$ – PyRulez Jan 21 '19 at 18:26
  • \$\begingroup\$ My opinion is subjective: That I liked the first part of the challenge, but the second part not so much. Okay, got it maybe you could add that to the challenge and describe how the spacing works there. One question which should be answered (in the challenge) for example: Is the space after the , obligatory or can a solution omit it? \$\endgroup\$ – ბიმო Jan 21 '19 at 18:58
  • \$\begingroup\$ I reformatted the post (didn't change the wording), feel free to roll-back if you don't like it. Another question popped up when doing so: Some examples seem to have a . at the end, is this on purpose? If so you should explain when it is required. Also is lower-case important? \$\endgroup\$ – ბიმო Jan 21 '19 at 19:31

KoTH: Iterated Nash bargaining!

In this king of the hill challenge, you must play an iterated Nash bargaining game. You and your opponent must return a number between 1 and 100 which says how much money out of £100 you want.

If the total amount requested by the players is less than £100, both players get their request. If their total request is greater than that available, neither player gets their request. However, to spice things up, it is iterated — you will play 200 rounds against each opponent.

Your bot should be a Python 3.7 function that takes 4 inputs in the following order: your current points, your opponent's current points, all moves you have played (in a list) and all moves your opponent has played so far (also a list).

Here are two examples, one plays the opponents last move (and 50 on the first move):

def copycat(themp, myp, theml, myl):
    if len(theml) < 1:
        return 50
        return theml[-1]

The other plays 50 if they have less than 50 points, and 70 otherwise:

def fiftyseventybot(thempoints, mepoints, themlist, mylist):
    if thempoints <= 50:
        return 50
        return 70

Your bot will play 200 rounds against each opponent, in the 'round robin' fashion .Whoever ends up with the most points wins. Standard loopholes are banned.

Have fun!


This is my first question, make sure to tell me if anything could be worded better or if anything is spelled wrong etc.

Also tell me whether you think this is a good idea and if you have any ideas to add to it.

Is there not enough of an incentive to change if both players are going 50? if so, what incentives could be created?

There seems to be disagreement between @PeterTaylor and @Spitemaster. I would like to reach some kind of consensus on this. Could anyone possibly comment on what they think?

| |
  • \$\begingroup\$ It seems to me that this won't work - neither player has any incentive to play anything other than 50. \$\endgroup\$ – Spitemaster Jan 11 '19 at 18:46
  • \$\begingroup\$ Agreed; furthermore, upon gaining an advantage on an opponent, it only makes sense to play greater than 50 every turn so that either you gain more points or neither of you gain any points so that you end with more points than them. \$\endgroup\$ – Sebastian Jan 11 '19 at 21:14
  • \$\begingroup\$ @Sebastian I can see why you would say that, but as you are trying to gain the most points over all rounds (playing every bot) you would want to maximise your score, meaning that tactic would lose you potential points as it relies on both of you not getting any points not being a bad outcome.(sorry that was quite a bad way of putting it but I hope you get my point) \$\endgroup\$ – Arkine Jan 12 '19 at 8:48
  • \$\begingroup\$ @spitemaster I originally thought that if you went for a higher number, you could try to force the opponent down, and you could use small numbers by finding when bots are constant and you’ve got no chance etc. Maybe there needs to be some kind of short term incentive for going high, like, for example, in the prisoners dilemma? \$\endgroup\$ – Arkine Jan 12 '19 at 10:08
  • \$\begingroup\$ The very idea of a Nash equilibrium is that neither player has an incentive to change. I don't think this is a good thing upon which to base a challenge. \$\endgroup\$ – Spitemaster Jan 12 '19 at 23:50
  • \$\begingroup\$ I think it might end up with interesting answers if there are any bots which do not actually aim for equilibrium. It depends on whether the bot cares more for maximizing its own score or minimizing the amount the other bot gets as an advantage \$\endgroup\$ – fəˈnɛtɪk Jan 13 '19 at 1:39
  • \$\begingroup\$ @Spitemaster, I can tell you from personal experience in earlier king-of-the-hill games that playing a Nash equilibrium may get you a fairly high position in these iterated games but it never wins. The winner usually plays a strategy which has a worse mean but high variance until they get an advantage, and then switches to the equilibrium. \$\endgroup\$ – Peter Taylor Jan 14 '19 at 16:29
  • \$\begingroup\$ @PeterTaylor In games like the Prisoner's Dilemma, the Nash equilibrium is defect. As there are ways of getting more points for both players, it is advantageous to not play that and instead try something semi-cooperative. In this game, there is no strategy that would be advantageous over the Nash equilibrium if both bots cooperated. For a bot to beat the 50 bot, you'd have to have a majority of bots willingly lose to either the bot that would win or the 50 bot. \$\endgroup\$ – Spitemaster Jan 14 '19 at 18:35
  • \$\begingroup\$ @Spitemaster, in practice that's not a problem. \$\endgroup\$ – Peter Taylor Jan 14 '19 at 21:26
  • \$\begingroup\$ Maybe changing the amount of money from 100 to 99 or any other odd number would solve it? \$\endgroup\$ – Embodiment of Ignorance Feb 4 '19 at 5:45
  • \$\begingroup\$ @EmbodimentofIgnorance Thats a good idea. It certainly would improve things but you might just get bots switching between rounded down and up halves only \$\endgroup\$ – Arkine Feb 6 '19 at 17:58
  • \$\begingroup\$ Or maybe a restriction that you can't play the same number more than 3 times in a row? \$\endgroup\$ – Embodiment of Ignorance Feb 6 '19 at 19:38
  • \$\begingroup\$ @EmbodimentofIgnorance I'm definitely going to implement your idea about an odd number, I think I might just change it to 99. However banning playing the same number all of the time wouldn't make a difference to too many bots just, in this example ,playing 50 and 49. \$\endgroup\$ – Arkine Feb 7 '19 at 19:05

Check List for Duplicates

Given a non-empty list of integers, return a truthy value if all entries are unique, and a falsey value of there are duplicate entries (or vice versa).


[1,2,3] -> false
[1,1,3] -> true
[1] -> false
[1,3,1,5] -> true

META: I couldn't find this as a challenge, but I cannot believe we didn't allready have this. Let me know if you can find anything related.

| |
  • \$\begingroup\$ Related \$\endgroup\$ – Mr. Xcoder Dec 31 '18 at 11:07
  • \$\begingroup\$ I expect this to be one byte in Jelly. \$\endgroup\$ – Adám Dec 31 '18 at 11:08
  • \$\begingroup\$ @Adám It's 2 bytes long, actually. \$\endgroup\$ – Mr. Xcoder Dec 31 '18 at 11:08
  • 1
    \$\begingroup\$ Hm, no Iit is so trivial, that everybody assumed it already exists… We have lots of related (and more interesting) challenges. \$\endgroup\$ – Adám Dec 31 '18 at 11:10
  • \$\begingroup\$ Can the input contain 0s or negative integers? Can we take input as an array/list of strings? Should the 2 outputs be consistent? \$\endgroup\$ – Shaggy Dec 31 '18 at 14:44
  • 1
    \$\begingroup\$ Possible duplicate \$\endgroup\$ – Shaggy Dec 31 '18 at 19:52
  • \$\begingroup\$ (Both my Japt solution and my second JS solution there would work for this, without any modifications) \$\endgroup\$ – Shaggy Dec 31 '18 at 20:53
  • \$\begingroup\$ let x=|v| v.iter().unique().count()>0 even short in Rust! but i would kind of like to see if one of the esolangs could get it down to 1 byte, though. would be fun. \$\endgroup\$ – don bright Jan 31 '19 at 2:56

Super Permutations

Find the super permutation for a set of size n. A super permutation of a set is one string that contains all permutations of that set. Here is a helpful video by Matt Parker


For a set of size 2 all the permutations are AB, BA but the super permutation is ABA because it contains the string AB and BA.
For a set of 3 all permutations are ABC,ACB,BAC,BCA,CBA,CAB and the super permutation is ABCABACBA.


Given a certain size n (n>=1) find a super permutation of that set. To do this you have to use a pattern explained in the video.


An integer greater than 0. This can be a function input superperm(n) or be taken from user input.


super permutation of that sized set. This can either be printed out or the return value of a function

Sample Inputs

all of these are the shortest for that length but this is not a requirement.

    1: A
    2: ABA
| |
  • 2
    \$\begingroup\$ Are you sure you don't want the shortest length to be the requirement? As you stated yourself, just concatenating all permutations is trivial, but if this is a [codegolf] challenge, everyone will use that trivial approach to save (loads of) bytes. I know a few programming language which could get all permutations and join them in 2 bytes.. Finding the shortest permutation would prove more difficult however, and seems like a more interesting challenge tbh. \$\endgroup\$ – Kevin Cruijssen Jan 30 '19 at 7:42
  • \$\begingroup\$ @KevinCruijssen the problem with the shortest permutation is that it's not known about 7 or 8. There is a pattern that gives one of the shortest solutions so maybe you should be required to follow that. \$\endgroup\$ – Jackson Jan 30 '19 at 23:53
  • \$\begingroup\$ This feels very dupey to me but I can't come up with the right search term(s) at the moment to find a possible target. I also agree with @KevinCruijssen on the scoring - some combination of byte count and length of output for a specific n would work better. \$\endgroup\$ – Shaggy Feb 1 '19 at 1:25
  • \$\begingroup\$ I don't know of a duplicate from before this sandbox answer was posted, but there is now a superpermutation challenge on main that uses a different scoring mechanism to encourage shorter superpermutations \$\endgroup\$ – trichoplax Feb 8 '19 at 20:53

Recently i made a post, but jumped the gun a little... I posted it before getting feedback and ended up getting it put on hold for being too arbitrary, but I have finally come here to get it properly fixed. Also I just got my Meta User fixed, so now I can post here!

Link to original post

Link to chat where all of this is being discussed

Basically I want to make the challenge where you create a quine that when given an input of 0 it outputs itself, and if given some other number it outputs a different quine. For example, abc outputting abc if given 0, abc outputting gef if given 1, abc outputting qwerty when given 255 etc... The scoring will be based on how little bytes can be used and how many extra different quines that it can output.

The problem comes with defining what defines different quine and how to balance the scoring so that coders will be encouraged to write short code, but still try to create different quines that aren't just altered copies of the original or each other

Examples of what not to do

abc      //original
abcd     //output
aabc     //output
aaabc    //output

stuff like this wouldn't be allowed, I just don't know how to turn that into a rule that can't be abused.

What I want examples

abc      //original
gefh     //output
uiop     //output
kerdp    //output

Basically all of the output quines are different from each other, nor are they similar

And of course no examining source code.

| |
  • \$\begingroup\$ I would say output a quine without using the same characters from the previous quine but there is already a challenge like that \$\endgroup\$ – Luis felipe De jesus Munoz Feb 6 '19 at 20:13
  • \$\begingroup\$ @LuisfelipeDejesusMunoz Yes, that would work, but I want to see if there is another way to do this without branching away from the original challenge \$\endgroup\$ – KrystosTheOverlord Feb 6 '19 at 20:21
  • 1
    \$\begingroup\$ Perhaps you can go back to the polyglot specs, and say that the outputted quines all have to be in different languages? \$\endgroup\$ – Jo King Feb 7 '19 at 13:10
  • \$\begingroup\$ @JoKing That might just work, if I do that I'll have to change the scoring system so that it doesn't push too hard on golfing, but hard enough that people are encouraged to make small programs, and also to try and make it output as many quines as possible. \$\endgroup\$ – KrystosTheOverlord Feb 7 '19 at 14:04

Break Hello World (Cops)/Fix Hello World (Robbers)


Your job is to write a broken hello world program. What do I mean by that? Well, you write a valid hello world program, and make changes to it.

Your probably thinking "easy peasy", right? Well, there's one other condition: it must be hard to fix.

Anyways, for the actual rules. First you write a valid hello world program. That means:

  • The characters sent to stdout form the string "Hello World!" exactly. Then the program halts gracefully (if given enough time and resources).
  • Nothing is read from stdin or sent to stderr.
  • No interacting with the operating system (i.e. no modifying files, randomness (unless it is pseudorandom and the seed is the same each run), internet, other commands, etc...)
  • No using built-in or imported hashes or cryptographic primitives. If the program implements cryptographic primitives, that's fine though.
  • Should work no matter how or on what platform it is run, assuming default options. The language it is written in should be reasonably cross platform and not cost money as well.

Now, make any changes you want to it. However, your score will be based on the edit distance between the valid and broken program (the lesser the better). The exact scoring will be described below.

The broken program can be any string you like (so calling it a "program" is technically a misnomer). Your submission will consist of:

  • The broken program
  • The edit distance between the valid and broken program, or any greater distance. (The reason you might want a greater distance is if the exact distance would reveal too much information. However, your score will suffer, and the robbers will have more flexibility, so be careful exercising this option). This number will be called your "brokenness" number.
  • The language and language version of the valid program. This language should not be one written for this challenge.
  • The sequence of literals appearing in the valid program, in the order they appear. (This is to encourage cops to scramble the program structure, not just hard coded values.)
  • What the score will be if it is not cracked and after you reveal the solution.
  • The date and time at which the program will be safe (as described below). (This way your program will be safe as soon as this time is reached, even if you have not had an opportunity to reveal the solution yet.) You may edit this in immediately after posting the solution, if you prefer, so that you will now the submission time.

After that, the robbers will have 168 hours (one week) to crack your submission from the date posted. If your submission is not cracked by then, your entry is safe. However, you can not claim your score until after you reveal the solution. To do this, edit your answer to include the valid program and an explanation as to why it works (if it takes a while to run). Also include what edits where made (since calculating the edit distance can be hard) and the word "safe" in the title.

How can your program be cracked? A robber just needs to write a valid hello world program (not necessarily the same as you wrote) whose edit distance from your broken program is less than or equal to your submission's brokenness number. The only other stipulation is that it has the same language and language version. In particular, it is not required to use the same literals as your program (this is to discourage cops from making their submission harder to crack this way).

And now for score. If the length of the broken program is L, the brokeness number is b, and the number of characters that can be used in your programming language is k, your score is (k^b)*(L+b)!/(L!b!), which you are trying to minimize. If your wondering were the heck that formula came from, it is very roughly the number of strings whose edit distance from your broken program is less than or equal to your submission's brokenness number (the exact value is hard to compute) (NOTE TO SANDBOX READERS: If you know a more accurate metric that isn't too complicated, let me know.). The idea is that the smaller the search space the robbers have to search, the more impressive it is if it does not get cracked. Also, please post the score in scientific notation for easy comparison.

This is , so the submission which claims the lowest score wins!

Example Answer:

Python 2.7, score 7.5×10^53 (Safe)
Broken Program: salida "Hola Mundo!"
Brokenness Number: 18
Literals: "Hello World"
Safe Date: Feburary 12th, 3:42 PM UTC.

Valid program: print "Hello World!"
Edits: Make 7 replacements to get to saida "Holao dorld!". Make 4 deletions to get to saida "Hola do!". Make 4 insertions to get to salida "Hola Mundo!".
Explanation: Uses python's builtin print command to send `"Hello World!" to standard output.


Welp, the cops did it again. They broke some hello world programs. Its your job to fix them.

Your probably thinking "easy peasy, I'll just rewrite it from scratch", right? Well, there's one other condition: you have a limited number of edits.

Anyways, for the actual rules. Pick a submission from the cop's thread that has not already been cracked, and is not safe. A submission is safe if it is over 168 hours (one week) old. The submission will have a broken hello world program, a brokenness number, and a programming language and language version, as well as some other useful information (including what literals in the cop's valid hello world program). Your submission must contain a valid hello world program in that language and language version whose edit distance to the broken program is less than or equal to the brokenness number. See the cop thread for what constitutes a valid hello world program. Also note that you are not required to use the same literals the cop used. They are only meant to give you a hint.

Your robber submission should consist of:

  • A link to the cop entry you are trying to break.
  • Your valid hello world program.
  • An explanation as to why it works (if it takes a while to run).
  • The edits you made to create the program (since calculating edit distance can be hard).

and then place a comment in the cops submission with a link to your submission. You get a point for each submission cracked. Note that only the first robber to crack a given cop submission gets a point. If you post a submission cracking a cop's submission, but it turns out another robber posted one before you, edit your submission to say that it is non-competing (or you can delete it if you want to). It is also non-competing if you crack a submission that is already safe.

This is , so whichever robber gets the most points wins!

| |
  • 2
    \$\begingroup\$ I don't think the requirement for solutions to include "The sequence of literals appearing in the valid program" is a great idea; in particular I suspect it would run into similar arguments over the definition of "literals" as we've previously had when challenges tried to regulate builtins, comments, strings, etc. Perhaps this won't end up that way, but I don't think it's worth the risk. \$\endgroup\$ – Kamil Drakari Feb 12 '19 at 15:19
  • 3
    \$\begingroup\$ I basically understand what you were trying to do with the scoring formula, but I don't think using "number of characters that can be used in your programming language" is a good idea. For one thing, I'm pretty sure there are at least some languages where all unicode could validly appear somewhere in the source code. I think a formula that only uses b and L would be better. Since L is calculated in bytes, I think the most neutral change would be to just replace k with 256. \$\endgroup\$ – Kamil Drakari Feb 12 '19 at 15:27
  • 1
    \$\begingroup\$ I also think it would be a good idea to put "also known as 'Levenshtein Distance'" next to your "edit distance" link, or even just use the term Levenshtein Distance instead. It's not a huge deal, but Levenshtein Distance seems to be the more common term in existing challenges (though "Levenshtein edit distance" seems to be a compromise with some precedent). \$\endgroup\$ – Kamil Drakari Feb 12 '19 at 15:33
  • \$\begingroup\$ Your scoring system is weird and confusing. Why not have the cop score be the Levenshtein Distance and say the lowest scoring safe program wins? \$\endgroup\$ – Beefster Feb 13 '19 at 0:35
  • 1
    \$\begingroup\$ @KamilDrakari Well, regarding literals, I'm not sure of a good way to encourage cops to scramble the program structure other than this and a popularity contest. Without that restriction, the challenge basically becomes "for what input does this program make it to the "print 'Hello World'". Also, yes, I think I'll make L and b be specified in bytes and k=256. And I'll edit Levenshtein Distance into the question. \$\endgroup\$ – PyRulez Feb 13 '19 at 0:39
  • 1
    \$\begingroup\$ @Beefster Then they came make the program as long as they want. They could either have a small "changeable" section, and make the rest of the program either raise an error or print hello world based on some NP-complete problem, or have a massive hello world program with only four or five errors. \$\endgroup\$ – PyRulez Feb 13 '19 at 0:41

Is This Randomizer Seed Beatable?

Randomizers of Pokemon, Zelda, Metroid games (among other games) have gained a lot of popularity in the last few years within the speedrunning community. Basically these are programs that shuffle around items, Pokemon, and even cosmetic things in a ROM of the game. It gives speedrunners a new and exciting challenge for a game they have played perhaps hundreds of times since items affect progression and can lead them to play the game very differently.

Randomizers also have logic that prevents them from making unbeatable configurations. We'll be looking at a simple, but generalized, form of this logic in this challenge.

Challenge Explanation

You will be given a list of rules as input describing some game world and its item requirements and a list of item locations. Your task is to determine if the item locations represent a beatable seed within the rules.

World Rules

The rules are a list of required items for accessing a location. A required item may have an associated quantity. For example, a simplified sampling of Super Metroid:

[] => Morph
[Morph] => BlueBrinstarBottomMissiles
[Missiles, Morph] => Bombs
[HighJump] => BlueBrinstarETank
[Morph, Bombs] => CrateriaDescentETank
[Supers, HighJump, Morph, Bombs] => Kraid
[Kraid] => Varia
[Varia] => Speed
[Varia, Speed] => IceBeam
[Kraid, Phantoon, Draygon, Ridley, Morph, IceBeam, Charge, 3 Missiles, 3 Supers, 3 ETank, Varia, Gravity] => END

It's possible for a location to be reachable by different sets of requirements. Conceptually, this means that any one set of requirements. Here's an example from Zelda: Ocarina of Time (referencing some glitches):

[DekuTreeBeaten] => ForestExit
[Stick] => ForestExit
[Nut] => ForestExit
[KokiriSword, DekuShield] => ForestExit

Keep in mind that the right hand side of the rules list in my example is actually a location id, not an item id. The special location id END indicates the ability to beat the game with those items.

Item Locations

You will receive a mapping of location IDs and which item they contain. For example:

KokiriSwordChest: HeartPiece
MidoHouse1: Hookshot
MidoHouse2: 5Rupees
DampeDig: ForestTempleBossKey
DampeRace1: NayrusLove
DampeRace2: HeartPiece
GoldGauntletsChest: DoubleMagic

What does it mean to be beatable?

A player begins a game with no items. If it is possible for the player to, through the continued acquisition of available items, reach the END location, then the seed is beatable. It doesn't matter if all items are obtainable as long as the END location is reachable.

This maps to a variant of graph reachability problems which can be solved relatively easily with a breadth-first search. (Other approaches may work as well)

Simple example (beatable)

World Rules:

[] => SwordChest
[] => ShieldChest
[Sword, Shield] => FireballScroll
[Fireball] => IceBeamScroll
[Fireball, Sword] => LightningScroll
[Fireball, IceBeam, Lightning] => END

Item Locations:

SwordChest: Fireball
ShieldChest: Sword
FireballScroll: Shield
IceBeamScroll: Lightning
LightningScroll: IceBeam

This seed is beatable with this item order: Fireball, Sword, Lightning, IceBeam. It's impossible to get the Shield because it's locked behind the FireballScroll which requires the Shield. But that doesn't matter because the END only requires the three elemental spells.

Simple example (unbeatable)

World Rules:

[] => SwordChest
[] => ShieldChest
[Sword, Shield] => FireballScroll
[Fireball, Shield] => IceBeamScroll
[Fireball, Sword] => LightningScroll
[Fireball, IceBeam, Lightning] => END

Item Locations:

SwordChest: Fireball
ShieldChest: Shield
FireballScroll: Sword
IceBeamScroll: Lightning
LightningScroll: IceBeam

This seed is unbeatable because Lightning is required, but is locked behind the Ice Beam Scroll, which requires the sword, which in turn is locked behind the Fireball Scroll, which itself requires the sword to access.

More test cases

More test cases can be found here.

Other Notes and Rules

  • You can accept the world rules and the item locations in any convenient format or representation, given these restrictions:
    • When multiples of one item are in a requirements list, you can represent it by repeating that item multiple times or by having a quantity and item id.
    • Both item and location ids must be taken in as alphanumeric strings. (i.e. no converting it to numbers or other more convenient values before passing it into your program/function)
    • The sentinel value for the "beating the game" location id must be END, all caps, three letters.
  • Item and location ids are case sensitive and must match exactly between the two inputs to be considered the same item or location
  • Each location can be reached only once, even if it is reachable from multiple sets of requirements
  • You may assume that every location id on the locations list appears at least once on the rules list and that there is at least one END in the rules list
  • You may assume that each location id on the locations list appears exactly once and contains exactly one item.
  • There is no concept of one-way doors that block off access to previously accessible locations. The requirements list is unordered.
  • Location ids and item ids are separate and distinct. For instance, Morph as a location is different from Morph as an item.
  • Output a truthy value for a beatable seed and a falsy value for an unbeatable seed.

Happy golfing!

Sandbox: there's a lot here. Any suggestions for explaining things better? Should I add more test cases?

| |
  • \$\begingroup\$ You might be interested in Rado, a language that's attempting to quickly(ish) solve this problem more generally. I'm not related to the project in any way, I just think it's interesting. \$\endgroup\$ – Spitemaster Feb 13 '19 at 21:40

MisterGeeky's query-to-list challenges:

It is up to you whether you interpret these challenges as following a pattern.

Challenge 1:- Given an array of random numbers and a target number, sample pairs in the array whose sum is closest to the target.

Minimize the error function. To explain this challenge, I need elucidate on the random list.

L = [8.76, 7.89, 6.98, 9.99]

That's just a handmade random list. Yours can be auto-generated of any length.

Say target = 42.

Find a tuple made from cartesian LxL whose sum of elements is closest to target.

These are obviously not the best words to pose the challenge with, they will be refined. How close is this to golf?

Challenge 1.5:- Extend the above problem with all known operations, and even increase the number of numbers that can be taken at a time to reach the target.

op = ['*', '**', '^', '/', '+', '-']

Assume usual meaning for each, ** is sometimes for exponentiation but you can use it for tetration, similar to knuth's up arrow notation. '^' is either XOR or exponentiation. You have the liberty to choose operators. I meant operators known to you in general. Just normal arithmetic should even do.

op = ['+', '-', '*', '/']

I also allow any binary function that doesn't trivially output the target value.

Challenge 2:- Find list of Adjacent Elements to a given element or element position in any 4-dimensional matrix. (ie, m rows* n columns * p sheets * 4th dim whatever)

Even I'm not sure how this is golf. But I typically like to think there's only one approach that's the correct answer. Feel free to argue with me on that :D The idea is that this knowledge gives you a starting point to find n-neighbours of a cell location.

So, you typically have 8 directions of search (4 pure and 4 combined). You start with listing the immediate neighbours

Challenge 2.5:- Find specified number of adjacent elements of a point in n-space. You are free to either sample at random, use rank of the point or use minimum euclidean distances.

Here, you find n-neighbors of a given item. Points for creativity.

Challenge 3:- build a simple recommender, takes a query and outputs a list (recommender as a suggestions lister is not easily defineable)

Challenge 3.5:- improve recommendation efficiency (too advanced for golf)

Third challenge is anything that combines knowledge from first and second challenge.


The above are to be refined as golfing challenges, shortest code is the best code.

Please comment your thoughts below. Thanks.

| |
  • 1
    \$\begingroup\$ all known operations, adjacent, recommender, efficiency? I'm missing some definitions here. \$\endgroup\$ – Adám Feb 25 '19 at 8:08
  • \$\begingroup\$ Hi, and thanks for using the sandbox! While this seems pretty clearly to be a work in progress, I don't think there is particularly much for readers to comment on at the moment. You might consider expanding the first idea into a more complete challenge first so you can receive more useful feedback. From the way the first challenge is worded, I think you may have some trouble with ensuring the error is sufficiently minimised if golf is the goal. \$\endgroup\$ – FryAmTheEggman Feb 25 '19 at 20:54
  • \$\begingroup\$ @FryAmTheEggman Yes, I aso think there are more eleqouent ways to pose the problem. I'm actually not sure what golf is. Is it heuristic shorthand? I'm slowly completing the challenge definitions. My aim is to also make them feel good to read, not just sound jibberish one can't relate with. So, your inputs would be most useful. \$\endgroup\$ – MisterGeeky Feb 26 '19 at 9:39
  • \$\begingroup\$ @Adám Um, I'll remember to do that, but I meant english words. Operation is assumed as binary input function yielding one result value. Adjacent is the direct nearest neighbours, left and right elements incase of a 1D list or array. There will be 8 adjacent elements for an element is a matrix and 26 adjacent elements for an element in a datacube. A recommender is a function that you assume can give you a list of suggestions based on an input-query or item selection. Efficiency is same as the time to get solution. I'll be more than happy to clarify further doubts. \$\endgroup\$ – MisterGeeky Feb 26 '19 at 9:50
  • 1
    \$\begingroup\$ I think I see what you mean by the first challenge now. Sorry about my language, I mean "golf" in the sense that the ultimate goal is code golf, that is, writing as short a program as possible. The first challenge appears fine in this regard now, but 1.5 will suffer from this the way you have it worded now. Since each competitor will want to minimise their code, they will implement as few operators as possible. You should certainly specify precisely which operators need to be supported. \$\endgroup\$ – FryAmTheEggman Feb 26 '19 at 15:31
  • \$\begingroup\$ @FryAmTheEggman I am yet to generalize to the maximum extent possible. Writing the question seems so much harder than actually answering it. Um, in 1.5, I mean to say replace the summation of tuples with any other operation to get near to target. I'd have liked to added more challenges along the lines of, you can sample more than two elements to get output, you can reuse but according to some limitation et cetera. These are not simple to pose, especially when this 1d/2d concept is supposed to analogize a higher dimensional thing. \$\endgroup\$ – MisterGeeky Feb 27 '19 at 15:56

Reducing switches in a binary matrix

A row's switch count is the amount of times the array switches from 1 -> 0 or 0 -> 1 when reading the array sequentially. As a Python function this looks like:

def row_switch_count(row):
    switch_total = 0

    last_r = row[0]

    for rr in row[1:]:
        if last_r != rr:
            switch_total += 1

        last_r = rr

    return switch_total

A matrix's switch count is the maximum switch count of all it's rows:

def mat_switch_count(bin_mat):
    max_switch = 0

    for row in bin_mat:
        count = row_switch_count(row)

        if max_switch < count:
            max_switch = count

    return max_switch

Write a function to reduce a matrix's switch count for each row to be less than a desired toggle count by permuting the elements in the nth column. You should permute as few columns as possible.

Permissible permutations

The only permutation allowed is moving the column. You can move a column's index, but you cannot mutate the column itself. For example, you cannot change a column [1, 0, 0] -> [0, 0, 1]. However, you can move a column within a matrix:

([1, 0, 0], ->  ([0, 0, 1],
 [0, 0, 0])      [0, 0, 0])


A binary array with rows > 1 and cols > 5. The sum of all rows in any given column less than 1.

A desired_toggle_count >= rows.


Note the solutions are not unique and not all solutions need to be provided. However, there is guaranteed to be a solution, since the trivial solution where you sort all the columns, is valid.














Sandbox comments

I think this question might have too many requirements to be interesting? Brevity is the soul of wit and this question is not very brief.

| |
  • \$\begingroup\$ 1. I think the definitions are not standard enough to assume in the first paragraph, and the task would be much more readable if the definitions came before the task specification. 2. NumPy is rather cryptic: it's optimised for speed rather than legibility (especially to non-Python programmers), so it's not very effective as a communication format. 3. The output section should be about formatting, not processing. 4. What happened to "n-dimensional" from the first line? \$\endgroup\$ – Peter Taylor Feb 28 '19 at 9:14
  • \$\begingroup\$ 5. I've clearly not understood the definition of toggle count, because I think ([1,0,1,0,0,0,1], [0,0,0,1,1,1,0]) from the second example has a toggle count of at least six. 6. Since each column has zero or one 1s, the Hamming distance constraint can be given without mentioning Hamming distance: the permitted operations are permuting the elements in the \$n\$th column, and you should permute as few columns as possible. \$\endgroup\$ – Peter Taylor Feb 28 '19 at 9:18
  • \$\begingroup\$ @PeterTaylor thank you for your feedback. I tried to address all of your suggestions. Please let me know if I can improve this puzzle further! \$\endgroup\$ – Seanny123 Feb 28 '19 at 16:09
  • \$\begingroup\$ OK, I get it now. I'm still not convinced by the test cases: why isn't ([1,0,1,1,1,0,0], [0,0,0,0,0,1,1]) a strictly better solution for the first one? Also, it might be worth adding a guarantee that there will be a solution. \$\endgroup\$ – Peter Taylor Feb 28 '19 at 18:16
  • \$\begingroup\$ @PeterTaylor in your example, you've modified one of the columns, which isn't permitted. I've added example mutations. Sorry, I got confused, when you said "permutation". \$\endgroup\$ – Seanny123 Feb 28 '19 at 18:36
  • 2
    \$\begingroup\$ I feel like the python code at the beginning is not particularly illuminating. I think the rest of your description is adequate, and I think you risk hiding more important details like the moving as few columns as possible. Speaking of, it is probably a good idea to state the number of columns moved in each solution. In fact, it may be a better idea to simply make that the output, as it will make other answers easier to verify and it capture what seems to be important. \$\endgroup\$ – FryAmTheEggman Mar 1 '19 at 20:01

(bit)Wise Images

Given a truth table and two images, use the truth table as a bitwise operation to the two images.

For example with the truth table:

  1 0
1 0 0
0 1 0

(Note that the top is the first image and the left is the second)

and the two images (0, 2, 4) (a 1x1 image, with the numbers being RGB values) and (30, 20, 10):

You would apply the above truth table to the numbers 0 and 30, of which's binary representations are 00000 and 11110. Using the truth table as a bitwise operation would get us 00000, or in decimal form 0.

This means that the red value of the first pixel would be 0.

Continuing this with the other RGB values would get us 2 and 4 for green and blue respectively.

So the output for this would be a 1x1 image with the only pixel having an RGB value of 0, 2, 4.


You can use any default input or output method.

You can assume that the two input images are the same dimensions.

You can support any image format you want as long as the image format supports RGB values from #000000 (0, 0, 0) to #ffffff (255, 255, 255).

The truth table can be in any format you want

| |
  • 1
    \$\begingroup\$ Are the images guaranteed to be the same dimension? What image formats should be supported (or is it up to us?)? Are we generating a 3rd photo or overwriting the two existing ones (due to asymmetric truth tables, 1+2 can be different from 2+1)? \$\endgroup\$ – Veskah Mar 2 '19 at 4:27
  • \$\begingroup\$ I think you should more clearly specify your value ranges. One would assume, your image channels contain eight bits of entropy. \$\endgroup\$ – Jonathan Frech Mar 2 '19 at 4:30
  • \$\begingroup\$ @Veskah I think both format and overwriting are covered by default I/O. \$\endgroup\$ – Jonathan Frech Mar 2 '19 at 4:31
  • \$\begingroup\$ @JonathanFrech I'll yield format. And a second reread shows it as the inputs being Source image + Modifier image, whereas I thought it was "do this to both" at first \$\endgroup\$ – Veskah Mar 2 '19 at 4:40
  • \$\begingroup\$ @Veskah I am sorry, but I neither understand what you mean by "I'll yield format." nor "Modifier image". \$\endgroup\$ – Jonathan Frech Mar 2 '19 at 4:42
  • \$\begingroup\$ @JonathanFrech The former is "Yeah, fair enough on format, you are correct", the latter is "Image order matters due to the possibly asymmetric truth tables. So you can say the 1st image is the source and the 2nd image is the modifier which will result in the 3rd output image." \$\endgroup\$ – Veskah Mar 2 '19 at 4:50
  • \$\begingroup\$ @Veskah Edited. \$\endgroup\$ – MilkyWay90 Mar 2 '19 at 16:13
  • \$\begingroup\$ @JonathanFrech Sorry, but what do you mean by "image channels" \$\endgroup\$ – MilkyWay90 Mar 2 '19 at 16:15
  • \$\begingroup\$ @MilkyWay90 with the numbers being RGB values -- I mean the image's three color channels. In what value range do they live? \$\endgroup\$ – Jonathan Frech Mar 2 '19 at 22:43
  • \$\begingroup\$ @JonathanFrech From 0 (0x00) to 255 (0xff) \$\endgroup\$ – MilkyWay90 Mar 3 '19 at 2:32

Venn of \$n\$ number of sets

Given positive integer \$n\$, output \$n\$ 2D bool images with same width and height such that:

  1. each image should be 4-connected, i.e. for each two pixels that are true, you can start from one and go up, down, left and right for some times to the other pixel, only passing through true pixels.

  2. each image should have no hole, i.e. the component should be 4-connected

  3. If we choose itself, its component or neither for each image, their intersection should be non-empty and 4-connected

Examples (only a finite amount of solution shown, but there are infinitely many more)

Input: 1



Input: 1



Input: 2


..... .....
.***. ..**.
..... ..**.
..... .....

Input: 2


..... .....
.**.. ..**.
..**. ..**.
..... .....

Input: 3


..... ..... .....
.**.. ..**. .....
.**.. ..**. .***.
..... ..... .***.

Input: 4


...**.. .***... ....... .......
...**.. .***... ..***.. .......
...**.. .***... ..***.. ..****.
....... .***... ....... ..****.
....... ....... ....... ..****.
....... ....... ....... .......

Shortest code in each language win


| |
  • 1
    \$\begingroup\$ im a little slow... what would be an example of an non-valid output? \$\endgroup\$ – don bright Mar 23 '19 at 3:31
  • \$\begingroup\$ So each image represents one Venn circle? This is a cool challenge. I would (1) say explicitly that each image represents one Venn circle, to make the question easier to understand, and (2) use a different term than "4-connected", which already has a different mathematical meaning. \$\endgroup\$ – Lopsy Apr 2 '19 at 20:25
  • 1
    \$\begingroup\$ @Lopsy I mean the 4-c here \$\endgroup\$ – l4m2 Apr 4 '19 at 4:04

Perfectly stable code

You are a.... Let's say prepared, programmer. You are working on the code to end all code, and it must be perfectly stable. No crashes, memory corruptions, mispellings, or anything else must get in your way. Everything else was set, but to your horrer you discovered that you had not accounted for the possiblity that the sun could actually flip a bit in your code! Naturally, you must now account for this.

The objective: A hello world program that still works if a single char is changed.


  • Has this been asked?
  • What kinds of limits should I impose to make it possible? Allow 10% of chars to be safe, limit the charset to just ASCII, ect.
  • Is it possible?
| |
  • \$\begingroup\$ This challenge is similar. \$\endgroup\$ – Esolanging Fruit Mar 7 '19 at 6:15
  • \$\begingroup\$ Of course it's possible \$\endgroup\$ – ASCII-only Mar 7 '19 at 6:16
  • \$\begingroup\$ In fact, it's solvable rather trivially in certain languages. \$\endgroup\$ – Esolanging Fruit Mar 7 '19 at 6:18
  • \$\begingroup\$ Would it be sufficiently different if I didn't have the requirement that the modification is syntactically valid? \$\endgroup\$ – J Atkin Mar 7 '19 at 6:18
  • \$\begingroup\$ Of course. But that would probably heavily restrict the possible language set, as seen in the other linked challenge \$\endgroup\$ – ASCII-only Mar 7 '19 at 6:43
  • 3
    \$\begingroup\$ The tag you're looking for is radiation-hardened, though most challenges deal with deletion rather than modification. I would strongly recommend using bytes rather than characters. In fact, if you want to make it more interesting and closer to the original premise (as well as a little easier), how about using changing bits instead? You should also add a winning criteria (I assume code-golf) and specify the exact output of (Hello, World!) \$\endgroup\$ – Jo King Mar 7 '19 at 10:56

Centurion Counter

The drinking game Centurion is extremely simple - 1 shot of alcohol (usually beer or cider) once a minute for 100 minutes.

Whilst playing the other day a friend commented that we didn't need the tracking app, and that we could have just written the program ourselves. So now it is your turn.


Write a program that once every 60 seconds produces a beep or sound to alert players a minute has passed, and then add one to the counter of how many shots have been had.

The counter starts at 1 (the first shot) and then ends at 100 when the last counter is taken.

| |
  • 2
    \$\begingroup\$ What's the winning criterion here? code-golf? \$\endgroup\$ – Ven Mar 14 '19 at 15:37
  • 2
    \$\begingroup\$ Aside from choosing a winning criterion, I think you need to be more explicit about what counts as a sound, or on what hardware this should work on. However, this is extremely similar to this challenge as it is, so you might consider changing up what you want. \$\endgroup\$ – FryAmTheEggman Mar 14 '19 at 18:30

There doesn't seem to be a "l337 5P34K" challenge, or I have not yet found one. How about it? Simple string manipulation so it should fall under "C0D3 60LF", right? I.E, Leet speak encoder (challenge one), and leet speak decoder (challenge two).

| |
  • 3
    \$\begingroup\$ You'll need to define the question a lot better than this. i.e. What substitutions define leet speak? If the challenge winning criteria is shortest program size, than code-golf is correct. The string part would be probably be tagged substitution . The closest I could find was the code-challenge Leet to English \$\endgroup\$ – Jo King Mar 15 '19 at 10:50
  • \$\begingroup\$ As you've found a translator, I'll think about an encoder challenge. \$\endgroup\$ – Shaun Bebbers Mar 15 '19 at 14:04

Plot an NACA Airfoil

NACA airfoils are described using a series of digits that represent the miscellaneous properties of the airfoil profile.

The purpose of this challenge is to receive an airfoil number as input, and plot the profile of the airfoil.

Background information:

4-digit NACA airfoils are generally described by their string NACA ABCC, where A,B are single digit integers, and CC is a 2-digit integer.

  • A is the maximum camber as a percentage of the chord length. Eg. A=2 means that the camber is 2% of the chord length.
  • B is the location (divided by 10) of maximum camber as a percentage of the chord length. Eg. B=4 means that point of maximum camber is 40% down the length of the chord.
  • CC is the profile thickness as a percentage of the chord width. Eg. CC=12 means that the width of the airfoil is 12% of the maximum chord length.

Using the example given above, NACA2412, a suitable profile plot would look something like this: NACA 2412 and NACA 0012

Note that in the image above, the Red line is the camber line and the purple is representative of the symmetrical airfoil NACA 0012.

Any airfoils with a representative number of NACA 00XX are symmetrical in nature because they possess zero camber.

Possible scoring criteria are and

Any feedback is welcome. I also plan on having more challenges for the 5-digit and 6-digit profiles. Eventually, I will add equations to this post too.

Another way this challenge could be run would be to have the programmer return a series of points around the profile. This could be judged both for accuracy and quantity of points returned. If this approach is used, this would probably be a challenge.

| |
  • 2
    \$\begingroup\$ What are you trying to achieve with popularity-contest? I highly recommend against using it unless you really know what you're doing, most of such challenges are closed as too broad (popularity-contest isn't a broadness waiver). On the other hand, code-golf is the most common winning criterion around here, so I highly recommend it. There are other issues, however, which make the challenge unclear. For example, what constitutes a valid plot image (including how axes, lines, areas and points can be represented)? How would the answer be judged on its accuracy? If the winning... \$\endgroup\$ – Erik the Outgolfer Mar 17 '19 at 22:31
  • \$\begingroup\$ ... criterion isn't just code golf, then I recommend using the code-challenge tag, since code-golf implies a pure golfing competition. \$\endgroup\$ – Erik the Outgolfer Mar 17 '19 at 22:32
  • \$\begingroup\$ There are well-defined equations relating the x and y coordinates, so perhaps submissions could return a set of (x,y) points, and they could be judged by how closely the entire set of points follows the profile lines? \$\endgroup\$ – JPeroutek Mar 17 '19 at 22:33
  • 3
    \$\begingroup\$ The spec is completely opaque to me. It should be written without assuming any aerofoil-specific knowledge, not as a refresher for someone who already knew it but may have forgotten. \$\endgroup\$ – Peter Taylor Mar 19 '19 at 8:52
  • \$\begingroup\$ I think your idea is good, but the details are pretty vague. \$\endgroup\$ – dfeuer Mar 19 '19 at 22:23

Optimize the JSON (WIP)

Consider function f which takes two objects data and default, and merge anything from default into data if data contains no such element. Take the two objects(if the one in your language can handle the required elements) or JSON as input, output a shortest JSON that, when given as data, output the same object as the original data do, as long as default doesn't change.

| |
  • 1
    \$\begingroup\$ If posted as it is now, I would flag it: closed as unclear what you're asking \$\endgroup\$ – Beefster Mar 19 '19 at 17:15
  • \$\begingroup\$ @Beefster That's what WIP means \$\endgroup\$ – l4m2 Mar 20 '19 at 9:34
  • 1
    \$\begingroup\$ I really have no idea what this challenge is. The title suggests making a representation smaller while the text seems to indicate some sort of merging process that really needs to be fleshed out. \$\endgroup\$ – Beefster Mar 20 '19 at 16:23
  • 2
    \$\begingroup\$ add some examples! \$\endgroup\$ – vityavv Mar 20 '19 at 16:53
  • \$\begingroup\$ @zevee Actually I don't know what I want on some situations, so this will be here for long time \$\endgroup\$ – l4m2 Mar 20 '19 at 22:17

Draw these shapes

Given: a width, a height, and a set of sets of points. Output: An image where each set of points is connected and colored in (like a shape). Each shape must be a different color from all of the other shapes, but the difference doesn't matter. The shapes must be in order; whether you start at the end or the beginning of the set doesn't matter, though.


//the code here has nothing to do with the actual challenge and just shows examples

document.getElementById("one").getContext("2d").fillRect(0, 0, 300, 300)
const ctx = document.getElementById("two").getContext("2d")
ctx.fillStyle = "black"
ctx.fillStyle = "lime"
canvas {border: 1px dotted black}
<pre>Width: 500, Height: 500, Set: [[[0, 0], [0, 300], [300, 300], [300, 0]]]</pre>
<canvas id="one" width="500" height="500"></canvas>

<pre>Width: 600, Height: 300, Set:
  [[0,0], [0,300], [300,0]],
  [[200,0], [600,0], [300,300]]
<canvas id="two" width="600" height="300"></canvas>

Scoring is .

| |
  • \$\begingroup\$ is there any rules about how long I have to wait before posting to the main site? \$\endgroup\$ – vityavv Mar 20 '19 at 23:52
  • \$\begingroup\$ It's usually best to wait at least 72 hours before going from the Sandbox to main. As for the actual challenge: do the colors need to be visually difference, or is changing a color from #FFFFFF to #FFFFFE enough difference (I assume the second, but if not, please explain how much different the colors have to be)? Also, is the input order of the points for the shapes important, where the last is always in front of the first? Or are we also allowed to have the green triangle behind the black one in your second example? \$\endgroup\$ – Kevin Cruijssen Mar 21 '19 at 12:01
  • 2
    \$\begingroup\$ @KevinCruijssen any difference is enough. Order can be either descending or ascending, but must go sequentially. I'll add those to the question \$\endgroup\$ – vityavv Mar 21 '19 at 15:12
  • \$\begingroup\$ You may want to add something about jpegs and other lossy image formats, and whether they are allowed. Also I think you should explain "in order" a bit more: do you mean later shapes will be drawn over earlier shapes (or vice versa)? \$\endgroup\$ – FryAmTheEggman Mar 22 '19 at 17:25
  • \$\begingroup\$ @FryAmTheEggman. In order means later shapes will be drawn over earlier shapes or vice versa, that's why I said "whether you start at the beginning or the end of the set doesn't matter though." Also, codegolf.meta.stackexchange.com/questions/9093/… says stuff about lossy formats (Programs may output via a common raster graphics image format) \$\endgroup\$ – vityavv Mar 23 '19 at 21:53
  • \$\begingroup\$ What are the width and height? \$\endgroup\$ – Artemis still doesn't trust SE Mar 26 '19 at 23:18
  • \$\begingroup\$ the width and height of the outputted image. BTW, I've posted this: codegolf.stackexchange.com/questions/182104/draw-these-shapes (only need one more re-open vote) \$\endgroup\$ – vityavv Mar 26 '19 at 23:34

Patch one line

First question I've written, feedback is highly appreciated. If you can think of a clever title, I'll take that too.


In an effort to prove to your employer that Git commit count is a worthless metric, you've decided to break up all your changes from now on line by line.

Golf a program which can edit a patch file to remove all changed lines except for one.

Patch file format

The patch file will be given by Git in the unified diff format, although git will append multiple file changes together:

diff --git a/afile b/afile
index bf70e9e..d2df230 100644
--- a/afile
+++ b/afile
@@ -1,8 +1,9 @@
-Lorem ipsum dolor sit amet,
+Lorem IPSUM dolor sit amet,
+++ (good luck parsing this line)
 consectetur adipiscing elit.
    Duis est elit, imperdiet ac dolor quis,
    volutpat commodo nunc.
diff --git a/bfile b/bfile
index c484b2b..db4afe5 100644
--- a/bfile
+++ b/bfile
@@ -1,11 +1,7 @@
-# /etc/bash.bashrc
 # If not running interactively, don't do anything
 [[ $- != *i* ]] && return
 [[ $DISPLAY ]] && shopt -s checkwinsize

Here are two accepted outputs for the above patch file:

diff --git a/afile b/afile
index bf70e9e..d2df230 100644
--- a/afile
+++ b/afile
@@ -1,8 +1,9 @@
 Lorem ipsum dolor sit amet,
+++ (good luck parsing this line)
 consectetur adipiscing elit.
    Duis est elit, imperdiet ac dolor quis,
    volutpat commodo nunc.
diff --git a/afile b/afile
index bf70e9e..d2df230 100644
--- a/afile
+++ b/afile
@@ -1,8 +1,9 @@
-Lorem ipsum dolor sit amet,
 consectetur adipiscing elit.
    Duis est elit, imperdiet ac dolor quis,
    volutpat commodo nunc.
diff --git a/bfile b/bfile
index c484b2b..db4afe5 100644
--- a/bfile
+++ b/bfile
@@ -1,11 +1,7 @@
 # /etc/bash.bashrc
 # If not running interactively, don't do anything
 [[ $- != *i* ]] && return
 [[ $DISPLAY ]] && shopt -s checkwinsize


Any other corner cases I'm missing?

You do not need to handle the following cases:

  • A file is deleted, renamed, or added
  • A file has changed its mode

You do need to handle the following cases:

  • An added line starts with ++
  • A removed line starts with --
  • There are changes in multiple files (although you can remove one of the diffs and git will still patch okay)


Is this much explanation necessary?

I added the stdin/stdout method since I imagine it's more conducive to golfing in some langs... Should I do any kind of bonus/penalty?

Your program may either take the name of the patch file as its first parameter and do an in-place edit (this will let GIT_EDITOR=/path/to/your/program git add -e apply the patch), or read from stdin and write to stdout such that the following will correctly apply the patch:

$ cat > oneline.sh << EOF
mv "$1" "$1.old"
/path/to/your/program < "$1.old" > "$1"
$ chmod +x oneline.sh; GIT_EDITOR=./oneline.sh git add -e

Refer to the EDITING PATCHES section of man git-add for some helpful info on editing the patch file.

| |

A Gödel numbering


In order to solve this challenge, you need to enumerate all possible programs in a turing-complete language given by you.


  • Either, you need to provide a function from a string-like type into a big-nat-like type, or you need to provide a program reading the program from STDIN and printing its Gödel number into STDOUT.

  • Your function needs to be bijective, such that every different (as given by its behaviour) function gets mapped to a different natural number.

    • Example: If your turing-complete language is Brainfuck where I/O is the tape before/after the program ran, +- and ++-- may be mapped to the same number, since they both are no-ops.
  • Your program must terminate for every possible input.
  • Give a specification of your used language in the post or link it.
  • This is a code golf (measuring in bytes).
| |
  • \$\begingroup\$ Our I/O rules are usually a bit more relaxed (e.g. you can print from a function to STDOUT), there's no need to restrict them as that's not the core of the challenge. \$\endgroup\$ – Erik the Outgolfer Mar 25 '19 at 18:28
  • \$\begingroup\$ @EriktheOutgolfer Well, that would actually be allowed, I'll still remove that rule \$\endgroup\$ – Mega Man Mar 25 '19 at 18:32
  • \$\begingroup\$ Yes, because "program" means "program or function", however that might not be the impression you'll give to everyone. \$\endgroup\$ – Erik the Outgolfer Mar 25 '19 at 18:33
  • \$\begingroup\$ I think the word you are seeking is injective (modulo effect) rather than bijective. \$\endgroup\$ – Jonathan Frech Mar 25 '19 at 20:33
  • \$\begingroup\$ If you allow for arbitrary languages, I can choose the language defined on \$\mathbb{N}\$ which executes the corresponding Turing machine using some Gödel numbering and submit the identity function as an answer to this challenge. \$\endgroup\$ – Jonathan Frech Mar 25 '19 at 20:36
  • \$\begingroup\$ @JonathanFrech Slightly less arbitrary: esolangs.org/wiki/Jot \$\endgroup\$ – Ørjan Johansen Mar 26 '19 at 2:01
  • \$\begingroup\$ @JonathanFrech Injective with restrictions, yes. About the arbitrary language thing: I think this challenge is more about finding the right language, but I don't know how to imclude that in the score \$\endgroup\$ – Mega Man Mar 26 '19 at 14:46
  • \$\begingroup\$ @ØrjanJohansen This was actually in my mind when creating this cg \$\endgroup\$ – Mega Man Mar 26 '19 at 14:46

Mutual quine without sharing characters

Write a chain of at least 2 programs in different languages, that each program except the last one outputs the next, and the last program outputs the first. You may not reuse a character used in one program in any other programs.

Each language you use must have an entry in Fewest (distinct) characters for Turing Completeness.

Your score is the sum of the square of the best score in that challenge for each language you use. Highest score wins. Other users could challenge your score by posting better answers in that challenge.


  • Bytes / characters.
  • How to define a proper quine for mutual quines? Without the restrictions specific to this challenge, someone will probably just print a string in most of the languages, and do all the encoding job in one most powerful language. But it might be not that relevant in this case, as that would most likely result in reusing characters.
  • Scoring: sum(ank - c), currently k=2 and c=0.
  • Is this cops-and-robbers?
| |
  • \$\begingroup\$ Ah oops, I actually did see that >.<. In that case Mutually Exclusive Quines in only one language \$\endgroup\$ – Jo King Mar 28 '19 at 0:41
  • \$\begingroup\$ @JoKing In addition to scoring, it also requires different languages. \$\endgroup\$ – jimmy23013 Mar 28 '19 at 0:51

Is the Art Gallery Fully Guarded? (WIP)

The Art Gallery Problem is a well-studied visibility problem concerning the minimum number of guards that must be placed within a polygon. This challenge will explore a simplified grid-based decision-problem variant to make input and visibility checking simpler.

You will receive a grid of walls and floors as input, representing the layout of the art gallery, and a number of guards (either as a list of locations or another value in the grid input.) You must determine whether all floor tiles are visible by at least one guard and return a truthy value if so and a falsy value otherwise.


A floor tile is considered visible to a guard if the line connecting the center of the floor tile to the center of the tile containing the guard does not pass through any wall tiles. If this line passes through the corner of a wall tile, visibility is not obstructed. (Sandbox: this can be an issue for floating point precision. Maybe a more discrete method should be used? Perhaps Bresenham's line algorithm?) The tile a guard occupies is also visible to that guard.


Key: . Floor, # Wall, G Guard

# . # G . .
. . # . . #
. . # # . .
# G . . . #
# # # . . #
. . . G # #

==> YES

. # . # # . . .
. # . . . . . #
. . . . . G . .
. . . . . . . .
. # . . . . . #
. # . # # . . .

==> NO

More TBD after visibility is hammered down

Rules, Notes, Assumptions

  • Standard challenge rules, IO methods, and loopholes apply
  • Guards may be taken in either as a list of coordinates or embedded within the grid.
  • You may assume that guards will always be standing on a floor tile
  • You may assume that grids will always be perfect rectangles, not jagged arrays
  • You may assume that grids will never be larger than \$100 \times 100\$

Happy Golfing!

| |
  • \$\begingroup\$ About visibility, It's actually OK. Instead of using floating point, you use rational number. \$\endgroup\$ – Xwtek Apr 8 '19 at 6:07
  • \$\begingroup\$ And yes, I mean Bresenham's Algorithm. \$\endgroup\$ – Xwtek Apr 8 '19 at 6:13

Calculator using only addition

Your task is to create a program or function that emulates a four-function calculator, capable of performing addition, subtraction, multiplication, and integer division. However, the catch is that your code must not use any mathematical operations other than addition. In other words, you must use only addition to implement the three other basic arithmetic operations.


Your program should take two numbers and an operation as parameters. Input can come in any form, whether it's through function parameters, standard input, etc. The operation can be represented however you want. You could use +, -, *, ÷, or "add", "subtract", "multiply", "divide", or whatever else is convenient. For division, you can assume that there will be no division by 0, and that the numbers will evenly divide.


Your program should output one number to STDOUT, the result of the calculation.


As mentioned earlier, you may not use any mathematical operation in your code other than the addition operator.


  • No mathematical operators other than addition, as specified above.
  • Bitwise operations are not allowed, but logical and comparison operators are.
  • Data type conversion is allowed.
  • Negation using a built in is allowed (e.g. -x or negate(x) are both fine).
  • Standard loopholes are forbidden.
  • It's , so shortest answer in bytes wins!


  • Wouldn't surprise me if this is a duplicate, but I couldn't find it. If it is, just put a link to the original in the comments please.
  • The input section seems like it could use some work, but I don't know what to change about it.
  • Other than that, let me know if there's anything that could be improved.
| |
  • 1
    \$\begingroup\$ This would work far better if the only operation allowed was subtraction. Then it ultimately looks a lot like a one-instruction computer \$\endgroup\$ – Beefster Apr 5 '19 at 16:08
  • \$\begingroup\$ Related - this challenge was closed. Do X without Y challenges are generally not well-received on this site. \$\endgroup\$ – Beefster Apr 10 '19 at 17:10

Word Calculator

This special calculator uses words instead of numbers, with these rules:

  • Addition joins two or more strings together in the same order they were inputted.

Repeated letters (example: aa, bb, etc) in the output become a single letter. If there is more than one repetition, then this is performed only on the first such instance detected, when going in a left-to-right direction.

(eg: tt becomes t, tttt becomes tt, etc)

  • cat+dog+tiger = catdogtiger

  • dog+cat+tiger = dogcatiger

  • dog+cat+tiger+tuna = dogcatigertuna

  • dog+cat+ttiger+tuna = dogcattigertuna

  • dog+cat+tttiger+tuna = dogcattigertuna

    (last example was originally = dogcattttigertuna, tttt is present but only the first repetition is removed, leading to the answer as shown)

  • Subtraction follows the same rules as the addition, but with a twist. Addition proceeds as usual, but when a subtraction is encountered, this subtracts as many characters as that string from whatever the output would have been before the subtraction.

You will not be expected to handle negative values.

  • cat+dog-tiger = c

  • cat+tiger-dog = cati

  • cat+dog+ttiger-tuna = catdogt

  • cat+dog+tttiger-tuna = catdogtt

  • cat+dog+ttiger-tuna-salmon = c

  • cat-dog = 0

The shortest code in bytes that performs the above addition and subtraction functions as described, is the winner.

Standard loopholes are not allowed.

| |
  • 1
    \$\begingroup\$ Does the reduction of even letters happen when the operation that caused the repeating letters finishes or at the end of the expression? Otherwise, seems like a pretty interesting challenge \$\endgroup\$ – Embodiment of Ignorance Apr 1 '19 at 1:55
  • \$\begingroup\$ I can't make any sense of "Subtraction removes as many characters as the last string, to all strings combined except it, in the same order they were inputted." Reverse engineering from the examples, I think the definition is that subtraction removes a number of characters equal to the length of the subtrahend from the end of the minuend. An example showing the reduction of even repeats after subtraction would be nice: the current example actually shows reduction after addition before the subtraction is performed. The letter e might work for examples: bee ends in a double letter. \$\endgroup\$ – Peter Taylor Apr 1 '19 at 9:50
  • \$\begingroup\$ So non-positive results are literally "0", not the empty string or something? What happens if you try and add to that? (p.s you don't have to define every behaviour. you can just say "you won't get an input that causes this") \$\endgroup\$ – Jo King Apr 6 '19 at 0:15
  • \$\begingroup\$ @JoKing Fixed. I hope I've included enough examples to clarify what the intention is. I've attempted to cover some stranger cases too to ensure that it's clearer and that there is less ambiguity surrounding what to do when. I generally don't expect negative or otherwise weird values to be handled, and I've added that. \$\endgroup\$ – Flog Edoc Apr 6 '19 at 0:18
  • \$\begingroup\$ @EmbodimentofIgnorance Let me know if it's clearer now. \$\endgroup\$ – Flog Edoc Apr 6 '19 at 0:24
  • \$\begingroup\$ This is performed only on the first such instance detected. But on your example dog+cat+tttiger+tuna = dogcattigertuna, there was more than one reduction. Am I missing something? \$\endgroup\$ – Embodiment of Ignorance Apr 6 '19 at 0:27
  • \$\begingroup\$ dog+cat+tttiger+tuna would originally have been dogcattttigertuna, the repetitions are tttt, but only one is removed, leaving the other tt intact. \$\endgroup\$ – Flog Edoc Apr 6 '19 at 0:28
  • 1
    \$\begingroup\$ But it says they become a single letter \$\endgroup\$ – Embodiment of Ignorance Apr 6 '19 at 0:29
  • \$\begingroup\$ @EmbodimentofIgnorance Fixed now. Hope it's clearer. \$\endgroup\$ – Flog Edoc Apr 6 '19 at 0:37
  • \$\begingroup\$ So the amount of repeated letters is just original letters divided by two floored? \$\endgroup\$ – Embodiment of Ignorance Apr 6 '19 at 0:44
  • \$\begingroup\$ @EmbodimentofIgnorance Whether you'd be doing that is up to your solution eventually, maybe that isn't the optimal golf. \$\endgroup\$ – Flog Edoc Apr 6 '19 at 0:48

Compute the order of a Rubik's Cube cycle without trivially counting them

See: Compute the order of a Rubik's Cube cycle without trivially counting them

I asked this question here the other day and it was closed as being a duplicate of another question which I had already linked in the original question followed by an explanation of a constraint that made the my challenge different. A discussion ensued in the comment section debating what made my question a duplicate of the other, mostly revolving around whether this constraint was observable or not.

I understand that the challenge at face value is an example of Do X without Y but I think it's still a quality challenge because:

  1. The constraint does not simply exist to require people to come up with loopholes or clever workaround to preform avoid a particular commonly used feature of programming languages. It's not the same problem with an unrelated constraint to "make it interesting".

  2. There really is no ambiguity in terms of whether or not the constraint is being followed for a particular answer. "Without Y" is not hard to define regardless of the language being used.

  3. It changes entire approach needed for the algorithm itself, not just specifics of the implementation. The trivial solution to the question will automatically be preferred by golfers, so the answers of the "duplicate" were not very interesting to me because they mostly worked in the exact same way. By prohibiting this trivial approach, there is still a very wide range of different degrees of efficiency that are possible to achieve through different implementations, and some of these are likely better suited for some languages than others, so I feel the answers will actually show significant diversity in their implementations, which in my opinion is a hallmark of a high quality challenge.

I really think this constraint introduces a meaningfully different and interesting challenge when compared to the other question and I want to see the creative solutions that golfers will come up with to solve it. But as I originally wrote it, and even with the addition of edits I made to make it more clear, it was apparently not sufficient to reopen the question.

Can anyone think of a way to write this question or define the constraint in a way that would make it more clearly not a duplicate, or eliminate the problems brought up in the comments without restricting the implementation further?

Do you think I'm only facing this scrutiny because I'm a newer member who hasn't posted much? Would someone with more reputation that me be willing to post it on my behalf?

| |
  • 2
    \$\begingroup\$ There is no ambiguity, Isn't there though? How would you tell that this program is following the constraint without actually knowing Pyth? \$\endgroup\$ – Jo King Apr 10 '19 at 1:28
  • \$\begingroup\$ @JoKing that’s not ambiguity. For example if a challenge were to prohibit the use of the a built in to_lower() function (which I’ve seen before on challenges with plenty of answers and upvotes) how would you know if a given answer was obeying that rule without actually knowing what a call to that language’s to_lower() function looked like? You wouldn’t, but that answer would still break the rules. But it wouldn’t be “ambiguous” because there’s still a clear difference between using such a built in function and not using one. \$\endgroup\$ – Conor Henry Apr 10 '19 at 2:12
  • 1
    \$\begingroup\$ Banning built-ins is also an unobservable requirement, and is common in older questions. In general, the community is leaning towards avoiding banning built-ins. In general though, programs using built-ins are far far easier to distinguish than whether a program is using a specific algorithm. \$\endgroup\$ – Jo King Apr 10 '19 at 5:34
  • 1
    \$\begingroup\$ The point of what I'm saying is that a constraint being unobservable is entirely different from there being cases where it's ambiguous if it's being followed. Whether or not an algorithm is obeying my constraint I suppose could be difficult to know immediately for some answers, especially if you're unfamiliar with the language it's written in, but at the same time the constraint is still defined quite clearly. Nobody reasonable person could possibly write an answer and not be sure if it is following this rule or not. That's what I mean by there's no ambiguity. \$\endgroup\$ – Conor Henry Apr 10 '19 at 19:10
  • 2
    \$\begingroup\$ It is ambiguous if two people can have different opinions on whether it is following the constraint. For example, what is a simulated cube? Is it a literal Rubik's cube datatype like Cubically uses? Does a 5x5x5 sided cube still count as a Rubik's cube? Does a list of numbers count? Two vectors? Non-cube topologies? I'm sure some answerers will have different opinions to yours, and even if you define all the above cases, there's going to be infinitely more possibilities that skirt the line. \$\endgroup\$ – Jo King Apr 10 '19 at 22:00
  • \$\begingroup\$ @JoKing A simulated cube is any data structure(s) that represents the state of a 3x3x3 rubik's cube, and is manipulated to represent the changes caused by preforming valid turns. A simulated 5x5x5 Rubik's would be a simulated cube because you can turn a 5x5x5 into a 3x3x3 by just removing stickers (or in the case of a data structure, ignoring them). As for a list of numbers, or two vectors, etc, if the purpose is to of it is to represent the state of the cube, and it is manipulated to simulate preforming valid moves on it, it's a simulated cube. Do you still think this is ambiguous? \$\endgroup\$ – Conor Henry Apr 10 '19 at 22:06
  • \$\begingroup\$ @JoKing Can you think of an example of an algorithm where you feel there could be reasonable, legitimate debate, as to whether or not it counts as "Performing the turns repeatedly on a simulated cube and counting the repetitions that were needed to reach the original state"? \$\endgroup\$ – Conor Henry Apr 10 '19 at 22:11
  • \$\begingroup\$ Maybe the challenge could be for an NNN cube with N as an input? Then, some limit on complexity or run-time should be able to weed out programs that just iterate through the cycle. \$\endgroup\$ – xnor Apr 13 '19 at 3:58
  • \$\begingroup\$ In the context of this site, we generally use "observable" to mean observable without looking at the code. So even if there's a strong argument that a constraint could be determined unambiguously, it's still a quality of the code, rather than of the output. I'm not aware of an outright rule against this, but it is generally advised against because it leads to unexpected arguments once the answers start coming in. The exceptions that are more likely to be welcomed are the trivial constraints like "source code is a palindrome" or "does not contain the letter e" \$\endgroup\$ – trichoplax Apr 24 '19 at 22:34
  • \$\begingroup\$ Personally I'd lean away from even those as they tend to suit a smaller set of languages. So there isn't a rule preventing you placing constraints on the source code, but it makes it more likely your challenge will be closed as unclear, so it might be worth considering what alternatives might achieve your underlying aim without the risk of arguments over what counts. \$\endgroup\$ – trichoplax Apr 24 '19 at 22:37
  • \$\begingroup\$ For example, some challenges exclude the simplest brute force approaches by saying "must complete within 60 seconds for each of the test cases" (the time period being chosen to be very easily achievable for most approaches, so that it doesn't even matter what machine is used to measure the time taken). That's still not perfect but seems to have worked well on several past challenges. \$\endgroup\$ – trichoplax Apr 24 '19 at 22:39
  • 1
    \$\begingroup\$ I can't think of a similar way of achieving your stated constraint without explicitly including it in the spec, but I thought I'd mention this example in case it prompts someone to think of a similar approach that could work here. \$\endgroup\$ – trichoplax Apr 24 '19 at 22:42

Product and Sum free set

Given some non-negative integer \$n\$ find a sum- and product-free subset \$S \subset \mathbb N = \{1,2,3,\ldots \}\$ of size \$|S|=n\$

EDIT: with the least possible maximum \$\max_{s\in S} s\$.


  • A set \$S\$ is called sum-free if for all \$a,b\in S\$ their sum \$a+b \not \in S\$.
  • A set \$S\$ is called product-free if for all \$a,b\in S\$ their product \$a\cdot b \not \in S\$.



Note that the sets for each \$n\$ might not necessarily be unique.

  n  S
  1  {2}
  2  {2,3}
  3  {3,4,5}
  5  {4,5,6,7}

EDIT: Ok, no this doesn't work either.

| |
  • \$\begingroup\$ I'm a bit concerned that this would just be output the first n odd primes, but maybe non-golfing languages can do something more interesting than that. \$\endgroup\$ – Emigna Feb 26 '19 at 10:09
  • \$\begingroup\$ @Emigna Thanks for the feedback, you're right this is not something I considered. Maybe it helps if we allow any number of additions/multiplications? But in this case I think you could just use [k+1,k+2,k+3,...,n] for some large enough k (depending on n). Maybe I should add some condition that requires the numbers to be very small to make it more interesting. It definitely needs some more work. \$\endgroup\$ – flawr Feb 26 '19 at 10:42
  • \$\begingroup\$ You can make this work by having a secondary scoring algorithm. You could, for example, score the programs by {bytes}*{total score for n=1 to 100}, where the score for an input is the highest number in the output set. \$\endgroup\$ – Spitemaster Feb 27 '19 at 18:28
  • 2
    \$\begingroup\$ Also note that the set {1} is not product free - 1*1=1, which is in {1}. \$\endgroup\$ – Spitemaster Feb 27 '19 at 18:29

Use input letters to create as many words as possible

I have the scrabble letters as magnets on my fridge and I was thinking: how many actual words could I make using only these letters. Obviously it would be hard to work out myself, so I challenge you to create a program which will take a string of characters as input, and your goal is to output as many words as possible using those characters.


  • The characters will be one string
  • Only the 26 letters of the alphabet will appear.
  • Letters may appear more than once
  • Letters can appear in any order. 5 e's might appear next to each other, and there might be other e's in the string.
  • There will always be at least a single letter, but it might not always be possible to create a valid word

Example, using the letters from Scrabble:



A list of valid English words, which you can separate with a space, newline or comma. A trailing newline at the end is fine.

Default loopholes are forbidden.

Meta discussion (not apart of the question)

  • Is a decent challenge for this? I'm more interested in more words being output than I am short code, but how best can I frame this challenge that the best result would be most words created and fewest characters left?
  • Should I restrict the input list to just the letters from Scrabble? I mean how can I evaluate whether a program prints as many as possible?
  • Should I provide a word list? I know there are challenges on this site where a word list is provided 1 and 2 and I'm sure there are a few others which I could not find.
  • This is my third question, so any other feedback
| |
  • 1
    \$\begingroup\$ I would highly recommend including the wordlist as an input and including a few trivial test cases so that people can easily test their answers. \$\endgroup\$ – Jo King Apr 26 '19 at 7:45
  • 1
    \$\begingroup\$ Not including the word list as input would benefit languages which have dictionary built-ins - everyone else would have to have a list of all English words in the code, which might be a little long, even given really good compression... \$\endgroup\$ – Matthew Apr 26 '19 at 8:28
  • \$\begingroup\$ Allow any reasonable output format rather than just text. Pass in word lists and letter sets as arguments. Making both constant turns this into a kolmogorov-complexity challenge. \$\endgroup\$ – Beefster May 1 '19 at 17:53

Hungry Blobs KoTH

This KoTH is inspired by Primer's Natural Selection Simulation. Your bot is a blob. In order to survive, you must eat pellets to regain energy. You can use additional energy to buy upgraded traits, like increased size (to eat smaller blobs), increased or decreased speed (also changes energy usage rate), or increased sight. Additionally, blobs can use energy to split into two blobs, which are "relatives".

Energy and Movement

Your blob starts off each round with 100 energy, and it has no limit on the amount of energy it can collect. The game is run in turns, with each blob having the option to move North, East, South, or West in any given turn, or stand still. Moving by defualt uses 1 energy, with standing still using 0.25 energy. The map's side length is ceil(0.25 * blobCount) * 2 - 1 units, with a minimum of 9 units. All blobs start on the edge of the map, with one placed in each corner and every subsequent blob being placed 2 units away from any others. Every 40 turns, a wave of circular pellets with a diameter of 0.8 are placed in random spots around the map, at least 1 unit from any edge. Each time a wave of pellets appears, the quantity of pellets (originally twice the number of blobs) in the next wave is decreased by 1, forcing the number of blobs to decrease over time. Each pellet restores between 25 and 35 energy. When a blob's energy is less than or equal to 0, it dies.


Blobs move in cardinal direactions at a rate of 1 unit/turn. A blob can sacrafice 40 energy in order to change its speed by 20%, up or down. Note that this is exponential, so a blob's speed will never reach 0 if decreasing, and speed up more each time it upgrades. The amount of energy used in a turn is equal to the square of the blob's speed, unless it does not move (it is then 1/4 of the normal amount).


Every blob starts at size 1. For 45 energy, the blob's size can be increased by 20%. Blobs are circular, with their diameter equal to their size. If two blobs overlap, the larger one will consume energy of the smaller one. The amount of energy consumed is smallEnergy * (bigSize - smallSize) / smallSize. Therefore, the energy of the smaller blob will never be completely consumed by the larger one, and instead will decrease until the energy usage per turn kills the blob. As with speed, size comes at a cost. The speed at which the blob moves is divided by its size, but the energy cost stays the same. Therefore, with a speed of 1.2 and a size of 1.2, the blob moves at the equivalent of speed 1 with the energy usage of speed 1.2.

Detection and Information

Blobs can see any pellets or other blobs within a distance of 3 units, plus half of the blob's size. For 35 energy, a blob can increase its search radius by 1 unit. When their functions are called, blobs are provided with:

  • The side length of the map
  • The position of the blob on the map
  • The positions of all pellets within their search radius, as well as their values
  • The positions of all blobs within their search radius, as well as their sizes and UIDs
  • The speed, size, search radius, and UID of the blob
  • A storage object unique to the blob
  • A storage object shared by all blobs related to the blob through splitting


As the challenge continues, the number of blobs decreases as starvation and hunting kills off blobs. In order to keep the map populated and continue the challenge, a blob can choose to split. Splitting costs 100 energy, and any remaining energy is divided evenly between the two blobs. The new blob keeps the size, speed, and detection distance of the original, and shares a communal storage object with all of its relatives. If one blob upgrades its traits or splits, it does not affect others (though the new blob still shares the communal object with all other relatives). Related blobs can still consume energy from each other.

Functions, Storage, and UIDs

In order to allow more complex learning behaviors, all blobs will be given an integer UID (Unique Identifer). These UIDs will be randomly generated each map, preventing strategies based on individual targets. When a blob's function is called, it is passed four objects:

  1. The side length of the map
  2. An object with two arrays: pellets, and blobs. Both arrays contain objects, both having a pos property containing the pellet or blob's position formatted as [x,y]. Pellets will have an energy property, while blobs will have a size property and a uid property
  3. An object containing various properties of the blob it is passed to: speed, size, searchRadius, uid, and pos. The pos array is formatted as [x,y]
  4. An object containing the two storage objects of the blob. A self property contains an individual storage object which can be modified however the blob sees fit (by manipulating properties of the object that is passed), and a communal property which can be modified by any relative.

Blobs are not moved immediately. The direction they return is recorded, and all blobs are moved at the same time after all are finished and before things like energy consumption are processed. In the event multiple blobs land on a pellet, the one closest to its center (relative to the center of the blob) receives it. If a blob lands on a pellet or smaller blob and, in the process uses its last energy, the blob will still consume the pellet/energy independent of whether that would would bring its total energy above 0.

In order for "relative" blobs to recognize one another, the communal storage must be used for each blob to record its UID in an array, or through some other system.

Return Values and Upgrades

In order to move or make purchases for upgrades to traits, the return value of the function is used. First, the meaning of the cardinal directions in terms of coordinates:

  • North = -Y
  • East = +X
  • South = +Y
  • West = -X

Note that [0,0] is the top left corner, and Y increases as you go down. The return value of the function should follow these rules:

  • To do Nothing: Return nothing, 0, null, undefined, false, or any other value that equates to false
  • To Move: Return one of four global variables: North, East, South, or West, which equate to "north", "east", "south", or "west" (which could also be used as a return value)
  • To Upgrade a Trait: Return one of four global variables: SpeedUp, SpeedDown, SizeUp, or SenseDistUp
  • To Split: Return the global variable Split

If an upgrade or split command is returned and the amount of energy required is greater than or equal to the energy of the blob, nothing will happen. If any part of a blob would be placed outside of the map by moving, it will move only so far that it reaches the edge exactly.

Predefined Library Functions

There are a few basic functions available by default, to save some time:

taxiDist(pt1, pt2, step = 1)

Returns the taxicab distance between two points (X distance plus Y distance), with an optional step parameter for distance each step travels (speed).

taxiDist([0, 0], [2, 2]) //4
taxiDist([3, 4], [1, 5]) //3
taxiDist([1.25, 1.3], [1.3, 1.4]) //0.15
taxiDist([0, 0], [5, 2.5], 2.5) //3
taxiDist([0, 0], [2, 4], 2.5) //2.4

hypotDist(pt1, pt2)

Returns distance between two points according to the pythagorean theorem

hypotDist([0, 0], [5, 12]) //13
hypotDist([4, 6], [8, 9]) //5
hypotDist([0, 1], [2, 1]) //2
hypotDist([1, 1], [2, 2]) //sqrt(2)

modDist(dist, amt)

Takes the inputted distance, rotates 90 degrees clockwise amt times, then returns the new value.

modDist(North, 1) //East
modDist(East, 2) //West
modDist(West, 3) //South
modDist(South, 4) //South

Example Blob

This blob will not move until it finds a pellet nearby. Then, it will move in the direction it thinks is most likely to reward it. If its energy is above 90, it will increase its sense distance. If its energy is ever above 110, it will split.

function(map, near, me, storage) {
    if (me.energy > 110)
        return Split;
    if (me.energy > 90)
        return SenseDistUp;
    if (!near.pellets.length)
        return null;
    var dirs = [0, 0, 0, 0];
    for (let p, i = 0; i < near.pellets.length; i++) {
        p = near.pellets[i];
        dirs[0] += me.pos[1] - p.pos[1];
        dirs[1] += p.pos[0] - me.pos[0];
        dirs[2] += p.pos[1] - me.pos[1];
        dirs[3] += me.pos[0] - p.pos[0];
    return [North, East, South, West][dirs.indexOf(Math.max(...dirs))];


  • Standard Loopholes are prohibited. Also, no Unstandard Loopholes.
  • No blob may attempt to modify or read any data not passed to it via its parameters
  • No blob may attempt to modify a return-value variable to sabotage other blobs
  • A round lasts until the only remaining blobs are relatives
  • No blob may modify data by injecting functions into its parameters which modify values using the this keyword
  • All submissions must either be in Javascript or a language which is not too different from Javascript (Python, for example). All answers will be converted to Javascript for the competition.
  • The winner is the blob which has collected the highest amount of energy in total across all rounds (from either pellets or consuming smaller blobs)
| |
  • \$\begingroup\$ Now that you've posted to Main, don't forget to edit your post here to shrink it and then delete it to save space. Thanks! \$\endgroup\$ – AdmBorkBork May 7 '19 at 19:39

Who's serving in table tennis?

Table tennis, also known as ping pong, is a well-known game in which players hit a ball back and forth across a table. One player serves the ball twice, and each time the ball is served, either player can score a point. Once the first player serves the ball twice, the second player gets to serve twice. Every two serves, the player which serves the ball switches. The game ends when one player has a score of 11 or more points and is two or more points higher than the other player.

Your task is to take the current score as input, and output a value depending on if player 1 should serve, player 2 should serve, or the game is over.

Input: The score of the first player to serve followed by the score of the other player. This can be as separate values or in a list, or another convenient data type.

Output: A distinct value for each possible case of output. For the test cases, I will use 1 to represent the player who serves first, 2 to represent the other player, and 0 to represent that the game is over.

Test cases:

player1score, player2score -> output

2, 0    ->  2
0, 0    ->  1
11, 0   ->  0
4, 4    ->  1
3, 2    ->  1
6, 9    ->  2
81, 82  ->  2
0, 29   ->  0
16, 13  ->  0
| |

Alternating Digit Divisibility

TODO: Could use a better title..


Given a list of positive integer \$L\$ with at least two integers, output a list of digits which alternating divide either number itself evenly, of the sum of the digits of this number. The alternating can be done [sum_of_digits, number_itself, sum_of_digits, ...], or [number_itself, sum_of_digits, number_itself, ...]
This no doubt sounds pretty vague, so here an example:

Input: \$L=[611,044,381]\$
Output: \$[[1,2,4],[1]]\$ (or \$[1,2,4,1]\$ or \$[1,2,4]\$)

The two alterations are one of these two possibilities:

[8,44,12]      [sum([6,1,1]),  044, sum([3,8,1])]
[611,8,381]    [611, sum([0,4,4]), 381]

As for which digits can divide these numbers:

[8,44,12]    →  [[1,2,4,8], [1,2,4], [1,2,3,4,6]]
[611,8,381]  →  [[1], [1,2,4], [1,3]]

Where the divisible digits that are present in all sublists of the lists are:


Challenge rules:

  • I/O is flexible. Input can be a list of strings, integers, 2D list of digits, etc. Output can be a list of lists of digits, a single flattened list of digits, a single flattened and uniquified list of digits, two lists printed on separated lines, a string, etc. The order of the outputs also doesn't matter, but state which one you've used in your answer.

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code (i.e. TIO).
  • Also, adding an explanation for your answer is highly recommended.

Test cases:

Input:                      Output:

[611,044,381]               [[1,2,4]], [1]]
[200,32000,4000]            [[1,2], [1,5]]

TODO: More to come, including some larger ones

| |

Help the library sort books

A library needs to sort its books, located in separate sections by language. Of course, each language has its own rule for collating strings, so your method should handle that ability.

Most languages will want to treat titles case-insensitively, but unfortunately, the library has a section of Klingon books. And Klingon's romanisation, in case you don't already know, is case-sensitive. As a result, you need to give a way to have the sorter treat two given characters as the same.

Some of the titles also contain numbers, and you need to deal with those as well. Fortunately, the friendly people at the library have written some functions for you to deal with that, so all you have to do is take in a handle to a function as one of your inputs.

Your challenge: Sort a list of book titles, given a collating sequence and a function handle that converts a number to its string representation in the respective language.

  • The collating sequence is a list of lists of strings. Given two strings A and B that appear respectively in the entries at indices i and j, respectively:
    • if i > j, then A should sort after B
    • if i = j, then A should sort the same as B
  • In case some elements of the sequence have multiple characters, use the max-munch rule to tokenise the string: e.g. if both l and ll appear in the collating sequence, then lll should be tokenised to ll l.
  • Any string of digits should be parsed as a number and passed to the callback. Each such string should be replaced by the result.
  • Any characters not appearing in the collating sequence should be ignored. If two strings differ only by such characters, then sort them however you like.

Test cases


english_letters = [["A", "a"], ["B", "b"], ["C", "c"], ["D", "d"], ["E", "e"], ["F", "f"], ["G", "g"], ["H", "h"], ["I", "i"], ["J", "j"], ["K", "k"], ["L", "l"], ["M", "m"], ["N", "n"], ["O", "o"], ["P", "p"], ["Q", "q"], ["R", "r"], ["S", "s"], ["T", "t"], ["U", "u"], ["V", "v"], ["W", "w"], ["X", "x"], ["Y", "y"], ["Z", "z"]]
arka_letters = [["t"], ["k"], ["x"], ["s"], ["n"], ["v"], ["f"], ["m"], ["d"], ["g"], ["p"], ["b"], ["h"], ["y"], ["c"], ["r"], ["z"], ["j"], ["w"], ["l"]]
function english_num_callback(num) {
  // convert a number to its representation in English
function arka_num_callback(num) { // handles nonnegative integers up to 9999
  if (num == 0) return "yuu";
  let kot = 0 | (num / 1000);
  let gal = 0 | (num / 100 % 10);
  let on = 0 | (num / 10 % 10);
  let ko = num % 10;
  let digits = ["yuu", "ko", "ta", "vi", "val", "lin", "kis", "nol", "ten", "los"];
  return (kot == 0 ? "" : digits[kot] + "kot") +
    (gal == 0 ? "" : digits[gal] + "gal") +
    (on == 0 ? "" : digits[on] + "on") +
    (ko == 0 ? "" : digits[ko]);
["Stack Exchange", "BB94 Channel!", "BB guns: all you wanted to know about them",
  "carrots", "A Grammar of Jbl", "69"], english_letters, english_num_callback =>
  ["A Grammar of Jbl", "BB guns: all you wanted to know about them", "BB94 Channel!",
    "carrots", "69", "Stack Exchange"]
["melidia", "diaklel", "44 miiko", "I Mess With the Librarians", "an isk ris tu lei",
  "lei e xion", "xagrisren et xep!", "on melkadren"], arka_letters, arka_num_callback =>
  ["xagrisren et xep!", "44 miiko", "melidia", "diaklel", "lei e xion",
    "an isk ris tu lei", "on melkadren", "I Mess With the Librarians"]
| |
79 80
82 83

You must log in to answer this question.

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