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

4730 Answers 4730

88 89
91 92

Anti Tic-Tac-Toe

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

The rules are:

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

Then X wins.

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

For example:


Is a bad game.

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

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

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


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

This is , so code in the fewest bytes


Ultra-modular representative of rational numbers


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


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

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

And this number is the representative of the said coset.

I/O format

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


Input -> Output

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

Meta Question

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


Is this a solvable Numberlink?

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

Smallest mudigiply number.


Given a positive integer \$n\$, a mudigiply number of \$n\$ is a number in which the products of its digits equals \$n\$.

For example, the number \$12\$ has the following mudigiply numbers: \$26\$, \$62\$, \$34\$, \$43\$, \$223\$, \$232\$, \$322\$.

Your job is, given a positive integer \$n\$, find its smallest mudigiply number. So for example, the smallest mudigiply number of \$12\$ is \$26\$.


Input/Output can be taken in any reasonable format, taking a positive integer n and returning íts smallest mudigiply number.


Input --> Output 

12  --> 26
18  --> 29
210 --> 2357
48  --> 68
360 --> 589
162 --> 299
480 --> 3458

This is , so shortest answer (in bytes) wins!


  • How should I handle the case where there are no mudigiply number, like \$1910\$? Returning -1, anything, or just say that the input always will have at least a mudigiply number?
  • Any other name than "mudigiply"? Wow I'm really bad at puns.
  • \$\begingroup\$ this is A068189 \$\endgroup\$
    – RubenVerg
    Commented May 24 at 14:52
  • 1
    \$\begingroup\$ I think it's best to make it so that the input always has a valid solution \$\endgroup\$
    – RubenVerg
    Commented May 24 at 14:57
  • \$\begingroup\$ 210 --> 567 and 480 --> 2568 \$\endgroup\$
    – Arnauld
    Commented May 27 at 14:52

Calculating Graph Power


Find characters common among all strings

  • \$\begingroup\$ If flexible with I/O, why are you even mentioning "an array of Strings" and "return them as an array"? \$\endgroup\$
    – Adám
    Commented Jun 6 at 11:44
  • \$\begingroup\$ Thank you Mr. Brudzewsky, I generalized it. ☺️ \$\endgroup\$
    – Mark
    Commented Jun 6 at 12:55

Please let me know if there are any tags or test cases I could add :3

Write in Deranı

Deranı is the constructed writing system used by Toaq, spoken in the fictional country Toaqgua. Its inhabitants have this really good stew and they believe in a hybrid whale/moth, but that's beside the point.

How Latin Toaq works

These letters are consonants: b c ch d f g h j k l m n nh p q r s sh t u ꝡ z '. The character after u is U+A761; its capital is U+A760. You may accept any of v or w or y in addition to or in place of it, but please specify this in your answer.

The vowels are a e ı o u. Note the lack of dot, this is U+0131; again you may accept dotted i. In either case its capital is dotless ASCII I.

There are four* diacritics:

◌́ (acute), ◌̈ (diaeresis), and ◌̂ (circumflex) indicate tone and are placed on the first vowel. These will be precomposed in the test cases, assuming SE doesn't normalize them.

◌̣ (dot below) goes on the first vowel of the last prefix.

  • If the part after the prefixes starts with a vowel, an apostrophe will appear before it: bea- + ebı = bẹa'ebı.
  • Beware that m and q may end a syllable, but q cannot start one; bẹaq'ebı is valid, *bẹaqebı is not, and bẹam'ebı is different from bẹamebı and bẹ'amebı (beam- ebı vs bea- mebı vs be- amebı).
  • If a vowel has both a tone and a dot, it will be represented as the precomposed vowel+tone with a combining dot diacritic (again assumong no normalization weirdness).
  • Per "first vowel of the last prefix" there might be multiple prefixes: be'ẹm'ebı is be- em- ebı, etc.

* Prefix Reform

This is something else you may implement.

In Prefix Reform, the dot below is removed, and the tone mark moves to the first vowel after the affected prefix. If the word had no tone previously, it is given ◌̀ (grave). Any apostrophe after the prefix (except if it ends in m) is also removed:

bẹ'ebı → beèbı
bẹ́'ebı → beébı
bẹq'ebı → beqèbı
bẹm'ebı → bem'èbı

How Deranı works

This is the Private Use Area allocation:

Derani PUA table

Transcript (the font in the image is Derani.ttf available at https://github.com/toaq/fonts/releases/tag/latest):

F16Bx F16Cx F16Dx
0 󱚰 m 󱛀 sh
1 󱚱 final m 󱛁
2 󱚲 b and u 󱛂 q 󱛒 end of prefixes
3 󱚳 p 󱛃 g and o 󱛓 quote
4 󱚴 f and e 󱛄 k 󱛔 subclause boundary
5 󱚵 n 󱛅 ' 󱛕 declarative full stop
6 󱚶 d 󱛆 h 󱛖 other full stop
7 󱚷 t 󱛗 interrogative full stop
8 󱚸 z 󱛘 start of cartouche
9 󱚹 c and ı 󱛙 end of cartouche
A 󱚺 s and a ◌󱛊 rising tone (acute) 󱛚 empty cartouche
B 󱚻 r ◌󱛋 glottal tone (diaeresis) ]󱛛[ compatibility space
C 󱚼 l ◌󱛌 hiatus tone (circumflex)
D 󱚽 nh ◌󱛍◌ hiatus mark
E 󱚾 j ◌󱛎◌ diphthong mark
F 󱚿 ch

Vowels and diacritics

Some letters represent both consonants and vowels. We will call these letters genderfluid. Dealing with ambiguities is done as follows:

  • When the first two letters are genderfluid and only the first is representing a vowel, place an apostrophe (F16C5) before it if one is not already present.
  • The diphthongs, aı eı oı ao, have a diphthong mark (F16CE) inserted between them.
  • Any other adjacent pair of vowels have a hiatus mark (F16CD) inserted between them.

No more than three consecutive vowels will appear, as that is illegal and the toaq police will come after me oh no


ubei, buei, bufi

Note that bufı is unreadable as *bufc due to syllable structure, etc.


Unlike in Latin Toaq, tones go on the first letter regardless of its gender, skipping any apostrophes that may be present (e.g. on ubeı it still goes on the u even though an apostrophe was added).


m at the end of a syllable (followed by a non-vowel) uses the 'coda m' glyph F16B1 instead. ameı uses regular m; am'eı and amfı use coda m.


Commas are used in Latin Toaq to mark subclause boundaries. These are converted into the subclause boundary mark.

Periods are replaced with the declarative full stop, unless they come after any of the words nha ba doa ka (regardless of tone) or are followed by a ] (because there are too many darn speech act particles which is what these are called), in which case they become the 'other full stop' instead.

Question marks are replaced with the interrogative full stop.

For all of these, a space is added before them.


A cartouche references a bound variable. Things that get cartouched are:

  • any word without a tone (or with a grave in Prefix Reform) following a determiner (one of ké báq hú hí já ní níjao níjuı sá sía tú tútu túq ló) with either an acute or circumflex
  • anything in braces {}
  • or shú and the word following it, which is surrounded with the quote mark character. The space is replaced with the compatibility space character.


The empty cartouche character is used when the word after a determiner is a speech act particle or another determiner, or the determiner is followed by a comma. Additionally every asterisk is converted to it, because again there are way too many determiners.


Toaq's method of marking the last prefix is to put a F16D2 after it. Prefix Reform does not affect its presence or placement.


Any single word after or shu, and any text between mo and teo (or momo...teoteo etc), is surrounded with the quote mark F16D3.

Test cases

Input Output
Ma nháo bï zao hôa súq? 󱚰󱚺 󱚽󱛊󱚺󱛎󱛃 󱚲󱛋󱚹 󱚸󱚺󱛎󱛃 󱛆󱛌󱛃󱛍󱚺 󱚺󱛊󱚲󱛂 󱛗
sá poq, ꝡë gı hóa 󱚺󱛊󱚺 󱛘󱚳󱛃󱛂󱛙 󱛔 󱛁󱛋󱚴 󱛃󱚹 󱛆󱛊󱛃󱛍󱚺 
hamụsıq 󱛆󱚺󱚰󱚲󱛒󱚺󱚹󱛂 
Paı súq sá ba. 󱚳󱚺󱛎󱚹 󱚺󱛊󱚲󱛂 󱚺󱛊󱚺 󱛚 󱚲󱚺 󱛖
hıaı 󱛆󱚹󱛍󱚺󱛎󱚹 
Kaqgaı jí, sá ë marao súq da. 󱛄󱚺󱛂󱛃󱚺󱛎󱚹 󱚾󱛊󱚹 󱛔 󱚺󱛊󱚺 󱛋󱚴 󱚰󱚺󱚻󱚺󱛎󱛃 󱚺󱛊󱚲󱛂 󱚶󱚺 󱛕
Amla áma sá nam ka. 󱚺󱚱󱚼󱚺 󱛊󱚺󱚰󱚺 󱚺󱛊󱚺 󱛘󱚵󱚺󱚱󱛙 󱛄󱚺 󱛖
Loı mí Jemu súq nha. 󱚼󱛃󱛎󱚹 󱛘󱚰󱛊󱚹󱛛󱛓󱚾󱚴󱚰󱚲󱛓󱛙 󱚺󱛊󱚲󱛂 󱚽󱚺 󱛖


This is ; shortest answer in bytes wins. Taı ba! (good luck!)


Interpret a Turing Complete Subset of your Language

  • Write a program which can interpret some programs exactly the same way as your (source?) language, where these can be used to model any computation.
  • Demonstrate how to do this.
  • Your Interpreter may have "features" your language doesn't have, but your demonstration may not use them.
  • You may not use a built-in which interprets the source language, like eval()

The feature set does not need to be made of characters or something, you just need to say what it is.

It's until i can think of something better.

Example: a javascript interpreter which only allows String.replace, functions, and the ternary conditional thing ? : may be able to be used as a convoluted slashes emulator.


  • This challenge was originally intended to make all languages equally interesting, but I think it still favors turing tarpits and golfing languages.

  • As with many Challenges which already exist, this one also gives actually interpreted languages kind of a leg up.

  • Making it illegal for turing completeness to arise from interpreter quirks is propably not that important. (like, ACE in my brainfuck interpreter?)

  • Banning eval might introduce rules-lawyering on what eval actually is, like, are Regexes allowed? is a built-in which evaluates arithmetic allowed? I'd say yes. It might also further favor turing tarpits, though it would nerf golfing languages which propably have an eval construct. It might also make the program more laborious to write, obviously, but

  • Allowing eval might make writing the program boring as well, as that's an established technique.

  • Making this is boring, maybe i should make it about the conciseness of an example program? It wouldn't devolve into HQ9+, but its discriminatory, like how is slashes supposed to calculate a factorial? I think is definitely the best option.

  • Adding the stipulation that the interpreter must be able to interpret itself turns this into a completely different, slightly harder, and maybe more interesting problem. For example: this Uiua Program


runs the 2-tag system for collatz sequences (on unary) (on Wikipedia). The corresponding Interpreter for a subset of Uiua which can be used to emulate 2-tag systems could be made to expect the program to be of the form

where A is ⊂:"B" or ⍤,0 any number of times, separated by |
and B is a string of numbers

You may consider this to be boring. I might investigate whether the "self-interpreter" stipulation actually solves this problem.

  • 1
    \$\begingroup\$ Welcome to cgcc, and interesting idea. Can you define "useful" more (maybe even formally)? Also, don't forget to add a winning criterion (such as code-golf) \$\endgroup\$ Commented Sep 26, 2023 at 21:11
  • 1
    \$\begingroup\$ Doesn't this allow someone to claim they are interpreting a subset of JavaScript of the form f=>(<brainfuck interpreter>);f( <brainfuck code> ) and just write a brainfuck interpreter as their submission? \$\endgroup\$ Commented Jun 25 at 11:06
  • \$\begingroup\$ @noodleperson yes, it does. That's what I didn't realize I was also saying and you spelled it out more clearly. The variant where it must be able to self interpret solves this in every language except brainfuck, but it might also make the problem really hard in general. \$\endgroup\$
    – jan
    Commented Jun 25 at 18:14

Minimum number of select-all/copy/paste steps for a string containing n copies of the original


Is it an option for the ls utility specified in POSIX.1-2017?

  • 1
    \$\begingroup\$ I don't think it's relevant to add a bonus related to XSI; bonuses are frowned upon, and it doesn't significantly change the problem. i'm not sure if a new challenge would be that different either, but maybe you can spin it in a materially different challenge. \$\endgroup\$ Commented Jun 27 at 7:39
  • 1
    \$\begingroup\$ d appears twice in the string provided in the output section. \$\endgroup\$
    – Arnauld
    Commented Jun 28 at 8:29

The Winner of a Trick in Zole

The Challenge

Write a function that determines the winner of a single trick in the Zole card game.


The idea for this challenge was suggested by a guy from one chat, who noticed my highly golfed code for this specific task. Initially, I wanted to write a highly optimized code for the task, getting rid of branches and stuff like that wherever I could. At the end, I wrote a proof-of-concept of a code in JS (with the aim to rewrite it later in C and make it truly branchless), and then, just for fun, I golfed the JS code as much as I could. I ended up writing a JS function which is 122 characters long (I'll submit my solution once the challenge is posted). It was a fun challenge for me, hopefully you'll like it as well.

A Short Intro into Zole

For those unfamiliar with Zole, a quick intro into the rules that are necessary for the task - the rules that determine the winner of a single trick. If you are interested, you can find the rest of the rules online, but they are not needed for a challenge.

Zole is a traditional Latvian card game, derived from the family of Schafkopf card games. The exact origins of Zole are unknown. This card game is highly popular in Latvia but is mostly unknown elsewhere.

Zole is played using 26 cards - 14 trumps and 12 non-trumps. The deck includes all Aces, Kings, Queens, Jacks, Tens, Nines, Diamond Eight and Diamond Seven. All Queens, Jacks and Diamonds are trumps, other cards are non-trumps. Each trick in played with each of three players playing one card, one player after another. Meaning, each trick consists of three cards, and the order of the cards in the trick is important. The winner of each trick is determined once all three cards are on the table.

The Rules

The rules of determining the winner are following:

  1. If there is at least one trump in a trick, the strongest trump in the trick wins. This case is the simplest because in Zole, all trumps have different strength, or there's no two trumps of equal strength. Trumps ordered by strength (lowest to highest) are:

7♦, 8♦, 9♦, K♦, 10♦, A♦, J♦, J♥, J♠, J♣, Q♦, Q♥, Q♠, Q♣

Yes, the ten is stronger than the king, and jacks and queens are stronger than the ace. Any trump is stronger than any non-trump. The queen of clubs is the strongest card in the game, and takes any trick it is in.

In case when there's at least one trump, the order of the cards plays no role to determine the winner. The strongest trump wins, the end.


  • 10♦, Q♦, K♣ - The king of clubs is not a trump, and the queen is stronger than the ten, the queen wins.
  • 9♥, A♥, 7♦ - the seven is the only trump in a trick, it wins.
  • J♠, J♣, A♠ - The jack of clubs is stronger than the jack of spades, and the ace of spades is not a trump, the jack of clubs wins.
  1. When there's no trump in a trick, then the suit of a winning card (sometimes called the requested suit) is determined by the first played card in this trick. Cards by strength (lowest to highest) are: 9, K, 10, A (again, the ten is stronger than the king). The strongest card of a requested suit wins. All cards in a trick that are not trumps and are of another suit play no role in determining the winner.

Examples (note that there are no trumps in these cases):

  • 10♥, K♠, 10♣ - Requested suit is hearts, no one added other heart, so the first card (the ten of hearts) wins.
  • 9♠, 10♥, A♠ - Requested suit is spades, the ace of spades is stronger than the nine of spades, the ten is out of suit and plays no role, the ace of spades wins.
  • K♣, 9♣, 10♣ - Requested suit is clubs, the ten is stronger than the nine or the king, the ten wins.

If you understood these rules then it should be clear that there can be no case when the winner is not determined. Your goal is to write a function that gets three parameters (three random cards from 26-card Zole deck) and returns the number of a card that wins the trick (0, 1 or 2).

A Few Test Cases

 K♠  Q♥  Q♦ The winner is 1 ( Q♥)
 K♥  K♦  8♦ The winner is 1 ( K♦)
 K♠  A♣  9♠ The winner is 0 ( K♠)
10♠  9♠  A♦ The winner is 2 ( A♦)
 9♣ 10♣  A♠ The winner is 1 (10♣)
 Q♦  9♦ 10♠ The winner is 0 ( Q♦)
 Q♠  Q♥  J♠ The winner is 0 ( Q♠)
 8♦  A♦  J♣ The winner is 2 ( J♣)
 9♥  A♠ 10♠ The winner is 0 ( 9♥)

Additional Info

For the sake of simplicity, let's assume that the first argument of your function is the first played card in the trick, the second argument is the second card etc. Let's also ignore all the rules regarding who should go first, what cards are allowed to play etc. What we need to know is that any combination of three cards from 26-card Zole deck is theoretically possible in a game (some are just less probable, but we ignore the probability). So, the sought-for function shouldn't follow the whole game, but should simply process one single trick. Or, in our case, three random cards.

You can choose how to define the data type for cards (simple integer, character, object, structure etc). You can be creative in defining cards as integers or similar types. Add the description of your data type in the comment.

Your code need not include the output function - just return 0, 1 or 2. Your code can also ignore the validation and sanitization of the data, let's assume that the data is correct (famous last words), and the input contains three different, valid cards.


Automatic Pikmin Count

Inspired by the feature in Pikmin 4.

In Pikmin 4, you can have up to eight types of pikmin in an onion and up to three types of pikmin outside the onion. Each area recommends three types of pikmin to bring. The onion's interface has an "auto" button which selects pikmin in the following fashion:

  • If possible, select equal amounts of each suggested pikmin type.
  • If there aren't enough of one type, get all of them and equal amounts of the rest (e.g. if 30, 30, 30 isn't possible, it may do 20, 35, 35).
  • If there aren't enough of all the suggested types combined, grab everything there is.
  • If the number of pikmin to select isn't a multiple of three, it grabs more of the kind you have most of (e.g. if the number of pikmin of each type is 300, 200, 100 and it needs to select 100 pikmin, it selects 34, 33, 33)
  • ...unless there's a tie (e.g. if the pikmin counts are 200, 200, 100 and it needs to grab 100 pikmin, it selects 33, 33, 34).
  • If a tie needs to be broken arbitrarily (e.g. a three-way tie), select up to 1 more of the first tied type listed.

The challenge is to write a function or program that takes three inputs: the number of pikmin that can be brought out (an integer in \$\left[0, 100\right]\$), the number of pikmin of each type (eight positive integers), and the recommended pikmin types (three indices into the previous array). You can take the pikmin types as 0- or 1-based indices, and you may assume they are sorted. It should then return an array of eight numbers indicating how many pikmin of each type are to be selected, which will always have at least five 0's. This is , so your score is your answer's length.

Test cases

Using 0-based indices

# to select; counts; indices => selections

100; [400, 450, 300, 250, 100, 30, 0, 10]; [0, 1, 2] => [33, 34, 33, 0, 0, 0, 0, 0]
100; [400, 450, 300, 250, 100, 30, 0, 10]; [3, 4, 5] => [0, 0, 0, 35, 35, 30, 0, 0]
37; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 3] => [12, 12, 0, 13, 0, 0, 0, 0]
38; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 3] => [13, 13, 0, 12, 0, 0, 0, 0]
38; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 2] => [14, 14, 10, 0, 0, 0, 0, 0]
39; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 2, 3] => [15, 0, 10, 14, 0, 0, 0, 0]
39; [30, 30, 10, 20, 100, 5, 1, 100]; [0, 1, 2] => [15, 14, 10, 0, 0, 0, 0, 0]
37; [30, 30, 10, 20, 100, 5, 1, 100]; [2, 6, 7] => [0, 0, 10, 0, 0, 0, 1, 26]
0; [400, 450, 300, 250, 100, 30, 0, 10]; [5, 6, 7] => [0, 0, 0, 0, 0, 0, 0, 0]
20; [400, 450, 300, 250, 100, 30, 0, 10]; [5, 6, 7] => [0, 0, 0, 0, 0, 10, 0, 10]
100; [10, 10, 10, 10, 10, 10, 10, 10]; [1, 2, 3] => [0, 10, 10, 10, 0, 0, 0, 0]

Sandbox questions

  • Besides , what else should this be tagged?
  • I feel like the wording is terrible and I would appreciate help cleaning up the specification and examples
  • Are there any edge cases I missed?
  • What should be the requirements for range for the total pikmin counts? In theory it can be up to 9999 of each type, but practically I don't think I've ever exceeded 500 or 600. Not that this matters for most languages, but I think it's best to be explicit.

Draw a Regular Reuleaux Polygon


Factoriadic Fraction Addition


Given two rational numbers represented in fractional factoriadic as defined below, add them, and output the result in balanced factoriadic.

Fractional factoriadic

Fractional factoriadic is a numeral system that represents every rational number using \$1/2\$'s place, \$1/6\$'s place, \$1/{24}\$'s place and so on (in general, \$1/{n!}\$'s place for each integer \$n \geq 2\$), with these digits of choice:

  • The digit at \$1/2\$'s place may be any integer.
  • The digit at \$1/6\$'s place may be \$1\$ or \$2\$.
  • The digit at \$1/{24}\$'s place may be \$1\$, \$2\$, or \$3\$.
  • The digit at \$1/{120}\$'s place may be \$1\$, \$2\$, \$3\$, or \$4\$.
  • Ad infinitum. In general, for every integer \$n \geq 3\$, the digit at \$1/{n!}\$'s place may be from \$1\$ to \$n-1\$ inclusive.

Mathematical remarks

Fractional factoriadic identifies \$\mathbb{Q}\$ as the direct limit of the following inclusion sequence: $$ \mathbb{Z}[1/2] \to \mathbb{Z}[1/6] \to \mathbb{Z}[1/{24}] \to \mathbb{Z}[1/{120}] \to \mathbb{Z}[1/{720}] \to \cdots $$


Here, the digits are MSD-first.

Fraction = intermediate representation = fractional factoriadic

0 = 0/2 = []
1 = 2/2 = [2]
2 = 4/2 = [4]
3/2 = 3/2 = [3]
-1/2 = -1/2 = [-1]
1/3 = 2/6 = [0, 2]
1/4 = 1/6 + 2/24 = [0, 1, 2]
2/3 = 1/2 + 1/6 = [1, 1]
3/4 = 1/2 + 1/6 + 2/24 = [1, 1, 2]
1/5 = 1/6 + 4/120 = [0, 1, 0, 4]
-1/4 = -1/2 + 1/6 + 2/24 = [-1, 1, 2]
7/3 = 4/2 + 2/6 = [4, 2]
[] + [] = []
[] + [1] = [1]
[0, 2] + [-1] = [-1, 2]
[0, 2] + [0, 2] = [1, 1]
[0, 1, 2] + [0, 1, 2] = [1]
  • 1
    \$\begingroup\$ Why no 1/1's place at the beginning? \$\endgroup\$
    – aeh5040
    Commented 2 hours ago

Reduce a string up to idempotency


Given a string consisting of printable ASCII characters (!0x21 ― ~0x7E), treat it as an element in the free idempotent monoid (as defined below) over the printable ASCII characters, and output the same element represented in the fewest characters as possible.

Free idempotent monoid

You should already know that the free monoid over a set is essentially the set of lists over the set, endowed with concatenation.

The free idempotent monoid is the quotient object of the free monoid that identifies the lists up to idempotency. In laymen's terms, if the list has two or more contiguous sub-lists that compare equal, the sub-lists can be replaced by one sub-list, while retaining overall equivalence of the list.


Here, the strings are double-quoted.

Input -> Output

"" -> ""
"x" -> "x"
"xx" -> "x"
"xy" -> "xy"
"!!?" -> "!?"
"+/+/" -> "+/"
"1+1+1" -> "1+1"
"1+2+1" -> "1+2+1"
"~~~" -> "~"
"TheThem" -> "Them"
"thethem" -> "them"
"cOUgh" -> "cOUgh"
"Xx" -> "Xx"
"198034034" -> "198034"
"...!...!" -> ".!"
"...!...?" -> ".!.?"
"Ook!Ook?" -> "Ook!Ook?"
  • 1
    \$\begingroup\$ Suggested test case: <o><oo> -> <o> \$\endgroup\$
    – aeh5040
    Commented 2 hours ago
  • 1
    \$\begingroup\$ Is it clear that the solution is always unique? \$\endgroup\$
    – aeh5040
    Commented 2 hours ago

Test for Irreducible Complexity (Check for Redundant Characters)

I may need some additional help coming up with the full spec for this competition. As of right now, this is just a concept.

Many interesting questions, such as the "42" question in this sandbox, involve finding the longest program which is not reducible. This means that no set of characters can be removed and still allow the program to function as desired.

The basic idea is that your program will test a Base Program to make sure that it contains no redundant characters. The input will consist of:

  • Base Program (in the same language as your answer)
  • Expected Output

Your program will simply evaluate all possible subsequences of the Base Program and verify that none of them give the Expected Output.

This challenge actually has a utility value to several other challenges. For example, it verifies the results of a "longest non-reducible"-type challenge. In addition, it could make sure that a golfed solution cannot be golfed further.

I assume that the winning criteria will be fastest program, as cycling through all the possibilities takes a long time.


A sequence of length N has 2^N subsequences. Even if each evaluation is done very quickly, it might be unfeasible to test any program with more than 20 or so characters in a reasonable amount of time.

  • \$\begingroup\$ Problem: some subsequences of legitimate answers may be pretty dangerous to the environment. You don't want to eval just everything. \$\endgroup\$ Commented Dec 23, 2013 at 16:59
  • \$\begingroup\$ @JanDvorak Yes that actually is a serious problem. To what extent is it possible to fix that? \$\endgroup\$
    – PhiNotPi
    Commented Dec 23, 2013 at 17:04
  • 1
    \$\begingroup\$ Forbidding any program with dangerous subsequences? :-) \$\endgroup\$ Commented Dec 23, 2013 at 17:05
  • 1
    \$\begingroup\$ A more reasonable (but very difficult) solution would be the requirement to implement a sandbox. \$\endgroup\$ Commented Dec 23, 2013 at 17:07
  • 2
    \$\begingroup\$ Even without dangerous behavior, the halting problem will be an issue: it's hard to tell whether a shortened program will terminate at all, especially for every conceivable input. \$\endgroup\$
    – MvG
    Commented Jan 7, 2014 at 23:49
  • \$\begingroup\$ Are you sure this is possible? The problem of testing if two functions/programs/turing-complete things are equivalent is undecidable - I'm fairly sure it's reasonable easy to constract a brainfuck program that you can't tell if you can remove even a single character. \$\endgroup\$ Commented May 16, 2021 at 4:44
  • \$\begingroup\$ Extending on my previous comment - Let's assume you have a solution to this. Take a brainfuck program you want to test if halts. Let it reduce it, now you have an equivalent irreducible program. Add +. in the end of it, and then try to reduce it again. If the code never halts, that +. is reducible and when you'll run it again it will be removed. Otherwise it's important, so it will be kept. The halting problem is undecidable, therefor this is undecidable. \$\endgroup\$ Commented May 16, 2021 at 4:54
  • \$\begingroup\$ You can also get its undecidablility from that in Unary it will tell you if a given program is minimal, which is known to be undecidable as well \$\endgroup\$ Commented May 16, 2021 at 5:25

Wordlist detector

You are to write a program which, given a list of words, constructs a regular expression to match all these words but nothing else. Both your program and the constructed regular expressions are to be as short as possible.

Input and Output

Input comes on standard input and consists of one line giving n, the total number of words, followed by n lines with one word each. The number of words will be less than 1000, the length of each word less than 30. Words will consist only of lower case ASCII letters, i.e. a-z. You may choose to ignore the first line and use EOF instead to end the list.

Output shall be written to standard output. It consists of a single line, giving a POSIX extended regular expression to match these words and no others. Since input for this regex is not restricted to letters only, elements like . or [^…] won't make too much sense, which limits the language in a natural way. You may choose whether you want to terminate the line with a newline or not. Programs may choose to print multiple lines of output, in which case only the last one will be used for scoring. So you might print intermediate results and continue searching for improvements.

Test cases

Each submission may be accompanied by one regular expression. When scoring the submissions, I'll use this regular expression to reconstruct a word list from it. The code to do this reconstruction can be found at the end of this post. The reconstructed word list must fit the input specification above in terms of word count and length. It would be nice if your own program would be able to regenerate that regular expression from the word list, but that is not a strict requirement. But please don't paste bogus programs just to submit a challenging regular expression, though.

These test cases will be collected and fed to all programs for scoring.


The final score of each program will be the program size plus the size of all its generated regular expressions for the inputs collected from submitted answers, including the example from this question. So short code which produces too long results might get beaten by longer code which generates shorter expressions.

Does this still qualify as ?

Submissions which generate an incorrect regular expression for one of the test cases will be disqualified, as will those which don't terminate in the allotted time. You can use the input reconstruction program below to check whether a produced regular expression does encode the correct word list.


All submissions are welcome, but in order to include your submission in the tournament, it must be executable with reasonable effort on my Linux machine. It shouldn't depend on any exotic libraries, or any specialized ones which take too much work away from your own program. It must operate in reasonable time, say no more than five minutes per input. Your output must be reproducible, so if you use randomization at some point, please seed the randomizer, and please don't terminate an improove loop by a timer measuring execution time or some such.

Tournament times

I'll run the first major tournament two weeks after posting this question. I'll include a table of the results in this question. I'll try to run tournaments repeatedly as late submissions arrive, but I'll not promise any regular schedule.


An very simple example application would be in Python 3 (53 chars):

print('|'.join(input() for i in range(int(input()))))

And here is a test case which could be posted along with the program, although this program obviously doesn't generate exactly this concise output:


The expansion of that expression could be turned into the following example input, which need not be posted as part of an answer since it can be deduced from the regular expression:


Regex expander program

And here is a program to turn regular expressions into word lists, again written in Python 3.

#!/bin/env python3
concat = set(('',))
altin = set(('',))
altout = set()
prev = None
stack = []
regex = iter(input())
for ch in regex:
    if ch == '(':
        stack.append((concat, altin, altout))
        altin = concat
        altout = set()
        prev = None
    elif ch == ')':
        prev, altin, altout = stack.pop()
    elif ch == '|':
        concat = altin
    elif ch == '[':
        ch = regex.__next__()
        cls = []
        while ch != ']':
            if ch == '-':
                crange = range(ord(cls[-1]), ord(regex.__next__()) + 1)
                cls.extend(map(chr, crange))
            ch = regex.__next__()
        prev = concat
        concat = set(w + c for w in prev for c in cls)
    elif ch == '?':
        prev = None
    elif ch >= 'a' and ch <= 'z':
        prev = concat
        concat = set(w + ch for w in prev)
        raise Exception("Illegal input")
if stack:
    raise Exception("Unclosed group")
words = sorted(concat)

This is restricted to the part of regular expression syntax which I expect for this answer. If you have good reason to use something I did not consider, feel free to do so although I will likely have to update this code to cope with it. If you find a bug, please let me know.

  • 2
    \$\begingroup\$ This is just Meta regex golf under the constraint that the two lists between them cover all possible words. Given that some people are tackling that existing question on that basis, this would qualify for closing as a duplicate. \$\endgroup\$ Commented Jan 8, 2014 at 8:45


(at the point, it's just something that came to me before i wake up, so it may need some adjusting, and i'd like some feedback as to if this could be fun)

The code challenge is to write a program that takes as input a calculation in Reverse Polish Notation and outputs the result. It must at least implement + - * /. It So far so easy, but to make it fun and "artistic", the following restriction applies:

  • The source code must rhyme when read. Example in PHP

    $iterator = str_split($a);
    foreach ($iterator as $key=>$value){
        if ($key > 3){

    (the rhyme is on value-virtue)

  • Lines whitout readable characters count as whitespace (the two lines with } in the example)

  • \$\begingroup\$ How does that example rhyme...? \$\endgroup\$
    – Doorknob
    Commented Jan 25, 2014 at 12:54
  • \$\begingroup\$ @DoorknobofSnow well, i'm not really a poet, that's why i propose it as a challenge for others :p. if you have a better example i'll replace it \$\endgroup\$
    – Einacio
    Commented Jan 27, 2014 at 15:58

Implement Kalah

The game of Kalah is a two-player board game in the Mancala family. Your implementation must:

  • Identify the active player ("Player 1" or "Player 2")
  • Display board state (in format specified below)
  • Accept input to allow that player to move (using index system below)
  • Announce a winner ("Player N wins")


Each player has a line of six spaces, called houses, and one additional space called a store. Each space holds seeds, which move from house to house in a counter-clockwise direction. The objective is to fill your store with seeds.

You must represent the board in the following two-row format with stores offset, where HH is a house and SS is a store:


The top row represents the number of seeds in player #1's spaces, and the bottom row represents the seeds in player #2's spaces. The S in each row is the respective player's store (player #1's is top-left, #2's is bottom right). Single-digit values should include a leading space.

In this challenge, user-input will identify each house numerically. Use a left-to-right, indexed-from-one scheme for both sides:

S 1 2 3 4 5 6
  1 2 3 4 5 6 S

Note that the players' stores are not numbered, because seeds placed in the store never move out.


Wikipedia has a good summary of the game and its rules:

  1. At the beginning of the game, three seeds are placed in each house.

  2. Each player controls the six houses and their seeds on his/her side of the board. His/her score is the number of seeds in the store to his/her right. [Clarification: from our perspective, player 1's store is to the left, player 2's store is to the right.]

  3. Players take turns sowing their seeds. On a turn, the player removes all seeds from one of the houses under his/her control. Moving counter-clockwise, the player drops one seed in each house in turn, including the player's own store but not his/her opponent's.

  4. If the last sown seed lands in the player's store, the player gets an additional move. There is no limit on the number of moves a player can make in his/her turn.

  5. If the last sown seed lands in an empty house owned by the player, and the opposite house contains seeds, both the last seed and the opposite seeds are captured and placed into the player's store. [Clarification: moves that end on an opponent's empty house end normally without a capture.]

  6. When one player no longer has any seeds in any of his/her houses, the game ends. The other player moves all remaining seeds to his/her store, and the player with the most seeds in his/her store wins.


(Parenthetical text should not appear in actual output.)

Player 1
 0  3  3  3  3  3  3
    3  3  3  3  3  3  0
> 2                      (prompt arrow and line break
                          are purely optional)
 Player 2
 1  1  0  3  3  3  3
    4  3  3  3  3  3  0
> 4

Player 2  (P2 gets a bonus turn from rule #4)
 1  0  3  3  3  3  3
    4  3  3  0  4  4  1
> 5

Player 1  
 1  0  3  3  3  4  4
    4  3  3  0  0  5  2
> 4

Player 1  (P1 captures P2's seeds in space 1)
 6  0  4  4  0  4  4
    0  3  3  0  0  5  2

Player 2
12  0  0 10  0  1  0
    0  0  0  0  0  1 13
 > 6

Player 1 wins            (because the non-finishing players gets
                          all remaining seeds on their side, it's 23-14)

Meta question: Would this be improved by removing some of the rules?

  • \$\begingroup\$ Do the players run the game once and then take it in turns to take moves, with the process ending only when the game ends? Or do they run the program once per move? \$\endgroup\$ Commented Jan 30, 2014 at 10:06

[This is the first time I'm using the sandbox. I want to get feedback/suggestions before posting the question.]

Make a spider web (standard, orb type) that fills frame in the ratio of n:m, where n, m are input integers. You may use the example below as a model (but you don't need to use labels).

spider web

Your web should have multiple radii, at least 4 of which attach directly to the frame. The remaining radii should attach to the outer outline (perimeter) of the web. The web should have at least 15 radii. The mesh spacing should be more or less uniform spacing (although occasional weaving mistakes" or crossings are encouraged and will receive a bonus).

This is code-golf, so the shortest code (minus bonuses) wins.

Bonuses (to be removed from the number of characters in your code). Bonuses are awarded for the following features that reflect the architecture of an actual web (as opposed to a perfectly symmetric rendering). They are somewhat greater than usual as an incentive for attention to detail and realism.

-mesh spiral instead of concentric circles: 40 pts

-assymmetric web: 31 pts. (e.g. height of capture area greater than width)

-irregularly spaced radii: 42 pts

-distinct segments between radii (straight or crooked, but not the arc of a circle): 32 pts

-outer and inner outline clearly distinct from the spiral: 41 pts

-irregular outer outline: 20 pts

-2 or more easily observable reverses in spiral: 40

The accept will be awarded on Feb. 20, 2014.

  • \$\begingroup\$ If there are bonuses then it isn't code-golf, by definition. It's not clear what output formats are acceptable. I'm not sure what you mean by "distinct segments between radii". "2 or more easily observable reverses" seems problematic: the ease of observing reverses is subjective, and might in addition depend on input and/or on the random numbers obtained. The weighting for the bonuses seems very arbitrary: is there any justification for it? \$\endgroup\$ Commented Feb 3, 2014 at 11:49
  • \$\begingroup\$ Re: bonuses, I should probably decide on the features I want included in the web, thereby eliminating bonuses altogether. Distinct segments means that there should be 2 straight mesh segments between radius n and radius n+2 (not sure whether this should be required in instructions to be updated.) Will give reverses more thought. \$\endgroup\$
    – DavidC
    Commented Feb 3, 2014 at 12:02

Write a PHP Code Golfer

Since my currently daily programming is in PHP, I tend to try the challenges on the site using that language, but frequently I large program because of the verbosity of the language. And then I have to strip it for presentation...

But this is not a tips question, it's an eviscerating challenge.

The objective is to write a program in the language of your choice that takes a PHP file and outputs a golfed valid PHP file with the same functionality.

The scoring will be the average reduction in percent of the result of running the program with 3 selected files (not yet selected, I was thinking of some open source library)

The output file should run on at least 5.4 (so shorthand arrays, function dereference, traits are available)

Since the score is the difference between the ungolfed and golfed files, techniques beyond minifying are encouraged, such as using code subtitution, eval, compression, $$ (variable variables), dereferencing...

Scoring example: The 3 sources have 450, 1200 and 3500 chars respectively

Answer 1
results lenghts: 250, 1000, 3300
reduction: 200, 200, 200 (44%, 17%, 6%) average: 22%

Answer 2
results lenghts: 350, 1050, 3150
reduction: 100, 150, 350 (22%, 13%, 10%) average: 15%

In this case Answer 1 would win, even tough both answers got the same total reduction (-600 chars)

  • \$\begingroup\$ It's a specialisation of codegolf.stackexchange.com/q/3652/194 , so would likely be closed as a duplicate. \$\endgroup\$ Commented Feb 4, 2014 at 22:44
  • \$\begingroup\$ @PeterTaylor I saw it. is similar, but I include an objetive goal and score. have any idea on how to make it more unique? \$\endgroup\$
    – Einacio
    Commented Feb 5, 2014 at 2:43
  • \$\begingroup\$ "Making it shorter" is too broad, can I just delete some comments? If not, can I only shorten one variable and it's ok. It's not very interesting like this... \$\endgroup\$
    – Fabinout
    Commented Feb 5, 2014 at 9:56
  • \$\begingroup\$ @Fabinout the objective is golfing the code. If you only remove some characters, I doubt you'll get a good score \$\endgroup\$
    – Einacio
    Commented Feb 5, 2014 at 15:27
  • \$\begingroup\$ Alright, the criterion is the size of the output source code. good clarification. \$\endgroup\$
    – Fabinout
    Commented Feb 5, 2014 at 15:55
  • \$\begingroup\$ Sum the bytes with the percents or separately? Also, no matter what sources you choose, make sure to paste the code into your questions; who knows when the code in the library will change? \$\endgroup\$
    – Justin
    Commented Feb 6, 2014 at 19:11
  • \$\begingroup\$ i'll edit the bit about scoring (with examples) tomorrow (when i come back to work). I'll post the test sources as a pastebin, but I'll wait to choose them until the question is polished enough and someone consider it interesting enough \$\endgroup\$
    – Einacio
    Commented Feb 6, 2014 at 19:34
  • \$\begingroup\$ Is there anyone more with questions? is still possible that it will be marked as a duplicate? or can i choose the sources and publish it? \$\endgroup\$
    – Einacio
    Commented Feb 13, 2014 at 19:22

Create diagonal code

Your task is to create a program that outputs d=s*sqrt(2).


  • Your program must be at least 4 lines long;

  • d=s*sqrt(2) cannot be hardcoded as is (so using ascii, compression, encoding, etc. is allowed and encouraged);

  • For each line of code n, pick up the nth character. The string obtained this way must be a valid program in a programming language of your choice, that must be different from the one you used for the main program. The obtained program must compile successfully, but it can throw errors, exceptions, etc.;

  • If at the nth line there is no nth character, you can consider that character as a whitespace or a newline. This cannot be done for the first 4 lines, which must be long at least n non-whitespace characters.

  • Your main program must end successfully (no errors, exceptions, etc.);

  • Internet access is forbidden;

  • Most upvoted answer in 2 weeks wins.

Happy coding!

I was unsure about making this a with several bonuses (polyglot answer, secondary program still valid, etc...).

Some bonuses for the code-challenge version:

Your valid answer starts with 0 points. You gain:

+10 if the secondary answer hides a third answer in it;
+15 for any other hidden answer;
+5 for every hidden answer that runs and ends successfully, without any problem;
+10 if your main answer is a polyglot;
+15 for every hidden answer that is a polyglot;

Which version would you prefer? Is there something you would change/improve in this question?

I personally like the one, but the KISS principle (Keep it simple, stupid!) reminds me that I may be wrong.

  • \$\begingroup\$ It's trivial to make the diagonal program be just whitespace (many scripting languages will accept this as a program) or H (valid program in H9Q+). \$\endgroup\$ Commented Feb 26, 2014 at 9:26
  • \$\begingroup\$ Nowhere does it say that the diagonal program must output your magic string: it doesn't even have to execute correctly. Your amendment doesn't really fix things: I can now have the second line be #H, the third be #HH, etc. \$\endgroup\$ Commented Feb 26, 2014 at 9:37
  • \$\begingroup\$ You're right; Don't know why, on a second read I messed up the meaning of your comment. Anyway, I suppose this excludes code-challenge unless I/we don't find a way to avoid such trivial solutions. I guess popularity-contest would still be ok, since more interesting solutions could be found, right? \$\endgroup\$
    – Vereos
    Commented Feb 26, 2014 at 9:41
  • \$\begingroup\$ I think my views on popularity-contest in general are well known. On further reflection, there are enough languages in which any string of bytes is a valid program that I don't think this question can work as is. If you want to save it, I think you need to look at doing something like a very difficult double-quine. \$\endgroup\$ Commented Feb 26, 2014 at 9:49
  • \$\begingroup\$ Thinking about quines and diagonals (which was the "spirit" of the question), what about a sort of mini-quine? The main program would have to display d=s*sqrt(2) only, and its diagonal must reproduce the code used to display the magic string (no comments allowed). It could be tagged code-golf or code-challenge. \$\endgroup\$
    – Vereos
    Commented Feb 26, 2014 at 11:04

Create a Karnaugh-map calculator

Given an input of a truth table, generate a corresponding K-map.


Input will be of the form 10110001 where each bit is a row of a truth table. Count from the left to the right; so that input would be a table of:

i2i1i0 f
0 0 0|1
0 0 1|0
0 1 0|1
0 1 1|1
1 0 0|0
1 0 1|0
1 1 0|0
1 1 1|1

Max 4 variables will be inputted

K-maps (a small explanation):

K-maps are a way of simplifying boolean-algebra expressions.

Let's say we have 4 variables: a, b, c, d. Let the truth-table be 1110101001111111 (and the columns on the truth table be labeled, from left to right: a, b, c, d). Arrange the variables like so:

ab\   00 01 11 10

Note the grey-code counting scheme.

Fill in the table with the corresponding values from the truth table:

ab\   00 01 11 10
   00 1  1  0  1
   01 1  0  0  1
   11 0  1  1  1
   10 1  1  1  1

Group the values in rectangles whose dimensions are the largest possible powers of two. Note that this table signifies a torus, so wrap over the left and right edges.

enter image description here

The expression for the truth table is the ors of the and of the unchanging elements. For this, that would be:

Purple group: ¬b ∧ ¬c (for 0's, make them 1 by notting the value)
Green group: ¬a ∧ ¬d
Black group: a ∧ d
Blue group: b ∧ ¬d

Expression: (¬b ∧ ¬c) ∨ (¬a ∧ ¬d) ∨ (a ∧ d) ∨ (b ∧ ¬d)


  • Generate a 2D K-map (for more variables, add on either side) and show the grouping. K-map must be of the form I used. For less variables, remove rows or columns and change the list on the top left corner.
  • assume alphabetical ordering on the variables, that is, the first variable is a, second: b, third: c, and so on.
  • Also show the expression. Rather than use the unicode characters, the following is permissible:

    ~ instead of ¬
    * instead of ∧
    + instead of ∨

Edit: Possible duplicate: More fun with gates: Karnaugh simplification

  • \$\begingroup\$ I think the grouping is not unique and therefore I might choose the most basic grouping (i.e. none). \$\endgroup\$
    – Howard
    Commented Feb 26, 2014 at 9:02
  • 1
    \$\begingroup\$ Although @Howard's concern is partially answered by "rectangles whose dimensions are the largest possible powers of two", it's not obvious to me why you haven't also circled the entire row 10 and the bottom-right quadrant. \$\endgroup\$ Commented Feb 26, 2014 at 9:29
  • \$\begingroup\$ @PeterTaylor You're right - didn't read that line. But still my main concern is correct: it is not unique. Or as your remark shows it is not optimal if you choose all rectangles. \$\endgroup\$
    – Howard
    Commented Feb 26, 2014 at 9:33
  • \$\begingroup\$ Also for higher number of variables you have to either go to n dimensional K-maps or you won't find all possible rectangles (they are no longer adjacent in the matrix). \$\endgroup\$
    – Howard
    Commented Feb 26, 2014 at 9:38
  • \$\begingroup\$ @PeterTaylor In priority: Biggest rectangles, then least number. That is a big rectangle, but it is redundant with the others because every 1 in it is already circled. \$\endgroup\$
    – Justin
    Commented Feb 26, 2014 at 16:44
  • \$\begingroup\$ @Howard Good point. I'll restrict it to 4 or less variables. \$\endgroup\$
    – Justin
    Commented Feb 26, 2014 at 16:47
  • \$\begingroup\$ For the expression: rather than using A and V, why not * and +? That's fairly conventional use of field notation to represent GF(2). \$\endgroup\$ Commented Feb 26, 2014 at 17:11
  • \$\begingroup\$ Ahem. OR is, of course, not the same as + in GF(2). But * and + is still the conventional notation for operations over the Boolean semiring. \$\endgroup\$ Commented Feb 28, 2014 at 15:31

Title: Implement ROT-13... in ROT-13


Challenge: Implement ROT-13 in code that works as both itself and as the ROT-13 version of itself.


Your score is calculated as a percentage of used, ROT-13 eligible bytes in total of both versions of the program divided by total bytes (all characters) of both versions.

A used, ROT-13 eligible byte is any character that is not part of a comment or ignored by the compiler/interpreter. For example, any character in a brainfuck program that is not +-<>[],. is not considered a used byte, and any character in a C program including and after // or inside /* */ is not considered a used byte. All special symbols in APL are not considered used, as are all characters in a Whitespace program (sorry).

Example scoring:

C: 21/32 = 65.625%

main(){printf("Hello World!");}
  • \$\begingroup\$ Originally this question was ROT-47, not ROT-13. The rules are chosen so that choice of language doesn't easily determine the winner; otherwise, whitespace would easily win. When I changed it to ROT-13 I made only [A-Za-z] count so that a language like golfscript or brainfuck would not automatically score 100%. Looking for thoughts on how to capture the idea without making it too "choice of language" dependent. \$\endgroup\$
    – durron597
    Commented Mar 3, 2014 at 21:13
  • \$\begingroup\$ Just saying, I have a C answer for the 47-version: qp.mniip.com/p/tz pick either of the lines \$\endgroup\$
    – mniip
    Commented Mar 3, 2014 at 21:29
  • \$\begingroup\$ @mniip Okay I undeleted it :) \$\endgroup\$
    – durron597
    Commented Mar 3, 2014 at 21:48

Convert input to ASCII Semaphore

With monitor resolutions getting higher and font sizes getting lower, a good programmer has to make efforts to ensure that output is accessible to the visually impaired. This can be problematic when the only display is in text. Toward this end, your assignment (if you choose to accept it) is to write a program that converts text input into ASCII art flag semaphore.


  1. Your program must accept any letter in the ASCII character set from A to Z (case insensitive) and spaces.
  2. The program can accept input in any way that is convenient for the language it is written in (stdin, command line, file, etc.).


  1. The program should output an ASCII art representation of the input string in flag semaphore. Follow this link to see the expected encoding.
  2. Line feeds and carriage returns should be interpreted as spaces.
  3. Numbers and other non-letters in the input may be ignored.
  4. You may use whatever ASCII art representation of the semaphore sender you like, but it must contain a person holding two flags and have distinct arms, legs, head, and flags. It must be at least 10x10 characters.
  5. Output may be either horizontal or vertical.


Input: Hello


|  |       ###
|__|      ####
         # ###
        #  ###
       /   # #
      /\   # #
     /  \  # #
     \  /  # #
      \/  ## ##
                   /  \
                  /\  /
                 #  \/
           ###  #
           ### #
            # #
         # ###
         # ###
         # ###
         # ###
         | # #
         |__ #
         |  |#
          ## ##
                   /  \
                  /\  /
                 #  \/
           ###  #
           ### #
            # #
         # ###
        #  ###
       #   ###
      /    # #
     /\    # #
    /  \   # #
    \  /   # #
     \/   ## ##
                   /  \
                  /\  /
                 #  \/
           ###  #
           ### #
            # #
         # ###
        #  ###
       #   ###
      /    # #
     /\    # #
    /  \   # #
    \  /   # #
     \/   ## ##
  /  \
  \  /\
   \/  #
        #  ###
         # ###
          # #
|  |       ###
|__|       ###
           # #
           # #
           # #
           # #
          ## ##


This is code golf. Shortest code wins.

  • \$\begingroup\$ define "easily recognisable". Would a simple 3x3 compass (say, with a head if not covered) do? say:.o. -|. /|. ; or even: ... xx. x.. (read by lines, dots represent spaces) \$\endgroup\$ Commented Mar 6, 2014 at 20:16
  • \$\begingroup\$ @JanDvorak Good catch. Edited to include distinct items that must be present and a minimum size. I'm not exactly sure how to make that rule more clear. \$\endgroup\$
    – Comintern
    Commented Mar 6, 2014 at 20:34
  • \$\begingroup\$ Define "person holding two flags". Is what I drew a person? Is this a (lying, due to formatting issues) person: o--? Are three x's on a vertical line a person? \$\endgroup\$ Commented Mar 6, 2014 at 20:43
  • \$\begingroup\$ @JanDvorak Ack! had to many tabs open and forgot to save my edit. I think number 4 for output should cover that. \$\endgroup\$
    – Comintern
    Commented Mar 6, 2014 at 20:47
  • \$\begingroup\$ Define "distinct arms, legs, head, and flags." But I suggest allowing very small figures as well, otherwise this will turn into a kolmogorov-complexity-like question with very little of the code actually involving generating a pair of directions. \$\endgroup\$ Commented Mar 6, 2014 at 20:51
  • 2
    \$\begingroup\$ Very similar to this question. The ascii art is more complex here so perhaps it's not close enough to be called a duplicate... \$\endgroup\$
    – Gareth
    Commented Mar 6, 2014 at 22:20
  • 2
    \$\begingroup\$ I disagree with @JanDvorak: I think this would be better with a fixed output spec which must be followed exactly. That way people can golf their code rather than the output. \$\endgroup\$ Commented Mar 6, 2014 at 23:59
  • \$\begingroup\$ Standard figures seem best to me as well. If you demonstrate a full "clock" of hand positions for the standard figure, then you can require those as output. That's easier to assess than free reign for variations. \$\endgroup\$ Commented Mar 7, 2014 at 0:14

With its strange choice of 9 different characters (plus space and newline), the ASCII art version of the FreeBSD logo has always looked to me as if it might be nicely formatted, obfuscated code is some programming language. (Is it?)

 ```                        `
s` `.....---.......--.```   -/
+o   .--`         /y:`      +.
 yo`:.            :o      `+-
  y/               -/`   -o/
 .-                  ::/sy+:.
 /                     `--  /
`:                          :`
`:                          :`
 /                          /
 .-                        -.
  --                      -.
   `:`                  `:`
     .--             `--.

Therefore I would like to challenge you to make it one: Either specify minimal changes to an existing programming language or minimal changes to this piece of ASCII art (making the artwork look different or significantly changing the character set used are definitely major changes), so that the logo, as source code generates meaningful output.

This should be a challenge, although I wouldn't mind some way of introducing hard scoring and run this as .


King of the Hill Fighting

In this game, a player controls 5 bots that attack the other players 5 bots. Each bot has life points, and has to reduce the other playres lifepoints to zero. This post is program that tests the controllers. It is in literate haskell.

> import Data.Set as S
> import Data.Map as M

Here is the arena:

   /|   |\
  B |   | J
 /|\|   |/|\
A | E---H | L
 \|/|   |\|/
  C |   | K
   \|   |/
20  12    4
  16    8   0

Positions are denoted by letters

> data Positions = A | B | C | D | E | F | G | H | I | J | K | L deriving (Show, Read, Eq, Ord)

Each player is presented a map in which their side is the one with A. Here is code that will reflect it so each player sees their own view.

> pairFlip = (\(x, y)->[(x,y), (y,x)])
> reflect = M.fromList $ [(A,L), (B,J), (D,G), (C, K), (E, H), (F, I)] >>= pairFlip

Lines denote connections.

> connections=S.fromList $
>   [(A,B), (A,C), (B,D), (C, F), (E, D), (E, F), (D, G), (E, H), (F, I)]
>   >>= pairFlip
>   >>= (\(x,y)->[(x,y), (reflect ! x, reflect ! y)])
> connected x y=(x, y) `S.member` connections

The numbers below are the number of life points of generation that each bot.

> regen = M.fromList $
>   [ (A, 20), (B, 16), (C, 16), (D, 12), (E, 12), (F, 12)
>   , (G, 8), (H, 8), (I, 8), (J, 4), (K, 4), (L, 0)]
  • \$\begingroup\$ Is there supposed to be a specification hidden in here somewhere? \$\endgroup\$ Commented Mar 14, 2014 at 16:30
  • \$\begingroup\$ @Peter Taylor Just not done yet. \$\endgroup\$ Commented Mar 14, 2014 at 16:44
  • \$\begingroup\$ You won't get lots of answers if it's limited to Haskell. \$\endgroup\$
    – ugoren
    Commented Mar 14, 2014 at 17:57
  • \$\begingroup\$ No no no, the above post is also a program for testing it. I will add in code that can take arbitrary programs and use them. \$\endgroup\$ Commented Mar 14, 2014 at 21:17

Create the perfect CSS reset stylesheet

Your job is to create a CSS reset stylesheet, That is, a stylesheet that you can apply to any HTML file, and the result will look the same in all webbrowsers. Because we all know that cross-browser interoperability is very important these days, and you want to make your website look pixel perfect everywhere.

The rules:

  1. You must be able to throw any valid HTML5 document at it and the result will look the same in the main browsers.
    For simplicity, you can assume that the HTML document does not contain any styles of its own or Javascript that changes anything. Just pure, static HTML that is valid HTML5.
  2. The main browsers are Firefox >= 22, Chrome >= 28 and IE >= 10.
  3. To avoid solutions like *{display:none} (which do indeed make all documents look the same in all browsers, yes) the result must be identical to the document without the stylesheet in one of the browsers.
    In other words, take your browser of choice and make the document look like that in the other browsers.

The winner is the stylesheet that works the best, again, on any HTML file that is valid HTML5 and uses no other styles. I'm not looking at efficiency. If you come up with a 100K stylesheet or one that slows the site down considerably, that doesn't matter, as long as the end result looks good.

That's the question so far. Now I have a bit of a problem with "any HTML5 document"; I know I could provide a test document that people can work with, but then you'll get answers that cater to only that particular test case, and that's not what I want. Not sure how to handle this. Ideas?
Also, I want to include Safari as a main browsers, but as I don't have a Mac, I can't test the results on it. Not sure how to handle that.

  • \$\begingroup\$ necolas.github.io/normalize.css ? \$\endgroup\$ Commented Mar 14, 2014 at 12:59
  • \$\begingroup\$ @PeterTaylor That breaks rule #3. \$\endgroup\$
    – Mr Lister
    Commented Mar 14, 2014 at 13:05
  • \$\begingroup\$ The result must be identical to the document without the stylesheet in one of the browsers. I assume you have loaded a webpage without a stylesheet before? If you mean that it can have the main stylesheets, and we just need to create a modification stylesheet, you should specify that. \$\endgroup\$
    – user10766
    Commented Mar 14, 2014 at 16:17
  • \$\begingroup\$ @hosch250 What I mean is that I want the document to retain its basic HTML-ness, so it shouldn't look like plain text. Take this fiddle for example; open it in all browsers, and then add CSS to it so that it looks like (your favourite browser) in all other browsers. If the name of such is "modification stylesheet" rather than "reset stylesheet", I apologise. \$\endgroup\$
    – Mr Lister
    Commented Mar 14, 2014 at 19:32
  • \$\begingroup\$ OK, I was thinking about how most HTML pages rely on CSS stylesheets to even be legible. If you took the CSS sheet off any webpage, it would not look the same; in fact, if the HTML wasn't laid out good using accessibility techniques, it wouldn't be legible. \$\endgroup\$
    – user10766
    Commented Mar 14, 2014 at 20:01
  • 2
    \$\begingroup\$ Pixel perfect isn't going to happen because of issues around anti-aliasing: CSS doesn't let you do things like enable ClearType on Safari/OS X or disable it on IE/Win. So the best anyone can do is somehow obtain the default stylesheets for the listed browsers (e.g. iecss.com but updated) and then find a minimal diff. \$\endgroup\$ Commented Mar 14, 2014 at 20:09
  • \$\begingroup\$ Guys, I'm not interested in solutions to the question right now. I want to know if the question is OK! Specifically if I can get away with not posting a testcase like the fiddle above. \$\endgroup\$
    – Mr Lister
    Commented Mar 14, 2014 at 20:38

music theory challenge

Create a program that takes some input in the form of frequency, waveform, and duration that generates an audio stream based on the input.

You can take input parameters however you choose, but if I input (translated to your method) 440Hz, sin(x), 3 seconds, your program should play or create a file for a sound 3 seconds long at 440 hertz on a sine wave.

Also, any output should be musically correct as far as frequency is concerned. See http://www.phy.mtu.edu/~suits/notefreqs.html for example frequencies

Since this is a popularity contest, the rest is up to you. I bid you Good programming!

Oh, and any use of external functions or APIs is ok, as long as they weren't developed specifically for this contest.

  • \$\begingroup\$ If the program takes "input in the form of frequency, waveform and duration" then where do linear functions fit? What do you mean "output should be musically correct as far as frequency is concerned" given that the input is frequency? Is it supposed to correct the input: "You said 494Hz but you must mean 493.88Hz"? And simple synth has been done before in various guises: see music. To differentiate this and make it non-trivial you could perhaps specify a set of basic synth operations which need to be configurable (e.g. input specifies generators, envelopes, filters, mixers). \$\endgroup\$ Commented Mar 14, 2014 at 8:39
  • \$\begingroup\$ On second thoughts, that would probably work better as a Code Review Code Challenge \$\endgroup\$ Commented Mar 14, 2014 at 9:23
  • \$\begingroup\$ @PeterTaylor I didn't even know about Code Review Code Challenges <intrigued>. Linear isn't the right word...and I think that statement is redundant anyway, so I'll nix it. \$\endgroup\$ Commented Mar 14, 2014 at 12:44
  • \$\begingroup\$ Actually, I'm going to re-write this challenge...I don't know yet whether it'll be here of on CR \$\endgroup\$ Commented Mar 14, 2014 at 13:07

Calculate pi using a unique method

Your task is to calculate or approximate pi using the most interesting method you know. Well-known things such as using inverse trig functions (asin, acos, atan) or commonly used convergent series are considered uninteresting.

You may calculate pi to any precision desired, but the more precision you can achieve, the better.

  • \$\begingroup\$ I couldn't find an exact duplicate of this, but I'd like to know if this overlaps too strongly with an existing question. \$\endgroup\$ Commented Mar 14, 2014 at 18:51
  • \$\begingroup\$ If you rule out convergent series, what's left? \$\endgroup\$ Commented Mar 14, 2014 at 20:02
  • \$\begingroup\$ @PeterTaylor If someone knows of a convergent series that isn't on Wikipedia, that would make a good answer. I know of an answer that does not use trigonometry or an approximation, but calculates the digits directly. \$\endgroup\$ Commented Mar 14, 2014 at 20:08
  • \$\begingroup\$ Is it in mathworld.wolfram.com/PiFormulas.html ? I've got some ancient code which uses a spigot hypergeometric evaluator to compute pi as 3*F(1/2, 1, 1, 8/5 ; 3/5, 4/3, 5/3 | 2/27), but I would expect that to count as well-known. \$\endgroup\$ Commented Mar 14, 2014 at 20:11
  • \$\begingroup\$ @PeterTaylor I'm familiar with it in layman's terms only, but I don't see it there. It could be related to some of them, but I don't see more than a small resemblance. It isn't original with me, BTW. \$\endgroup\$ Commented Mar 14, 2014 at 20:22
88 89
91 92

You must log in to answer this question.

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