What is the Sandbox?

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

To post to the Sandbox, scroll to the bottom of this page or click on the "Add Proposal" link below, and click "Answer This Question". Click "OK" when it asks if you really want to add another answer. Write your challenge just as you would when actually posting it. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it. When you think your challenge is ready for the public, go ahead and post it, replace the post here with a link to the challenge and delete it.

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

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

Add Proposal

Search the Sandbox

Browse your pending proposals

Get the Sandbox Viewer to view the sandbox more easily

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

  • \$\begingroup\$ How are tags added to questions? \$\endgroup\$ – guest271314 Jan 9 '19 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 '19 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – S.S. Anne Sep 26 '19 at 15:57
  • 1
    \$\begingroup\$ @JL2210 We now have a permanent info box that links to the Sandbox, so the featured tag isn't necessary \$\endgroup\$ – caird coinheringaahing Sep 29 '19 at 13:43

2665 Answers 2665


Originally posted on main site, moved here for more suggestions. Better scoring mechanics required.


I've been browsing all those challenges and was thinking "yeah, they're good, but what if we make GoL one?", so here it goes.


Build starting setting for either Conway's Game of Life or other similar cellular automaton (restricted to ones with binary cell state) which after known amount of generation will include square area containing representation of QR code decodable to string "Hello, world!".

  • Cell (non-empty state) is interpreted as black pixel, no cell as white.
  • Your automation should take at least one generation until result (no hardcoded results allowed).
  • Your automation operates on infinite board.
  • Not sure if this option will be useful, but you can specify scaling ratio: single integer, setting side of square encoding single pixel. Pixel's color is color of cell dominating by count in it (you can specify 50/50 edge case resolution in your answer). Obviously, in this case side of output area should be proportional to scaling ratio. This option doesn't affect scoring.
  • It's not necessary, but nice to provide either link to online demo or .rle file.

Example result

enter image description here

Decodes to "Hello, world!"


Your score is calculated as

score = (initial amount of cells)^2*(number of generations until result) + (number of cells out of output area)*5

Lower score is better.

Happy GoLfing!

  • 1
    \$\begingroup\$ I think this challenge is interesting, although I suggest that the scoring criterion be a combination of the number of initially on cells and the number of generations necessary to get to the final output, without counting the number of on cells in the output (otherwise there's an aspect of QR code golf in the challenge as well, which complicates matters more). Also, I don't really understand the 4th bullet point. Finally, you seem to want to allow different binary cellular automata to compete, just like different languages. Is this true? \$\endgroup\$ – Erik the Outgolfer Jul 14 '19 at 22:48
  • \$\begingroup\$ @EriktheOutgolfer Why would including amount of cells out of output area be bad? It only counts cells which aren't part of QR code, so it seems acceptable. 4th point may probably need some illustrations to make it easier to get (or just remove that). You got the last part right. \$\endgroup\$ – val says Reinstate Monica Jul 14 '19 at 23:34
  • \$\begingroup\$ Oh, I misread the "out of output" part. So you allow extraneous on cells outside of the QR code with a penalty? \$\endgroup\$ – Erik the Outgolfer Jul 14 '19 at 23:36
  • \$\begingroup\$ @EriktheOutgolfer I think that is more or less fine to have some cells on field as long as output in specified area is correct by itself. \$\endgroup\$ – val says Reinstate Monica Jul 14 '19 at 23:37
  • 2
    \$\begingroup\$ Could you clarify what classes of automata are eligible? You've specified only binary (two possible cell states). What neighbourhoods are valid? Only the standard 3 by 3 Moore neighbourhood, or also other size and shape neighbourhoods like Von Neumann neighbourhoods? Must all cells in the neighbourhood contribute equally to the outcome (a totalistic automaton) or can different patterns of the same number of "on" cells give different results? \$\endgroup\$ – trichoplax Jul 16 '19 at 21:06
  • 1
    \$\begingroup\$ Where you choose to draw the line is entirely up to you, but it could have a large effect on the nature of the challenge. For example, if arbitrary size and shape neighbourhoods are allowed, with rulesets based on the arrangement of "on" cells rather than just how many are "on", it may be possible to choose a ruleset that gives the output in a single step (maybe - I haven't thought it through). Whether you see that as a bad thing or an interesting way of solving the challenge will determine how restrictive you choose to be. Personally I'd stop short of allowing quite that much flexibility... \$\endgroup\$ – trichoplax Jul 16 '19 at 21:09
  • \$\begingroup\$ Is there a standard for QR that avoids all disagreement as to what's a valid code? On further thought, it might be better just to requre a fixed output pattern, like some pixel version of Heelo World, and not have the whole QR layer. \$\endgroup\$ – xnor Jul 16 '19 at 21:35
  • \$\begingroup\$ In particular, following @xnor's comment, does "decodable to" mean that errors are allowed as long as they're below the threshold for correction? \$\endgroup\$ – Peter Taylor Jul 17 '19 at 10:55

How long's left?

Posted here.

  • \$\begingroup\$ Shouldn't the third test case be FifTy Nine MiNutes And ForTy Six SeConds? \$\endgroup\$ – Erik the Outgolfer Jul 9 '19 at 19:26
  • \$\begingroup\$ @EriktheOutgolfer Thanks, fixed \$\endgroup\$ – Geza Kerecsenyi Jul 9 '19 at 19:27
  • \$\begingroup\$ @Shaggy the challenge here isn't to calculate the number of syllables: it's to find the first number that has the same number of syllables as the distance from the current time. \$\endgroup\$ – Geza Kerecsenyi Jul 11 '19 at 21:14
  • \$\begingroup\$ Ah, OK, I get it now. Yeah, I think that's sufficiently different, so; ignore my previous comment! \$\endgroup\$ – Shaggy Jul 11 '19 at 21:17
  • \$\begingroup\$ Could you please clarify how many syllable each number has? (A list should help.) \$\endgroup\$ – tsh Jul 12 '19 at 7:38
  • \$\begingroup\$ @tsh done, see now. \$\endgroup\$ – Geza Kerecsenyi Jul 12 '19 at 15:05

Irish Snap: Variant Rules


Recently, me and a couple of my friends decided to play some cards, and one of them suggested the game 'Irish Snap', which was the inspiration for this challenge. However, I later learnt that the game has a lot of different rules that work ,some of which are listed here. The rules that are in this challenge aren't currently listed on that page, hence the name, 'Variant Rules'

The Challenge

Given an array of 3 cards, output a truthy or falsey value depending on if they make a valid snap in a game of Irish snap.


The input will be an array of 3 numbers, ranging from 1-13 inclusive, with 11 being jack, 12 being queen and 13 being king. The last number in the array will be the number at the top of the stack of cards.


The 4 different criteria for if cards make an Irish snap are a snap:

  • The top and middle cards are the same
  • The top and middle cards have a difference of one
  • The top and bottom cards are the same
  • The top and bottom cards have a difference of one

If any of these criteria are met, you must output a truthy value. As well as this, for the two criteria that require the cards to have a difference of one, it 'wraps around', meaning that an ace and a king are considered to have a difference of one, and vice versa.

Test Cases

Input -> Output
1 13 7 -> False
1 4 13 -> True
9 3 6 -> False
8 9 7 -> True
2 6 5 -> True
12 5 11 -> True
10 4 8 -> False
12 13 7 -> False
9 7 10 -> True
7 3 1 -> False
  • 1
    \$\begingroup\$ Wikipedia describes a substantially different game under the same name. Is there any less ambiguous name for this? \$\endgroup\$ – Peter Taylor Aug 6 '19 at 8:27
  • 1
    \$\begingroup\$ Although I don't think there is a less ambiguous name for it that I can find, the version I described is a combination of the alternate rules listed below the section you linked: 'conventional snap', 'runs', 'sandwiches' and the last rule I listed is basically a combination of 'runs' and 'sandwiches'. How could I change the name to reflect this? \$\endgroup\$ – EdgyNerd Aug 6 '19 at 8:38
  • \$\begingroup\$ Should I change the name to "Ultimate Snap", as that's what Wikipedia says those rules are commonly referred to as? \$\endgroup\$ – EdgyNerd Aug 6 '19 at 8:42
  • 1
    \$\begingroup\$ I think runs as described requires all three cards and in the right order. Maybe "Irish snap: variant rules" would be a suitable title, and the introduction can reference Wikipedia and say that the exact rules we'll be using aren't listed (at time of writing the question). \$\endgroup\$ – Peter Taylor Aug 6 '19 at 8:49
  • \$\begingroup\$ Ok, I've added in all of those suggestions \$\endgroup\$ – EdgyNerd Aug 6 '19 at 11:23
  • 1
    \$\begingroup\$ As our token Irishman, I endorse the keeping of "Irish Snap" in the challenge name! \$\endgroup\$ – Shaggy Aug 7 '19 at 21:22
  • \$\begingroup\$ Do you think I'll be able to post this now? \$\endgroup\$ – EdgyNerd Aug 20 '19 at 9:44

Find the Lowest Common Ancestor of Two Nodes In A Binary Tree

Any two separate nodes in a binary tree have a common ancestor, which is the root of a binary tree. The lowest common ancestor(LCA) is thus defined as the node that is furthest from the root and that is the ancestor of the two nodes.

The following are binary trees and the lowest common ancestors of the some of their nodes.

Binary Tree 1

The LCA of 13 and 15 is 14.

The LCA of 47 and 49 is 48.

The LCA of 4 and 45 is 40.

The LCA of 13 and 14 is 14.


Write the shortest program possible that accepts as input the root of a binary tree and references to any two nodes in the binary tree. The program returns a reference to the LCA node of the two inputted nodes.


The binary tree does not have nodes with parent field references in any form. You may not use parent field references in your program.


The root of a binary tree and references to any two nodes in the binary tree. This may be in the form of a reference to the root object or even a list that is a valid representation of a binary tree.


Returns a reference to the node that is the LCA of the two inputted nodes.

Definition of a Binary Tree

A tree is an object that contains a value and either two other trees or pointers to them.

The structure of the binary tree looks something like the following:

typedef struct T
   struct T *l;
   struct T *r;
   int v;

If using a list representation for a binary tree, it may look something like the following:

[root_value, left_node, right_node]
  • 2
    \$\begingroup\$ I mostly like your binary tree questions, but it would be nice if your definition was more inclusive of languages without the concept of pointers. Something like 'input will be a tree where a tree is either something containing a number and two other trees, or else something representing nothing. A tree must not be ambiguous'. This would include strings like [5[][7[6[][]][8[][]]], where a tree is [number tree tree] or [] as well as the usual standard binary tree structures and lists \$\endgroup\$ – Jo King Aug 9 '19 at 6:45

Truth Table Composition

Given 2 or more truth tables, output the "shortest" way to compose the first N-1 tables to form the last (Nth) table.


  • Standard loopholes/io rules apply.
  • Input is a "list" of truth tables
    • A truth table is a "list" of rows that contain the inputs and the corresponding output
      • The input will always be the same length for a given table
      • There must be \$ 2^N \$ rows in a given table, where N is the number of inputs in the table
      • Each row must have distinct input
      • Inputs and outputs must both be "booleany" e.g.:
        • true/false
        • 1/0
        • truthy/falsey
        • "Bob"/"Sally"
    • The input can be in any reasonable format.
      • Any of the formats shown here are reasonable.
      • Taking the output first (ie for &: 1,1,1;0,0,1;0,1,0;0,0,0) is reasonable.
      • Input that requires non-trivial logic to convert is not reasonable.
      • When in doubt, ask in the comments.
  • Output is a "nested structure"
    • Each level of the nest contains information of the:
      • Truth table that was used
      • The ordered inputs (of this structure)
    • If a node is a leaf (one of the inputs to the final truth table) it must:
      • Be distinguishable from the other nodes
      • Contain the index of the input to the final table
    • Output format must be reasonable (see details under input)
  • "Shortest" is measured by the number of nodes in the output structure.
  • It will always be possible to construct the last table with the first N-1.
  • You do not need to handle invalid input.
  • This is , so the answer with the smallest asymptotic time complexity wins! Answers that do not aim to be efficient are also welcomed.

Yes, I'm done with rules now. Sorry.

Test Cases

For these test cases, the output is explained below. Note that this is not the output format you have to use! - $N is the Nnt input to the final table (0-indexed) - N(...) is the Nnt input table applied to ... (also 0-indexed) - Arguments are comma separated and are in this format. - Note that N() is different from $N; the former is the Nnt truth table applied to nothing (only valid in the case of truth tables 1 and 0), and the latter is the Nnt input to the final table.


1 0 0
0 1 1
0 0 0
1 1 1

$1 (length 1; leaf; gives the second input)
1 0
0 1

1 1 1
0 0 1
0 1 0
1 0 0

1 0 1
1 1 0
0 0 1
0 1 0

0($1) (length 2; the first table (not) applied to the second input)
1 0
0 1



0(1()) (length 2; the first table (not) applied to the second table (true))
0 1
1 0


1 0
0 1

0($0) (length 2; the first table (not) applied to the first input to the final table)
0 1
1 0

1 1 1
0 1 0
1 0 0
0 0 0

1 1 1
0 1 1
1 0 1
0 0 0

1 1 0
0 1 1
1 0 1
0 0 0

1(2($0,$1),0(1($0,$1))) (length 8; "(A | B) & !(A & B)")


I think more test cases are needed, but am unsure what to add.

This is my firstsecond challenge, so all feedback is welcome!

  • \$\begingroup\$ The idea is good, I think. I had trouble understanding at first read though, and didn't understand at all your $ things. I suppose $1 is the same as 1() but I'm not sure. Suggested test case: Input : (1,0;0,1) ; (1) ; (1,0;0,1) with Output : 0() and not 0(1()) or 1(0()). \$\endgroup\$ – V. Courtois Aug 13 '19 at 14:40
  • \$\begingroup\$ @V.Courtois $0 is the first input to the final table, $1, the second etc. 0(...) is the first input table, 1(...) is the second, etc. Any recommendations on a better format? \$\endgroup\$ – tjjfvi Aug 13 '19 at 14:43
  • \$\begingroup\$ @V.Courtois Added your test case, though 0() is not a valid output as (1,0;0,1) takes in 1 input, not zero, it should be 0($0) \$\endgroup\$ – tjjfvi Aug 13 '19 at 14:46
  • \$\begingroup\$ Do you mean $0 is the input on the first row of the output table? It got even more foggy... Plus, isn't a truth table's order meaningless? I mean, you even swapped the order of the rows in the last test case. And I just noticed now the # notation... Would you mind clarifying it all? Those signs are nowhere defined in the challenge ^^' \$\endgroup\$ – V. Courtois Aug 13 '19 at 14:52
  • \$\begingroup\$ OH ; and by re-reading all the text I saw that your & is strange: why does 0&0 get 1?? \$\endgroup\$ – V. Courtois Aug 13 '19 at 14:53
  • 1
    \$\begingroup\$ @V.Courtois The "&" is not an &, it is an iff/not xor \$\endgroup\$ – tjjfvi Aug 13 '19 at 14:54
  • \$\begingroup\$ Oh my bad then, I didn't know for this one. \$\endgroup\$ – V. Courtois Aug 13 '19 at 14:56
  • \$\begingroup\$ @V.Courtois Tomorrow I’ll revise the test case format \$\endgroup\$ – tjjfvi Aug 14 '19 at 0:38
  • \$\begingroup\$ @V.Courtois I explained & slightly revised the notation; is it clearer now? If you have any suggestions, they would be very welcome. \$\endgroup\$ – tjjfvi Aug 14 '19 at 12:30
  • \$\begingroup\$ Ah yeah, it looks clearer now. The test case of length 8 is really helpful in the process, too, for guys like me that in general read the test cases before reading what is the actual challenge about :) Let's hear other points of view about this challenge, for my part I don't see any problem now. \$\endgroup\$ – V. Courtois Aug 14 '19 at 12:38
  • 1
    \$\begingroup\$ You can remove the "Exception: if there are 0 inputs, there must be 1 row." line, \$2^0=1\$. \$\endgroup\$ – Erik the Outgolfer Aug 15 '19 at 22:16
  • \$\begingroup\$ For languages that support ND array, a ND array (each dimension has size 2) would be a natural representation of a N-ary truth table. \$\endgroup\$ – user202729 Aug 16 '19 at 4:44
  • \$\begingroup\$ In your example is "1 1 1" = "(1, 1) -> 1" or "1 <- (1, 1)"? \$\endgroup\$ – user202729 Aug 16 '19 at 4:46
  • \$\begingroup\$ Also: do you know any polynomial time solution to this problem? \$\endgroup\$ – user202729 Aug 16 '19 at 4:48
  • \$\begingroup\$ @EriktheOutgolfer shame. I'll fix that. \$\endgroup\$ – tjjfvi Aug 16 '19 at 13:16

Planting Steiner Trees

In the following we are talking about Steiner trees, which are similar to minimal spanning trees: The goal is connecting all nodes via some paths such that the resulting graph that is as short as possible. In contrast to minimal spanning trees when constructing steiner trees you can add additional nodes.

In the following we are talking about points in the real 2d plane and when we are talking about distances and lengths, we are talking about the euclidean distance.

Also, a graph will comprise a set of points where the edges are straight lines between pairs of those points. The length of a graph will be the sum of the length of all edges.

So a steiner tree is a shortest graph connecting all given points possibly with inserting additional points. The following image shows the difference between a minimall spanning tree (blue) and a steiner tree (red).

It is known that it is very difficult to find steiner trees.

enter image description here


Write a program that accepts a list of 2d points and tries to find/approximate a steiner tree of minimal length connecting those points by possibly introducing more points. (It does not have to find the an actual steiner tree.)

The program should output a list of all the points (including coordinates) of the constructed graphs, a list of all edges (including their lengths), the total length of the graph and a graphical representation of the grap.

The program should have a running time of no more than about half a minute for each of the examples on a reasonable computer.

You should also explain how your algorithm works.


The program must be evaluated on all the [NOT YET] given test cases. The score is the sum of the total length of all test cases. The lowest score wins.

Test cases


(cos(2*pi*a/9),sin(2*pi*a/9)) for a = 0,1,...,8


Meta: I need to find a good set of test cases. Suggestions are appreciated.

If you have any suggestions, feel free to edit/add. Any improvements of the text are appreciated too.

@El'endia Starman Pointed out some interesting n-gon configurations

  • 3
    \$\begingroup\$ It is known that Steiner trees for regular n-gons where 7 <= n <= 12 are simply the n-gon with one side removed. 4,5,6 all have interesting configurations though. \$\endgroup\$ – El'endia Starman Oct 31 '15 at 0:03

Shortest Persistent Object in 5-Char JS

The []+=` subset of JavaScript is known to be Turing-complete. A key part of the construction is obtaining persistent objects whose properties can be set and retrieved in a loop.

Most expressions won't evaluate to constant values. For example, [] != [] when compared by reference. However, some expressions, such as [].name, return the same object every time they are evaluated.

The Task

The following should hold when e is substituted with your submission:

  • (e) instanceof Object (this includes functions and arrays)
  • (e) == (e)

This is , so the shortest valid submission (measured in bytes) wins.


Cleaning the dishes

In this task, you will be given a bar of soap with a width of 1 or more units, which will be inputted as an integer. You will also be given a plate, which you will have to clean, using the soap as few times as you can. The plate will be inputted as a an array of 2 different characters, one of which is the 'dirty' character, and one of which is the 'clean' character. The plate will be at least 1 character. You will have to output an array with the 'clean' character representing the plate, and a third unique character to represent in what positions the bar of soap was placed. None of these 3 unique characters may be whitespace.

How much the soap cleans:

n//2-1 on each side for odd n
n//2-1 on the left side of the soap bar for even n
n//2   on the right side of the soap bar for even n


An integer greater than or equal to 1. A series of 2 unique characters to represent clean portions and dirty portions. Here, '=' represents a dirty portion, and '-' represents a clean portion. '+' represents where the soap was placed.


3 ===- : -+--
32 ================================ : ---------------+----------------
1 ==== : ++++
5 ----- : -----
4 -====- : --+---
3 -====- : --+-+-
7 === : +--
6 - : -
6 -==-===- : ---+----
5 -==--==- : ---+--+-
3 -==--==- : --+--+--


  • There are multiple solutions. Any one of them are acceptable, as long as they use the soap the minimum amount of times possible.
  • This is a contest, so the shortest answer in bytes wins!
  • The plate may only be non-whitespace characters, and have 2 unique characters.
  • The soap may only be one non-whitespace character, unique from the other 2 used in the plate.
  • Standard loopholes are not allowed.

Posted: Cleaning the dishes

  • \$\begingroup\$ If "soap input may only contain the characters '0' through '9', and may be multiple characters", then can it not be passed as an integer argument to a function? \$\endgroup\$ – Unrelated String Sep 4 '19 at 4:15
  • 1
    \$\begingroup\$ i already specified rules about soap input in the first paragraph, so i will erase that rule. \$\endgroup\$ – girobuz Sep 4 '19 at 20:34
  • \$\begingroup\$ There seem to be multiple possible outputs, e.,g.: 3 =-=-= could be either +--+- or -+--+, yes? If that is true, can we output any of them? \$\endgroup\$ – Chas Brown Sep 7 '19 at 23:34
  • \$\begingroup\$ Yes, any output is acceptable, as long as it works, and is the minimum. \$\endgroup\$ – girobuz Sep 7 '19 at 23:53

Battleship KotH

This is a pretty rough idea to start but I figured I would drop it in the sandbox so that people can start to think about it and I will remember to do it.

The idea here is a that combines the game, battleship with .

The rough idea is that two enemies would face off, each turn irradiating a location in their opponents source code. Then the opponents source code would be recompiled and then try and attack back.

Some additional thoughts I've had:

  • We will likely want to limit the size of the board to a specific rectangular size

  • I would like there to be a feedback from shooting your opponent (in the game battleship this is hit/miss) so that you are doing more than just firing randomly. Perhaps programs might irradiate a single bit (flipping its value) and get back its value before it was irradiated.

Language choice is a bit tough since I would like something multipurpose and flexible but I don't want to have to deal with the security issues that are involved in compiling and running a fully featured programming language.

  • \$\begingroup\$ radiation-hardening tends to work best with deletion. This is going to need a maximum byte count to be fair, otherwise the best strategy is excessive amounts of whitespace and comments. Love the idea though. \$\endgroup\$ – Beefster Sep 17 '19 at 14:22
  • \$\begingroup\$ You don't actually have to limit yourself to a specific language on this one. It wouldn't be that hard to use a shell script to run whatever languages are available. One question though: is each program able to read the source code of the other or is each attack supposed to be blind? If you're worried about security, you could run the controller in a docker container or VM. \$\endgroup\$ – Beefster Sep 17 '19 at 14:26

Injection from two strings to one string

  • \$\begingroup\$ Do you think that a reasonably number of languages won't implement the following: convert the strings into numbers (e.g. treat each character as a base 128 digit) then give a resulting string of those two numbers joined by some other character? I haven't spent too long thinking about it but that seems very short in most languages. I suppose there are other variants though where you map characters to some subset and then join them. \$\endgroup\$ – FryAmTheEggman Sep 24 '19 at 20:42
  • 2
    \$\begingroup\$ @FryAmTheEggman I imagine the solution used is going to depend on the language: what builtins it has, if it's more high-level or low-level, etc. But there may well end up being a prevalent algorithm. \$\endgroup\$ – negative seven Sep 24 '19 at 20:57
  • \$\begingroup\$ Why strings? Lists of integers, (even restricted to a range) work as well but don't have the complexities that strings do when it comes to printables etc. I feel like the simpler challenge is going to be the better one. \$\endgroup\$ – Post Rock Garf Hunter Sep 26 '19 at 3:30
  • 1
    \$\begingroup\$ @FryAmTheEggman Don't worry, I've thought of a totally different approach that I think would be shorter for many languages. \$\endgroup\$ – xnor Sep 26 '19 at 4:46
  • 2
    \$\begingroup\$ @SriotchilismO'Zaic Restricting the character set seems to me like a reasonably simple detail, while making it about strings encourages creativity with string operations, converting to string representations, etc. Also, I personally think string input/output is much more appealing to look at and easier to consume than a list of numbers. \$\endgroup\$ – negative seven Sep 26 '19 at 14:38

Code Golf Measurer © 2019

Hexdumps used with xxd look something like this:

00000000: 666f 6f20 6261 7220 7370 616d 2065 6767  foo bar spam egg
00000010: 730a                                     s.

Your task is to convert a hexdump in this form in to the number of bytes used.


  • Usual loopholes forbidden.
  • This is , so shortest valid answer in bytes wins.
  • You may or may not include the newline at the end of text (0a). This means that if the hexdump ends in a newline (0a), that input may have it's output reduced by one.
  • An empty input must output 0.

Test cases:

00000000: 4865 6c6c 6f2c 2077 6f72 6c64 2120 4865  Hello, world! He
00000010: 6c6c 6f2c 2077 6f72 6c64 210a            llo, world!.

returns 27 or 26

00000000: 0a                                       .

returns 1 or 0

00000000: 6368 616c 6c65 6e67 650a                 challenge.

returns 10 or 9

00000000: 4865 6c6c 6f2c 2077 6f72 6c64 21         Hello, world!

returns 13

returns 0


  • Is this clear?
  • Is this a duplicate?
  • Other tags?
  • 1
    \$\begingroup\$ Does the extra rule mean that the input can have an optional trailing newline, or that the results in all of your test cases could be reduced by 1? If you mean the former I recommend adding a test case that doesn't end with a newline. If you mean the latter then I recommend explicitly saying the file will end with a newline character. Also I suppose this is a string challenge. Thanks again for using the sandbox :) \$\endgroup\$ – FryAmTheEggman Oct 3 '19 at 20:55
  • \$\begingroup\$ @FryAmTheEggman It means that all test cases could be reduced by one. This was intended as a code golf byte counter, and the newline most certainly isn't usually included. I'll clarify this and add another test case to highlight it. \$\endgroup\$ – gadzooks02 Oct 4 '19 at 15:17
  • \$\begingroup\$ So: discard all the input except the last line, and parse hex? Or just output the last line and claim that your output is in hex? IMO it would be a more interesting problem with xxd input, where the last line is not present. \$\endgroup\$ – Peter Taylor Oct 5 '19 at 9:00
  • \$\begingroup\$ @PeterTaylor If I were to switch to xxd, would that be a valid edit, or would that be too big a change such that I would have to post another challenge? \$\endgroup\$ – gadzooks02 Oct 5 '19 at 9:45
  • \$\begingroup\$ I'm sure far more significant edits have been made to sandboxed challenges in the past. \$\endgroup\$ – Peter Taylor Oct 5 '19 at 13:10
  • \$\begingroup\$ @PeterTaylor In that case, edited. \$\endgroup\$ – gadzooks02 Oct 5 '19 at 14:52

ASCII Sum of your code

Encoding is nice, adding things is also nice. Let's do both !

Your task will be to create a program that read itself, convert every of its character into ASCII values and return the sum of those numbers.


Let's say your program is Hello, world !. Convert every character into ascii values

H  e   l   l   o   ,  (space) w   o   r   l   d   (space) !
72 101 108 108 111 44 32      119 111 114 108 100 32      33

Now, sum everything into a meaningless very useful value

72 + 101 + 108 + 108 + 111 + 44 + 32 + 119 + 111 + 114 + 108 + 100 + 32 + 33
= 1193

Here it is, Hello, world! returns 1193 !


  • The code have to read itself and calculate the result
  • Standard loopholes are not allowed
  • This is codegolf, so the fewer bytes wins.
  • Non-standard languages with non-ASCII characters should use their own codepage's encodings (Thanks for @Veskah for this rule)


  • Is the challenge clear enouth ?
  • Is there an already existing challenge like this one ?
  • is this considered as a duplicate of this challenge ?
  • 2
    \$\begingroup\$ I would probably have non-standard languages use their codepage's encodings (pretty much all of them should be 8 bytes) to crunch their output. The big hammer approach would be to ban non-ASCII languages but I would not recommend that. \$\endgroup\$ – Veskah Oct 23 '19 at 14:06
  • 3
    \$\begingroup\$ Requiting the code to read itself and do the calculation is a non-observable requirement. Since it seems you don't want programs that just hardcode the value, I think the best way to be just to require the program take in an input string to use. Regardless, I don't really see room for interesting golfing in the challenge, since pretty much any normal-ish language has built-ins to take ASCII values and compute sums, and weird languages that don't have already done these as subtasks for many many challenges. \$\endgroup\$ – xnor Oct 25 '19 at 0:52
  • \$\begingroup\$ @xnor Does this challenge with string input already exist ? \$\endgroup\$ – The random guy Oct 25 '19 at 7:06
  • 2
    \$\begingroup\$ I don't remember an exact one, but I'm finding very close ones: averaging ASCII values and summing then counting binary 1's, which was closed as a duplicate of one without the character adding. I also found an unrestricted quine challenge with the same task as yours. So I think there's a good chance this would be closed as a duplicate either way. \$\endgroup\$ – xnor Oct 25 '19 at 7:11
  • 1
    \$\begingroup\$ Yup, the last one is quite the same as mine. Duplicate it is then. \$\endgroup\$ – The random guy Oct 25 '19 at 7:13

Java vs C++

Now posted at Time to settle this: Java vs C++

  • \$\begingroup\$ How vital is the validation to the challenge? \$\endgroup\$ – Unrelated String Aug 27 '19 at 21:01
  • \$\begingroup\$ @UnrelatedString I think it's fairly integral if the story is considered. Gotta inform the user that they're feeding you crap. Also it should add an extra element of challenge. \$\endgroup\$ – Mr Redstoner Aug 27 '19 at 21:07
  • 3
    \$\begingroup\$ @MrRedstoner Validation is generally considered tedious by the users of this site, rather than challenging. I'd recommend reconsidering - clearly the validation code could make use of the submissions as a subroutine. There are also a couple near dupes 1 2 but I haven't found a precise dupe. That said, thanks for using the sandbox! \$\endgroup\$ – FryAmTheEggman Aug 28 '19 at 0:36
  • 1
    \$\begingroup\$ getHTTP would result in... get_h_t_t_p? get_http? Error? Some other thing? \$\endgroup\$ – Chas Brown Aug 28 '19 at 1:42
  • \$\begingroup\$ @ChasBrown should be get_h_t_t_p, I shall add that. @FryAmTheEggman While I considered it part of the story, if those are the standards I figure I'll remove it and say the validation was done by a previous part of code. \$\endgroup\$ – Mr Redstoner Aug 28 '19 at 5:24
  • \$\begingroup\$ "If it is neither, output/return a falsey value." I would change this to something like "If it is neither, any unspecified behavior is fine (return a falsey value; give an error; try to convert it somehow anyway; etc.)." As mentioned by @FryAmTheEggman, validation is usually considered a distraction of the actual challenge (and can sometimes even double the code of the program/function for those answering), so most challenges assume the given input will always be valid. Apart from that the entire challenge looks fine, so +1 from me. Thanks for using the Sandbox! :) \$\endgroup\$ – Kevin Cruijssen Aug 28 '19 at 9:32
  • \$\begingroup\$ @KevinCruijssen Dang it missed that during the edit. Thanks for telling me! \$\endgroup\$ – Mr Redstoner Aug 28 '19 at 10:42
  • \$\begingroup\$ What should be returned from an input of a__b (two underscores)? \$\endgroup\$ – Value Ink Aug 29 '19 at 1:03
  • 1
    \$\begingroup\$ @ValueInk That would be invalid input. 'You may assume all input to be valid'. Therefore I refer you to the ANSI C standard for undefined behaviour. \$\endgroup\$ – Mr Redstoner Aug 29 '19 at 6:00

Can Jimmy escape the ghosts?

Posted: Can Jimmy escape the ghosts?

  • 1
    \$\begingroup\$ S'all good, no problem \$\endgroup\$ – Veskah Oct 17 '19 at 14:05

Substitute Unprintable ASCII Characters

Have y'all ever written an answer with unprintable ASCII characters in it and wished that there was an easy way to represent those characters in a printable way? Well, that's why the Control Pictures Unicode block was invented.

However, manually substituting these characters into one's answer is time-consuming, so that's what today's challenge is about: swapping out the nasty invisible characters for nice, readable characters.


You will be given strings that contain a mix of ASCII-only characters (i.e. the UTF-8 code point of each character will be in the range: \$0 \lt char \le 127\$).


For all unprintable characters, replace it with its corresponding character in the Control Pictures Unicode range.

In other words:

  • Characters in the range \$0 \lt char \lt 9\$ are replaced with their corresponding character
  • Vertical tabs and newlines (9 and 10) aren't replaced
  • Characters in the range \$11 \le char \lt 32\$ are replaced with their corresponding character
  • Spaces (32) aren't replaced
  • The delete character (127) is replaced with its corresponding character:


Characters are given as escapes for nice formatting here, but each character will be replaced with the unprintable character

In -> Out
\x1f\x1c\x1f\x1e\x1f\x1e\x1f\x1f\x1e\x1f\x1e\x1f -> ␟␜␟␞␟␞␟␟␞␟␞␟
Hello\x07World! -> Hello,␇World!
\x01\x02\x03\x04\x05\x06\x07\x08\x0c\x0b\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f -> ␁␂␃␄␅␆␇␈␌␋␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡


  • All standard loopholes are forbidden
  • Character substitutions must be made according to the Control Pictures Unicode block


This is code-golf so the answer with the fewest amount of bytes wins.

Test-Case Generator

I have provided a test case generator for y'all. It prints inputs in the way they will be passed to your program and outputs the expected result.

Try it online!

  • \$\begingroup\$ "DEL" (ASCII 127) is also unprintable. Also, did you mean 0≤char≤127? \$\endgroup\$ – Bubbler Nov 15 '19 at 8:00
  • \$\begingroup\$ Updated! (I forgot DEL wasn't printable) \$\endgroup\$ – Lyxal Nov 15 '19 at 8:04
  • \$\begingroup\$ I think you need to give test input as JSON (i.e. with escapes) \$\endgroup\$ – Adám Nov 15 '19 at 8:46
  • 1
    \$\begingroup\$ Space has a substitution character (). Should it be replaced? I think you should clearly state that ≤ (or < 32) and 127 should be replaced. \$\endgroup\$ – Adám Nov 15 '19 at 8:48
  • \$\begingroup\$ Updated accordingly. \$\endgroup\$ – Lyxal Nov 16 '19 at 1:33

A Spherical Die


I have a spherical die, but it's a cheap one so it doesn't work properly. When I roll it, it doesn't always land directly on a "face" marking, but instead can result in an ambiguous result ("is that a 6, a 4 or a 2?")


Assume the die is a perfect, evenly-weighted Unit sphere (i.e. all points on the surface are radius 1cm from the center) , such that a "roll" can result in any point on the sphere being the uppermost point (the "roll value").

Assume that, if the die is placed or rolled such that 1 is at the "north pole", the conventions of a normal die will follow, i.e:

  • 6 will be at the "south pole"
  • 4, 5, 3, 2 will be on the "equator", clockwise in that order, equidistant around the sphere.

So, before it's rolled, the die looks like this:

image of die

The Challenge

Given a simulated roll of the die with the conditions above (i.e. coordinates representing the top of the die after it's rolled), identify the closest value (1-6) to that point (i.e. what the roll value should resolve to).


A co-ordinate on the sphere.

There are a few co-ordinate systems used for spheres, the two I'm familiar with (and so will provide examples in) are as follows:

  • P(1, φ, Θ) where φ is the "azimuth angle" (0..360), Θ is the "polar angle" (0..180)

  • P(x,y,z) where \$x^2+y^2+z^2=1\$

(note: the conversion between the two is: x = cos(φ)·sin(Θ); y = sin(φ)·sin(Θ); z = cos(Θ))

for clarity:

  • roll "1" is at P(1,n,0)
  • roll "2" is at P(1,270,90)
  • roll "3" is at P(1,180,90)
  • roll "4" is at P(1,0,90)
  • roll "5" is at P(1,90,90)
  • roll "6" is at P(1,n,180)


The nearest value (1-6) to that point. If the point is equidistant to two or more points, output any one of them.

Usual exclusions etc. apply.

  • \$\begingroup\$ Does anyone know the maths for this? Feel free to edit it in! \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 9:40
  • \$\begingroup\$ I'm not sure I understand: You want us to generate a random point on a sphere and output the face of the die it corresponds to? \$\endgroup\$ – flawr Nov 22 '19 at 9:57
  • \$\begingroup\$ yeah, so generate a random point on the sphere, then find the nearest "face" - i.e. the nearest of the 6 points (top, bottom, 4 points on opposite sides around middle) \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 11:11
  • \$\begingroup\$ This will be exactly equivalent to a uniform distribution over 6 values, just based on the symmetry of the situation. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 12:33
  • \$\begingroup\$ @AlienAtSystem yes, all outcomes are equally likely; but the challenge is determining which number any given point on the face of the sphere is closest to \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 13:04
  • 2
    \$\begingroup\$ That's not the challenge as posted. Right now, it's "Takes no input, returns the number the (internally generated) random point is closest to" which is, under the consensus of no unobservable requirements simply equal to "Takes no input, returns uniform random value from 1-6". If you want the challenge to be "Input is point on sphere, output is number it's closest to", then write that. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 13:09
  • \$\begingroup\$ @AlienAtSystem I've edited to try and make it clearer what I'm looking for. Is it clearer now? \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 13:15
  • \$\begingroup\$ It's clearer that my point still stands. Look, "Make Voronoi cells on sphere" and "Generate uniformly random points on sphere" are both good challenges. But when put together like that, they annihilate each other and give you an extremely quick shortcut right from Input (None) to output (a die roll) that doesn't require calculation of either part. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 13:21
  • 2
    \$\begingroup\$ @AlienAtSystem thanks for the feedback, I'd never heard of a Voronoi cell before. What I'm asking, then, is "generate a random point on a sphere and say which Voronoi cell that point is in". Can you explain why that doesn't work? Note that I'm asking for both the point and the cell to be output, not just the cell - otherwise I agree, given the "no unobservable requirements" rule it would be possible to just generate a random number and pretend you'd done it properly (although that would be against the spirit of it) \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 13:24
  • \$\begingroup\$ Would it be better for the point on the sphere to be the input, then? \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 13:27
  • \$\begingroup\$ If you want the challenge to be about finding the points it's closest to, yes. \$\endgroup\$ – AlienAtSystem Nov 22 '19 at 13:31
  • \$\begingroup\$ I want it to be a good challenge on this theme, whatever that would look like :) \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 13:33
  • \$\begingroup\$ Although I don't think the current challenge is bad, it's usually best to not have multiple challenges into one nor multiple outputs (since some languages aren't able to output more than once very easily). The two challenges are: 1. Generate a random coordinate on a sphere (in whichever coordinate system you want); 2. Given a (random) coordinate on a sphere, output the dice-value closest to it. No. 1 already is a challenge, so I agree it might be better to rewrite it to challenge No. 2. I do like the general idea though, so +1 from me. \$\endgroup\$ – Kevin Cruijssen Nov 22 '19 at 14:36
  • \$\begingroup\$ It would also need some info about the size of the sphere, and what to do when the coordinate is exactly in the center between two or three poles. \$\endgroup\$ – Kevin Cruijssen Nov 22 '19 at 14:39
  • \$\begingroup\$ @KevinCruijssen Thanks, that's helpful. \$\endgroup\$ – simonalexander2005 Nov 22 '19 at 14:40

OEIS A125959

https://oeis.org/A125959 is a sequence I submitted. It is the following array, which then repeats:

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

This is a rather useful array for quickly calculating the digital root of the product of any two numbers (i.e the iterative sum of the digits of the product). See the OEIS link if you're interested in the details.

The challenge is to print the array in the shortest number of bytes.




The above array. It can be output as strings with new lines, or as a nested array, or an array of strings; but not as a single-line sequence (i.e. the 2d-nature of the array must be reflected in your output).

  • 4
    \$\begingroup\$ So it's the multiplication table mod 9, except 0s are 9's? \$\endgroup\$ – xnor Nov 25 '19 at 12:58
  • \$\begingroup\$ @xnor is it? I hadn't spotted that before. Does that stop it being an interesting challenge? \$\endgroup\$ – simonalexander2005 Nov 25 '19 at 13:49
  • 1
    \$\begingroup\$ I believe it does (because it is "create a 10x10 table of the function (-~a*-~b-1)%9+1" now). \$\endgroup\$ – my pronoun is monicareinstate Nov 25 '19 at 14:05
  • 2
    \$\begingroup\$ I think it makes it too similar to generic print-a-multiplication table challenges, but others might disagree. \$\endgroup\$ – xnor Nov 26 '19 at 2:10

Bake the cookie

Quick intro

So i was playing cookie clicker yesterday, and I thought about something. We keep producing cookies, without any loss. What if your cookies failed? This is where I thought about a clicker that would cook a cookie. Don't click too much, or the cookie will be overcooked!


Your task will be to create a function that will "bake" a cookie :

  • Your function will have to randomly select a number between 5 and 10 : it will establish the cooking duration of your cookie (and so, the number of time you'll have to call the function to cook your delicious cookie).
  • Each time you call that function, it will iterate the baking process of your cookie.
  • Your function should return "Undercooked" if your cookie is not fully cooked, "Overcooked" if you ... overcooked it, and "Cooked" when the cookie is baked just right.


Since I'm bad at explaining things, an example will show you more clearly what needs to be done. Let's call my function bake() :

bake()    // The random number generated is 6, so i need to call my function 6 times





bake()    // We hit the 6th function call, the cookie is baked.

bake()    // The 7th call overcooked the cookie. Congratulation, you ruined it.


  • The random number of iterations has to be set the first time you call the function. It has to be between 5 and 10 (inclusive).
  • A cookie has to be undercooked before being cooked, and has to be cooked before being overcooked. The 3 steps have to be reachable. A cookie can't uncook itself, therefore you can't go from cooked to undercooked, or from overcooked to cooked (it's too late, you ruined the cookie anyway).
  • The function can have as many parameters as you please.
  • Classic rules apply, no standard loopholes
  • This is codegolf, so the shortest code wins.


  • Is the challenge clear enough ?
  • Should I go with this method to iterate the "baking" process ?
  • Are there some rules I could add to make it more exciting ?
  • Does this challenge exist already ?
  • Should we bake pies instead ?
  • \$\begingroup\$ I'm assuming bake() will take no parameters and will have to store the count somehow, which means you might want to include some rules about file and global variable I/O. I also did a small editing pass. \$\endgroup\$ – Veskah Dec 2 '19 at 16:14
  • \$\begingroup\$ @Veskah I never thout about restricting bake()'s parameters, gonna edit the rules to include this particulatiry. Also, thanks for the edits. \$\endgroup\$ – The random guy Dec 3 '19 at 8:12
  • \$\begingroup\$ I don't think I understand what you are trying to accomplish. Why do you refer to the submission always as a function? Could it not be a program? Similarly, your edit to allow arbitrarily many parameters conflicts with the general tone that seems to imply that we should be storing state between calls. I think you will want to try explaining the task simply, perhaps even to the level of a non-programmer. \$\endgroup\$ – FryAmTheEggman Dec 8 '19 at 19:47

Universal Self-correcting Program

The idea here is to make a program that can tolerate errors in its own code, while still functioning correctly.

Since "error" is too broad, we will define it by a single bit flip. Of course, more tolerant versions, that could accept swapping any character with any other character would still be valid.

This program is universal in the sense that you can write any other self-correcting program (with the same tolerance) -- more on that later.


1) This program takes as input a triple-redundancy string of characters, and outputs a corrected string.

2) This program executes correctly with any bit flip in its own code.

(1) Triple redundancy codes

A triple redundancy code consists of simply repeating each bit, character or byte 3 times. In this case we use characters.

Correction is done by taking the majority of the characters, so (A,A,B) is corrected to A, (A,B,B) is corrected to B and so on.

AAA => A
AAB => A

This is a very crude an inefficient code for correcting single bit errors, but it is the least complex, which is why I think may be the best choice here. Hamming codes are better but a little more complex.

(2) Error tolerance

Our program will be defined as error tolerant if it performs the desired decoding function for any single bit flip in its own code. It may take longer for some inputs or when some flips occur, but it should always terminate.

Putting it together

The error-tolerant program can receive as input a (possibly faulty) program, and outputs a error-free program. Therefore, if a single-bit error occurs anywhere in the system comprised of (decoder,input program), a corrected program will still be output.


I don't actually know if this is possible, quite possibly it won't be achievable in every language. If it is too hard, we may relax the tolerable errors.


The score will reflect the reliability of your program to errors. Tolerance is simply the number of bit flips you code accepts anywhere. It must be at least 1 (accept 1 bit flip anywhere). Size is the length of your program in bytes.

The score is Score = Size / 2^Tolerance

Lowest score wins.

Note: Several other challenges are possibly solved by solving this one (which would make sense given its universality!) by hardcoding the input.

Detect if your program has been mutated

Write a program that always outputs “2012” - even if it's modified!

This solves the "Who Watches the Watchmen?" problem involved in error correcting programs, like in this challenge:

Meta radiation hardener

since the decoding program itself tolerates errors (what good would be an error correcting program that is itself in error? :p).

  • 2
    \$\begingroup\$ Check the radiation-hardening tag for duplicates and rules clarifications, too. \$\endgroup\$ – AdmBorkBork Mar 7 '18 at 19:17
  • \$\begingroup\$ @AdmBorkBork Thanks, I wasn't aware of that. It appears no one has proposed a Universal radiation hardener yet (this is universal only in the sense of bit flip errors; those are actually a good model for radiation though!). \$\endgroup\$ – Real Mar 7 '18 at 19:30
  • 1
    \$\begingroup\$ Again Lenguage win lol \$\endgroup\$ – l4m2 Jan 8 '19 at 14:53
  • \$\begingroup\$ Even though your scoring involves code length you should use code-challenge instead of code-golf for challenges that are not solely scored by code length. \$\endgroup\$ – Laikoni Jan 10 '19 at 20:14

Golfing with 2s

It is well-known that all positive integers can be represented via a sum of powers of 2. For example, 13=2^3+2^2+2^0. We can rewrite the 3 and 0, to get 13=2^(2+2/2)+2^2+2^(2-2). A shorter representation might be 13=2^2^2-2-2/2, or a more repetitive one 13=2+2+2+2+2+2+2/2


Your task is, given a nonnegative integer as input, output/return a string containing only 2s and elementary operations, which when evaluated will yield that integer. These operations are +, -, *, /, ^, and appropriate parentheses. Use of multiple consecutive 2s (22, 222, etc) is not allowed.

However, the string should tend to be one of the shorter representations of the integer in question. So for the above example with 13, 2^2^2-2-2/2 and 2^2^2-2/2-2 are the shortest representations.

The input can be in any convenient format, but the output must be in the above format, either to a file or STDIO.


Short code and efficient representation are both prioritized, so the score is the length in bytes plus the average length of the returned string for 9, 57, 554, 1894, 25993, 113193, 2998225, and 52748566.


Standard loopholes not allowed

Standard input/output forms apply

Some degree of brute forcing is allowed, but the program must be able to handle each of the test cases in under a minute each.

Example outputs

0            2-2
1            2/2
2            2
3            2+2/2
4            2^2
5            2^2+2/2
6            2^2+2
7            2^2+2+2/2
8            2*2*2
9            2*2*2+2/2
10           2*2*2+2
57           2^(2^2+2)-2^2-2-2/2
554          2*2^(2*2*2)+2*2^2^2+2*2*2+2
1894         2*2^(2*2*2+2)-(2^2^2-2)*(2*2*2+2+2/2)
25993        (2*2^(2*2*2+2)-2*2^(2*2*2)-2^2-2-2/2)*(2^2^2+2/2)
113193       2*2^2^2^2-(2^(2*2*2+2)-2^(2^2+2)-2^2^2-2-2/2)*(2^2^2+2+2/2)
2998225      (2*2^2^2^2-(2^(2*2*2+2)-2*2*2-2-2/2)*(2*2*2+2+2/2))*(2^2^2+2*2*2+2/2)
52748566     (2*2^(2^2^2+2^2)-2^2^2^2-2*2^(2*2*2+2)-2*2^(2*2*2)-2^(2*2*2)-2*2*2-2/2)*(2^2^2-2-2/2)*2
  • \$\begingroup\$ It doesn't have to be optimal. It should tend to be optimal but you can trade it out for a much shorter program if it helps. \$\endgroup\$ – Exalted Toast Dec 8 '19 at 8:10
  • \$\begingroup\$ It might be a good idea to clarify length - do you mean the actual string length or the number of operations and 2s used? \$\endgroup\$ – FryAmTheEggman Dec 8 '19 at 20:19
  • \$\begingroup\$ Added clarification for both. To Fry, I mean the string length, but I'm not entirely sure what the difference is. \$\endgroup\$ – Exalted Toast Dec 9 '19 at 0:39
  • \$\begingroup\$ Can we use the numbers 22, 222, etc. in the output? \$\endgroup\$ – 79037662 Dec 10 '19 at 16:33
  • \$\begingroup\$ No. Will add clarification for that as well. \$\endgroup\$ – Exalted Toast Dec 12 '19 at 0:33
  • 1
    \$\begingroup\$ Can we submit a function that takes a value and returns a string? Typically you should try and avoid restricting input and output, and just rely on the community standards \$\endgroup\$ – Jo King Dec 13 '19 at 3:26
  • 1
    \$\begingroup\$ in reasonable time I know this is hard to specify, but as it stands it is too broad: what is meant by "reasonable time"? Some previous challenges say things like "it should run within a minute on a modern computer for inputs less than..." \$\endgroup\$ – Luis Mendo Dec 16 '19 at 9:47
  • \$\begingroup\$ Yeah, I'm not really sure how to specify it further. I only really added it because when I showed this challenge to my friend, they wrote a brute-force that goes through every string with those 8 characters and finds the shortest one, and it would take a few minutes for inputs > 30. Does being able to run each of the test cases in under a minute sound good? \$\endgroup\$ – Exalted Toast Dec 16 '19 at 19:15
  • \$\begingroup\$ That's the usual tactic, though you should probably specify what computer it is run on, since some will be faster than others. A possible idea could be the answerer has to run the biggest test case to completion, which should eliminate the worst of the brute force scripts \$\endgroup\$ – Jo King Dec 18 '19 at 7:33
  • \$\begingroup\$ Giving the integers you'll be testing with might allow people to optimise those specific inputs sneakily - maybe ask for a TryItOnline link and then give every answer a score yourself? Just a suggestion. \$\endgroup\$ – FlipTack Dec 27 '19 at 19:10

Title: When is Hannukah?


The input will be a year between 1583 and 2250.


The Gregorian date of the first evening of Hannukah that year. That is the day before the first full day of Hannukah. Your code should output the month and day of the month in any easy to understand human readable form of your choice.


2013    November 27 
2014    December 16
2015    December 6  
2016    December 24 
2017    December 12 
2018    December 2  
2019    December 22
2020    December 10 
2021    November 28 
2022    December 18
2023    December 7  
2024    December 25 
2025    December 14 
2026    December 4  
2027    December 24
2028    December 12 
2029    December 1  
2030    December 20 
2031    December 9  
2032    November 27 
2033    December 16

How do you do this?

It could hardly be simpler. We start with a couple of definitions:

We define a new inline notation for the division remainder of \$x\$ when divided by \$y\$: $$(x|y)=x \bmod y$$

For any year Gregorian year \$y\$, the Golden Number, $$G(y) = (y|19) + 1$$ For example, \$G(1996)=2\$ because \$(1996|19)=1\$.

To find \$H(y)\$, the first evening of Hannukah in the year \$y\$, we need to find \$R(y)\$ and \$R(y+1)\$, the day of September where Rosh Hashanah falls in \$y\$ and in \$y+1\$. Note that September \$n\$ where \$n≥31\$ is actually October \$n-30\$.

$$R(y)=⌊N(y)⌋ + P(y)$$ where \$⌊x⌋\$ denotes \$x-(x|1)\$, the integer part of \$x\$, and

$$N(y)= \Bigl \lfloor \frac{y}{100} \Bigr \rfloor - \Bigl \lfloor \frac{y}{400} \Bigr \rfloor - 2 + \frac{765433}{492480}\big(12G(y)|19\big) + \frac{(y|4)}4 - \frac{313y+89081}{98496}$$

We define \$D_y(n)\$ as the day of the week (with Sunday being \$0\$) that September \$n\$ falls on in the year \$y\$. Further, Rosh Hashanah has to be postponed by a number of days which is

$$P(y)=\begin{cases} 1, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)\in\{0,3,5\} & (1)\\ 1, & \text{if } D_y\big(\lfloor N(y)\rfloor\big)=1 \text{ and } (N(y)|1)≥\frac{23269}{25920} \text{ and } \big(12G(y)|19\big)>11 & (2)\\ 2, & \text{if } D_y\big(\lfloor N(y)\rfloor \big)=2 \text{ and } (N(y)|1)≥\frac{1367}{2160} \text{ and } (12G(y)|19)>6 & (3)\\ 0, & \text{otherwise} & (4) \end{cases}$$

For example, in \$y=1996\$, \$G(y)=2\$, so the \$N(y)\approx13.5239\$. However, since September 13 in 1996 was a Friday, by Rule \$(1)\$, we must postpone by \$P(y)=1\$ day, so Rosh Hashanah falls on Saturday, September 14.

Let \$L(y)\$ be the number of days between September \$R(y)\$ in the year \$y\$ and September \$R(y+1)\$ in year \$y+1\$.

The first evening of Hannukah is:

$$ H(y)=\begin{cases} 83\text{ days after }R(y) & \text{if } L(y)\in\{355,385\}\\ 82\text{ days after }R(y) & \text{otherwise} \end{cases} $$

Notes and thanks

Thank you to @Adám for pointing me to the rules. To keep things simple, this challenge assumes the location to be Jerusalem.

  • \$\begingroup\$ Please type out the rules on that image into actual text. Challenges are supposed to be self-contained, while that image will be subject to link rot. Also, it's lacking an explanation how the Golden Number G is calculated. \$\endgroup\$ – AlienAtSystem Dec 29 '19 at 20:26
  • \$\begingroup\$ What if the given year has no Hannukah? Or there are two "first day of Hannukah"s in the given year? \$\endgroup\$ – Adám Dec 30 '19 at 10:56
  • \$\begingroup\$ @Adam. Now you have confused me! For which years between 1900 and 2100 were there 0 or 2 Hannukahs? \$\endgroup\$ – Anush Dec 30 '19 at 11:01
  • \$\begingroup\$ @Anush Ah, I didn't notice the range. 3031 will have 0 and 3032 will have 2. \$\endgroup\$ – Adám Dec 30 '19 at 11:17
  • \$\begingroup\$ Hold on, the first evening? That'd be the day before before the "first day of Hannukah". You should be very clear about this. \$\endgroup\$ – Adám Dec 30 '19 at 11:26
  • \$\begingroup\$ Hm, I just noticed that there's a risk of people actually not implementing the algorithms, but instead relying on a built-in calendar conversion. Though you don't state it, the answer is always the 24th day of the month Kislev in the Hebrew year CivilYear+3761. \$\endgroup\$ – Adám Dec 30 '19 at 11:47
  • \$\begingroup\$ Also, you may want to extend the valid input range. Otherwise it will often be shortest to hard-code the dates, e.g. in base 30. \$\endgroup\$ – Adám Dec 31 '19 at 14:31
  • \$\begingroup\$ @Adam Could you please double check the formula in the question actually matches the example dates I have given. If so, I will post the question. \$\endgroup\$ – Anush Dec 31 '19 at 14:43
  • 1
    \$\begingroup\$ Working on it... \$\endgroup\$ – Adám Dec 31 '19 at 15:00
  • 1
    \$\begingroup\$ OK, I've tried it now and it works. It actually works. However, don't go ahead and post yet; There are a few issues to address. \$\endgroup\$ – Adám Dec 31 '19 at 15:39
  • \$\begingroup\$ The first day of Hannukah day 84 if Rosh Hashanah is day 1, so you need to add 83 to get the first day of Hannukah, but 82 to get the evening before. \$\endgroup\$ – Adám Dec 31 '19 at 15:40
  • \$\begingroup\$ The last three paragraphs are superfluous as your range is bigger. However, I also suggest adjusting the range somewhat. If you go above 2239 then .NET won't help (which may be good or bad depending on whether you want to push people to implement the actual algorithm instead of just converting the Hebrew date using the built-in. In any case, the Hebrew calendar isn't really defined beyond 2250. \$\endgroup\$ – Adám Dec 31 '19 at 15:47
  • \$\begingroup\$ You can however pull back the earliest year to 1583, but not earlier, as that's the first year of the civil calendar. \$\endgroup\$ – Adám Dec 31 '19 at 15:49
  • \$\begingroup\$ The mathematical formulas are really awkwardly written. Maybe MathJax those? I can do it if you want. \$\endgroup\$ – Adám Dec 31 '19 at 15:50
  • 2
    \$\begingroup\$ I would adjust the output requirements to read "The Gregorian date of the first evening of Hannukah." to pre-empt people just submitting print("24 Kislev"). \$\endgroup\$ – AlienAtSystem Jan 1 at 8:24

Eats, shoots and leaves

As you know, a panda eats shoots and leaves. Your task today is to write a panda in as few bytes as possible.

      / \
     7   5
    / \   \
   2   6   9
      / \   \
     3   8   4

Here this tree has two branches, 1-7-6 and 1-5-9. The branch 1-7-6 has a shoot 2 and leaves 3 and 8, while the branch 1-5-9 has a leaf 4. After eating the shoots and leaves, your panda should output the following tree:

      / \
     7   5
      \   \
       6   9

If your panda is a program or function, it must output the tree in the same format that you input it. Alternatively it can be a subroutine that modifies the tree in-place.

If it helps, you can assume that the tree has at least two nodes, and/or that each node has at most two child nodes.

No standard loopholes.

  • \$\begingroup\$ What is a shoot, and what is a leaf? Is this question asked to remove all leaf nodes (nodes without children) in a tree? \$\endgroup\$ – tsh Jan 13 at 1:30
  • \$\begingroup\$ @tsh For the purposes of the story, a shoot is a node which has no child nodes but whose parent has at least one grandchild node. Otherwise as you notice it has no effect on the outcome. \$\endgroup\$ – Neil Jan 13 at 10:58

Write a Whitespace Interpreter

Your challenge is to write an interpreter for Whitespace. Given a string consisting of spaces, tabs, newlines, and potential other characters, as well as possible inputs for the Whitespace program itself, output the result of the given Whitespace program.

Here an overview of the Whitespace language and its builtins:

Whitespace is a stack-based language which uses only three characters: spaces (ASCII codepoint 32); tabs (ASCII codepoint 9); and newlines (ASCII codepoint 10). Every other character is ignored.
It only has a couple of basic builtins, which I will go over below. Whitespace has both a stack, which can only consists of integers. As well as a heap, which is a map of integers (both the key and value).

From here on out I will be using S for spaces, T for tabs, and N for newlines to make the text more compact.

Stack Manipulation (always starts with leading S):

  • Push a number to the stack: SS, followed by either an S/T for positive/negative respectively, followed by some S and/or T which is the binary representation of the number (S=0; T=1), followed by a trailing newline N. Some examples:
    • SSSTN pushes the number 1; a positive integer with binary 1.
    • SSTTSN pushes the number -2; a negative integer with binary 10.
    • SSSTSTSN pushes the number 10; a positive integer with binary 1010.
    • SSTTTSSTSSN pushes the number -100; a negative integer with binary 1100100.
    • Pushing number 0 is an edge case, since it can be done in multiple ways. Some examples:
      • SSSN: push a positive integer without any binary digits.
      • SSTN: push a negative integer without any binary digits.
      • SSSSN: push a positive integer with binary 0.
      • SSTSSSN: push a negative integer with binary 000.
  • Duplicate the top of the stack: SNS.
  • Copy the 0-based \$n\$th item from the top of the stack to the top of the stack: STS followed by a number similar as mentioned earlier (excluding the leading SS). I.e. let's say the stack currently contains the integers [47,12,0,55], then we could use STSSTSN to copy the 0-based 2nd item (which is the 12 in this case) to the top. So the stack becomes: [47,12,0,55,12].
    • NOTE: This index may not be negative. On TIO this would result in a negative index error, but that same program would push a 0 in the vii5ard interpreter, and it could even be different in yet another interpreter. For the sake of this challenge, you can therefore assume a given copy will never be negative. So the copy will always start with STSS, followed by the binary of the top-to-bottom index, followed by a trailing N.
  • Swap the top two items on the stack: SNT.
  • Discard the top item of the stack: SNN.
  • Discard/slice \$n\$ items from the top of the stack, but keep the top item: STN, followed by a number similar as mentioned earlier (excluding the leading SS). I.e. let's say the stack currently contains the integers [1,2,3,4,5,6,7], then we could use STNSTTN to discard 3 items from the stack (except the top one). So the stack becomes: [1,2,3,7].

Arithmetic (always starts with leading TS):

  • Addition; add the top two items on the stack together: TSSS.
  • Subtraction; subtract the top item of the stack from the (top-1)th item of the stack: TSST.
  • Multiplication; multiply the top two items on the stack: TSSN.
  • Integer division; integer divide the (top-1)th item of the stack by the top item of the stack: TSTS. (NOTE: Since Whitespace only has integers, this will always be integer division and never result in decimal values.)
  • Modulo; take the modulo of the (top-1)th item of the stack with the top item of the stack: TSTT.

For each of these two argument builtins the same applies: if none or only a single integer is on the stack, this will result in an error. How you implement this error in your interpreter is up to you, as long as the program stops when this occurs. I thought about not allowing it for the sake of this challenge, but decided not to because it's a commonly used strategy to stop a program with an error when printing hardcoded texts, using the approach explained in this Whitespace codegolfing tip.

Heap Access (always starts with leading TT):

  • Pop the top two items of the stack, and store the top item in the (top-1)th address of the heap: TTS. I.e. let's say the stack contains the integers [1,2,3,4,5] and the heap already contains [{2:10}]. When you use this store builtin twice in a row, the stack would contain [1] and the heap will contain [{2:3},{4:5}] (note how the {2:10} has been replaced with the {2:3}).
    • NOTE: Just like with the Arithmetic builtins, if no or a single argument is given, it will cause an error. But for the sake of this challenge you can assume this will never be given for this builtin.
  • Pop the top item of the stack, and push the item corresponding with that heap address to the top of the stack: TTT. I.e. let's say the stack contains the integers [1,4] and the heap contains [{2:3},{4:5}]. If you now use the retrieve builtin once, the stack would become [1,5] (and the heap will remain the same).
    • NOTE: If you use an address that isn't in the heap yet (or the heap is empty), it will push a 0 to the stack instead.

Flow Control (always starts with leading N):

  • Mark a location in the program with a label: NSS, followed by some (optional) S/T which weren't used by previous labels yet, followed by an N. I.e. if you're only using a single label in your full program, NSSN would be what to use when code-golfing. If you need two or three labels, you can add NSSSN or NSSTN.
    • Although it is possible to have multiple of the same labels in the TIO and vii5args interpreters, it will cause issues, so we assume the input will always only create a label once.
    • Also, although NSSN would be a logical first label to use, it's completely valid to use a label NSSTSTSTTTSN instead as only label in the program.
  • Call a subroutine with the given label: NST, followed by some (optional) S/T, followed by an N. I.e. NSTTSTSTTTSN would jump to the label TSTSTTTSN as subroutine.
  • Jump unconditionally to a label: NSN, followed by some (optional) S/T, followed by an N. I.e. NSNN would jump to the (empty) label N and continue the program flow from there.
  • Jump to a label if the top of the stack is exactly 0: NTS, followed by some (optional) S/T, followed by an N. I.e. if the stack is currently [4,1,0] and we'd use NTSSN, it would jump to the label SN and continue the program flow from there (with stack [4,1]). If instead the stack is currently [4,1] and we'd use the NTSSN, it would jump past it to the next builtin below it (with stack [4]).
  • Jump to a label is the top of the stack is negative: NTT, followed by some (optional) S/T, followed by an N. I.e. if the stack is currently [4,1,-10] and we'd use NTTTN, it would jump to the label TN and continue the program flow from there (with stack [4,1]). If instead the stack is currently [4,1] and we'd use the NTTTN, it would jump past it to the next builtin below it (with stack [4]).
    • Minor note: There is no Jump to label if positive builtin available in Whitespace.
  • End a subroutine, and go back to the caller: NTN.
  • End the entire program: NNN (everything after that becomes no-ops).

I/O (always starts with leading TN):

  • Pop the top integer, and print as character with that codepoint to STDOUT: TNSS. I.e. if the stack is currently [10,101] and we'd call the TNSS twice, it will output a lowercase e followed by a newline to STDOUT.
  • Pop the top integer, and print as integer to STDOUT: TNST.
  • Pop the top integer, and read a character from STDIN, for which its codepoint-integer will be stored in the heap with the popped integer as address: TNTS. I.e. if the stack is [0,0], the heap is empty, and STDIN contains the capital letter I, and we'd use TNTS. The stack will become [0] and the heap [{0:73}]. (After which we could use the retrieve builtin TTT to put this input on the stack.)
  • Pop the top integer, and read an integer from STDIN, which will be stored in the heap with the popped integer as address: TNTT.

Challenge rules:

  • You can assume the Whitespace input is always valid with the builtins above. So the compilation phase would always succeed.
  • You can assume executing the Whitespace input will never result in any errors, except when the Arithmetic builtins will only get 0 or 1 stack-arguments instead of the required 2. Although there are loads of other possible errors when executing a Whitespace program, like negative indices, jumps to labels that doesn't exist, read from STDIN when it's empty, etc. For the sake of this challenge you can assume none of those kind of errors will occur, and the input-program is error-free (except for the Arithmetic builtins).
  • You can assume the additional inputs given will be valid as well. So an integer when we want to read an integer or a character / string of multiple characters if we want to read those.
  • The Whitespace program-input can be taken in any reasonable format. Could be a string, list of characters, list of codepoint-integers, etc. Same applies to the other inputs.
  • Any non-whitespace character in the Whitespace-program input is ignored. You can assume the no-op characters will only be printable ASCII. So the Whitespace input will only contain the UTF-8/ASCII characters with the codepoints [9, 10, 32..126].

General rules:

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

Test cases:




Double speak!
DDoouubbllee  ssppeeaakk!!


Pastebin with the actual programs using spaces, tabs, and newlines including no-op comments, instead of the STN.

TODO: Add more test cases. I will add a couple more copy-pastes from Whitespace answers, as well as some custom made test cases to cover all the builtins (i.e. I've never used the slice builtin in a codegolf challenge thus far).

  • \$\begingroup\$ *"From here on out I will be using S for spaces, T for tabs, and N for newlines to make the text more compact." and readable! T_T \$\endgroup\$ – Noodle9 Jan 15 at 13:28
  • \$\begingroup\$ @Noodle9 ;) I wouldn't even be able to use tabs anyway, since StackExchange automatically converts them to four spaces when displaying (hence also the pastebin with the actual copy-pasteable test cases at the bottom). \$\endgroup\$ – Kevin Cruijssen Jan 15 at 13:31
  • \$\begingroup\$ Ah, interesting. This challenge looks great except my first concern is finding (literally being able to see) bugs in test-cases! :-) \$\endgroup\$ – Noodle9 Jan 15 at 13:33
  • \$\begingroup\$ @Noodle9 Do you mean while you're working on your own implementation, or for the test cases I've provided? Since all test cases I've added are actually answers for challenges here on CGCC. :) The third test case for this one; fourth for this one; fifth for this one; etc. I could also add a Whitespace-TIO link for each individual test case, then the paste-bin is redundant as well for copy-pasting and it can be verified at the same time. \$\endgroup\$ – Kevin Cruijssen Jan 17 at 14:21
  • \$\begingroup\$ Was more joking than anything (literally be able to see whitespace), but yes it was in the context of writing my own interpreter. \$\endgroup\$ – Noodle9 Jan 17 at 14:58

Buildings made from cubes

In this challenge, you are provided with a set of \$n\$ identical blocks and need to determine how many unique buildings can be constructed with them. Buildings must satisfy the following rules:

  1. No overhangs - each block must either be on the ground or supported by one or more blocks directly underneath it.
  2. All blocks must be aligned to a unit-sized grid.
  3. All blocks in a building must be connected to at least one other block by at least one face, and the blocks must form a single connected unit.
  4. Buildings are not unique if they can be mapped to another building by reflection or rotation in the X/Y plane.

e.g. These are the same:

  1. If a building is rotated between horizontal and vertical, that does result in a different building

e.g. These are different:

The challenge is to determine how many different house designs are possible using a given number of cubes. Input and output are both a single integer (using any standard method).

Clearly for 1 cube, only 1 design is possible. For 2 cubes, 2 designs are possible (lying down and standing up). For 3 cubes, there are 4 possibilities, and for 4 cubes there are 12 (see images below).

Beyond 4, I’m less confident but I think the first 8 terms are 1,2,4,12,35,129,495,2101. If we can verify this, I may submit the sequence to OEIS.

This is . The winning entry is the one that can determine the number of buildings for the highest value of \$n\$. This will be tested on an 8th generation Core i7 with 16 GB RAM running Ubuntu 19.10. Default loopholes and IO rules apply.

Cube images generated using usecubes.

  • \$\begingroup\$ this looks perfect for fastest-code. with fastest-algorithm it's difficult to do complexity analysis on the solutions. \$\endgroup\$ – ngn Jan 4 at 23:53
  • \$\begingroup\$ @ngn thanks, I’ve amended the alternative suggestion \$\endgroup\$ – Nick Kennedy Jan 5 at 0:23
  • 3
    \$\begingroup\$ it may be good to mention explicitly that all blocks must form a single connected component, otherwise 2 separate 1x1x2 pieces would technically satisfy rules 1-4 \$\endgroup\$ – ngn Jan 5 at 1:47

Is it time?

A time in the format hhMMss is represented by six numbers in the range 0..9 (e.g.100203 for 3 minutes after 2 minutes after 10am (10:02.03), or 155603 for three seconds after 56 minutes after 3pm (15:56.03).

Treating these times as integers, these numbers are therefore in the range 000000 to 235959; but not all numbers in that range are valid.

Normally, though, integers aren't represented with leading 0s, right?

So, this challenge is to take a numeric input (without leading 0s), and say whether it represents a proper time or not when the leading 0s are put back.


Any integer, as a string or an integer type, in the range 0..235959 inclusive. all numbers as strings will be input with no leading 0s (e.g. 2400, not 002400). The time 000000 maps to 0; or exceptionally as .


Truthy/Falsy value - by which I mean there must be a consistent distinction in the output between True and False - e.g. True could be output as 1 and False could be any other output (or even a variable output) - as long as it can be documented how to tell what is True and what is not.

More Challenge Details

Given the input integer, figure out if the number represents a time (truthy) or not (falsy).

A number represents a time if a time (hhMMss) with leading 0s removed is the same as the number.

e.g. 00:00.24 is represented by 24
e.g. 00:06.51 is represented by 651 e.g. 00:16.06 is represented by 1606
e.g. 05:24.00 is represented by 52400
e.g. 17:25.33 is represented by 172533

There are therefore some numbers that can't represent times:

e.g. 7520 - this can't represent hhMMss because 00:75:20 isn't a time

As a general rule, the valid numbers fall into the pattern:


The following numbers are the entire set of inputs and the required answers for this challenge

seconds only (e.g. 00:00.ss, with punctuation and leading 0s removed, -> ss)
0 to 59 - Truthy
60 to 99 - Falsy

minutes and seconds (e.g. 00:MM.ss, with punctuation and leading zeros removed, -> MMss)
100 to 159 - Truthy
160 to 199 - Falsy
etc, up to:
2300 to 2359 - Truthy
2360 to 2399 - Falsy
2400 to 2459 - Truthy
2460 to 2499 - Falsy
etc, up to:
5900 to 5959 - Truthy
5960 to 9999 - Falsy

hours 0..9, minutes and seconds (e.g. 0h:MM.ss with punctuation and leading zeros removed -> hMMss)

10000 to 10059 - Truthy
10060 to 10099 - Falsy
etc, up to:
15800 to 15859 - Truthy
15860 to 15899 - Falsy
15900 to 15959 - Truthy
15960 to 19999 - Falsy

20000 to 20059 - Truthy
20060 to 20099 - Falsy
20100 to 20159 - Truthy
20160 to 20199 - Falsy
etc, up to:
25800 to 25859 - Truthy
25860 to 25899 - Falsy
25900 to 25959 - Truthy
25960 to 25999 - Falsy
etc, up to:
95800 to 95859 - Truthy
95860 to 95899 - Falsy
95900 to 95959 - Truthy
95960 to 99999 - Falsy

hours 10..23, minutes and seconds (e.g. hh:MM.ss with punctuation and leading zeros removed -> hhMMss)

100000 to 100059 - Truthy
100060 to 100099 - Falsy
100100 to 100159 - Truthy
100160 to 100199 - Falsy
etc, up to:
105800 to 105859 - Truthy
105860 to 105899 - Falsy
105900 to 105959 - Truthy
105960 to 109999 - Falsy

This pattern is then repeated up to:

235900 to 235959 - Truthy
236000 onwards - Falsy

leading 0s must be truncated in the input, if strings are used.

Code golf, so least bytes wins - usual rules apply

  • \$\begingroup\$ Is 0 a valid time? Is 240000 a valid time? \$\endgroup\$ – tsh Jan 10 at 2:41
  • \$\begingroup\$ If input number is 0, should the string equivalent be "0" or ""? \$\endgroup\$ – tsh Jan 10 at 2:43
  • \$\begingroup\$ on a 24 hour clock times go from 00:00.00 to 23:59.59 - so that's the range. I wanted 0 to be "0" as a string, but I see from my wording why you asked - I guess I can accept "" as well (but I can't see a situation where that's better for a language anyway) \$\endgroup\$ – simonalexander2005 Jan 10 at 9:01
  • \$\begingroup\$ Just an fyi, there was some discussion a while ago about truthy/falsy since our old approach didn't accommodate languages without if constructs very well. I think it would be better to say one of true/false must have a consistent value, and anything else is valid for the other. \$\endgroup\$ – FryAmTheEggman Jan 20 at 19:43
  • \$\begingroup\$ Would this be a better challenge if the valid time needed to be output, instead of just true/false (with undefined behaviour if the input is invalid)? \$\endgroup\$ – simonalexander2005 Jan 22 at 10:09

Bucket and Minimize

The challenge - given a numeric list L and an integer N as inputs, write a function that:

  1. finds the bucket sizes for L such that it is split into N whole buckets of equal or near-equal size, and
  2. returns for each element in L the minimum of that element's bucket.

Example -

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

Compute the bucket sizes with the following:

\$\left \lfloor \frac{| L |}{N} \right \rfloor + 1\$ elements go into \$|L| \bmod N\$ buckets, and

\$\left \lfloor \frac{| L |}{N} \right \rfloor \$ go into the rest,

where |L| is the length of L. For the above, we get

floor(12/5)+1 into 12 mod 5 buckets, and floor(12/5) in the rest:

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

Finally, we output a list where each element is the minimum of its bucket:

[0, 0, 0, 3, 3, 3, 6, 6, 8, 8, 10, 10]

Some test cases:

In -> Out

[1, 2, 3, 4], 1 -> [1, 1, 1, 1]

[1, 2, 3, 4], 2 -> [1, 1, 3, 3]

[0, 2, 4, 6, 8], 3 -> [0, 0, 4, 4, 8]

[9, 3, 0, 1, 5, 7, 4, 6, 8, 10, 12, 11, 2, 13], 5 -> [0, 0, 0, 1, 1, 1, 4, 4, 4, 10, 10, 10, 2, 2]

I had to implement something like this the other day for sorted lists, though for this challenge L need not be sorted.

This would be my first challenge submitted, please offer feedback as you see fit :-)

  • \$\begingroup\$ @FryAmTheEggman thanks for the info. updated \$\endgroup\$ – scrawl Jan 21 at 9:40
  • \$\begingroup\$ "floor(12%5)+1 into 12 mod 5 buckets, and floor(12%5) in the rest". Shouldn't those floor(12%5) be floor(12/5) based on your \$\left\lfloor\frac{|L|}{N}\right\rfloor+1\$ formula? \$\endgroup\$ – Kevin Cruijssen Jan 22 at 10:40
  • \$\begingroup\$ @KevinCruijssen er, yes. keeping things conventional. in my preferred language (k4) % is float division. i'll update it to avoid confusion. thanks! \$\endgroup\$ – scrawl Jan 22 at 12:27
  • \$\begingroup\$ Ah ok. In most languages I know % is modulo and / is division. :) I thought maybe % was integer-division in your language of choice, making the floor obsolete. But your edit is indeed clearer. \$\endgroup\$ – Kevin Cruijssen Jan 22 at 12:47

I am pretty new to this but I wanted to create a challenge! It would be a challenge and the purpose is to create a program that differentiates polynomials.

A polynomial, for the purposes of program input, is going to be a string representing additions and subtractions of monomials of the form kx^d where k, d can be any real numbers (negative, 0 or positive) and x is the variable. The string can have an arbitrary amount of spaces around the + and - signs but one can assume that x is always followed by ^ which is always followed by a number.

Examples of polynomials would include

3x^2 + 3x - 1

-4x +3x^2 - 8 + x^-100

x + x + x + x - x - x - x - x

Would it be more interesting if the polynomial was allowed to have more variables and the program had to differentiate with respect to a specific variable? Or assuming the only variable that shows up is x and differentiate with respect to x is interesting enough?

New contributor
RGS is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • \$\begingroup\$ Some suggestions: allow flexible input format (that's default on the site). So the polynomial could be represented as a numeric array for example. I would got for the one-variable case, as other variables would be constants from the point of view of (partial) differentiation and would uselessly complicate dealing with the coefficients. Be sure to include test cases \$\endgroup\$ – Luis Mendo yesterday
  • 1
    \$\begingroup\$ Oh -- dupe? \$\endgroup\$ – Luis Mendo yesterday
  • \$\begingroup\$ I'm not sure why, but it seems that lots of people are excited about this type of challenge, like you are. We've wound up with a glut of challenges involving parsing and symbolic manipulation of polynomials. And this part tends to work out similarly whether you're differentiating or multiplying or adding or whatever. So I'd suggest making parsing not be a focus of this challenge. \$\endgroup\$ – xnor yesterday
  • \$\begingroup\$ @xnor so what would your suggestion be? \$\endgroup\$ – RGS yesterday
  • \$\begingroup\$ @RGS I'm for Luis Mendo's suggestion to allow the polynomial to be represented as an array of numbers. Maybe the one-variable case is too basic here though. \$\endgroup\$ – xnor yesterday
  • \$\begingroup\$ @xnor and it also becomes a dupe as per his link, no? What if instead of differentiation, the challenge is to expand a product of an arbitrary number of polynomials? \$\endgroup\$ – RGS yesterday
  • \$\begingroup\$ @xnor oh oh I know, it could be about getting a specific coefficient, just as in the setting of generating functions! What do you guys think? Should I write the proposal? \$\endgroup\$ – RGS yesterday
  • \$\begingroup\$ I see we have a challenge about multiplying two polynomials (given as lists). I think multiply n would be too similar. I do like getting one coefficient as opposed to producing the whole polynomial, but that still might not be different enough. \$\endgroup\$ – xnor yesterday
  • \$\begingroup\$ @xnor the question linked receives as input two polynomials of degree equal to the length of the list. I don't want to have to give a list of length 1000 to represent the polynomial x^1000... So it would be different in 1. Arbitrary number of polys 2. Input formatted differently 3. Compute and return a specific coefficient \$\endgroup\$ – RGS yesterday
  • \$\begingroup\$ @RGS How would you represent polynomials then? As a list of (coefficient, exponent) pairs? \$\endgroup\$ – xnor yesterday
  • \$\begingroup\$ @xnor that is what I was thinking. That, or the string. And then the arbitrary number of polynomials will be a list of those things or a big string xD \$\endgroup\$ – RGS yesterday

Count Syllables

The goal of this challenge is to write a program that can count the syllables in a word as accurately as possible.


On STDIN, your program will receive a number X followed by X lines, each containing a single word. Simple enough. (Should there be a limit on the size of X?) The words will come from this list.



Your output should be to STDOUT and have X lines. On each line should be the number of syllables counted in that word.



To score you program, it will receive a long secret list of words to test. All programs will receive the same list of words. For each word, the number of syllables that your program got wrong will be added to the score of the program. If it output a 4 or a 2 when the word had 3 syllables, then one point will be added. If it said a 15 instead of a 3, then 12 points will be added to the score. The lower the score, the better.

For example, if for the above input your program output 3 2 2 2 (which would be produced by a program that counts strings of vowels), then the program would receive a score of 2.


Your program should not access any external files (such as the word list). Also, your program should be no more than 5,000 bytes long (is this a reasonable limit?).

The winner will be the person whose program has the lowest score, therefor the most accurate syllable counter. The deadline for submissions is [some time at least a month away].


I am open to all constructive criticism. Is 5,000 bytes a reasonable limit for the program size? How long should the official scoring test be? How long should the deadline be?

  • 10
    \$\begingroup\$ This has one major flaw: the output is subjective. How many syllables do these words have? Every; victory; hierarchy; desire; oil; hour; poem. The only real way I see to work around this is for you to produce a marked-up version of the word list. \$\endgroup\$ – Peter Taylor May 29 '12 at 20:40
  • \$\begingroup\$ I was really worried about that, and I don't see a way around it. \$\endgroup\$ – PhiNotPi May 29 '12 at 20:42
  • 1
    \$\begingroup\$ I personally would love to see more language processing challenges. I agree with @PeterTaylor on the difficulty of some words. Perhaps taking a specific text(s) and identifying explicitly in the challenge which words will have how many syllables? \$\endgroup\$ – Gaffi Jun 8 '12 at 3:34
  • 2
    \$\begingroup\$ @PeterTaylor ...Or maybe you could filter ambiguous words out of the reference list? \$\endgroup\$ – user16991 Feb 8 '15 at 1:19
  • 1
    \$\begingroup\$ What's the point of the first line of input? \$\endgroup\$ – msh210 Apr 27 '16 at 20:05
  • 2
    \$\begingroup\$ If you provide a reference list, A hyphenated reference list, and hide a secret list which may or may not include members of the reference list, this would be a reasonable challenge \$\endgroup\$ – Rohan Jhunjhunwala Sep 17 '16 at 0:05
  • \$\begingroup\$ Do you plan to post this? If not, I'd be happy to adopt it. (If you don't respond within two weeks, by community standards, I'm allowed to do so.) \$\endgroup\$ – MD XF Aug 18 '17 at 3:20
  • \$\begingroup\$ The example of inaccurate program that would score 2 - did you mean to output 3 1 1 2 rather than 3 2 2 2? \$\endgroup\$ – Heimdall Nov 9 '17 at 18:31
  • \$\begingroup\$ A reference list could be dynamic: potential contestants can ask for words of their choice to be added to the list. They won't know what's on the secret list but will try to make their programs as accurate as possible (according to your syllable count) so they should always be able to ask for specific words they are not sure about. Of course, you could make it in different language. In my language, Slovene, it's much clearer how many syllables words have. How about Solresol, haha! \$\endgroup\$ – Heimdall Nov 9 '17 at 18:38
  • \$\begingroup\$ I am going to adopt this if you don''t respond \$\endgroup\$ – Christopher Dec 20 '17 at 16:48

Play Simple 2-Dimensional Minecraft

Recently I found this video of "HansLemurson" showing a computer that was built in minecraft, which runs minecraft. He is playing minecraft on a computer that was built in minecraft that is running on his computer. To be specific, it is a two dimensional version with an 8x8 grid of cells. There is gravity, block placement, and even jumping. It is worth noting that the computer is single purpose. The same person has built programmable computers, but making them single purpose allows the computer to be much smaller.


The minecraft world is an 8x8 grid (one horizontal and one vertical dimension). The grid is comprised of either Xs (representing blocks) or empty spaces. The player is an X that is blinking on and off about once every second.

There are two modes in the game, controlled by a toggle switch. The first mode is movement. This is controlled by a WASD-like button arrangement. If the player chooses to move left/right/down, the computer checks to see if the space immediately in that direction is empty. If so, then the player moves into that space.

If the player chooses to move up, then the computer checks that the block underneath the player is solid. If so, then the player moves upward two units. Notice that this can propel the player into a solid block. If this happens, the player is obscured by the solid block, but can still move to an empty block next to him. When the player is inside on a solid block, the game continues as if the block isn't there, although the block is still there once the player leaves it.

After each move, the player falls down one unit if there is empty space there. This simulates gravity. This is also why moving up moves up two units, so that the gravity makes a net movement of up one unit. Gravity does not cause the player to fall all of the way to the ground, just one unit.

The second mode is block placement. In this mode, the same exact WASD buttons are used. Instead of moving the player, they toggle the state of the block in that direction. If the player presses "left" and there is a block there, then the block is destroyed. If there is not a block there, then a block is placed. Again after this move, the player is again subject to gravity. The blocks are not subject to falling.

Toggling the toggle switch does not count as a move, and does not invoke gravity.

The game board is a torus, so all actions (movement, block creation) can wrap around the board. The board does not scroll with the player. The player moves, and the blocks stay in the same place.

The challenge

You challenge is to write the shortest program that simulates this game. Your program should display and update the map correctly (with Xs as blocks, and with the blinking player). It should accept input from a button that toggles the state and four buttons for movement and actions. This is code golf.

There are imaginary bonus points for adding more features (block types, game size, etc) to your game.


  • 2
    \$\begingroup\$ With more complicated challenges I find that it helps to do a reference implementation so that you have a very concrete idea of how much work is involved. Aside from that, I like it. \$\endgroup\$ – dmckee --- ex-moderator kitten Jun 3 '12 at 20:11
  • \$\begingroup\$ Is the blink rate selected to fit with the ANSI escape sequence? Either way I would explicitly allow that, because it's the obvious way to do it on compatible terminals. \$\endgroup\$ – Peter Taylor Jun 5 '12 at 7:14
  • \$\begingroup\$ The blink rate wasn't selected to be anything specific. I think that I will broaden the restriction. Maybe any blink rate between 3 blinks per second to 1 blink every 2 seconds. \$\endgroup\$ – PhiNotPi Jun 5 '12 at 20:21
  • \$\begingroup\$ @programmer5000 No, for two main reasons: First, challenges can go extended periods of time in the sandbox before they are posted and/or adopted. In the past I've posted challenges after not touching them for 4 years. Second, deleting this answer will not reduce lag, as deleted answers are still present, simply not visible. Users with sufficient rep will see all 4040 answers in the sandbox, and you will too once you earn the "view deleted answers" privilege. \$\endgroup\$ – PhiNotPi Apr 13 '17 at 18:15

I've Got The Key, I've Got The Secret

A cryptography challenge in 2 parts.

Part 1

Implement a pair of programs in any language (the two programs could be in different languages if you wanted) to encode and decode a string of plaintext.

Input and Output

The encoder must take the plaintext (and an optional key) and return an encoded string. The decoder must take the cyphertext (and an optional key) and return the plaintext exactly as it was given to the encoder.


  • The encoding and decoding code must be entirely implemented in the language - no libraries or cryptography functions may be used.
  • The code (encoder+decoder) cannot be longer than 1024 characters.

Part 2

Implement programs (multiple programs per answer, one answer per entrant) which crack your opponents encryption algorithms.


The cyphertext.


The plaintext that generated the ciphertext.


I will upvote all answers to part 1 which have working encryption and have obviously made an attempt at golfing their answer.

In order to be eligible to win, an entrant will have to have taken part in both parts of the question. Overall score will be (length of shortest program that cracks your code-(length of encoder+length of decoder)). Highest score wins and winning entrant's entries will be accepted on both questions.

  • 1
    \$\begingroup\$ The obvious place for this to fall flat on its face is if someone is able to implement AES or something similar within the 1024 character restriction. \$\endgroup\$ – Gareth Jun 13 '12 at 13:06
  • 1
    \$\begingroup\$ Probably better if the methods of the part one programs are disclosed in non-obfuscated language, though with the short length restriction this may not be necessary. \$\endgroup\$ – dmckee --- ex-moderator kitten Jun 13 '12 at 15:23
  • 2
    \$\begingroup\$ Forget AES: RSA is easily doable. That aside, you need to define "crack" in part 2. \$\endgroup\$ – Peter Taylor Jun 13 '12 at 15:35
  • 1
    \$\begingroup\$ Also, it's not clear whether "optional key" means that it's optional to make the algorithm unkeyed (doesn't make much sense, I admit) or optional to supply it, in which case it uses a default key. \$\endgroup\$ – Peter Taylor Jun 13 '12 at 15:42
  • 1
    \$\begingroup\$ @PeterTaylor I just put optional in to leave it up to the implementer whether or not they wanted to have the key input or hard-coded (or use no key). I'd have thought everyone would have the key input into their program, but I didn't want anyone to feel forced into it by the spec. Hmm, if RSA is doable within the character restriction I'll end up with a load of unbreakable codes which would make for a pretty crap part 2. By crack I meant cyphertext goes in, some time later plaintext comes out. Would restricting the character count further help, or is this question beyond help? \$\endgroup\$ – Gareth Jun 13 '12 at 16:05
  • 3
    \$\begingroup\$ On that definition of crack, I can brute force for the length of the decoder plus a few bytes to iterate over all keys of the right length and some heuristics to check plausibility of the plaintext. The brute force cracker might even be shorter than the decoder if the decoder wasn't written in GolfScript... I think this question may be beyond help. \$\endgroup\$ – Peter Taylor Jun 13 '12 at 16:28
  • 3
    \$\begingroup\$ @PeterTaylor Okay, thanks. I like the 'build your own - knock everyone else's down' aspect of this question though. I'll have to find another area where it could apply. \$\endgroup\$ – Gareth Jun 13 '12 at 16:34
  • 2
    \$\begingroup\$ @Gareth I too like the competitive nature of this idea. I'm looking forward to a question with this plan in mind! \$\endgroup\$ – Gaffi Jun 13 '12 at 19:31
  • 1
    \$\begingroup\$ I think it would be better to split this into a "cops" post and a "robbers" post. \$\endgroup\$ – wizzwizz4 Feb 16 '17 at 9:46
  • 1
    \$\begingroup\$ @wizzwizz4 Wow, this is another blast from the past. I think this pre-dates the cops-and-robbers tag. I always seem to be ahead of my time. :-) \$\endgroup\$ – Gareth Feb 16 '17 at 9:49
  • 1
    \$\begingroup\$ Can we delete this because the sandbox lags so much and this hasn't been touched in 5 years? \$\endgroup\$ – programmer5000 Apr 13 '17 at 17:35

You must log in to answer this question.

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