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

Sandbox FAQ


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

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.


The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

  • Parts of the challenge you found unclear
  • Comments addressing specific points mentioned in the proposal
  • Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.


Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal, use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

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

4705 Answers 4705


Possible binaries

This challenge is inspired by the AoC 2020, Day 14 - Part II, created by Eric Wastl and his team, which asks to output the possible binary values from a bitmask.

Let's say we've a bitmask like "10X0X0", then we've to find the possible binary values that can be generated by replacing an X with either 0 or 1.

So, the possible binaries are ["100000", "100010", "101000", "101010"].
When each of them are converted in decimal, then these are [32, 34, 40, 42] respectively.
And, finally the sum is 148.

Test cases

["0", "1"]
[0, 1]

INPUT: "0"

INPUT: "1"

INPUT: "1X0"
["100", "110"]
[4, 6]

INPUT: "1X0X1"
["10001", "10011", "11001", "11011"]
[17, 19, 25, 27]

["0000000", "0000001", "0000100", "0000101", "0010000", "0010001", "0010100", "0010101", 
"1000000", "1000001", "1000100", "1000101", "1010000", "1010001", "1010100", "1010101"]
[0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85]

INPUT: "1X1X1X1X1X1X1X1X1X1X1"
OUTPUT: 1789569024

INPUT: "1X01X01X01X01X01X01X01X01X01X01X01X0"
OUTPUT: 201053554790400

INPUT: "X000X000X000X000X000X000X000X000X000X000X000X000"
OUTPUT: 307445734561824768

INPUT: "101"

["000", "001", "010", "011", "100", "101", "110", "111"]
[0, 1, 2, 3, 4, 5, 6, 7]


  • It is guaranteed that \$ 0 \leq \text{count}(X) \leq 12 \$ and \$ 1 \leq \text{length}(mask) \leq 48 \$.
  • Input can be either a string, or an array of chars (non-empty).
  • Output will be the sum of the binaries in decimal.
  • This is a , so fewest bytes will win!


  • Is the challenge's text clear enough?
  • Is the constraint on count of X sufficient?
  • Although I've tried a search, but is this a duplicate?
  • Any suggestions/improvements in the attribution?
  • Any tricky test case?
  • \$\begingroup\$ Is there an upper bound on the size of an input bitmask? It would probably be good to provide one, but if there’s intentionally no upper bound, you should have a test case where the input is longer than 64 bits. \$\endgroup\$ Commented Dec 14, 2020 at 18:54
  • \$\begingroup\$ What about empty lists? (I'd like to have it as undefined, so we don't need to handle that special case). I believe the permutation tag doesn't apply here. And maybe an example for XXX? \$\endgroup\$
    – xash
    Commented Dec 14, 2020 at 18:55
  • \$\begingroup\$ @water_ghosts - Yes, there is an upper bound, I've edited that. \$\endgroup\$
    – vrintle
    Commented Dec 15, 2020 at 2:51
  • \$\begingroup\$ @xash - No, there will be no empty list/string. Added the example, and striked off the tag for now, but maybe it could be related somehow.. \$\endgroup\$
    – vrintle
    Commented Dec 15, 2020 at 2:54

Output a unique sign sequence

  • 3
    \$\begingroup\$ Is shortness of the answer not supposed to be a factor at all? That is, we don't try to golf our answers? Even more, are voters supposed to consider just the sequence, or the code producing it? I'm not quite sure if "How clever is the implementation" is meant to apply to the code itself or just the general strategy. \$\endgroup\$
    – xnor
    Commented Sep 22, 2020 at 23:14
  • \$\begingroup\$ @xnor No, golfing your answer is unimportant, but perfectly acceptable. Voters should consider both the code and the sequence, but primarily the sequence. The code should mainly be considered for how "elegant/clever/good" the vote perceives it to be. "How clever is the implementation" kinda applies to both the code and the strategy. Using language-specific tricks are a reason to consider code "clever" as is implemented a fully generalised method that any language to pick up and use with no trouble \$\endgroup\$ Commented Sep 22, 2020 at 23:34
  • 2
    \$\begingroup\$ I think this works much better as answer-chaining than as pop-con. As evidence I'd say that almost half of the challenge being devoted to explaining the voting rather than the challenge isn't a good sign. I think looking at recent successful pop-cons shows that pop-cons are generally only good if the task just won't lend itself at all to another scoring criterion. This, at least to me, seems like a great idea for answer-chaining. \$\endgroup\$ Commented Sep 24, 2020 at 19:08
  • 2
    \$\begingroup\$ @FryAmTheEggman I do dislike the fact that this is a pop-con, and the only reason it is, is because I couldn't find any other criteria which would inspire the creativity in sequences I'm looking for (e.g. the reductive attitude of code golf would make this very boring). The issue I see with making it answer chaining is that the winning criteria is a bit iffy. "Second-to-last" isn't the best winning criteria as already discussed on meta, but it gets even worse when new answers aren't more difficult than previous ones, as the challenge will continue ad infinitum until (cont) \$\endgroup\$ Commented Sep 24, 2020 at 19:19
  • 1
    \$\begingroup\$ (cont) people get bored and stop posting, rather than new answers are genuinely too difficult to make. There are an infinite number of sign sequences, so "running" out isn't an issue, and each new answer isn't more difficult because there are so many to choose from. Furthermore, I don't think it'd inspire the creativity I'm looking for. I don't think it'd be as bad as, say code golf, but I feel like people will resort to posting basic sequences in order to keep the chain from dying, thus extending it way beyond being fun \$\endgroup\$ Commented Sep 24, 2020 at 19:20
  • \$\begingroup\$ I had initially thought that preventing the obvious abuse cases was relatively simple (no prefix/suffixes and not periodic) but I've realised that it would actually be much more difficult than that. I still think this probably works better if massaged into something that works for answer-chaining, but you are probably right that it isn't as good a fit as my first impression was. \$\endgroup\$ Commented Sep 24, 2020 at 20:36
  • 1
    \$\begingroup\$ This might be interesting as a cops-and-robbers challenge, though it would have to be a finite slice of an infinite sequence in that case. \$\endgroup\$
    – Beefster
    Commented Oct 2, 2020 at 19:21
  • \$\begingroup\$ @Beefster I think the only (or maybe best) way this could work as a CnR is where the cops reveal their code+language (and maybe a few terms of the sequence) and the robbers have to find the generating function for that sequence, but that would almost definitely lead to obfuscated code, rather than „how is the sequence generated“ being the focal point for answerers, which pivots away from the main idea of the challenge being interesting sequences, not interesting code \$\endgroup\$ Commented Oct 2, 2020 at 19:51

Calculate longest Stack Exchange streak

  • \$\begingroup\$ I'd say the best input format would be nested maps/dictionaries/whatever in the language's most normal data structure with the schema given in the input format, or alternatively (i.e. leave it up to the answerer), the exact text format you gave above (minus the var visited = ). \$\endgroup\$
    – pxeger
    Commented Mar 24, 2021 at 14:05
  • \$\begingroup\$ I think for a internet challenge in general it is fine to ask for the input data to be parsed after collecting it from the internet. I'd expect most of the variance to come from trying to find shortcuts in parsing in this case anyway. Finding users who are good test cases might be tricky - so perhaps including some made-up results which test basic stuff (skipped months/years, February) could be nice. I don't know that CGSE is new enough to not have any weird calendar stuff (missing days, etc.) that should be specified. \$\endgroup\$ Commented Mar 24, 2021 at 22:15
  • \$\begingroup\$ Not sure why, but if I go to https://codegolf.stackexchange.com/users/daily-site-access/66833 (my user id is 66833), I just get a blank page? Challenge-wise, I think that this is pretty clear, and I agree with the other commenters that the default format is perfectly fine. You are missing an objective winning criteria however \$\endgroup\$ Commented Mar 30, 2021 at 21:39
  • \$\begingroup\$ Thanks for your input! @ChartZBelatedly it's a blank page indeed, but viewing the source helps. It was intended to be a [code-golf] challenge, I assumed that was the default. I'm missing test cases too, of course. \$\endgroup\$
    – Glorfindel
    Commented Mar 31, 2021 at 9:01
  • \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$ Commented Apr 6, 2021 at 1:04

Did I die or not?

  • 1
    \$\begingroup\$ Perhaps add a few cases to make sure solutions check for exactly 12 wrong guesses? Like "ABCD...Z", "L" -> True and "ABCD...Z", "M" -> False \$\endgroup\$ Commented Apr 20, 2021 at 19:38
  • 1
    \$\begingroup\$ @ManishKundu Added \$\endgroup\$ Commented Apr 20, 2021 at 23:32

It almost works (C&R)

Cops thread

Robbers thread

  • \$\begingroup\$ Looks really fun! \$\endgroup\$
    – math scat
    Commented Jul 12, 2021 at 14:00

Laggy text editor

  • \$\begingroup\$ Your example only submit an input after hitting Enter. Am i required to follow this behavior or may I consider each key press as an input? \$\endgroup\$
    – tsh
    Commented Mar 1, 2022 at 7:50
  • \$\begingroup\$ @tsh I'm not quite sure how to deal with "prompting for input" in general, but I guess you can take each key press as an input if you want. \$\endgroup\$
    – emanresu A
    Commented Mar 1, 2022 at 7:56
  • \$\begingroup\$ A fiddle which delay every input 5 second \$\endgroup\$
    – tsh
    Commented Mar 1, 2022 at 8:38
  • \$\begingroup\$ @tsh Thanks! (filler) \$\endgroup\$
    – emanresu A
    Commented Mar 1, 2022 at 8:49

Fill in the next numbers

  • 1
    \$\begingroup\$ Perhaps a better title would be "Fill in the gaps with previews" (previews because the gaps contain the next number to be seen, so the gaps "preview" the sequence) but it also sounds rather strange. \$\endgroup\$
    – ophact
    Commented Feb 26, 2022 at 14:59
  • 2
    \$\begingroup\$ I would like to exclude the "prime" part in the example. It makes me confuse this challenge is about doing something to test a number is prime or not. \$\endgroup\$
    – tsh
    Commented Mar 3, 2022 at 2:11
  • 1
    \$\begingroup\$ Also, instead of show gaps as numbers, underscore could be less confusion, as _ 2 3 _ 5 _ 7 _ _ _ 11. And say any gaps (underscore) should be filled by right hand values. \$\endgroup\$
    – tsh
    Commented Mar 3, 2022 at 2:12
  • 1
    \$\begingroup\$ I agree with @tsh that I wouldn't mention 'primes' since it might lead to confusion. The example could still be 2,3,5,7,11 and people can see for themselves they're primes, but I just wouldn't mention this explicitly. So the sentence "For example, if the input is the first 5 prime numbers:" would be: "For example, if the input is:" and # primes in the code block would be # input. Apart from that it's a great challenge, and I've already prepared a solution for when it goes to main in the near future. :) \$\endgroup\$ Commented Mar 3, 2022 at 13:41

Eh, codegolf shmodegolf

  • 2
    \$\begingroup\$ Nice idea! You probably want a general procedure people can follow to do this, and I don't think the initialisms is a good idea. \$\endgroup\$
    – emanresu A
    Commented May 18, 2022 at 10:34
  • \$\begingroup\$ @emanresuA You're probably right about the initialisms. I added an example of an ungolfed python function that solves the challenge, and some restrictions on the input. Do you think more things should be specified? \$\endgroup\$
    – JSorngard
    Commented May 19, 2022 at 10:34
  • 1
    \$\begingroup\$ This looks fine! Leave it for another day or two though just in case. \$\endgroup\$
    – emanresu A
    Commented May 19, 2022 at 11:04
  • 1
    \$\begingroup\$ I suggest adding some more test-cases (especially starting with more than one consonant). Also, re: last sentence - definitely specify what to expect as input (only letters? at least one vowel? will the input start with a vowel?) and add some test-cases accordingly if necessary. In the end, please clean up the post (one can view edit history if interested in the evolvement of the question), so we can see what you intend to post and maybe give some feedback on that. \$\endgroup\$
    – pajonk
    Commented May 19, 2022 at 12:02
  • 2
    \$\begingroup\$ I recommend stating the rules of shmification used in this challenge explicitly - I guess this will be three points (to present briefly): 1. consonants up to first vowel replaced with shm; 2. prepend shm to words beginning with vowel; 3. no vowels = no shm. Also, I suggest altering the example program to actually solve the challenge or removing it altogether to avoid confusion. \$\endgroup\$
    – pajonk
    Commented May 19, 2022 at 17:43
  • \$\begingroup\$ @pajonk Thank you, excellent points. I have added rules and updated the code to solve the challenge as it is stated. \$\endgroup\$
    – JSorngard
    Commented May 20, 2022 at 10:48
  • \$\begingroup\$ You should specify that vowels are specifically aeiou (and not y). Also, can we assume the input only contains lowercase letters? \$\endgroup\$
    – pxeger
    Commented May 20, 2022 at 14:54
  • \$\begingroup\$ @pxeger The input being lowercase letters is already specified, but I moved it and added a line about what the vowels are, thanks :D \$\endgroup\$
    – JSorngard
    Commented May 20, 2022 at 19:33
  • \$\begingroup\$ Maybe some words on output formats? People will wonder whether they can output as a list with two elements, a function that returns two words, or whether it has to be a single string joined with a space. \$\endgroup\$
    – chunes
    Commented May 22, 2022 at 7:28
  • \$\begingroup\$ @chunes I changed the output to be a single string containing the reduplicated version of the input, that way it is clearer what format the output should be. \$\endgroup\$
    – JSorngard
    Commented May 23, 2022 at 8:55
  • \$\begingroup\$ After the change, rule 3 no longer makes sense. Instead of saying "only repeated," maybe "unchanged" or "leave it alone"? \$\endgroup\$
    – chunes
    Commented May 23, 2022 at 9:01
  • \$\begingroup\$ @chunes You are completely correct, thanks! I have changed rule 3 to say that words without vowels should be returned unchanged. \$\endgroup\$
    – JSorngard
    Commented May 23, 2022 at 9:15
  • 1
    \$\begingroup\$ I've edited this down to a stub now that it's been posted to save space \$\endgroup\$
    – naffetS
    Commented May 24, 2022 at 18:02
  • \$\begingroup\$ @Steffan thanks! \$\endgroup\$
    – JSorngard
    Commented May 24, 2022 at 20:11

Collatz Encoding

  • \$\begingroup\$ What should the input 0 output? \$\endgroup\$ Commented Apr 29, 2022 at 14:08
  • \$\begingroup\$ @BgilMidol "Your challenge is to write a function or program which takes an integer (n>0) as input" i.e. 0 will never be an input \$\endgroup\$ Commented Apr 29, 2022 at 14:08
  • \$\begingroup\$ oh, i didn't see that \$\endgroup\$ Commented Apr 29, 2022 at 14:16

Make Spanish from Latin

Note: In the final challenge \$N\$ will be a concrete number (I am thinking about 100), but while this is in the sandbox it is subject to change so I have left it as \$N\$. Currently \$N=133\$

This challenge is based off of a list of \$N\$ Castilian Spanish words and the words they originate from.

You are to write a program or function which takes the origin word as input and outputs as close as possible the Castilian derivative. Your program should be no longer than \$N\$ bytes.


To calculate your score run your program on every origin word and calculate the distance between your output and the correct answer. Your score is the sum of all these distances.

The distance here is a modified version of Levenshtein distance. It is the same as Levenshtein distance except replacement steps that add or remove a diacritic cost only 1 of a step as opposed to their normal 2. This is because if you guessed á instead of a that's not as bad as if you guessed f instead of a.

You can use this code to calculate the distance between two strings.

The goal is to have as low a score as possible.

About the list

All of the origin words, spare 2, are Latin words (Late or Classical depending on the word). The two exception is ezkerra (the origin for izquierda) which is of Basque origin and brixta (the origin for bruxa) which is of Proto-celtic origin. It has been added as an extra curve-ball in case you can get all the others with a little space to spare.

Verbs are always in the infinitive form and nouns in the nominative singular.

The words are not chosen randomly but rather I have focused on choosing words that follow a number of simple rules. The list is also organized so that words that undergo similar transformations are grouped together. This is for your ease of use, nothing more.

The list

imperatrix, emperatriz
cicatrix, cicatriz
actrix, actriz
matrix, matriz
carex, carrizo
radix, raíz
falx, hoz
fovea, hoyo
formica, hormiga
fodiare, hozar
folia, hoja
filum, hilo
filius, hijo
filia, hija
ficum, higo
filare, hilar
ficcare, hincar
afflare, hallar
fundus, hondo
profundus, profundo
fungus, hongo
fabulare, hablar
furnus, horno
bufus, búho
ferrum, hierro
fetere, heder
fagea, haya
faba, haba
facienda, hacienda
facere, hacer
fastidium, hastío
fastidiare, hastiar
factor, hechor
factum, hecho
tectum, techo
octo, ocho
octavus, ochavo
noctu, noche
lacte, leche
iactare, echar
coctus, cocho
dictatum, dechado
phalanga, palanca
capere, caber
sapere, saber
lupus, lobo
lacrima, lágrima
lacuna, laguna
eruca, oruga
pater, padre
mater, madre
liber, libro
thema, tema
theatrum, teatro
thesaurus, tesoro
thesis, tesis
thorax, tórax
aether, éter
anthropologia, antropología
orthographia, ortografía
sapphirus, zafiro
philosophia, filosofía
echo, eco
chalare, callar
chamaeleon, camaleón
chaos, caos
materia, materia
resistentia, resistencia
aurum, oro
taurus, toro
autumnus, otoño
canna, caña
annus, año
ungla, uña
plangere, plañir
stringere, estreñir
signa, seña
scribere, escribir
stare, estar
stabulare, estabular
stipare, estibar
stria, estría
strix, estrige
studiare, estudiar
stimulare, estimular
stillare, estilar
sternutare, estornudar
statuere, estatuir
spirare, espirar
sputare, esputar
spina, espina
speclum, espejo
spectrum, espectro
squama, escama
squamosus, escamoso
squalidus, escuálido
scalare, escalar
scandere, escandir
scutum, escudo
scutella, escudilla
scriptor, escritor
sobrina, sobrina
sobrinus, sobrino
secta, secta
sector, sector
sibilare, silbar
subire, subir
subito, súbito
suspirum, suspiro
subiugare, subyugar
corvus, cuervo
fossa, huesa
socrus, suegro
lupus, lobo
acutus, agudo
tecula, teja
apicula, abeja
flamma, llama
flammare, llamear
planus, llano
plagare, llagar
plorare, llorar
plovere, llover
plicare, llegar
clavis, llave
clamare, llamar
gladius, gladio
gleba, gleba
globus, globo
blandus, blando
blancus, blanco
brixta, bruxa
ezkerra, izquierda
  • \$\begingroup\$ I think it's interesting in that it should be near impossible to get a perfect score without built-ins. As a suggestion I'd remove the non-ASCII words, or at least normalise them, and perhaps not let \$N\$ be too high. Also, I wonder what the default cat program would be. \$\endgroup\$
    – Jo King Mod
    Commented Mar 3, 2020 at 12:31
  • 2
    \$\begingroup\$ @JoKing I am looking to somewhat twart perfect scores, I feel there should always be some room for improvement, It just is a little hard to balance this with golfing-languages ability for expressiveness. I am interested to hear what ranges for \$N\$ you think are too high. I started out by avoiding any non-ASCII characters, but it was really hard to build up a representative corpus of words. Plus the accents and eñe really are a feature of the language. I may adjust the scoring so that i and í for example are only half away from each other so that the penalty is small. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Mar 3, 2020 at 13:05
  • \$\begingroup\$ Suggested title: Hispanize these words. Also mention that words should be in lowercase. Finally I think it makes more sense to restrict programs to \$N\$ characters rather than \$N\$ bytes. \$\endgroup\$
    – SunnyMoon
    Commented Nov 20, 2020 at 15:24
  • 7
    \$\begingroup\$ I'm not a fan of "Your program should be no longer than N bytes". I think a scoring rule which incorporates both the Levenshtein distance and the byte count would be better, as in the Moby Dick challenge: it would allow more languages to compete, and would allow for more creativity. \$\endgroup\$ Commented Nov 22, 2020 at 23:43
  • 1
    \$\begingroup\$ @RobinRyder I think that metrics that combine two non-obviously related factors such as in the Moby Dick challenge or as you are suggested rarely work. In fact I can't even think of an example I feel is good. They simply require fine tuning that can only really be done in retrospect. I also don't know how this would allow more languages to compete and I certainly don't know how it would "allow for more creativity". If you have a specific metric in mind and a compelling reason why that metric would not be broken I would be happy to try it out and see. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Nov 23, 2020 at 1:38
  • 2
    \$\begingroup\$ Sorry, I'll expand: with a low, hard limit on the number of characters, non-golfing languages don't stand a chance (hence the "more languages" part). If instead you set a high hard limit, it will be possible to reach a (near) perfect score, with no incentive to golf or search for trade-offs (hence the "creativity" part). There surely exists a sweet spot for the character limit where neither of these issues arise, but (a) it will be hard to find and (b) it will be highly language-dependent. \$\endgroup\$ Commented Nov 23, 2020 at 7:53
  • 1
    \$\begingroup\$ @RobinRyder I think that 100 characters is plenty of characters for nearly any language to implement something a bit more complex than cat (e.g. replace ^f with ^h). I also think that it would require quite a few characters any language to acheive a perfect score. More than half of the words have seemly random vowel mutations that are not covered by any general rule. The only way I can see a perfect score is a compression decompression method. It seems to me to write the de-compressor and make up for the loss would require a deal of room. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Nov 24, 2020 at 15:56
  • \$\begingroup\$ What I'm saying is that I think that sweet spot is actually very large. And I think that adding more dimensions to the problem only increase the risk of missing the sweet spot. \$\endgroup\$
    – Wheat Wizard Mod
    Commented Nov 24, 2020 at 15:57
  • \$\begingroup\$ Some possible typos (I'm a native Castillian Spanish speaker and I'm familiar with Latin): afflare, hallar; factor, factor; chalare, callar \$\endgroup\$
    – Luis Mendo
    Commented Dec 20, 2020 at 18:00
  • \$\begingroup\$ @LuisMendo hallar and chalare are definitely typos. But hechor was intentional. I suspect your hang up is that factor and hechor are doublets but factor is more similar to the Latin. There are plenty of words here for which the Latin is not a direct translation or the Spanish or vice versa (even factor is not). I chose to include hechor because it is a good example of some of the changes that I want to highlight, (f -> h and ct -> ch). \$\endgroup\$
    – Wheat Wizard Mod
    Commented Dec 21, 2020 at 23:26
  • 1
    \$\begingroup\$ The thing is, I never heard hechor. But I just checked in the dictionary and it is included, albeit as an old form, not in current use \$\endgroup\$
    – Luis Mendo
    Commented Dec 21, 2020 at 23:46

Race some Robots

Based on RoboRally, but uses some different/simplified rules

In this KoTH, you will be coding a Python bot that attempts to race around a factory, reaching two specific places before the other bots, who are doing the same thing. The way you'll reach these places - the "checkpoints" - is by sending instructions to the bot, telling it where to move.

The Factory

The factory is represented by a \$13 \times 10\$ 2D list, where each cell has a different component, each represented by a 2 character long string. The factory will be constant for the KoTH, and is the following 2D list (coordinates are shown around for reference):

    0     1     2     3     4     5     6     7     8     9    10    11    12
0 [['  ', '  ', '> ', '  ', 'vv', 'C2', '  ', '  ', '  ', '  ', '^^', '  ', ' ' ],
1  ['  ', '  ', '  ', '  ', 'vv', '  ', 'lv', '< ', 'l<', '  ', 'R^', '<<', '<<'],
2  ['  ', '  ', '  ', '<<', 'R<', '  ', 'v ', '  ', '^ ', '  ', '  ', '  ', '*v'],
3  ['  ', '  ', '  ', '  ', '  ', 'lv', 'r<', '  ', 'r^', '< ', '< ', 'l<', '  '],
4  ['PA', '  ', '  ', '  ', 'lv', 'r<', '  ', '  ', '  ', '  ', '  ', '^ ', '  '],
5  ['  ', '  ', '  ', '  ', 'v ', '  ', '  ', '  ', '  ', '  ', 'r>', 'l^', '  '],
6  ['  ', '  ', '  ', '  ', 'l>', '> ', '> ', 'rv', '  ', 'r>', 'l^', '  ', '  '],
7  ['  ', '  ', '  ', '  ', '  ', '  ', '  ', 'v ', '  ', '^ ', '  ', 'R>', '>>'],
8  ['  ', '  ', '  ', '>>', '>>', 'Rv', '  ', 'l>', '> ', 'r^', '  ', '^^', '  '],
9  ['  ', '  ', '> ', '  ', '  ', 'vv', '  ', '  ', '  ', '  ', 'C1', '^^', '  ']]

We will use compass directions in the explanations to refer to the direction a bot is facing, with "North" being the top of the factory (so \$(0, 0)\$ is the North-West corner).

This is fairly complicated, so we'll go over what each string means:

  • : This is just a blank square. Nothing special happens.

  • C1/C2: Checkpoints 1 and 2. You must visit Checkpoint 1 first, then Checkpoint 2. The first bot to do both wins.

  • > /< /v /^ : These are conveyer belts. At the end of each "register" (explained below), they move any robot on them one square in the corresponding direction.

    • For example, if a bot is on \$(5, 6)\$ at the end of a register, it is moved to \$(6, 6)\$.
  • r>/r</rv/r^/l>/l</lv/l^: These are corner conveyer belts. If pushed onto these squares by a conveyer belt, the bot is rotated 90 degrees clockwise (rX) or counter clockwise (lX). At the end of each register, any bot on them (not bots that were just moved onto them) is moved one square in the corresponding direction.

    • For example, if a bot is moved from \$(6, 6)\$ to \$(7, 6)\$ while facing North, it is rotated 90\${}^\circ\$ clockwise and now faces East.
    • If this same bot then doesn't move during the next register, then it is pushed South to \$(7, 7)\$, facing East.
  • >>/<</vv/^^: These are double conveyer belts. If a bot is on one of these at the end of a register, it is moved once in the corresponding direction, and the conveyer square it lands on then moves it a second time

  • R>/R</Rv/R^: These are corner double conveyer belts, specifically right turn corners. As with normal right corner conveyer belts, they rotate a bot 90\${}^\circ\$ clockwise when pushed on to, but they then immediately move the bot in the corresponding direction.

    • For example, a bot facing South who ends a register on \$(11, 1)\$ would be pushed once to \$(10, 1)\$, rotated to face West, then pushed to \$(10, 0)\$.
  • *v: This is the Reboot square. If a bot moves off the board, it is "rebooted": it receives 2 Spam cards, is placed on this square and all remaining instructions are ignored for this round. The bot is now facing South, and, if another bot is rebooted while a bot is on this square, the first bot is pushed one square to the South.

  • PA: This is the Priority Antenna. It cannot be moved, you cannot move into the square, and is used to determine who acts first each round.


Gameplay is very simple. The game is broken into rounds, and one round is structured as follows:

  • First, play order is determined. Bots act in inverse order to their Manhattan distance to the Priority Antenna, with ties broken by the bot with the most "horizontal" (East-West) distance going first.
  • Then, each bot is dealt 9 "programming cards" from their hand (initially 20, but it can grow). Each "programming card" contains a single instruction for the bot (e.g. Move 1, Left Turn, etc.). The bots then simultaneously* each choose 5 cards, discard the other 4, and order the 5 chosen from 1st to 5th.
  • There are now 5 registers, one for each chosen card. A register proceeds as follows:
    • The card for each robot for that register is revealed, and the instructions are executed in play order.
    • Once all instructions are resolved, the conveyer belts all activate, potentially moving any bots.
    • Then, each bot fires a laser, in a straight line in front of it, until it either hits another bot, a wall, the Priority Antenna or misses all other bots.
    • If a bot is hit by a laser, it receives a Spam instruction, which is added to its "programming cards".
    • If a bot is on Checkpoint 1, it is now able to visit Checkpoint 2 to win. If it is on Checkpoint 2, it wins.
    • The next register begins, and the process is repeated.
  • After all 5 registers are completed, and everything is resolved, each deck of programming cards are reshuffled with all programming cards, and the next round begins.

If a bot moves into the same square as another bot, that bot is pushed back one square in the direction the first bot is moving. For example, if Bot 1, facing East, moves from \$(7, 4)\$ to \$(8, 4)\$, and Bot 2 is already in \$(8, 4)\$, then Bot 2 is pushed to \$(9, 4)\$. Note that, if pushing a bot would push it into the space of another bot, both are pushed.

*: For the purposes of the KoTH, each bot will be given their cards, and will return their chosen instructions in some arbitrary order.

Programming Cards

Each bot has a deck of programming cards, initially 20. The decks are all identical, and consist of:

  • 3 Move 1 cards: the bot moves forward one square
  • 2 Move 2 cards: the bot moves forward exactly two squares
  • 2 Move 3 card: the bot moves forward exactly three squares
  • 3 Right Turn cards: the bot stays in place, and rotates 90 degrees clockwise
  • 3 Left Turn cards: the bot stays in place, and rotates 90 degrees counter clockwise
  • 3 U-Turn cards: the bot stays in place and rotates 180 degrees
  • 2 Move Back cards: the bot moves moves backwards one square, without rotating
  • 2 Again cards: the bot repeats the previous instruction
    • Note that these don't "stack": playing an instruction, followed by 2 Agains does the instruction a total of 3 times, not 4

Additionally, bots can increase the number of cards in their deck by taking damage from lasers, or by rebooting. In this case, they receive Spam cards, which are added to their deck:

  • Spam cards: a random card from the bot's programming deck is chosen, and that is the instruction carried out this register. At the end of the round, the Spam card is removed from your programming deck.
    • Note that this does stack: if the drawn card is a Spam card, you repeat until a non-Spam card is drawn. All drawn Spam cards are removed from your deck.

Starting positions

Finally, we come to the start. At the very beginning of the game, the 6 players are placed on the 6 starting positions, in a random order. The positions are \$(1, 1)\$, \$(0, 3)\$, \$(1, 4)\$, \$(1, 5)\$, \$(0, 6)\$ and \$(1, 8)\$. Each bot may choose which direction they begin facing.


You are to write a function in Python 3 that takes the following arguments:

  • round: an integer, beginning at 0, counting what round the game is on
  • order: an integer from 1 to 6, indicating the bot's order of play, with 1 being first and 6 being last
  • position: a 3-tuple (x, y, d) consisting of your zero-indexed coordinates in the factory, and a character, one of NESW, indicating the direction you're facing
  • score: a boolean, indicating whether you have landed on Checkpoint 1 yet.
  • cards: a list of 9 two character strings, indicating the cards you've been dealt
    • M1/M2/M3/MB indicate Move 1, 2, 3 and Back respectively
    • RT/LT/UT are Right, Left and U-Turn
    • Ag/Sp are Again and Spam
  • bots: a list of 3-tuples (x, y, d) of the coords and directions of all other bots
  • factory: the factory matrix above.

It should then return the following:

  • If round is 0, it should return one of N/E/S/W to indicate its starting direction
  • Otherwise, it should return a list of up to 5 of the strings from cards, indicating its registers. Note that the first element of this list will be the first register, the second the second and so on. If you return fewer than 5 strings, the list will be filled with randomly drawn cards from your programming deck that weren't in cards until there are 5 elements.

Once the first bot finishes a register on Checkpoint 2, after its score is True, the game is finished, and the winner receives 1 point.


Every combination of 6 bots will play 3 games together. The winner of a game receives 1 point, and the bot with the most number of points after all the games wins.

Example Bots

Sandbox note: once I've written the controller, I'll add in a couple basic example bots


A completely random bot, it shuffles the cards dealt and returns the first 5:

import random

def random_bot(round, order, position, score, cards, bots, factory):
	if round == 0:
		return random.choice('NESW')

	while cards[0] == 'Ag': random.shuffle(cards)
	return cards[:5]

Example round

*to be added*


  • Thoughts?
  • Is this clear enough?
  • The original game of RoboRally is super dynamic. I worry that bots may not be able to handle that without being super complex. Thoughts?
  • Is this a dupe?
  • Tags are , , , and . Suggestions?
  • Any further feedback?

Note: If you are seeing this first, you might want to sort by active.

Unhappy numbers ascii art

Draw a square (or a rectangle as close to a square as possible) that represents the cycle of an unhappy number.

[ short description of unhappy numbers here + example ]

[ square formating rules ]


Unhappy integer.


ASCII art.


 4 -  16 - 37 
20         58
42 - 145 - 89
  • \$\begingroup\$ The cycle of an unhappy number is a constant. \$\endgroup\$
    – J B
    Commented Mar 7, 2011 at 23:42
  • \$\begingroup\$ @JB: thanks, I will rephrase the question. I didn't mean the 4 cycle. (Why did I chose 4 as an example? :/ ) \$\endgroup\$
    – Eelvex
    Commented Mar 8, 2011 at 4:56
  • \$\begingroup\$ @Eelvex This is an nice challenge. Are you still interested in finishing it? \$\endgroup\$
    – J Atkin
    Commented Feb 7, 2016 at 19:06
  • 1
    \$\begingroup\$ This challenge proposal has been inactive for over a month. I would like to take ownership of the challenge and make it ready for posting. Please let me know within the next 2 weeks if you have any objections and would still like to finish and post this challenge yourself. \$\endgroup\$
    – J Atkin
    Commented Feb 10, 2016 at 0:19
  • \$\begingroup\$ @JAtkin, no objections. \$\endgroup\$
    – Eelvex
    Commented Feb 12, 2016 at 11:20
  • 1
    \$\begingroup\$ If this was posted, can you please delete it? \$\endgroup\$
    – MD XF
    Commented Aug 17, 2017 at 16:58


  • \$\begingroup\$ I quite like this challenge, but why are there four possible outputs for xxxx, X? Was it not specified that the first occurrence should be capitalized and only that one? \$\endgroup\$
    – user100690
    Commented May 27, 2021 at 19:31
  • \$\begingroup\$ I'll change it so that it's always the first option. \$\endgroup\$
    – pxeger
    Commented May 28, 2021 at 7:35
  • \$\begingroup\$ May we take a list of words as input? A list of characters? Or a list of lists of characters/character codes? (I think it's not covered by the I/O link you provided) \$\endgroup\$
    – pajonk
    Commented Jul 5, 2022 at 8:38
  • \$\begingroup\$ @pajonk I think it's generally understood that a string and list of characters are interchangeable. But I'll add notes about the other two. \$\endgroup\$
    – pxeger
    Commented Jul 5, 2022 at 9:05

When will the DVD logo hit the corner?


Numbers vs. Strings: Language fitness challenge

  • \$\begingroup\$ The thing is, lenguage is quite easy to golf down due to how its encoding works and it'd require a lot of diligence to create one that's almost certainly optimal. The longer you make a solution, the more potential there is for it to be smaller. \$\endgroup\$
    – emanresu A
    Commented Sep 13, 2022 at 5:24
  • \$\begingroup\$ May I take input as a list of characters for the string task? \$\endgroup\$
    – alephalpha
    Commented Sep 13, 2022 at 9:41
  • \$\begingroup\$ @alephalpha Yes. \$\endgroup\$
    – Bubbler
    Commented Sep 13, 2022 at 9:53
  • 2
    \$\begingroup\$ One concern I have about the string task is that it seems relatively easy in a language like BQN, which treats strings as arrays of characters and is good at manipulating arrays. I wouldn't think of BQN as being a good language for string-handling, though. Maybe the string task should involve more of the standard string-manipulation builtins like case conversion, search-and-replace, etc. \$\endgroup\$
    – DLosc
    Commented Sep 16, 2022 at 19:20
  • \$\begingroup\$ @DLosc I changed the string task to one that involves string replacement. Does it look better? \$\endgroup\$
    – Bubbler
    Commented Sep 19, 2022 at 4:17
  • \$\begingroup\$ @pxeger "Given a nonempty string s consisting of uppercase letters..." \$\endgroup\$
    – Bubbler
    Commented Sep 19, 2022 at 10:30
  • \$\begingroup\$ @Bubbler Wow, I'm not good at reading. \$\endgroup\$
    – pxeger
    Commented Sep 19, 2022 at 10:31

Complete the landscape

  • \$\begingroup\$ Related \$\endgroup\$
    – Beefster
    Commented Sep 28, 2020 at 22:04
  • 1
    \$\begingroup\$ I'd recommend allowing the golfer to choose any three consistent distinct values for Field/Road/City \$\endgroup\$ Commented Jan 26, 2023 at 22:38
  • \$\begingroup\$ Why does the tile information need to include the number of cities? Shouldn't just the edges be enough? \$\endgroup\$ Commented Feb 5, 2023 at 20:06
  • 1
    \$\begingroup\$ @Jacob "As the number of cities on a tile is redundant for this task, you may choose instead to only work with 17 tiles (as 2 tiles are duplicated when ignoring cities) and take input as lists in the form [N, E, S, W] instead, giving this list of tiles". The original description of tiles came from this challenge \$\endgroup\$ Commented Feb 5, 2023 at 20:12

Stronger and stronger radiation

This is a challenge where answers create successively more radiation-hardened programs.

The first answer will be a program that is at least 2 distinct bytes long that outputs 1, with an optional trailing newline, and nothing else. However, when any single character is removed, it should output 0. For example, if abc outputs 1, then all of bc, ac and ab should output 0.

The second answer should then be a program that is at least 3 bytes long, with at least 2 distinct bytes, that outputs 2. When any single character is removed, it should output 1, and when any 2 characters are removed, it should output 0. So if abcde outputs 2, then:

  • All of bcde, acde, abde, abce and abcd should output 1, and
  • All of abc, abd, abe, acd, ace, ade, bcd, bce, bde and cde should output 0

And so on such that the \$n\$th answer is a program that is at least \$n+1\$ bytes long, with at least 2 distinct bytes, that outputs \$n\$. When any \$k\$ bytes are removed for \$1 \le k \le n\$, it should output \$n-k\$.

Languages may be reused, but not in consecutive answers. Different versions of the same language count as the same language. You may not answer twice in a row, and you must wait an hour between answers.

The last answer posted is the winner. This will update as new answers are posted, but the latest valid answer will be considered the current winner.


  • Is this clear enough?

  • Tags are , and . Any others?

  • Any additional feedback?

  • I'm concerned that this might be too difficult, and so it's unlikely that more than 2 or 3 answers will be posted. I'm considering changing it to:

    The \$n\$ answer is a program that is at least \$n + 1\$ bytes long that outputs \$n\$. When any \$n\$ bytes are removed, it should output \$n-1\$


  • \$\begingroup\$ An answer isn't allowed to read its own source code, right? \$\endgroup\$ Commented Jun 14, 2023 at 11:33

PETSCII banner

PETSCII on CodGolf.StackExchange

In an other world... I was using a PET 2001 who used some particular PETSCII charset.

The screen green on black, with 40 columns and 25 lines, was only able to display characters from this charset. No way to draw dots or lines...

But in the chaset, there is some and , which, ( by the use of reverse video in order to obtain 16 chars: ' ','▖','▗','▘','▝','▀','▄','▐','▌','▞','▚','▟','▛','▜','▙','█' ) make us able to draw graphics on a 80x50 dots plan.

Using an internal clock triggering IRQ, I've done a animated prompter like this:

Animated display sample Hello world!

The goal of this is to make a similar banner, with same charset, (but using UTF-8 characters: ' ','▖','▗','▘','▝','▀','▄','▐','▌','▞','▚','▟','▛','▜','▙','█'). Warn, this charset use inverted lower/upper cases.

  • This imply the use of PETSCII charset, I will post them there as a json string, before getting this out of the sandbox if some interest...

  • The tool have to change his position 20 time per second.

  • The tool must accept as argument, the string to display.

  • The tool must add date and time in the form - WDay MDay Mnth Year, HH:MM:SS -

  • Scrolling have to be done bit per bit: I.E.: by half character!

  • Shortest code...
    • -3 if size of console is not limited to 40 columns
    • -5 if cpu usage stay less than 90% (On my poor Core(TM)2 Duo CPU E8400 @ 3.00GHz, with 4G ram)
    • -5+ if cpu usage stay less than 50%
    • -5+ if cpu usage stay under 5%


  • 3
    \$\begingroup\$ as for the CPU bonuses - what is the target environment, what is the smoothing factor, and what processes count against this measure? \$\endgroup\$ Commented Dec 15, 2013 at 6:19
  • \$\begingroup\$ This sandbox post has had little activity in a while and little positive reception from the community. Please improve / edit it or delete it to help us clean up the sandbox. \$\endgroup\$
    – user58826
    Commented Jun 9, 2017 at 15:32

Do-nothing Polyglot

This challenge requires you to write a polyglot which contains a comment in as many languages as possible.

The comment must say This is a polyglot comment.

The program must do nothing at all.

Besides comments, your code may contain no-ops from the language(s) you are using, if it helps incorporate more languages into your answers. For example in bash we could use :. Or in the family, something like the following may be used, as long as it compiles:

if (0) {
    statements with side effects

Since this is a challenge, the answer with the most languages wins, so I think this should also be tagged

  • \$\begingroup\$ I think it is funny that the content of the comment makes it so that H9+ cannot be included. Yes, tag it [code-challenge]. \$\endgroup\$
    – Justin
    Commented Mar 16, 2014 at 2:27
  • \$\begingroup\$ Many languages use # or // to signify comments. Perhaps restricting the counting so that each type of comment is counted only once. In other words, //This is a polyglot comment would only count for 1 language, not fo C, C++, Java, ... \$\endgroup\$
    – Justin
    Commented Mar 16, 2014 at 5:13
  • 5
    \$\begingroup\$ What is a "program" for the purposes of this question? In particular, are compiled languages going to be excluded because the compiler won't be able to find an entry point? \$\endgroup\$ Commented Mar 16, 2014 at 17:33
  • \$\begingroup\$ What does no-ops mean? \$\endgroup\$
    – Mohammad
    Commented Mar 18, 2014 at 17:37
  • 3
    \$\begingroup\$ I think that in some esolangs it's not entirely decided what counts as a comment. Maybe you should say that the code must contain the text this is a polyglot comment. \$\endgroup\$ Commented Mar 16, 2017 at 4:24
  • \$\begingroup\$ Thanks! Posting this (after I edit it) \$\endgroup\$
    – user63187
    Commented May 2, 2017 at 20:40
  • \$\begingroup\$ Yeah I removed the post as it was horrible and not well recived \$\endgroup\$
    – user63187
    Commented May 16, 2017 at 15:17


In the near future, the legal world is crumbling. If a case lasts longer than three days, the defendant is assumed to be guilty. Prosecutors create false evidence to get their guilty verdict or flawless record. Defense attorneys are forced to retaliate, claiming that the ends justify the means. In the trials and tribulations of the courtrooms of tomorrow, how will we ever get justice for all? This truly is the dark age of the law.

Luckily, the world has you. Just 11 short years ago, you were a ragtag rookie lawyer in a world of big fish, but you had potential and it showed. You always trusted your client, no matter how bad things looked. You were able to cut through the deception and reach the truth. When times got hard, you forced your biggest smiles. Of course, it was only 3 years before a little misunderstanding cost you your badge, but that's all cleared up now. You're back, ready to protect those no one else will and make miracles happen.

Except... You're pretty sick. For some reason you can't quite remember, you've got a crippling fear of cold medicine. Clearly, you're in no position to stand at the bench. If you can't be there to clear your client's name, you'll have to write a program to do it for you!

For this challenge, you'll be writing a program that can take your place in a cross-examination. There are three different things you need to keep track of: Facts, Evidence, and Statements.

  • Facts
    • There are 26 Facts, named A, B, C... Y, Z. Usually, only a small number of them will be relevant, but you must be able to handle all of them if necessary. Contrary to their name, a Fact can be either True or False.   You are never told the Facts, but you can figure them out from your...
  • Evidence

    • Evidence is the most important thing for you to have, because it's how you know the Facts. You could make the case* that Evidence is everything in court. Pieces of Evidence have a name and a description of their relevance to the Facts. Evidence comes in two flavours: Direct and Circumstantial. Direct Evidence proves a Fact, while Circumstantial Evidence proves a fact if and only if a condition is met.   You get your Evidence as input in this format:

      Direct Evidence
      Name of evidence: [Fact] is <true/false>.
      Circumstantial Evidence
      Name of evidence: If [Fact] is <true/false>, then [Fact] is <true/false>.
  • Statement

    • A Statement is a declaration of Fact by a witness. There are also two kinds of Statements: Absolute and Conditional. An Absolute Statement claims a Fact, while a Conditional Statement claims a Fact if and only if a condition is met. Statements are taken as input in the same format as the second half of a piece of Evidence.

Your job is to analyze your Evidence to determine the Facts, then try to find contradictions in the Statements.

A Statement can contradict either an earlier Statement or a piece of Evidence. If a Fact is proven to be True or False and the witness claims the opposite, that is a contradiction. Note that If A is true, then B is true. and If A is true, then B is false. do not contradict unless A is true.


Input comes from either stdin or a file, in exactly this format:

<One or more pieces of Evidence on their own lines>
<One or more Statements on their own lines>


If there is a contradiction between a proven fact and something the witness claims, you must find the first Statement that contains the contradiction. If it contradicts the Evidence, output this:

Objection! Statement n contradicts this piece of evidence:

followed by a space and the name of the contradicted Evidence. n is replaced with the number of the contradicting Statement (starting at 1). If, instead, the witness contradicts themselves, output this:

Objection! Statement n contradicts statement m.

n is replaced with the number of the contradicting Statement and m is the number of the contradicted Statement (both starting at 1. m < n).

If there are no contradictions, output this instead:

No objections, Your Honor.



My badge: L is true.
Thinker Clock: C is true.
Receipt: If C is true, then W is false.
A is true.
B is false.
If A is true, then W is true.
H is true.
C is false.


Objection! Statement 3 contradicts this piece of evidence: Receipt


Metal detector: B is true.
If B is true, then A is true.
A is false.


Objection! Statement 2 contradicts statement 1.


Stuffed animal tail: N is false
A is true.
N is false.


No objections, your honor.


  • The Evidence will never contradict itself. Evidence is infallible.
  • There will never be a logic loop (e.g. If A is true, then B is true., If B is true, then A is true.)

* If you know what I mean

  • \$\begingroup\$ Objection! According to the first example, If A is true, then B is false is equivalent to If A is false, then B is true, however this would cause the statement about contradictions incorrect. More detail on the first example: C is false, so the assertion from the Receipt doesn't apply; W is true, since A is true. \$\endgroup\$
    – cjfaure
    Commented Jun 4, 2014 at 16:59
  • \$\begingroup\$ Hold it! The Thinker Clock found at the scene proves that C is true! Since we know C is true, the Receipt shows that W is false! The witness claims that A is true in the first line of their testimony, but then says that if A is true, W has to be true! By indirectly claiming that W is true, their testimony contradicts the evidence! \$\endgroup\$ Commented Jun 4, 2014 at 17:09
  • 1
    \$\begingroup\$ Wouldn't the Thinker Clock be the evidence being contradicted, then? There's more direct contradiction between the Thinker Clock and the last statement. \$\endgroup\$
    – cjfaure
    Commented Jun 4, 2014 at 17:14
  • \$\begingroup\$ Of course, saying that C is False is a contradiction... *desk slam* but the challenge requires you to find the first statement to contain a contradiction! [Present -> Challenge Spec] It reads, and I quote, "...you must find the first Statement that contains the contradiction". Take that! \$\endgroup\$ Commented Jun 4, 2014 at 17:21
  • \$\begingroup\$ Ace Attorney strikes again! \$\endgroup\$
    – cjfaure
    Commented Jun 4, 2014 at 17:30
  • 1
    \$\begingroup\$ So basically this is a presentation of 2-SAT. The third example is wrong: statement 2 contradicts stuffed animal tail. And I agree with Trimsty that where you have a chain of reasoning there isn't a unique "contradicted Evidence", so I think that you should make it clearer what you mean by that. \$\endgroup\$ Commented Jun 4, 2014 at 20:48
  • \$\begingroup\$ @PeterTaylor I will figure out a way to formalize it better \$\endgroup\$ Commented Jun 4, 2014 at 20:52
  • \$\begingroup\$ @githubphagocyte Yep, my bad. That was a typo. \$\endgroup\$ Commented Jun 4, 2014 at 20:53
  • \$\begingroup\$ I feel like in many languages this scores for this will be dominated by string handling. \$\endgroup\$ Commented Jun 5, 2014 at 15:57
  • \$\begingroup\$ Hello! This looks like a good but abandoned meta post, would you be willing to offer it for adoption? (If you want to, you can still post to main.) Due to community guidelines, if you don't respond to this comment in 7 days I have permission to adopt this. \$\endgroup\$
    – user58826
    Commented Jun 9, 2017 at 16:48

You say goodbye, and I say hello

In this challenge, you have to make a program that outputs Hello, World!. That's not all though! When the program is reversed, it has to output Goodbye, World!.

Unfortunately, there are a few boring rules:

  • No using comments, i.e., the Python code print"Hello, World!"#"!dlroW ,eybdooG"tnirp is illegal

This is , so try to do it in the least number of bytes.

(Should the forwards/backwards tasks be changed? I think they are probably too easy. Let me know if you have any suggestions.)

  • 2
    \$\begingroup\$ You're missing a golden opportunity to make a Beatles reference. \$\endgroup\$ Commented Nov 4, 2015 at 18:11
  • 2
    \$\begingroup\$ This is a good point. Typically in good palindrome challenges at least comments should be banned; you can take a look at this for some examples of good rules in a palindrome challenge. \$\endgroup\$ Commented Nov 5, 2015 at 21:06
  • 1
    \$\begingroup\$ @quartata Thank you for the example! This is what the sandbox is good for. \$\endgroup\$
    – DanTheMan
    Commented Nov 6, 2015 at 17:35
  • 1
    \$\begingroup\$ Your answer may...? :) \$\endgroup\$ Commented Nov 8, 2015 at 1:07
  • \$\begingroup\$ Do you think I can just go ahead and post this as a challenge? \$\endgroup\$
    – DanTheMan
    Commented Nov 9, 2015 at 18:05
  • 2
    \$\begingroup\$ What counts as a comment? Unexecuted code? Strings which are pushed and never used? etc etc \$\endgroup\$
    – Sp3000
    Commented Nov 10, 2015 at 10:06
  • \$\begingroup\$ I don't think it's too easy. Easy questions get lots of answers and therefore plenty of upvotes for you. That said, there's probably a duplicate or near duplicate out there somewhere. \$\endgroup\$ Commented Nov 16, 2015 at 10:43
  • \$\begingroup\$ it makes lots of language impossible. Maybe comment have penalty \$\endgroup\$
    – l4m2
    Commented Dec 31, 2017 at 14:43

What shape is that polygon?

Given an ASCII figure made of /, \, |, and _, write a program that determines (1) if the figure is a closed, non-self-intersecting polygon (meaning it has at least three sides that connect to form a loop), and if so, (2) how many sides the polygon has and (3) if the polygon is convex (all internal angles are less than 180˚) or concave (not convex, note that no polygons have 180˚ angles).

The multiline input is the ASCII figure. It can be assumed that the input only contains the four characters listed above.

If the figure is not closed or self-intersects (or has more than 2 sides connecting at the same point), the program should print Not a polygon.

The number of sides the polygon has is determined by the following chart.

Sides   Name
3       Triangle
4       Quadrilateral
5       Pentagon
6       Hexagon
7       Heptagon
8       Octagon
9       Nonagon
10      Decagon
11      Undecagon
12      Dodecagon
>12     n-gon (where n is the number of sides)

The output should be in the format <concavity> <polygon name> if (1) is satisfied.

Test cases

 /  \__

==> Concave hexagon


==> Concave 17-gon


==> Not a polygon

/ \
| |

==> Convex octagon

I need a little assistance on getting stricter definitions of points intersecting, so help would be appreciated. Thanks!

  • 1
    \$\begingroup\$ I like the concept of this challenge. A good test case would be including a line that goes inside the polygon as well as lines that doesn't even touch the polygon (unless you are going to guarantee that they will touch) \$\endgroup\$ Commented Dec 6, 2015 at 19:45
  • \$\begingroup\$ Your first two examples look wrong: those polygons are clearly concave. \$\endgroup\$ Commented Dec 7, 2015 at 9:45

Capsa, a card game KotH!

Capsa, known by many times, including the name Big Two in English, is a popular card game in East Asia and South East Asia, especially throughout China, Hong Kong, Indonesia, Macau, Malaysia, Singapore and Taiwan. There are many variations and house rules. The rules of this particular variation are thus:

  • This game will be played between exactly four bots. The cards are dealt between everyone, so that everyone has 13 cards.
  • Rank is ordered with 2s before As as follows: 2, A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, hence, the name Big Two.
  • Suits are ordered as follows: Spades, Hearts, Clubs, Diamonds
  • Ordering runs rank first then suit. Thus, 7 of Hearts > 7 of Diamonds > 6 of Hearts, the lowest card is the 3 of Diamonds, and the highest, the 2 of Spades

You can play cards in sets of one, two or five cards, (singles, pairs, or five-card poker hands). Each set must always be bigger than the one before.

With singles, play may proceed in this way: 1 3H, 2 4H, 3 5D, 4 5C, 1 10S, 2 Pass, 3 JD, 4 Pass, 1 2S, 3 Pass

Pairs are ordered by the higher suit in the pair. 6C6H is of a lower rank than 6D6S. Play may proceed in this way: 3 3D3C, 4 6D6H, 1 6D6S, 2 JHJS, 3 Pass, 4 ADAC, 1 Pass, 2 Pass

Poker hands are ordered in the following way, from lowest in rank to highest in rank:

  • Straight: Five cards that are consecutive in rank, e.g. 6H 7S 8D 9H 10C or JS QH KD AS 2C. Rank is determined by the highest card, with suit used as a tie-breaker.
  • Flush: Five cards with the same suit, e.g. 5H 7H 10H QH AH Rank is determined first by suit, then by highest card.
  • Full house: A three of a kind with a two of a kind, e.g. JD JS JH 3D 3S. Rank is determined by the triple, without regard for the pair.
  • Straight flush: Five cards that are consecutive in rank and are all of the same suit, e.g. 6H 7H 8H 9H 10H. Ranked the same as straights, with suit as a tie-breaker
  • Four-of-a-kind: Four cards of the same rank, with any 5th card, e.g. 9D 9C 9H 9S 4S This hand is known as the bomb. Wins any round of poker hands it is played in, unless someone else plays their own bomb.

Any five-card hand that is higher than the previous five-card hand played is eligible. For example, you can play a full house on a straight.

Rules of play:

  • At the beginning of the game, the cards are dealt between everyone, so that everyone has 13 cards. The first player is the one that holds the 3 of Diamonds and they must play this card first, whether singly, with another 3 in a pair, or in a poker hand.
  • A round begins with the first player playing a single card, a pair or a poker hand. Every other player either respond with the same number of cards (you must play singles on singles, never a pair or a poker hand), or that player passes for that round.
  • A player may pass even when they have a playable card, but they must pass if none of their cards are high enough in rank, that is, if they have no playable cards. For example, in a round of poker hands, if you only have a flush as a five-card set, but another player has already played a full house, you must pass, as your flush is too low.
  • The round ends when all but one player passes. That last player wins the round and starts the next round.
  • The game ends when one player has played all of their cards.

Possible scoring systems:

  • Bots are judged by the number of games they win over (TBD) games that they play. So if we have seven bots to test, we'll play them until every bot has played more than (TBD) games.
  • Bots are judged by the number of cards they have left at the end of the game. (The winner will obviously have 0 cards at the end of the game).

Here is the link to a preliminary controller and two bots to test against.

  • 1
    \$\begingroup\$ "The cards are dealt between everyone, so that everyone has 13 cards" belongs in the "rules of play" section, even if that means having to repeat it. \$\endgroup\$ Commented Dec 30, 2015 at 11:09
  • \$\begingroup\$ @PeterTaylor Done. If you have any comments on the controller linked at the bottom of this post, I'd love to hear them. Thanks \$\endgroup\$
    – Sherlock9
    Commented Dec 30, 2015 at 11:27

Let's Play Unikong

In honor of April Fool's day, we shall have an epic battle to see who can play Unikong best. Or, rather, whose program can play it best.


Write a program in any language to play the game Unikong. It should seek to try and score as high as possible.


Whomever's program has the highest average score, over 10 games wins.


Standard rules apply. Additionally, your program must actually play the game, not change the score variable by some other means, and you can read the variables from the game to avoid trolls and downvotes, but not modify any variables to make it easier. I will run the tests myself and will use the first 10 runs to calculate the score. Please include any specific instructions needed to run your program.

Notes: This would be my first question, so hopefully I got the format right. Are the rules clear enough? Do I need to clarify anything?

  • 2
    \$\begingroup\$ Do not require a video, run the programs yourself and see how far they get without your input. No pressing continue. \$\endgroup\$ Commented Apr 1, 2016 at 17:09
  • \$\begingroup\$ Uh, will that link exist beyond today? If not then I think you'd need to find a way to replicate it (not sure about copyright here...). Anyway, I'm not really sure what counts as cheating. I think it will be hard to ban everything that's bad, so it might be better to write a controller that only allows looking at certain variables and only allows the basic player input. \$\endgroup\$ Commented Apr 1, 2016 at 17:09
  • \$\begingroup\$ @FryAmTheEggman I've changed the link to something that will remain after April Fool's. \$\endgroup\$ Commented Apr 1, 2016 at 22:02

Reverse the lengths


In this challenge, your task is to reverse the lengths of an array-of-arrays, while keeping its concatenation intact.

More explicitly, your input is an array of arrays of nonnegative integers, which you may assume to fit in the native int type of your language. The input may be an empty array or an array of empty arrays, or it may contain arrays of different lengths. You can take the input in any reasonable format.

Your output shall be another array of arrays, again in any reasonable format. The concatenation of the output shall be equal to the concatenation of the input, so it contains the same integers in the same order. However, the sequence of lengths in the output shall be the reverse of that of the input.


Consider the input array

A = [[4,10],[0],[],[3,3,2],[1]]

The concatenation of A is

B = [4,10,0,3,3,2,1]

and its length sequence is

C = [2,1,0,3,1]

The correct output is


since it's the unique array with concatenation B and length sequence reverse(C).

Rules and scoring

You con write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed.

Test cases

TODO: make more

[] -> []
[[]] -> [[]]
[[],[],[1]] -> [[1],[],[]]
[[1,2],[4,5,6]] -> [[1,2,4],[5,6]]
[[4,10],[0],[],[3,3,2],[1]] -> [[4],[10,0,3],[],[3],[2,1]]

Sandbox comments

I'm debating whether I should guarantee that the input is non-empty, and/or only contains non-empty arrays. In some languages (like J), empty arrays make the challenge significantly harder, but on the other hand, I don't want it to be too easy either.

  • \$\begingroup\$ Just an FYI "reshape" operations pretty heavily trivialise this. I don't think it would be crazy to ban them, but it's probably fine with them also. \$\endgroup\$ Commented Jun 7, 2016 at 17:12
  • \$\begingroup\$ I'd prefer the more general challenge of splitting an array the same way as another array of arrays with equally many elements. \$\endgroup\$
    – xnor
    Commented Jun 8, 2016 at 0:28
  • \$\begingroup\$ @FryAmTheEggman I'd prefer not to explicitly ban any builtins. If that leads to 3-byte Jelly answers, so be it. :P I also suspect Jelly would win anyway... \$\endgroup\$
    – Zgarb
    Commented Jun 8, 2016 at 14:35
  • \$\begingroup\$ @xnor That would be essentially be this challenge, but with only arrays-of-arrays. Do you think they would be different enough not to be duplicates? \$\endgroup\$
    – Zgarb
    Commented Jun 8, 2016 at 14:39
  • \$\begingroup\$ Even if the depth is fixed at 2, the shortest approach would most likely still be the be the same in many languages. It's a borderline dupe, and since it takes only one gold badge user to close a duplicate, it will probably end up closed. \$\endgroup\$
    – Dennis
    Commented Jun 8, 2016 at 17:23
  • \$\begingroup\$ @Zgarb I'm not sure if I'd count it as a dupe, but I think reversed input vs general array wouldn't make much difference there. I expect most solutions would just work with the reversed input as if it were a general array. \$\endgroup\$
    – xnor
    Commented Jun 8, 2016 at 20:50
  • \$\begingroup\$ @xnor Reversed input has the added complexity that the same array must be used for content and shape. That's not a big problem for some languages, but I'd expect another approach to outgolf the pop/map approach with the added overhead of creating a second reference for the reversed array in, e.g., Python. I admit I haven't tried it yet though. \$\endgroup\$
    – Dennis
    Commented Jun 9, 2016 at 0:24
  • \$\begingroup\$ I think what you call "concatenation" of the array is called "flattening". \$\endgroup\$ Commented Oct 13, 2016 at 18:24

The Secret Handshake

This is based off of this sandbox comment.

This is a challenge of secrecy.

The goal of this KOTH is to write a program that is capable of identifying itself amongst a crowd of other programs. In order to do this, you must develop a secret handshake which will be recognized only by other copies of the same program.

A single game involves every program competing at once. There will be five instances of each program in the arena, and the winner will be the first program to correctly identify the four other copies. After a large number of games, the submission with the most victories will be the overall winner.

The Gameflow:

  1. Each program receives a number which tells the number of bots in the arena, which is five times the number of submissions. The bots are arranged in a circle, and they are each considered ID #0 from their own perspective, with N-1 being the maximum ID number.
  2. Then the game cycle starts. At this point, each bot will be awaiting input.
    1. Your bot will receive input consisting of an ID number and an optional message.
      • For example, 7 hi means that bot #7 said hi to you.
      • If the ID number is 0, then there will not be a message. This would occur if it is your turn but there is no message to receive.
    2. Now, your bot is allowed to output a guess consisting of four ID numbers.
      • If those four numbers are the IDs of your teammates, then your team will win that game.
      • You will receive no confirmation of an incorrect guess.
    3. Next, you must output a message to send. The message will be a destination ID number followed by up to 3* characters. Example messages: 7 4 w 12 #?Q.

*This number is subject to change. Larger messages make it harder to fake a secret handshake. I hope that a very short message forces people to use multi-step handshakes. It might also be interesting to limit it to 1-character messages.

Sandbox Notes

Something that I haven't quite figured out is how the controller program will determine which bot gets to move each turn. I suppose it would be simplest go in order: Each bot has an "unread message queue" and receives/sends one message each turn. The bot immediately after you (ID #1) then moves next.

Alternatively, there could be a set turn order which is unrelated to the ID order, simply to make it impossible for one bot to tell which bot moves next.

  • \$\begingroup\$ 1. I don't think it needs a turn order: the only problem with adding simultaneous moves would be the need to account for ties. (You are going to run it more than once to pick a winner, right?) 2. I would keep the guess per turn without penalty for guessing wrong. A good strategy will allow a team to win before anyone wins by blind guessing. Too harsh a penalty for bad guesses will bias the game too much in favour of the last person to update their bot so that it fakes the responses of other teams. \$\endgroup\$ Commented Nov 11, 2014 at 10:43
  • 3
    \$\begingroup\$ The idea is quite amusing, but something tells me there must exist a not too hard to find optimal strategy to maximize the chances of winning. The fight would likely occur around sending fake messages to the competitors. Second problem I see is, the first contestants will be at a huge disadvantage since the new players will see exactly how their code works. So much for secrecy. I think the challenge would be more interesting if the code was kept secret, but this is hardly compatible with the spirit of this site. \$\endgroup\$
    – user16991
    Commented Jan 24, 2015 at 6:48
  • \$\begingroup\$ @PhiNotPi are you still interested in this challenge? Would you be willing to allow me to implement this? \$\endgroup\$ Commented Jul 29, 2016 at 20:23
  • \$\begingroup\$ @RohanJhunjhunwala Sure, you can implement this. I don't think I ever started on a controller for it, mainly because I don't think this challenge will be as fun in practice as in theory. \$\endgroup\$
    – PhiNotPi
    Commented Jul 30, 2016 at 13:17

Solve the Nonogram!

It is time to embark on a perilous quest to defeat the British Intelligence. The aim of this challenge is to write the shortest code that will solve a Nonogram.

What is a Nonogram?

Nonogram Puzzle

The rules are simple. You have a grid of squares, which must be either filled in black or left blank. Beside each row of the grid are listed the lengths of the runs of black squares on that row. Above each column are listed the lengths of the runs of black squares in that column. Your aim is to find all black squares. In this puzzle type, the numbers are a form of discrete tomography that measures how many unbroken lines of filled-in squares there are in any given row or column. For example, a clue of "4 8 3" would mean there are sets of four, eight, and three filled squares, in that order, with at least one blank square between successive groups. [1][2]

So the solution to the above Nonogram would be:

Solved nonogram

Implementation Details

You can chose to represent the Nonogram however you would like and take it as an input in whatever way you deem fit for your language. Same goes for output. The aim of this challenge is to literally just get the job done; if you can solve the monogram with whatever output your program gives, that is valid. One caveat is you can't use an online solver :)

You are, of course, free to use any language you want and since this is code golf, the entries will be sorted in the order: accuracy -> length of code -> speed.

This problem is very algorithmically challenging in that there is no completely efficient solution to it and as such, you won't be penalized for not being able to solve larger ones, although your answer will be heavily rewarded if it is able to handle big cases (see bonus). As a benchmark, my solution works for up to roughly 50x50 within 5-10 mins.


I actually learnt about Nonograms from a cryptographic Christmas card released by the British Intelligence here. The first part was basically a massive 25x25 Nonogram. If your solution is able to solve this, you will get kudos :)

To make your life easier in terms of data entry, I have provided how I represented the data for this specific puzzle for your free use. The first 25 lines are the row clues, followed by a '-' separator line, followed by 25 lines of the col clues, followed by a '#' separator line, and then a representation of the grid with the square clues filled in.

7 3 1 1 7
1 1 2 2 1 1
1 3 1 3 1 1 3 1
1 3 1 1 6 1 3 1
1 3 1 5 2 1 3 1
1 1 2 1 1
7 1 1 1 1 1 7
3 3
1 2 3 1 1 3 1 1 2
1 1 3 2 1 1
4 1 4 2 1 2
1 1 1 1 1 4 1 3
2 1 1 1 2 5
3 2 2 6 3 1
1 9 1 1 2 1
2 1 2 2 3 1
3 1 1 1 1 5 1
1 2 2 5
7 1 2 1 1 1 3
1 1 2 1 2 2 1
1 3 1 4 5 1
1 3 1 3 10 2
1 3 1 1 6 6
1 1 2 1 1 2
7 2 1 2 5
7 2 1 1 7
1 1 2 2 1 1
1 3 1 3 1 3 1 3 1
1 3 1 1 5 1 3 1
1 3 1 1 4 1 3 1
1 1 1 2 1 1
7 1 1 1 1 1 7
1 1 3
2 1 2 1 8 2 1
2 2 1 2 1 1 1 2
1 7 3 2 1
1 2 3 1 1 1 1 1
4 1 1 2 6
3 3 1 1 1 3 1
1 2 5 2 2
2 2 1 1 1 1 1 2 1
1 3 3 2 1 8 1
6 2 1
7 1 4 1 1 3
1 1 1 1 4
1 3 1 3 7 1
1 3 1 1 1 2 1 1 4
1 3 1 4 3 3
1 1 2 2 2 6 1
7 1 3 2 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

There can be only 1!

Your task is, given a positive integer n, to generate an expression that equals to the number n.

The catch is: you're only allowed the number 1 in the output.

The operators at your disposal are:

  • +, -, * and /
  • sqrt (as s)
  • ceil and floor (as c and f respectively)
  • ! (factorial)
    • The factorial, in this case, only works for positive integers.

You are also allowed to stack 1's together, so something like 11 is acceptable in the output. However, they count as the same amount of 1's that's in the number (so 11 counts as 2 1's).

You must also include brackets in the output, so that the expression in the output, when executed through the order of operations, will result in the input.


  • Input = 24, one possible output = (1+1+1+1)!
  • Input = 11, one possible output = 11
  • Input = 5, one possible output = c(s((1+1+1+1)!))
    • The ceiling of the square root of 24 is 5.


  • You are guaranteed that the input is a positive integer from 1 to 2^31-1.
  • Your program must work for any positive integer up to 2^31-1, even if they are not tested.
  • Your program must finish processing all outputs for all numbers in the set in 1 hour.
  • The results for every run of the program must be exactly the same - also, no seeds.
  • You are not allowed to have imaginary numbers anywhere in the output (so no s(some negative number)).
  • You are also not allowed to have numbers larger than 2^31-1 anywhere in the output, even when they are sqrted or /ed (so no (((1+1+1)!)!)! or ((1+1+1+1)!)!).

Set of Numbers:

945536, 16878234, 32608778, 42017515, 48950830, 51483452, 52970263, 54278649, 63636656, 78817406, 89918907, 90757642, 95364861, 102706605, 113965374, 122448605, 126594161, 148064959, 150735075, 154382918, 172057472, 192280850, 194713795, 207721209, 220946392, 225230299, 227043979, 241011012, 248906099, 249796314, 250546528, 258452706, 276862988, 277140688, 280158490, 286074562, 308946627, 310972897, 322612091, 324445400, 336060042, 346729632, 349428326, 352769482, 363039453, 363851029, 392168304, 401975104, 407890409, 407971913, 425780757, 459441559, 465592122, 475898732, 482826596, 484263150, 506235403, 548951531, 554295842, 580536366, 587051904, 588265985, 588298051, 590968352, 601194306, 607771869, 618578932, 626776380, 667919873, 681786366, 689854904, 692055400, 697665495, 711608194, 734027104, 750869335, 757710567, 759967747, 777616154, 830071127, 833809927, 835873060, 836438554, 836945593, 863728236, 864158514, 871273503, 881615667, 891619600, 897181691, 918159061, 920521050, 924502226, 929983535, 943162304, 950210939, 950214176, 962610357, 974842859, 988572832

(These are 100 random numbers from 1 to 1 billion.)

Scoring System:

Your score is determined like so:

  • Your program will be tested against the random numbers in the set.
    • You must provide the output generated using the numbers random numbers in the set (either inside your answer or as a pastebin link).
  • Your then have two "scores": A primary score and a secondary score.
    • Your primary score is (no. of 1's in output)*(no. of operators in output). If your primary score is the lowest, you win.
    • Your secondary score is your byte-count, and is only used in the case of a tie-breaker - the person with the lowest byte-count wins.


  • Anything that I need to clear up?
  • Is this challenge a dupe?
  • \$\begingroup\$ Is implicit multiplication allowed? \$\endgroup\$ Commented Sep 11, 2016 at 1:23
  • \$\begingroup\$ @LegionMammal978 No, it is not allowed. You must use *. \$\endgroup\$
    – clismique
    Commented Sep 11, 2016 at 1:43
  • \$\begingroup\$ For the tiebreak, do parentheses contribute to the operator count? \$\endgroup\$ Commented Sep 11, 2016 at 1:49
  • \$\begingroup\$ Does the code need to be deterministic (that is, do random algorithms need to set the PRNG seed to ensure the same results each time)? \$\endgroup\$ Commented Sep 11, 2016 at 1:51
  • \$\begingroup\$ Surely at least one output must be hardcoded? \$\endgroup\$ Commented Sep 11, 2016 at 4:45
  • \$\begingroup\$ Related, though I don't believe it's a dupe. \$\endgroup\$ Commented Sep 11, 2016 at 8:47
  • \$\begingroup\$ code-challenge can't be used along with other scoring tags. \$\endgroup\$ Commented Sep 11, 2016 at 11:18

Telegraphy Golf: Decode Baudot Code


In 1870 Émile Baudot invented Baudot Code, a fixed-length character encoding for telegraphy. He designed the code to be entered from a manual keyboard with just five keys; two operated with the left hand and three with the right:

Baudot 5-key keyboard

The right index, middle and ring fingers operate the I, II, and III keys, respectively, and the left index and middle fingers operate IV and . (Henceforth I'll use their Western Arabic numerals, i.e. 1, through 5.) Characters are entered as chords. To enter the letter "C," for example, the operator presses the 1, 3, and 4 keys simultaneously, whereupon a rotating brush arm reads each key in sequence and transmits a current or, for keys not depressed, no current. The result is, in modern terms, a 5-bit least-significant-bit-first binary encoding, in which our example, "C," is encoded as 10110.

5 bits??

You might be thinking that 5 bits, which can express at most 32 unique symbols, isn't enough for even all of the English letters and numerals, to say nothing of punctuation. Baudot had a trick up his sleeve, though: His character set is actually two distinct sets: Letters and Figures, and he defined two special codes to switch between them. Letter Shift, which switches to Letters mode, is activated by pressing the 5 key alone (00001), and Figure Shift is activated with the 4 key (00010).


Your challenge is to write a program or function that decodes Baudot Code transmissions.

A real transmission would begin with some initialization bits, plus a start and stop bit before and after each character, but we're going to skip those and only worry about the 5 unique bits for each character. Input and output formats are discussed below.

Baudot's Code

There are two different versions of Baudot Code: Continental and U.K. We're going use the U.K. version, which doesn't include characters like "É" from Baudot's native French. We're also going to leave out all of the symbols in the U.K. version that aren't among the printable ASCII characters. You will only have to decode the characters in the table below, all of which are printable ASCII characters except the final three control characters that are explained below the table.

The "Ltr" column shows the characters in Letter mode and "Fig" shows the Figure mode characters:

        Encoding             Encoding
Ltr Fig  12345       Ltr Fig  12345
--- --- --------     --- --- --------
 A   1   10000        P   +   11111
 B   8   00110        Q   /   10111
 C   9   10110        R   -   00111
 D   0   11110        S       00101
 E   2   01000        T       10101
 F       01110        U   4   10100
 G   7   01010        V   '   11101
 H       11010        W   ?   01101
 I       01100        X       01001
 J   6   10010        Y   3   00100
 K   (   10011        Z   :   11001
 L   =   11011        -   .   10001
 M   )   01011        ER  ER  00011
 N       01111        SP  FS  00010
 O   5   11100        LS  SP  00001
 /       11000

The last three rows in the right column are control characters:

  • ER is Erasure. Baudot's telegraphy machines would print an asterisk-like symbol for this character to tell the reader that the preceding character should be ignored, but we're going to be even nicer to the reader and actually omit (do not print) the preceding character. It acts the same in both Letter and Figure mode.

  • FS is Figure Shift. This switches the character set from Letters to Figures. If the decoder is already in Figure mode, FS is treated as a Space (ergo SP in the "Ltr" column). When the decoder is in Figure mode it stays in Figure mode until an LS character is received.

  • LS is Letter Shift. It switches the character set from Figures to Letters. If the decoder is already in Letter mode, LS is treated as a Space. When in Letter mode the decoder stays in Letter mode until an FS character is received.

The decoder always starts in Letter mode.

Here's an example with Figure Shift, Letter Shift, and Space:

01011 10000 00100 00001 00010 10000 11100 00001 10101 11010
  M     A     Y   LS/SP FS/SP   1     5   LS/SP   T     H

This yields the message MAY 15TH. As you can see, the first 00001 (Letter Shift/Space) character acts as a space, because the decoder is already in Letter mode. The next character, 00010 (Figure Shift/Space) switches the decoder to Figure mode to print 15. Then 00001 appears again, but this time it acts as Letter Shift to put the decoder back in Letter mode.

For your convenience, here are the characters in a format that's perhaps easier to digest in an editor, sorted by code:



Input will be a string, array, or list of bits in least-significant-bit-first order. Each character will be represented by a quintet of 5 bits. Bits may be in any reasonable format, e.g. a binary string, an array of 0s and 1s, a string of "0" and "1" characters, a single very large number, etc., as long as it maps directly to the bits of the transmission.

Every transmission will have at least one printable quintet and at most 255 quintets (printable or otherwise), i.e. 5–1,275 bits inclusive.

The input can contain only the bits of the transmission, with two allowed exceptions: Any number of leading or trailing 0 bits and/or, for string input, a single trailing newline may be added to the transmission. Leading or trailing bits or characters cannot be added before or after each quintet, i.e. you cannot pad each quintet to 8 bits or separate quintets with any additional bits, e.g. "01111\n11100".

Notes & edge cases
  1. The transmission will contain only the characters in the "Ltr" and "Fig" columns in the table above. You will never receive e.g. 01110 in Figure mode, because it is absent from the "Fig" column.

  2. It is assumed that the decoder will always be in Letter mode at the beginning of a transmission. However, the first character may be an FS character to switch to Figure mode immediately.

  3. When the decoder is in Letter mode, it may receive an LS character, and when it is in Figure mode it may receive an FS character. In either event a Space character must be printed (see Output).

  4. The ER character will never be the first character in a transmission, nor will it ever immediately follow an LS, FS, or another ER.

  5. An FS character may immediately follow an LS character and vice versa.

  6. Neither the LS nor FS character will be the last character in any transmission.

  7. The / and - characters may be received in either Letter mode (codes 11000 and 10001, respectively) or Figure mode (10111 and 00111).


Output may be in any reasonable format, the most reasonable being ASCII (or UTF-8, for which all of the represented characters are the same as ASCII). Please indicate in your answer if your output is in another encoding or format.

  • The space character (see 3. above) should be an ASCII space (0x20) or your encoding's equivalent, i.e. what you get when you press the space bar.


This is code golf. The shortest code in bytes wins.


  • Standard loopholes are forbidden.

  • Trailing spaces and/or a single trailing newline are allowed. Leading spaces or other characters (that are not part of the transmission) are disallowed.

  • You may not use any built-in or library functions that decode Baudot Code (or any of its descendants, e.g. Murray Code, ITA-1, etc.).

Test Cases

Input: 001101000010100111101110010101
Output: BAUDOT
Input: 11010010001001100011110111101111100
Output: HELLO
Input: 01011100000010000001000101000011100000011010111010
Output: MAY 15TH
Input: 00010001000001000001011101110011100101010010110101010001111100101
Output: 32 FOOTSTEPS
Input: 10110000110101011100111100001111011010000001101110
Output: GOLF
Input: 000100011000001111100000100010110111001100010110010000111111
Output: 8D =( :P
Input: 0000100001000010000100010001111011111011000011100010001
Output (4 leading spaces):     -/=/-
  • \$\begingroup\$ This is quite similar to the Morse decoding question. The main thing it adds is the three control characters. It might be worth adding a cross-reference in a comment after posting the question. \$\endgroup\$ Commented Sep 19, 2016 at 21:56
  • 1
    \$\begingroup\$ Can the transmission start with erasure? \$\endgroup\$
    – Sp3000
    Commented Sep 20, 2016 at 1:00
  • \$\begingroup\$ @Sp3000 No. Good catch. I had a note to that effect but apparently accidentally deleted it. \$\endgroup\$
    – Jordan
    Commented Sep 20, 2016 at 1:07
  • \$\begingroup\$ Can an erasure follow a shift that is acting as a space? \$\endgroup\$
    – Phlarx
    Commented Sep 20, 2016 at 14:16
  • \$\begingroup\$ @Phlarx Nope. ER will never follow LS or FS. \$\endgroup\$
    – Jordan
    Commented Sep 20, 2016 at 14:17
  • \$\begingroup\$ Thank you for your feedback, all. I've posted the challenge: codegolf.stackexchange.com/questions/94056/… \$\endgroup\$
    – Jordan
    Commented Sep 21, 2016 at 13:23
  • \$\begingroup\$ Don't forget to take of this answer in the Sandbox. " 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. " \$\endgroup\$
    – Linus
    Commented Sep 22, 2016 at 19:29

my first post on here, be gentle ;)

Find all anagrams within a text

Somehow I stumbled upon an implementation of a school assignment from about a year ago, and after having seen many amazing and mindblowing code-golf solutions on here, I thought it's time I bring my own challenge and see how much you guys can blow my mind again ;)

The assignment

Given a text, find all words that have at least one other word in the text as an anagram (case insensitive). Multiple occurrences of the same word are not counted.

The output shall be grouped by words that are an anagram of each other.


  • How you handle input/output is up to you. Function-parameters, file-io, standard in/out, whatever works the best for you.
  • You must be able handle any non-empty input as long as you don't run into language or memory limitations.
  • The output does not have any fixed formatting. That means you may put them each group at a line, or put them all at one line but use different delimiters, a 2d array, some other exotic data-structure your language of choice happens to have, as long as it makes reasonable sense, it is considered correct. (This means that for example if you are just writing a function, that function does not need to display the output, it could just provide it as a return-value.) Just keep in mind the requirement that the words that are an anagram of each other should be grouped together.
  • The order in which the output appears does not matter. That applies to the order of the groups as well as the order of the words within the group.
  • A group of only one word is invalid, since that fails the "have at least one other word in the text as an anagram" requirement. (just omit them from your output ^^)
  • Each word should only appear once in the output
  • All interpunction characters are stripped away from the word before checking for anagrams. That means that "it's" and "its" are the same word (and thus both are an anagram of "sit"). My sample program at the bottom uses http://en.cppreference.com/w/cpp/string/byte/ispunct as check if a character is an interpuntion character. If your language has such a method, you may use it. Otherwise take the characters from the default C locale as specified on there:


  • All other characters are part of the word and treated as is, so "a" and "á" are not the same.


Given the following input text (the actual text I was given as example by school :P, no idea where this text is coming from...)

Parts of the world have sunlight for close to 24 hours during summer. Dan went to the north pole to lead an expedition during summer. He had a strap on his head to identify himself as the leader. Dan had to deal with the sun never going down for 42 consecutive days and his leadership strap soon became a blindfold. He wondered what kind of traps lay ahead of him.

the following output would be correct:

  • 24, 42
  • deal, lead
  • and, dan
  • parts, strap, traps

Or this would also be correct:

24, 42 | deal, lead | and, dan | parts, strap, traps

This one would not

24, 42 , deal, lead , and, dan , parts, strap, traps

(since the groups are not obvious)

My own (non golfed) version to check

The is the exact program I submitted to school back then. You may use it to check your own results.

Added bonus: If it happens to be that this program has a bug (I haven't found them yet) your submission is allowed to have it as well, since it is used to check the result. (In that case you are of course not required to have said bugs)

#include <string>
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <algorithm>
#include <cstring>

void stringRemoveInterpunction(std::string& string);
void stringToLower(std::string& string);
std::string stringToAnagramIdentifier(std::string word);

 * due to use of std::ispunct and std::tolower it may not work for text with non-ascii characters??!
int main(int argc, char* argv[]) {
    if (argc < 2) {
        std::cerr << "usage: " << argv[0] << " <filename>" << std::endl;
        return 1;

    std::ifstream fileStream(argv[1]);
    if (!fileStream) {
        std::cerr << "Could not open file " << argv[1] << std::endl;
        return 2;

    // map to store the anagrams, key is so called "anagram identifier", value is a list of the words.
    std::map<std::string, std::set<std::string>> anagrams;

    // read words separated by whitespace from the file
    for (std::string word; fileStream >> word;) {
        // remove interpunction & convert to lowercase, since casing should be ignored
        stringRemoveInterpunction(word); stringToLower(word);

        // add to anagrams-store

    // display all the anagrams
    for (auto anagram : anagrams) {
        // skip entries which contains only one item, no anagrams found
        if (anagram.second.size() <= 1) {

        // output a comma-separated list of the anagrams
        auto anagramIterator = anagram.second.begin();
        std::cout << *anagramIterator++;
        while (anagramIterator != anagram.second.end()) {
            std::cout << ", " << *anagramIterator++;
        std::cout << std::endl;

    return 0;

void stringRemoveInterpunction(std::string& string) {
    string.erase(std::remove_if(string.begin(), string.end(), std::ptr_fun<int, int>(&ispunct)), string.end());

void stringToLower(std::string& string) {
    std::transform(string.begin(), string.end(), string.begin(), std::ptr_fun<int, int>(&std::tolower));

std::string stringToAnagramIdentifier(std::string word) {
    // sort the characters
    std::sort(word.begin(), word.end());
    return word;

Sandbox Questions

  • Do i need to add other tags, or is just code-golf enough?
  • I'm not completely sure about the upper-limit of the input text. My idea was that the code should be able to handle any size input as long as its within the memory-limits of the language. Like you don't have to write "memory optimal code" or something, but also shouldn't asume it is smaller than X. I could also just pick an upper limit of "1 kilobyte" or something to avoid any uncertainty about the requirements I think this is fine now as it is.
  • Someone in the comments below asked how to handle special characters like $?() so I took a look at how my "check program" handled that and it strips them away before doing the anagram check. So I added a rule for that, but while writing that I felt it makes it needlessly complicated and I'm considering ditching that rule and altering my check-program to reflect that (but then I cant claim its the exact same anymore :( )
  • Any other parts that are not clear?
  • \$\begingroup\$ What happens if there are 3 that are anagrams, such as eat ate tea? Are they all printed in one line / group? \$\endgroup\$
    – FlipTack
    Commented Dec 19, 2016 at 17:27
  • \$\begingroup\$ @Flp.Tkc yes, like "parts, strap, traps" in the example \$\endgroup\$ Commented Dec 19, 2016 at 17:29
  • \$\begingroup\$ I suggest you remove the grouping rule, since it's not really the interesting part of the challenge. It just adds code and limits the solutions. It's apparent which of the words that are together anyway. I do suggest they have to be grouped though, but without the need for delimiters. \$\endgroup\$ Commented Dec 20, 2016 at 23:24
  • \$\begingroup\$ I think the memory rule is fine. I'm quite sure people will write a script that in theory would work for any input length if it wasn't for language or memory limitations. I also suggest you guarantee at least one character in the input. Otherwise people would need to add code just to handle empty input and that's not the interesting part of the challenge. \$\endgroup\$ Commented Dec 20, 2016 at 23:29
  • \$\begingroup\$ You should add rules regarding special characters. Are it's, sit and its anagrams? What about hyphens? Can there be any special characters such as $?() etc? How are they treated? \$\endgroup\$ Commented Dec 20, 2016 at 23:31
  • \$\begingroup\$ @StewieGriffin The grouping thing is a natural result of my solution to the problem back then, and imo its a fun part of the challenge, so I'm not totally sure about removing it. About the memory limit: I'm totally fine with the guarantee of at least one character if you think empty input needs special handling (i didnt think it would, but I dont really care :P) And yes, you are correct about special characters. I'd say "it's" is two words: "it" and "s". All special characters are ignored, so essentially regarded as whitespace between words. I'll add that \$\endgroup\$ Commented Dec 20, 2016 at 23:35
  • \$\begingroup\$ welp, turns out I handled special characters differently, I strip them away from the word, so "it's" becomes "its", guess that'll be the rule then since I want to keep as close as possible to the original program \$\endgroup\$ Commented Dec 20, 2016 at 23:48
  • \$\begingroup\$ @StewieGriffin I added a rule about special character handling, but I'm not completely sure about it, thoughts? (see my added "sandbox question") \$\endgroup\$ Commented Dec 21, 2016 at 0:05
  • \$\begingroup\$ parsing and anagrams are relevant tags, maybe strings too, but I'm not sure about that one. \$\endgroup\$ Commented Dec 21, 2016 at 7:43
  • \$\begingroup\$ !"#$%&'()*+,-./:;<=>?@[]^_{|}~ are all the non-alphanumeric ASCII-characters, except \` . I suggest you include the missing two symbols in the list to ignore, and say: "All non-alphanumeric characters (except spaces and newlines) must be trimmed away. So, it's and its are the same word." (You might want to rephrase that since my English isn't perfect, but something along those lines. If this is the rule then R2D2 and dr.22 will be anagrams, I'm not sure if that the desired behavior..? \$\endgroup\$ Commented Dec 21, 2016 at 10:17
  • \$\begingroup\$ PS! I don't mean to be difficult, it's just that in my experience you'll get these questions sooner or later. So it's a good thing to sort it out while it's still in the Sandbox :) \$\endgroup\$ Commented Dec 21, 2016 at 10:20
  • \$\begingroup\$ @StewieGriffin those two characters should have been included, look at the list from en.cppreference.com/w/cpp/string/byte/ispunct where I got it from, somehow I messed up the copy-paste :( And about "what is desired behaviour?" Im honestly not sure, I never really thought about it before you mentioned it and then I looked at how my sample program handled it. I remember putting in the ispunct-trim for stuff like commas after a word, im not sure about characters within the word... \$\endgroup\$ Commented Dec 21, 2016 at 10:26
  • \$\begingroup\$ You can say that the input will not have any special characters except ' and -. Those two must be trimmed away. I think you must include those two, since these can be found in many texts. \$\endgroup\$ Commented Dec 21, 2016 at 10:34

You must log in to answer this question.

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