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]

| |

2956 Answers 2956

79 80
82 83

Plot an NACA Airfoil

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

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

Background information:

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

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

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

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

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

Possible scoring criteria are and

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

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

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

Optimize the JSON (WIP)

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

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

Draw these shapes

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


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

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

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

Scoring is .

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

Patch one line

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


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

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

Patch file format

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

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

Here are two accepted outputs for the above patch file:

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


Any other corner cases I'm missing?

You do not need to handle the following cases:

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

You do need to handle the following cases:

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


Is this much explanation necessary?

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

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

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

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

| |

A Gödel numbering


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


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

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

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

Mutual quine without sharing characters

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

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

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


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

Is the Art Gallery Fully Guarded? (WIP)

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

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


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


Key: . Floor, # Wall, G Guard

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

==> YES

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

==> NO

More TBD after visibility is hammered down

Rules, Notes, Assumptions

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

Happy Golfing!

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

Calculator using only addition

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


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


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


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


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


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

Word Calculator

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

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

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

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

  • cat+dog+tiger = catdogtiger

  • dog+cat+tiger = dogcatiger

  • dog+cat+tiger+tuna = dogcatigertuna

  • dog+cat+ttiger+tuna = dogcattigertuna

  • dog+cat+tttiger+tuna = dogcattigertuna

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

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

You will not be expected to handle negative values.

  • cat+dog-tiger = c

  • cat+tiger-dog = cati

  • cat+dog+ttiger-tuna = catdogt

  • cat+dog+tttiger-tuna = catdogtt

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

  • cat-dog = 0

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

Standard loopholes are not allowed.

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

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

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

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

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

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

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

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

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

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

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

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

Product and Sum free set

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

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


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



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

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

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

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

Use input letters to create as many words as possible

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


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

Example, using the letters from Scrabble:



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

Default loopholes are forbidden.

Meta discussion (not apart of the question)

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

Hungry Blobs KoTH

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

Energy and Movement

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


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


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

Detection and Information

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

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


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

Functions, Storage, and UIDs

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

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

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

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

Return Values and Upgrades

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

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

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

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

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

Predefined Library Functions

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

taxiDist(pt1, pt2, step = 1)

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

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

hypotDist(pt1, pt2)

Returns distance between two points according to the pythagorean theorem

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

modDist(dist, amt)

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

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

Example Blob

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

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


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

Who's serving in table tennis?

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

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

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

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

Test cases:

player1score, player2score -> output

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

Alternating Digit Divisibility

TODO: Could use a better title..


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

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

The two alterations are one of these two possibilities:

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

As for which digits can divide these numbers:

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

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


Challenge rules:

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

General rules:

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

Test cases:

Input:                      Output:

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

TODO: More to come, including some larger ones

| |

Help the library sort books

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

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

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

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

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

Test cases


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

Will it be red sauce, brown sauce, or no sauce at all?

Unfortunately Danny Baker's Sausage Sandwich game has been taken off the air again, and I'm suffering from withdrawal already. Please alleviate my symptoms by writing a program or function to play the Sausage Sandwich game.

You need to guess how the target prefers to eat a sausage sandwich, given one of the three sauce options. Given an input positive integer n, then the following applies:

  • There is a uniformly 1 in n chance that the target chooses no sauce at all.
  • Otherwise, there are equal chances of red sauce or brown sauce.
  • However, if n is even, then there are n-1 remaining chances, which don't divide by 2. If you draw this n-1th chance you should consistently (for a given n) output the same answer. Please indicate how this is chosen in your answer.
  • Output must consist of the phrases "red sauce", "brown sauce", or "no sauce at all", in any of lower, sentence, title or upper case.

This is , so the shortest program or function that breaks no standard loopholes wins.

| |

Print the Golfican sequence

The Golfican sequence is a sequence of integers, \$u\$, defined as follows:

  • If \$n\$ is a power of \$2\$, then \$u_n=\log_2n+1\$.
  • If \$n\$ in not a power of \$2\$, then \$u_n=u_p\$, where \$p\$ is the number of numbers from \$1\$ to \$n\$ inclusive which are not powers of \$2\$.

So, the first numbers in this sequence are \$1,2,1,3,2,1,3,4\$ and so on. Your job is to write a program which takes a number, \$x\$, as input, and outputs \$u_x\$. This is , so the shortest program in bytes wins.

I couldn't find a corresponding OEIS sequence for this. Thoughts?

| |
  • \$\begingroup\$ So \$p = n - 1 - \lfloor \log_2 n\rfloor = n - u_{b(n)} = n - \ell(n)\$ where \$b(n)\$ is the largest power of 2 less than \$n\$ and \$\ell(n)\$ is the length of \$n\$ in base 2? \$\endgroup\$ – Peter Taylor May 17 '19 at 8:27
  • \$\begingroup\$ I suppose it would be. \$\endgroup\$ – RamenChef May 17 '19 at 16:36


| |
  • 2
    \$\begingroup\$ (1) IMO the multiple-box requirement is essential to make it an interesting question. Otherwise it's just the hundredth shortest path question, and probably should be closed as a dupe. (2) "If your solution can only retrieve the first box, 10x penalty" is a really bad idea. See Things to avoid when writing challenges: chameleon questions, bonuses in code golf. \$\endgroup\$ – Peter Taylor May 17 '19 at 10:34
  • \$\begingroup\$ @PeterTaylor: Thanks, I've removed the bonuses and outlawed brute force. \$\endgroup\$ – Phil H May 17 '19 at 10:55
  • 2
    \$\begingroup\$ Banning brute force is also discouraged, as a non-observable requirement. Some people use a time limit to rule out the slowest kinds of brute force instead. For example, must process any of the test cases in under 1 minute (the time limit being chosen generous enough to make no difference to most approaches, so it doesn't even matter which computer it's measured on) \$\endgroup\$ – trichoplax May 18 '19 at 16:28
  • 1
    \$\begingroup\$ @trichoplax: I've modified to replace the brute force note with a time limit \$\endgroup\$ – Phil H May 20 '19 at 13:42

Balanced City Splitting

Right now, there exist N cities that are connected by N - 1 roads in a tree. All is well, but unfortunately, the country's infrastructure is unable to support so many cities and as the population has gone down, it is both practical and necessary to close exactly one city. However, as people migrate to larger areas, the government wants to make sure no remaining cluster of cities is too much larger than the other ones (closing a city also closes all of the roads connected to it).

Let there be N cities. Choose a city v. Then, S is the set of the sizes of the remaining subtrees after v and all edges connected to it are deleted. The score for v is max(S) - min(S). Find the minimum possible score for any city v if v is not a leaf node (because then S = {N - 1} and this isn't even a problem).


N = 5

1 2
1 3
1 4
1 5

The minimum score for this would be 0; if you remove 1, then you are left with 4 subtrees each of size 1. The final minimum score is 0.

N = 9

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

If you removed 2 or 7 (it's symmetrical), you'd be left with subtree sizes 1, 1, 6. If you remove 4, you're left with 1, 1, 3, 3. Neither is that great, but of those choices, 4 is the best and your minimum score is 2.


This is so the shortest code in bytes wins.

Standard loopholes apply. You may take input in any reasonable format and your output should be a single integer. Input constraints will be something reasonable; if your program can't handle regular 32-bit integers, please specify the constraint and I will accept it if it's reasonable enough. Your solution must theoretically work for any input though.


  • is the problem spec clear enough?
  • I will probably add more examples
| |
  • \$\begingroup\$ Can't this be done rather easily in O(n)? For fastest code the I/O performance would be the bottleneck. \$\endgroup\$ – user202729 May 22 '19 at 3:59
  • \$\begingroup\$ @user202729 I'll have to think about that; that might be true. I remember I solved it in theory at some point (untested); if so I'll just make it code-golf. \$\endgroup\$ – HyperNeutrino May 22 '19 at 4:00
  • \$\begingroup\$ The test data should be publicly available so that the scoring is objective. \$\endgroup\$ – Peter Taylor May 23 '19 at 14:50
  • 1
    \$\begingroup\$ It's quite easy to do in linear time: pick an arbitrary vertex at which to root the tree and perform DFS, labelling each vertex with the size of the subtree rooted there. Then for each vertex the sizes of the parts remaining if you delete it are the sizes of its children and n-1 minus the sizes of its children; the latter can be calculated and the min and max found in time linear in the number of children, and the sum of the number of children over all vertices is linear in the number of vertices because it's a tree. \$\endgroup\$ – Peter Taylor May 23 '19 at 15:12
  • \$\begingroup\$ @PeterTaylor Right. i remember how to do this now. Thanks, I'll make it code-golf and make examples public once I make them \$\endgroup\$ – HyperNeutrino May 23 '19 at 23:16

Output efficient Church encodings of natural numbers

The Church encoding of a natural number \$n\$ in lambda calculus is the higher-order function which takes a function \$f\$ to its \$n\$-fold iterate \$f^n = f \circ \cdots \circ f\$. For example,

0 = \f.\x.x
1 = \f.\x.f x
2 = \f.\x.f (f x)
3 = \f.\x.f (f (f x))


Write a function or program which takes a natural number \$n\$ and outputs a lambda calculus expression which is \$\beta\eta\$-equivalent to the Church encoding of \$n\$.


Any natural number, including possibly 0.


A lambda calculus expression in any format of your choosing, as long as it's an encoding that is pure data, or an equivalent in your programming language (e.g. if you wanted to write a submission in lambda calculus itself, the output must be a term which has a normal-form equivalent). Acceptable types of output would include a string or a data structure.

Whatever output format you choose, it must be a format which unambiguously maps to lambda calculus terms, and allows specifying any general lambda calculus term. You must then specify the mapping.

One possibility for a somewhat compact string encoding of typical lambda calculus terms would include terms such as:

\(0=\f x.x)(compose f g=\x.f(g x))(succ n=\f.compose f (n f)).succ(succ(succ(succ 0)))

Here, \ represents a lambda; lambda binding is considered right-associative; and function application is written as a concatenation and is considered left-associative. Then for example, \v1 v2 v3.body is syntactic sugar for \v1.\v2.\v3.body. As in the above example, this language also has syntactic sugar for let-style expressions where \(f a1 ... an=fbody).letbody (which in more verbose languages might be read as let f a1 ... an=fbody in letbody) is syntactic sugar for (\f.letbody)(\a1 ... an.fbody).


The crucial part of the challenge is that the encoding must be efficient: the output for input \$n\$ must be of length or total size \$O(\log n)\$.


This is : shortest submission in bytes wins. (In case of a tie, I might compare the "lambda complexity" of the outputs for input 2019, defined as the number of function applications plus the number of lambdas plus the number of variable terms excluding variables in lambda binders.)

Sandbox questions

I'm wondering whether the output format specification might be too lax. (For example, what if somebody gets a shorter submission using highly nonstandard syntax such as specifying that function application is right associative instead of left associative, so instead of s(s(s(s 0))) they could write s s s s 0?) On the other hand, if I required my "lambda calculus with syntactic sugar" format, then that might be considered akin to "here's my newly invented language, try golfing in it" which I'd think would be frowned on. Plus it might disadvantage languages which are good for golfing data structure creation but not as good for golfing output formatting.

| |

Optimize Grocery Bagging

You've gone to the store and are at the checkout. Now since you want to be environmentally conscious (or are somewhere that charges for bags and want to save money), you've brought a few reusable bags and would like to minimize the number of plastic bags you use (There are no paper bags here).

Each reusable bag can carry 5 kg (5,000 grams) of groceries and each plastic bag can carry 2.5 kg (2,500 grams) of groceries. You will be given a list of weights of groceries (in whole grams) and a number of reusable bags and your task is to output a configuration of bagging that requires the fewest number of plastic bags.


  • Input: 1 reusable bag, groceries: [150, 500, 800, 1250, 2000, 300, 550, 400, 750, 900, 1000, 600]
    • Output: Reusable[2000, 1250, 1000, 750], Plastic[600, 900, 550, 150, 300], Plastic[500, 800, 400]

More TBD

Rules and Assumptions

  • Standard rules and loopholes apply
  • Any convenient input or output method is acceptable as long as which bags are reusable is unambiguous in the output (without calculating anything).
  • You may assume that there are no groceries larger than 2.5 kg. (No jugs of milk)
  • All groceries listed require a bag. Unbaggable groceries will not be listed. (No hypothetical 24-packs of toilet paper)
  • Any grocery item can be bagged with any other. (No need to worry about bread and cans of beans being in the same bag)
  • Groceries cannot be split into multiple bags.
  • There is no double-bagging.
  • Complexity doesn't matter. There may be inputs that would require computation past the heat death of the universe to complete.

Happy Golfing!


Sandbox: This could work as a problem or due to the naive solution being in \$O(n!)\$. Thoughts?

| |
  • \$\begingroup\$ Related: codegolf.stackexchange.com/q/109797/25180 \$\endgroup\$ – jimmy23013 May 28 '19 at 22:39
  • \$\begingroup\$ This is NP-hard. \$\endgroup\$ – jimmy23013 May 28 '19 at 22:40
  • \$\begingroup\$ @jimmy23013 yes, indeed. If this were shifted to fastest-code it would necessarily drop the "guaranteed optimality" requirement. \$\endgroup\$ – Beefster May 28 '19 at 23:13
  • \$\begingroup\$ @jimmy23013 I guess this is only different from that linked challenge in that there are two bag capacities instead of just one. \$\endgroup\$ – Beefster May 28 '19 at 23:17
  • \$\begingroup\$ Do you mean requiring the minimum number of bags? If not required optimal, how do you decide whether an answer is valid? \$\endgroup\$ – jimmy23013 May 28 '19 at 23:18
  • \$\begingroup\$ As I remembered (USACO fence8), fast solutions to this problem may use strategies depending on the input data (e.g. try putting heavier things in bags first). You may have to specify exactly how it is scored if you change it to fastest-code. \$\endgroup\$ – jimmy23013 May 28 '19 at 23:22

Beziér me a curve!

Task: Create a program that will, given a number N, create a Beziér curve with N control points and output its equation.

The definition of a Beziér curve is $$ B(t) = \sum_{i=0}^n{{n\choose i}(1-t)^{n-i}t^iP_i} $$

Practically, this means that for a quadratic Beziér cuve: $$ B(2) = \sum_{i=0}^2{{2\choose i}(1-t)^{2-i}t^iP_i}\\ B(2) = {2\choose 0}(1-t)^2P_0 + {2\choose 1}(1-t)tP_1 + {2\choose 2}t^2P_2\\ B(2) = (t^2-2t+1)P_0 + 2(t^2-2t+1)P_1 + t^2P_2\\ B(2) = P_0t^2-2P_0t+P_0 + 2P_1t^2-4P_1t+2P_1 + P_2t^2 $$

where \$P_0\$ is the first control point, \$P_1\$ is the second control point and \$P_2\$ is the third control point.

Note that De Casteljau's algorithm may be useful.


  • The input will be a number (string or number).
  • The output will be a list of lists. Take an element \$l_n\$ of the top-level list. The elements of \$l_n\$ will be all the terms that, in the expanded form, are multiplied by \$P_n\$. -1t and t^1, as well as t^0 are all fine.
  • Standard loopholes are not allowed.

Test cases


  ["t^2", "-2t", "1"],
  ["2t^2", "-4t", "2"],


  ["-t^5", "5t^4", "-10t^3", "10t^2", "-5t", "1"],
  ["t^5", "-4t^4", "6t^3", "-4t^2", "t"],
  ["t^5", "2t^4", "t^3"],
  ["-t^5", "t^4"],

The program with the shortest length wins. Be creative!

| |
  • \$\begingroup\$ It would be more accurate (and IMO less confusing) to say that the task is to output the Bernstein basis polynomials of degree n, $$b_{a,n}(t) = \sum_{k=a}^n (-1)^{a+k} \binom{n}{k} \binom{k}{a} t^k$$ In line with Avoid cumbersome I/O formats I would also suggest outputting the polynomials as lists of coefficients, i.e. as a double array / matrix with $$A_{ij} = (-1)^{i+j} \binom{n}{i,j}$$. However, all of this is moot because now that I've rewritten it like that I see it's a dupe of codegolf.stackexchange.com/q/69424/194 \$\endgroup\$ – Peter Taylor May 29 '19 at 8:22

Reading the text of the millitext font

There is a font here that fits each character into a single, 1x5 pixel block. It does this (assuming you're using an LCD screen) by using the RGB channels of each pixel to expand the one pixel into three subcolumns, one for each channel. Your task is to take in a string of text that describes this font and return the correspond text encoded.

Millitext Alphabet


I've abbreviated each color to a one character symbol (R=red, G=green, B=blue, C=cyan, Y=yellow, M=magenta, W=white).

Input Format

The input format for this is pretty open. You can have the input be an array containing each column, an array containing each row, a char[][], or anything like that. You can also choose to use the full words "red", "green", "blue", with uppercase/lowercase of your choice (but it must be consistent for each word! You cannot use "RED" and also do "green" or "Blue").

If your language happens to support it, you can also have input be colors (however that might work, I don't know off-hand).

You can assume that the input will ONLY contain encoded characters in the alphabet above (in particular, there will be no spaces or punctuation in your output).

Output Format

You can either output a string or some sort of character array. You can chose whether the letters are uppercase or lowercase, but they must all have the same case.




This is code golf, so shortest answer wins!

Test set

| |

I Love U So Much!

Just print i love u, or I Love U.

But, because i love u so much, there is two rule.

  1. At least there must be one I, and one U. Capital or not is regardless.
  2. Every I and U must be stick together. No sole i and sole u.

This is , so shortest code with byte wins.

| |
  • \$\begingroup\$ What is preventing me from just putting a comment or no-op at the end with #IU or something similar? \$\endgroup\$ – AdmBorkBork Jun 11 '19 at 12:36
  • \$\begingroup\$ @AdmBorkBork Ah, I forgot that. Every I and U must be stick together. \$\endgroup\$ – LegenDUST Jun 11 '19 at 12:37
  • \$\begingroup\$ That's better, but it still allows, for example, BrainFuck to just type out the necessary > and < and put IU at the end as a comment/no-op. If that is your intention, that's fine, just wanting to point it out. \$\endgroup\$ – AdmBorkBork Jun 11 '19 at 12:42
  • 4
    \$\begingroup\$ IMO this is too boring to be worth posting. The string isn't compressible, so it's just a case of taking the string "ui love ", rotating by one character, and printing (finding a workaround in the languages where one would normally print with print). \$\endgroup\$ – Peter Taylor Jun 12 '19 at 10:54
  • \$\begingroup\$ @PeterTaylor Maybe I could make string more complicated? \$\endgroup\$ – LegenDUST Jun 12 '19 at 11:11

Trace My Triangles

Triangular is a 2D programming language that reads its code in the shape of the smallest triangle that the code will fit into, ignoring all whitespace. Its IP starts at the very top point of the triangle, and traverses the code starting in a Southeast direction. The IP's direction can be changed with the following directional switches (Note that "." is a no-op):

  ` /
 < . >  
  , \


You will be given a single input string p which represents a valid Triangular program. Your task is to write a program or function, which will print or return the actual execution order of p. Instructions in p which are never reached by the IP can be ignored.

You may assume the following:

  • p will contain only characters which are necessary for a Triangular program to be valid; no need to account for whitespace.
  • p will only switch directions via the directional switches listed above. The o,e,c and z instructions will not be used.


Input:                    Output:
F\(?)1/%-<                F(1<-%/?\)

,%./                      ,%/

\@~/;<                    \~<;/@

123456                    136

This is code-golf, so the shortest byte count wins.


  • Is this a good idea for a question/not a dupe?
  • Is the requirement clear enough?
  • What other test cases should I be adding, if any?
  • Should jump-related instructions - (, ) and ] - also be among the things that can be disregarded?
  • Should any other sorts of instructions be disregarded?
  • Would any other assumptions make this more manageable/fun?
| |

I'm not able to find a challenge which will return as an integer how many days until Christmas based on an input like DDDD-MM-YY. So...

How many days until Christmas?

Work out the number of full days until Christmas based on today's date based on the Western Christianity date source.

Write a program, method, function, routine or sub-routine that accepts an input of the current date according the the Gregorian calendar source. The date may be in any format as long as you use the full year (so 2019-09-11 rather than 19-09-11). Other than requiring the full year, the date format is up to you (DD/MM/YYYY or MM/DD/YYYY or even formally written dates like Wednesday 12th June 2019). Please state what date format you are using in your answer.

An integer is displayed according to your standard output.


input -> output:

12/06/2019 -> 196 days until Christmas*
12/25/2019 -> 0 days until Christmas**

* DD/MM/YYYY format
** MM/DD/YYYY format
| |
  • 1
    \$\begingroup\$ Subset of this? \$\endgroup\$ – Adám Jun 12 '19 at 13:18
  • 1
    \$\begingroup\$ @Adám Or really similar to Christmas Eve Eve, just accumulate the days rather than printing "Eve." \$\endgroup\$ – AdmBorkBork Jun 12 '19 at 13:22
  • \$\begingroup\$ Yes, thanks. Those challenges are specifically for technologies that have DateTime functions built in, my suggested challenge would be more suitable for technologies that don't know what date it is or what timezone they are in, like the Sinclair and Commodore 8-bit machines, for instance. Because you would have to specify the date and the rest would have to be worked out with some programmings. \$\endgroup\$ – Shaun Bebbers Jun 12 '19 at 14:15

Is this set doubly orderable?

For input you are given a set of four or five sets of strings. Each string is at least two characters long; those first two characters are always digits but the remaining characters can also be letters.

The set of sets is doubly orderable if an ordered list can be constructed using one element from each member of the set such that:

  • The first characters of each element of the list are in nondescending order
  • The second characters of each element of the list are separately in nondescending order
  • If any elements of the list have more then two characters, then those elements are all wholly equal with each other and appear at the beginning of the list (while still satisfying the other conditions).

Although there is an ordering on the list itself, the original sets can be sampled in any order necessary to achieve a valid list.

Example valid lists:

13  24  25  36
13e 13e 13  13
33s 37  37  37

Example invalid lists:

13  33  15  35  (first character not in order)
13  15  33  35  (second character not in order)
13e 24s 25  36  (different overlong strings)
33  37s 37s 37s (overlong strings are not first)

For output you should have:

  • A consistent value indicating that the set is not doubly orderable
  • A consistent value indicating that the set is can be doubly ordered using only 2-character strings
  • A list of all overlong strings of which one is needed to make a valid list.

Full example:

1. 13 23 33 14 24 34 15 25 35 16 26 36 17 27 37
2. 33s 15e 16 17e
3. 34 25
4. 17e 37

In this example the 34 and 25 in set 3 force us to use either 33s or 15e from set 2 and therefore the 37 from set 4, with a number of options from set 1. Since all the valid lists begin with either 33s or 15e, these are the outputs.

| |
  • \$\begingroup\$ I find this spec quite confusing. (1) ISTM that the property "doubly ordered" should really be "doubly orderable". (2) The order of the elements in the list can be inferred to be arbitrary from the fact that the spec talks about a set of sets, but it would be much better to make this explicit. E.g. change the second paragraph to start "The set of sets is doubly orderable if a list can be constructed by taking one element from each member of the set and ordering them so that:". (3) On the third bullet, do the elements have to be equal or just the suffixes? \$\endgroup\$ – Peter Taylor Jun 12 '19 at 13:40
  • \$\begingroup\$ @PeterTaylor (3) Yes, the elements have to be wholly equal in this case. \$\endgroup\$ – Neil Jun 12 '19 at 14:31

Proving that a Russian cryptographic standard is too structured

| |
  • \$\begingroup\$ Nice challenge. I have some suggestions for usability for solvers. Please say what language your example code is in (C?), and an online runnable version -- the community standard is TIO which is maintained by a site mod (example in Python). A pseudocode version or explanation would also be appreciated. It would be useful to include a listing of the permutation as 256 numbers from 0 to 255 written in base 10. The references would be cleaner as inline hyperlinks. \$\endgroup\$ – xnor Jun 6 '19 at 21:39
  • \$\begingroup\$ You should allow submissions to be programs or functions, which is default. Also, please change the scoring to bytes. I sympathize with wanting a fair comparison for 7-bit vs 8-bit languages, but past efforts have proved unpopular, and people now generally think of competitions as being within each language. You can leave the conversion to bits for your personal leaderboard. \$\endgroup\$ – xnor Jun 6 '19 at 21:46
  • \$\begingroup\$ Also, please make the challenge as self-contained as possible, which means putting into the challenge body the parts of the linked papers that are important for solvers. Here, I think this is mainly how the function p works. In particular, what does it mean that the table k is an affine function, and how can it be implemented as such? Does s have any structure? \$\endgroup\$ – xnor Jun 6 '19 at 21:52
  • \$\begingroup\$ Thanks a lot for your comments! I have updated the challenge and did my best to take them into account. Is it clearer now? \$\endgroup\$ – picarresursix Jun 6 '19 at 23:50
  • \$\begingroup\$ Yes, thanks for the edits. Now that you've explained that the core of the code is discrete log, I have some questions on that which other solver might have too. I take it the char declaration is to limit the values to 8 bits and discard bits? If I think of the field of size 256 as GF_2[X] modulo a certain irreducible polynomial, does the update a=(a<<1)^(a>>7)*29 correspond to multiplying by a polynomial? Could the initialization be l=0, a=1 instead? Note that LaTeX is enabled here, in case it's easier to write formulas. It also could help to say that ^ is xor, not power. \$\endgroup\$ – xnor Jun 7 '19 at 0:21
  • \$\begingroup\$ The answer to your questions are yes---mostly. The unsigned char are indeed used to discard some bits. We could alternatively replace a=(a<<1)^(a>>7)*29 with a=(a<<1)^(a>>7)*285 (where 256^29==285, in which case we wouldn't need the unsigned chars. This code snippet indeed corresponds to a multiplication by a polynomial. However, we cannot start at l=0,a=1. For some reason, the designers of $\pi$ used a variant of the logarithm such that $\log_2(1)=255$ instead of $\log_2(1)=0$. Both are "correct" in the sense that $\alpha^{255} = \alpha^{0} = 1$ but this variant is less common. \$\endgroup\$ – picarresursix Jun 7 '19 at 0:28
  • \$\begingroup\$ I added these clarifications to the challenge. \$\endgroup\$ – picarresursix Jun 7 '19 at 0:45
  • \$\begingroup\$ The output of your C code seems to not match the table. \$\endgroup\$ – xnor Jun 7 '19 at 1:02
  • \$\begingroup\$ The table was wrong rather than the C code. Thanks for catching it! I fixed it as well as the corresponding TIO link. To further simplify the verification, I added a link to the wikipedia page of Kuznyechik which contains the table of the function p. \$\endgroup\$ – picarresursix Jun 7 '19 at 1:18
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$ – xnor Jun 7 '19 at 1:57

Continue a progression

The \$k\$th generalized mean \$M_k\$ of a set of numbers is defined as $$M_k(a_1,\dots,a_n)=\root^k\of{\frac{a_1^k+\dots+a_n^k}n}.$$ \$M_0\$, the geometric mean, is defined through a limit \$\lim_{k\to0} \root^k\of{\frac{a_1^k+\dots+a_n^k}{n}} = \root^n\of{a_1\cdot\dots\cdot a_n}\$. \$k\$ does not have to be integer.

An arithmetic progression is (according to Wikipedia) a sequence of numbers such that the difference between consecutive terms is constant. A geometric progression is a sequence of numbers such that the ratio between consecutive terms is constant.

There is a simple way to generalize these (that also explains why on earth is geometric progression named geometric): for a progression of order \$k\$ for any 3 consecutive elements \$a\$,\$b\$,\$c\$ \$M_k(a,c)=b\$. This way, the arithmetic progression is of order 1 and the geometric progression is of order 0. The order does not have to be integer.

The task is, given 3 real positive numbers \$a,b,c\$, to find the next term in the progression formed by them.


  • If multiple valid outputs exist, you can output any of them.
  • It is guaranteed that a valid output exists.
  • An output is valid if \$|o_{correct}-o_{program}| \le10^{-5} \cdot \max(o_{correct}, 1)\$.

Sandbox stuff

  • I still have to prepare some test cases, especially for non-integer orders.
  • Has this been asked before?
  • Do multiple correct outputs ever exist? I feel like very often there are infinitely many.
  • Does Mathematica have a built-in?
  • Should I add a time limit? I feel like brute-forcing all floating point numbers and checking if they are valid outputs might be shorter than actually calculating.
  • Should I restrict the order to be integer, or even just 0 or 1 (leaving only arithmetic and geometric progressions)?
  • Is there a simple and beautiful formula for the next term that I was unable to find and that all answers will have to copy from each other? I could neither get Mathematica nor myself to solve any related equations.
  • Is the grammar correct enough?
| |
  • \$\begingroup\$ I think The task is, given 3 real positive numbers ... is a bit problematic, as receiving them sounds like a daunting task. \$\endgroup\$ – Jonathan Frech Jun 13 '19 at 15:21
  • \$\begingroup\$ @Jonathan Surely reading three numbers or taking them as function arguments or whatever is your language's alternative is the least thing you have to do here? \$\endgroup\$ – the default. Jun 13 '19 at 15:25
  • \$\begingroup\$ I think proving that submissions will always meet your validity criterion will be rather daunting. This will probably further encourage solutions that just try every single floating point number? I'd recommend saying that floating point issues won't be counted against the submission, but you still have a bit of a problem. If you do add a time limit I'd recommend saying that it only need be tested on the cases you provide (and maybe remind users that hardcoding is a loophole ;) ) \$\endgroup\$ – FryAmTheEggman Jun 13 '19 at 17:30
  • \$\begingroup\$ The time limit only on the test cases thing makes sense to me. What does "not counting floating point issues mean"? I think most solutions will have to use binary or ternary search, and that needs a, uh, stopping precision or a iteration count to be close enough. I think we can remove the need to verify it on all numbers by preparing a lot of test cases! \$\endgroup\$ – the default. Jun 14 '19 at 3:58
  • \$\begingroup\$ Not every solution will use that, and even if they do they may still run into a problem where they can't get a solution well enough based on their native floating point type and have to do a bunch of extra work. I think it works well as a catch-all that prevents golfers from having to struggle with weird edge cases. But generally I think you are right that just having enough test cases will be good enough (also I didn't get notified by your comment because someone else has commented already, you'd need to use @). \$\endgroup\$ – FryAmTheEggman Jun 14 '19 at 18:08
  • \$\begingroup\$ @FryAmTheEggman double-precision floating points have around 14 digits of precision, and 1e-8 is a perfectly common epsilon for such tasks (and I use 1e-5). And if I assume floating point numbers are arbitrary precision, that implicitly disallows binary/ternary search, as it will never produce the exact answer. And since the only two solutions I know are Mathematica NSolve and alternatives and searching for the order and then for the next number, this disallows all remotely interesting solutions known to me. \$\endgroup\$ – the default. Jun 15 '19 at 2:46
  • \$\begingroup\$ Assuming the languages that people use to answer your challenge will use a reasonable convention is not a particularly good one! I didn't meant arbitrary precision but arbitrarily larger precision based on what you have specified. It is probably fine the way you have it, I just think it is better to think about nonstandard languages when you can. If you put no time limit, some solutions may try to iterate over all floating point numbers of a particular precision, for example. Sorry if this has gotten out of hand, maybe I'm not doing a good job explaining what I mean? \$\endgroup\$ – FryAmTheEggman Jun 15 '19 at 3:16
  • \$\begingroup\$ So in short, given inputs \$a,b,c\$ find a \$k\$ such that \$a^k + c^k = 2b^k\$ and then find and output a \$d\$ such that \$d^k = 2c^k - b^k\$? There is a significant problem in that \$k=0\$ is always a solution to the first equation, so I think that the geometric mean would have to be tested first as a special case. \$\endgroup\$ – Peter Taylor Jun 18 '19 at 11:03
  • \$\begingroup\$ @PeterTaylor I think so. I feel like there actually is a simple and beautiful solution that everyone will have to copy from each other here. \$\endgroup\$ – the default. Jun 18 '19 at 11:08
79 80
82 83

You must log in to answer this question.

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