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 at 7:51
  • \$\begingroup\$ @guest271314 You can use this markup to create a tag in a draft: [tag:code-golf] \$\endgroup\$ – DJMcMayhem Aug 29 at 15:19
  • \$\begingroup\$ Why no featured anymore? Can't we have it auto-added or something? \$\endgroup\$ – JL2210 Sep 26 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 at 13:43
  • \$\begingroup\$ I think the sentence 'replace the post here with a link to the challenge and delete it' may specify that the deletion should be done immediately . \$\endgroup\$ – AZTECCO Oct 5 at 19:39

2568 Answers 2568


UTF-8 repair

UTF-8 is the standard by which most of the world operates. Software that was intended to take in other encodings have been modified or wrapped to use UTF-8 as input and output, some with bugs and/or sloppy adherence to the standard. Even rock-solid software with years-old implementations of UTF-8, such as Java, can contain numerous UTF-8 implementation errors.

The challenge

Given a string of characters as input, apply a list of transformations to it. The transformations can be applied in any order, but should have the same result as if the transformations were applied in the listed order.

  • Replace overlong sequences with their equivalent minimal-length encodings.
  • If a byte taking the form 0b11111xxx occurs, replace it, and up to three trailing bytes of the form 0b10xxxxxx, with a single replacement character (\uFFFD).
  • Replace any run of extraneous bytes taking the form 0b10xxxxxx with a single replacement character.
  • If a byte of the form 0b11xxxxxx is followed by an insufficient number of bytes of the form 0b10xxxxxx (either because of a byte of the borm 0b11xxxxxx or the end of the file/string), replace it and any trailing 0b10xxxxxx bytes with a single replacement character.
  • Convert a high surrogate character followed by a low surrogate character to the utf-8 encoding of the supplemental plane codepoint it represents.
  • Replace extraneous surrogate characters with the replacement character.
  • Remove the initial byte order mark (\uFEFF), if one occurs at the start of the string.
  • Keep all other characters intact. Make particular care to make sure that null characters are handled correctly.

The following are errors:

  • An inverted byte order mark (\uFFFE) occurs at the start of a string.
  • The transformed string consists of more than 16 codepoints, and more than 1/8 of them correspond to bad byte sequences.
  • The input string consists of more than 32 bytes, and more than 1/8 of them do not correspond to a valid character, an overlong character, or a surrogate character.

If an error occurs, use an error indication mechanism (return a null pointer, utilize a tagged union indicating an error condition, set an global error variable, throw an exception, raise a signal, whatever), and do not output anything other than an optional error message. Otherwise, print the whole transformed string.

Standard loopholes apply. As with all code golf challenges, shortest submission wins.

Test cases:

To be added if this submission gains traction.


Reverse a regex

The .NET regex engine has the ability to process a regex in right-to-left order. There are some subtle differences between right-to-left and left-to-right order, so for the purposes of this challenge, right-to-left order is equivalent to running a reversed regex on a reversed string.

But how do you reverse a regex? Aha, that's where you come in. You need to write a program or function that reads a regex and writes one that will match reversed strings.

Fortunately reversing regexes is quite simple: break them down into symbols and concatenate them in reverse order. The symbols you should support are as follows:

  • Unquoted nonmagic characters
  • Quoted characters
  • Character classes (anything from [ to an unquoted ])
  • Symbols with repetition suffixes (assume that any of +*? or {...} is a valid repetition suffix)
  • Parenthesised regexes (the inner regex will itself need to be reversed)

So for instance the reverse of a{2,}(\*[b-g])+ is ([b-g]\*)+a{2,}.

TODO: More examples, rules, loopholes.

Should I add lookaheads/behinds to the list or is that too complex?

  • \$\begingroup\$ Character classes and repetition suffixes, at the very least, need more detail. Obviously some advanced repetition suffixes simply can't work, but which ones should be implemented? \$\endgroup\$ – Peter Taylor Nov 3 '17 at 11:16
  • \$\begingroup\$ @PeterTaylor I don't understand why they can't work. You'll be able to assume that the input is a valid regex, so you'll be able to treat a+? as the symbol a+ with a suffix of ?. \$\endgroup\$ – Neil Nov 3 '17 at 13:42
  • \$\begingroup\$ I had possessive quantifiers particularly in mind. I do retract the "obviously": now that I'm trying to think of an explicit example, it's not easy. But I'm still confident that one can be constructed. \$\endgroup\$ – Peter Taylor Nov 3 '17 at 18:26

Find local Minimum

META: This is just meant as an introductory challenge for functional input (black box functions) and hopefully establish some more inputs.

Given a real number e > 0 and some black box function f: (0,1) → (-10,10) ⊆ ℝ, return a value x that is within e of a local minimum x* that means x ∊ [x* - e, x* + e].


  • A value x* is local minimum of f if and only if there is some a > 0 such that f(x*) < f(x) for all x ∊ (x* - a, x* + a) \ {x*}. This means all other points in some neighbourhood must have a strictly greater function value. (This definition is just for this challenge and might be different from other definitions.)
  • The input function f can assumed to be differentiable and satisfy f'(0) < 0 and f'(1) > 0 which means there are no local minima at 0 and 1.
  • You can assume that |f'(x)| < 1000 this means the function cannot be to steep.
  • You can use your native floating point numbers and assume e is sufficiently great. (That means greater than the machine precision of your floating point type.)
  • You can use any language for which there are defaults for black box functions input in the standard IO meta post. If there are no such default for your language feel free to add one in the sense of the definition of black box functions, and make sure to link your proposals in that definition. Also don't forget to vote on them.


x*                 f(x)
0.5                x*(x-1)
0.5                (x+1/2)^(2*k-1) * (x-3/2)^(2*k-1) for k=1,2,...,1000 
2*(k+1/4)/(2*n-1)  -sin(pi*(2*n-1)) for n=1,2,3,...,159 (for every applicable k there is one minimum)
  • \$\begingroup\$ FWIW there was a black-box function question a long time ago: codegolf.stackexchange.com/q/3839/194 . On a separate issue, being differentiable is quite a weak condition: is it strong enough to make this answerable? I don't know the whole zoo of nasty counterexamples in analysis, but ISTM that to have a local minimum you need a second derivative, and to solve for a black box you probably want at least the second derivative to be continuous. \$\endgroup\$ – Peter Taylor Nov 6 '17 at 14:47
  • \$\begingroup\$ Thank you for the feedback. You're right, right now it is not answerable, I found an counterexample, and also with requiring second derivatives we can solve it as a black box function. \$\endgroup\$ – flawr Nov 6 '17 at 20:13

I asked this question in main site. Got a very bad review. So, I would be glad if any kind soul here would like to help me make this question better. And Some feedback on how can i make it good.

Given any input, you need to encode / decode it in or from base 16, 32, 64.

So your task will be to make a base 16, 32, 64 encoder / decoder.

Standard Loopholes apply.
and that's all
In any format you like.
The inputs will be the 
i. Data
ii. Task (encoding or decoding) (0 or 1)
iii. Base (16 or 32 or 64)

The Encoded/Decoded data

The shortest code in byte wins.

Reference : RFC

  • \$\begingroup\$ Just as a starter, I would remove the "It should not be a builtin" (see this) Secondly, rather than link to a website with a description of what you mean, include that description in your question. Finally, allow function answers, rather than restricting to a full program. \$\endgroup\$ – caird coinheringaahing Nov 5 '17 at 16:10
  • \$\begingroup\$ @cairdcoinheringaahing thanks. I will add those changes \$\endgroup\$ – Kishan Kumar Nov 6 '17 at 2:36

The Guardian of the Chessboard

Given a collection of chess squares1, output the chess piece with the smallest value, together with its position, that is able to reach all the given squares in a single step.

1 - A chess square is a notation of a position on an 8x8 grid, with the x-axis being labeled with letters instead of numbers, meaning for example that the notation of 3|2 would be c2.


Input must be received as a collection of strings, each string representing a chess square. You may assume that the chess square will always be in the range a1 - h8.

Example Input: [ "b7", "c4", "h1", "g8" ]


Output must be in the format [piece][square], with piece being the notation of the chess piece, such as N, Q or K, and square being the notation of the square that the chess piece has to be located at.

You may either return a string from a method or directly output the result to stdout.


  • Note that you have to use the chess piece with the least possible value, so if there is a choice between for example Queen and Bishop, you would choose the Bishop. See below for a table noting the piece values.
  • Special moves such as pawn's first move, en passent and castling do not have to be respected.
  • This is , shortest code in bytes, in any programming language wins.
  • Standard loopholes are forbidden.

Data Table

Here you can look up each pieces value and its notation character.

|  Piece | Value | Character |
| Pawn   | 1     | P         |
| King   | 2     | K         |
| Knight | 3     | N         |
| Bishop | 3     | B         |
| Rook   | 5     | R         |
| Queen  | 9     | Q         |

Test Cases

Input -> Output

[ "b7", "c4", "h1", "g8" ] -> Bd5

(TODO: Add more testcases)


  • Duplicates?
  • Possible misunderstatings?
  • Task changes?
  • \$\begingroup\$ Reach in exactly 1 step? Is 0 step allowed? What about multiple steps? \$\endgroup\$ – user202729 Nov 6 '17 at 1:23
  • \$\begingroup\$ @user202729 Thanks, clarified. \$\endgroup\$ – Ian H. Nov 6 '17 at 8:55
  • \$\begingroup\$ Needs a mention of special cases (pawn's first move, en passant, castling): should we assume that none of them are available? \$\endgroup\$ – Peter Taylor Nov 6 '17 at 14:35
  • \$\begingroup\$ @PeterTaylor That's correct, I added it to the rules section, thanks! \$\endgroup\$ – Ian H. Nov 6 '17 at 16:27

Ternary Parity of Substrings


The ternary parity of a string is the number of 1's in its ascii bitstring mod 3. For instance, the ascii values for "Hello World!" are:

H:72 e:101 l:108 l:108 o:111 space:32 W:87 o:111 r:114 l:108 d:100 !:33

Converting each ascii value to binary gives:

H:1001000 e:1100101 l:1101100 l:1101100 o:1101111 space:100000 W:1010111 o:1101111 r:1110010 l:1101100 d:1100100 !:100001

Concatenating these together gives the combined bitstring:


Which has 45 1's. As a result, the ternary parity of "Hello World!" is 45%3 = 0.


Write the shortest program in the language of your choice that does the following:

  • Takes a string, s, as input.
  • Finds S, the collection of all substrings of s
  • Calculates the ternary parity of each element of S
  • Creates a ternary string, q, by concatenating the parity bits of each element in S
  • Outputs the ternary parity of q. That is, the number of 1's in q mod 3.


Input and output may use any of the standard methods listed here. The program must output three distinct values that indicate ternary parity. For instance, the program could print "one", "two", or "three", it could exit with an error code of 0, 1, or 2, or could be a function that returns False for 1 and Null for 2, and 100 for 0, etc.

Test Cases

"Hello World!" => 0
"foobar" => 2
"ABCDEFG" => 1
"abcdefg" => 0
"One" => 2
"Four" => 0
"2049" => 1
  • 2
    \$\begingroup\$ One element of a good question is a clear motivation. This looks like a random mishmash of operations. Why should anyone care about the result of this calculation? \$\endgroup\$ – Peter Taylor Nov 7 '17 at 10:14

Output an Anagram! No Not That One!

Given a list of unique strings that are anagrams of each other, output an anagram of those words that is different from each word in the list.

The strings will be alphanumeric, and there is guaranteed to be a valid anagram.

The program or function can, but doesn't have to be non-deterministic, meaning given the same input, multiple running a of the code can yield different outputs, as long as every possible output is a valid one.

Test Cases

[Input] -> Possible output
[ab] -> ba
[aba, aab] -> baa
[123, 132, 231, 312, 321] -> 213
[hq999, 9h9q9, 9qh99] -> 999hq
[abcde123, ab3e1cd2, 321edbac, bcda1e23] -> ba213ecd

Sandbox questions

  • Is this a duplicate of anything?
  • Any other test cases I should include?
  • 1
    \$\begingroup\$ I should probably post my other sandboxed challenge at some point... \$\endgroup\$ – MildlyMilquetoast Sep 27 '17 at 1:23
  • 1
    \$\begingroup\$ Should it output the same string each time given the same array of strings as input? \$\endgroup\$ – Shaggy Sep 27 '17 at 10:17
  • \$\begingroup\$ What do you mean by "unique" in the first sentence? \$\endgroup\$ – Peter Taylor Sep 27 '17 at 19:43
  • \$\begingroup\$ @PeterTaylor Did that clear it up? \$\endgroup\$ – MildlyMilquetoast Sep 27 '17 at 20:42

Clear the centrally significant on bits

Related and inspired by.


Input is a single positive integer n.


It's easiest to describe this by example.

n = 433

Take n's binary representation.

bin(n) = 110110001 

Note which bits are on.

^^ ^^   ^

Set the center bit of those that are on to 0. (if there is an even number of 1 bits, set both to 0).

^^ !^   ^

Finally, represent the input as an integer again.

unbin(110010001) = 401

Test cases

1 => 0
13 => 9
115 => 99
236 => 204
433 => 401
732 => 652
1555 => 1539
1556 => 1028

Additional Rules


Bring an end to the Vigil

Vigil, being the supreme moral paragon of programming languages, inspires us all to write bug-free code without exceptions through supreme medieval punishment.

However, every hero has their weakness, and Vigil's weakness is on line 98:

    print("Vigil has failed to uphold supreme moral vigilance.")

Your goal is to write a Vigil program that forces Vigil to experience an exception, reach this line, and print this error. Because it's not enough to merely succeed at our master plans, but instead we ought to succeed efficiently, the shortest answer in bytes wins.

Draft proposal notes

  • This is a language-specific challenge in the Vigil language alone. (Is there a tag for that?)
  • I'm not sure if a standard challenge is the best way to measure a winner in this scenario, but it's the primary measure that comes to mind.
  • I'd like to ham this up a bit more with narrative. Maybe about us being the villains. The title could be wittier.

Inverse Radiation Hardened Quine


Radiation hardened quines have been around for a long time. The basic idea is that it's (possibly) a valid quine, and if you remove any character, it's still valid. But what about the other way around? What if you added a character?

Challenge Description

Develop a program which will output its source code, even when a character is inserted in any position in the source code.


This program is a quine. It shouldn't take any input.


When the quine runs, it should either output its own source code, or the source code of the proto-quine.


Programs are scored on their robustness. That is, for a given program, if the characters "a", "!" or "😷" could be put into the program at any point and it remain a quine, then the program has a score of 3. I leave the burden of testing what characters work for your program up to you. Note that in languages with a limited character set (such as HQ9+ or brainfuck) characters that do nothing yield no score. You couldn't write a normal quine in brainfuck and then claim that every single unicode codepoint except the few used in a brainfuck program was your score.

Finally, other than that, standard rules apply.

  • \$\begingroup\$ Not a bad challenge, but could use some more fleshing out. Take a look at the framework of some other challenges, both here and in main, to see what the usual framework is. \$\endgroup\$ – Gryphon Nov 17 '17 at 0:58
  • \$\begingroup\$ To clarify, I mean specifically the usual: brief story about the challenge (optional), "Your Task:", task, "Input:" input methods, "Output:", output methods, "Examples:", examples, "Scoring:", scoring method. That framework works well for most challenges \$\endgroup\$ – Gryphon Nov 17 '17 at 1:00
  • \$\begingroup\$ Can we chose where the character is inserted? \$\endgroup\$ – ATaco Nov 17 '17 at 1:13
  • \$\begingroup\$ @ATaco no, it has to be valid for anywhere. Otherwise, somebody would make a safety box for the character. \$\endgroup\$ – Jakob Lovern Nov 17 '17 at 1:21
  • \$\begingroup\$ I would suggest clarifying your scoring section, specifically specifying "robustness" better. I'm pretty sure I get what you mean, but others may misinterpret that. Other than that, this looks like a great challenge. +1 \$\endgroup\$ – Gryphon Nov 17 '17 at 1:57
  • \$\begingroup\$ Is the emoji bad? I put it in there to demonstrate únicode, but I'm not sure the point is that obvious. \$\endgroup\$ – Jakob Lovern Nov 17 '17 at 2:41
  • \$\begingroup\$ Nah, it's fine. The example makes it more clear. I might add something to specifically say that it doesn't count if a character can be inserted twice (or at least, that's my understanding of the rules), but other than that, you should be good. \$\endgroup\$ – Gryphon Nov 17 '17 at 3:24
  • \$\begingroup\$ To be certain, when you say it should output "it's own source code, or the source code of the proto-quine" then, after a character is added, your code may either output the original code or the modified code? Is it alright if a single submission does one or the other depending on the type or location of the inserted character? \$\endgroup\$ – Kamil Drakari Nov 17 '17 at 15:34
  • \$\begingroup\$ @KamilDrakari yeah, as long as it does do at least one of the two. \$\endgroup\$ – Jakob Lovern Nov 17 '17 at 18:16

Rhythm Generator

Your task: given a number n from 2 to 5 inclusive, (pseudo)randomly generate a valid rhythm in the time signature n/4, and output using the system explained below. It must have an equal chance of choosing each valid rhythm.

Background Information:

In music, collections of beats are called "measures." You can only fit a certain number of beats in a measure, determined by the time signature. For example, a time signature of 4/4 would mean that you can put 4 (as determined by the first number) quarter note (determined by the second number) beats in the measure.

There are different kinds of notes. For the purposes of this challenge, the following characters will represent different kinds of notes (and how many quarter note beats each one is worth):

W        Whole note                4
H        Half note                 2
K        Dotted Half note          3
Q        Quarter note              1
D        Dotted Quarter note       1.5
E        Eighth note               0.5
F        Dotted Eighth note        0.75
S        Sixteenth note            0.25

(There are other kinds of notes but they do not apply to this challenge)

Note: A dotted note takes 1.5 of the length of its non-dotted counterpart.

In a n/4 measure there can only be n quarter note beats. Some notes take more than a beat, some less. But the total number of beats needs to add up to n.

For example, here are some valid 4/4 measures (separated by newlines):


And here are some examples of valid 3/4 measures:


So, your task is to generate a rhythm and output it in that format.

So now let's make some music!

Test Cases:

Coming soon. Will be a complete list of all possible valid rhythms.


Moore-Penrose inverse

In linear algebra the pseudo-inverse of a matrix is a generalization of the inverse of a matrix which doesn't necessarily exist. One definition of a pseudo-inverse is called the Moore-Penrose inverse which shall be denoted by A⁺ in the following. Further let Aᵀ denote the transpose of the matrix A.


The Moore-Penrose inverse of the matrix A is defined for all matrices A in a way such that it satisfies the following four properties:

  • AA⁺A = A
  • A⁺AA⁺ = A⁺
  • (AA⁺)ᵀ = AA⁺
  • (A⁺A)ᵀ = A⁺A


Your task in this challenge is, given a matrix real A (non-zero and non-empty) to compute its pseudo-inverse as defined above.

  • You're allowed to receive input as a single list, array, list of lists etc.
  • The input is a single non-zero, non-empty matrix with real entries
  • The input matrix is not necessarily square
  • Your program/function either returns the pseudo-inverse or prints it to STDOUT
  • You don't need to handle floating point inaccuracies
  • The behavior on invalid input (eg. []) is left undefined


Here are some possible examples (note the different (in)accuracies):

[4] -> [0.25]
[1 1; 1 0] -> [0 1; 1 -1]
[12 4 9; -9 1 3; -6 6 15] -> [0.0467129 -0.0342457 -0.0217785; 0.0115298 0.0022497 0.0160292; 0.0251844 0.0076240 0.0404324]
[0 1 0; 0 0 1; 0 0 0; 2 0 0] -> [0 0 0 0.5; 1 0 0 0; 0 1 0 0]
[1 1 2 3] -> [0.0667; 0.0667; 0.1333; 0.2]
[0; 0; 1] -> [0 0 1]
[1 0 0 0 0; 2 0 0 0 0] -> [0.2 0.4; 0 0; 0 0; 0 0; 0 0]


  • Should I ban built-ins (looking at Octave/Matlab, Mathematica etc.)?
  • Is the part with floating-point inaccuracies formal/objective enough?
  • Are more examples needed?

Tags: , , ,

  • \$\begingroup\$ Having no challenge for computing a SVD, maybe I should reduce this to only computing the SVD of a matrix since that would be the heart of this challenge anyway. What do you think? \$\endgroup\$ – ბიმო Nov 22 '17 at 15:00

Examining the Student's Swing

The 2017 Level 1 Mathematics and Statistics NCEA examination paper has been making headlines in New Zealand for being 'impossible' and bringing students to tears.

One of the questions involves a children's playground swing, and finding where the holes in the swing seat should be placed. But lets generalise the problem in code in the fewest number of bytes, in case they have to solve for a different swing (in a different exam).


Find how far apart the holes in the board need to be if the shape of the rope stays the same, given the following swing setup:

  • The rope hangs from a cross beam at a height h, and will have a parabolic shape, as presented in the exam (rather than a catenary shape), and will maintain this shape with the seat.
  • The rope is connected to the crossbeam at two points, that are separated by a distance d.
  • The lowest point (vertex) of the rope sits above the ground at a height of v.
  • We have an adequately sized wooden board for the seat, and we want this to be at a height s above the ground.

Exam questions often have a visual representation to help clarify the question, so I've also included one:

enter image description here


  • inputs must take positive real values
  • s will be greater than v
  • output must be correct to at least 2dp.
  • This is , therefore, the lowest byte count in each programming language wins
  • Standard rules apply, and no forbidden loopholes

Test Cases

(h,d,v,s) -> hole separation
(4, 6, 1, 1.2) -> 1.549
(10, 4, 2, 4) -> 2
(14.5, 12, 2.5, 5.5) -> 6
(4.25, 3.4, 0.5, 1.2) -> 1.468

Sandbox Questions

  • First time question, so any recommendations would be great
  • Any recommendations for how I can make this a well received question?
  • are there any rules I'm missing, or should add?
  • is this a duplicate?
  • What other tags should this question have?
  • \$\begingroup\$ About the output must be correct to at least 2dp. part, I'm afraid that there will be some problems from that requirement. A better requirement is "the algorithm in the code must be able to theorically calculate to infinite precision, but numerical error from programming language type limit is acceptable". / Also, the "the rope is always in parabolic shape" is weird, is that correct? If so you should highlight it. (normally a unweighed rope has catenary shape, and a weighed rope has the shape of multiple straight line segment) / Otherwise the challenge looks good. \$\endgroup\$ – user202729 Nov 22 '17 at 7:48
  • \$\begingroup\$ Thanks for the suggestions; the 2dp was based on the exam question requirement of showing your working to 2dp, though I understand the precision issue. Maybe I just remove that rule? I didn't know about catenary shape, the exam question just used a parabola, so I'll highlight that fact. \$\endgroup\$ – Ayb4btu Nov 22 '17 at 8:39
  • \$\begingroup\$ So in other words, given (h,d,v,s) output d sqrt((s-v)/(h-v)). I don't think it's a duplicate, but I also think that the reason that it isn't is because everyone has previously (and correctly) concluded that calculating a square root without restrictions to prohibit builtin sqrt functions is too trivial to be worth posting. \$\endgroup\$ – Peter Taylor Nov 22 '17 at 15:00
  • \$\begingroup\$ @PeterTaylor Well, (you know) on this site it is generally discouraged to post a "puzzle", because once the first answer had been posted, the other answers can just use that - and your comment has already specified the method. / You meant sqrt should be prohibited? That will lead to the (well-known) do X without Y problem. \$\endgroup\$ – user202729 Nov 22 '17 at 15:15
  • \$\begingroup\$ @user202729, no, I did not mean that. I meant that "Calculate sqrt without a builtin sqrt" would be a duplicate (although maybe only of closed questions). See codegolf.stackexchange.com/q/73/194 and linked questions. \$\endgroup\$ – Peter Taylor Nov 22 '17 at 15:25
  • \$\begingroup\$ @PeterTaylor This exam question certainly simplified down to a trivial coding answer; I think I was more posting due to the story behind it. I'll have a think about if or how to make it a bit more challenging. Will just mean that it may not be as closely related to the exam question on which it is based. \$\endgroup\$ – Ayb4btu Nov 22 '17 at 20:29

View float numbers in graphical binary

IEEE 754 is a well known format for representing floating point numbers.

Your task is to give an input to the user where he/she enters a signed float number and represents clearly the number in a color separated by functional area binary 32 bit single representation, like:

  • You do not have to append the captions like they are in the figure.

  • You must follow the order Sign, Exponent, Fraction

  • You may choose whatever colors you want, as they are distinguishable from each other and from the binary text numbers.

  • The input (I suggest a text box) does not have to forbid invalid values, but if does not, the graphical binary view needs to indicate the invalidity. You can leave it empty or replace with some text like "ERROR" or "INVALID".

  • Every little change on the input needs to make the binary view to be immediately updated. Changing and have to confirm with an "OK" like button is not acceptable.

No winner, unless I see some very creative answer. I would like to see a golfed and an ungolfed version of the code.

  • 1
    \$\begingroup\$ Needing the output to be dynamically updated based on the input changing (and not an OK or the like) is going to drastically limit the languages that can participate. \$\endgroup\$ – AdmBorkBork Nov 21 '17 at 18:58
  • 1
    \$\begingroup\$ Additionally to what @AdmBorkBork said, the requirement of dynamically updating the output & validating input is just distracting from the real challenge. I'd just leave behaviour on invalid input undefined. \$\endgroup\$ – ბიმო Nov 22 '17 at 15:08

Optimise Retina transliterations

For the question Translate Morse code based on tone duration I stupidly created the following transliteration:


The first thing wrong with it is that it 2, 8 and 9 transliterate to themselves, so they are superfluous. This saves 6 bytes:


The next thing to notice is that we have some runs of consecutive letters, but because they're not ordered we can't reduce them. Let's sort them:


We can now save another 3 bytes by using the run G-K, a byte by using the run M-O, and 3 bytes by using the run R-W:


Total 13 bytes saved. Note that there are other optimisation opportunities but I think they might be too difficult be worth adding to the question; for instance, inserting a C (at a cost of 2 bytes) allows the creation of the run A-E for a 3-byte saving, which is still overall a byte saved; inserting all of the letters to achieve run A-Z would then be simplified to L.

Is the Retina command string too inflexible an input format? I suppose input could be in the form of an unordered mapping from printable ASCII to printable ASCII, but output would need to be the actual Retina syntax, including appropriate quoting, because the length of the result is important.

(Quoting: The characters -dEOHhLlwpoR`\ need to be quoted except that the letters don't need to be quoted as part of a range.)

Should this be a question or ?


A Knight's Walk

On a chessboard, a knight has two options for movement: it can move one square horizontally and two squares vertically, or two squares horizontally and one square vertically. In short, it can follow the path drawn by an upper-case "L". These can be oriented in any way, and as such, a knight has 8 potential moves from any given position.

There have been a number of challenges posted at one time or another regarding knights and their movement because they're so mathematically interesting (and the problems are easy to state) but we're going to go for a basic one that I haven't seen.

The Challenge

Given two 2d coordinates (x1, y1), (x2, y2) return the minimum number of moves required to travel from (x1, y1) to (x2, y2).

There are no other pieces on the board, and you may assume that the coordinate values given are valid (a set of two integers) though they may not be unique. You may also assume that each individual coordinate value will be between 0 and 255, and that the board is large enough that you needn't consider edges.

Input Format

As long as the coordinates are inputted in the order x1 y1 x2 y2 you can accept them as four separate values, two tuples, two lists, etc...


(0, 0) (1, 2) => 1
(0, 0) (1, 1) => 2
(125, 125) (126, 127) => 1
(-100, -100) (0, 100) => 100
  • \$\begingroup\$ You might want to more explicitly state that negative numbers must be supported. Also, 'less than 128' applies only to inputs? or to anything? \$\endgroup\$ – Rɪᴋᴇʀ Nov 24 '17 at 0:24
  • \$\begingroup\$ Will do! And I'm not sure what you mean by that second part: I mean the input values will individually have absolute values of less than 128 a.k.a. (-127, -127) to (127, 127). This is totally a point I'm flexible on though. I just figured there may be languages that don't support very large numbers in any given memory location, and didn't want to give them additional hoops to jump through. Edit: Should I just make the valid range 0-255? \$\endgroup\$ – Willbeing Nov 24 '17 at 1:45
  • \$\begingroup\$ I'd recommend making it 0-255, yeah. I don't really think it's fair to have input be -127, +127, and then the boundaries of the chesboard be infinity. That's just kinda contradictory. \$\endgroup\$ – Rɪᴋᴇʀ Nov 24 '17 at 2:14
  • \$\begingroup\$ Do you think I should keep a bound like 255 at all? Would 2^16-1 or 2^32-1 be better? My whole premise with picking a number like this was that I want it to be easy to represent any number you'd run into, but impossible to use any kind of naive recursion to solve it \$\endgroup\$ – Willbeing Nov 24 '17 at 3:31
  • \$\begingroup\$ "impossible to use any kind of naive recursion to solve it" - Why? I don't understand your argument. / What is the winning criteria? \$\endgroup\$ – user202729 Nov 24 '17 at 13:29
  • \$\begingroup\$ @Willbeing I think 255 is fine, it doesn't matter too much. I've seen successful challenges that only require you to support up to 255, but that's it. \$\endgroup\$ – Rɪᴋᴇʀ Nov 24 '17 at 14:35
  • \$\begingroup\$ @user202729 Yeah, it sounds odd when its played back to me, hahaha. I only care if the program deterministically produces the correct step count. I still think limiting the input size is probs a good idea, just not for that reason anymore. \$\endgroup\$ – Willbeing Nov 24 '17 at 19:21

Clean duplicate website from my history


I am looking for help to monitor my history. I parsed everything, but I am not yet happy with the final result. Could you help me? I want to remove following same website.

My history looks like this:

| url                                               | id |
| https://codegolf.stackexchange.com/q/147318/15214 | 4  |
| https://codegolf.stackexchange.com/q/148927/15214 | 4  |
| https://en.wikipedia.org/wiki/Code_golf           | 3  |
| http://lichess.org                                | 2  |
| https://en.wikipedia.org/wiki/Code_poetry         | 1  |

But I want it to be:

| url                                               | id |
| https://codegolf.stackexchange.com/q/148927/15214 | 4  |
| https://en.wikipedia.org/wiki/Code_golf           | 3  |
| http://lichess.org                                | 2  |
| https://en.wikipedia.org/wiki/Code_poetry         | 1  |
  • If I browse a site, then another one, then the first one. I keep all of them.
  • If I browse a site, then another part of the same site. I keep only the first one.
  • The list is ordered from young to old. (we keep the older)

This challenge is inspired by my day work, but it is not related in any ways with anything in it.


  • Input is a list of identifier.
  • Output is a list of two elements (identifier's index, identifier).
  • No Empty input
  • No standard loophole
  • This is code-golf, so shortest answer in bytes wins.

Examples Input and Output

2 links on website 1


[ 1, 1 ]



1 link on website 2, then 3 links on website 1


[ 1, 1, 1, 2]



1 link on website 1, then 1 link on website 2, then 2 link on website 1


[ 1, 1, 2, 1]




  • Should I allow outputs as list of object, list of tuple or dictionary/map?
  • Should I ask for url parsing where identifier is the hostname?
  • 1
    \$\begingroup\$ Question title and tag? \$\endgroup\$ – user202729 Nov 24 '17 at 14:11
  • 1
    \$\begingroup\$ Also I think the I/O specification (Input is a list of two elements. / Output is a list of two elements.") seems to contradict the test cases. \$\endgroup\$ – user202729 Nov 24 '17 at 14:33
  • \$\begingroup\$ @user202729 Update title, tag and I/O specs. Thank you. \$\endgroup\$ – aloisdg Nov 24 '17 at 14:53
  • \$\begingroup\$ You definitely should allow using tuples, maps and dictionaries for input and output. In fact, that's an understatement. You should read the meta post on I/O methods. URL parsing will make the challenge more interesting, IMO. \$\endgroup\$ – NieDzejkob Nov 24 '17 at 19:12

File Selection

In this challenge, you will be given a number of files and a series of instructions corresponding to simulated key-mouse press combinations performed in a file explorer (rules below) and you are to return the files that are selected.

There are two "program states" you need to store: the target (which is the last file selected) and the files selected so far (this starts as [])

Static Combinations

These can be given as any constant values that are distinct from each other.

  • Ctrl-A: Select all files. Does not change the target.
  • Esc: Deselect all files. Sets the target to None.
  • Up-Arrow: Select only the file directly above the target. This should have no effect if the target was the first file. This should select the last file if there is no target. Sets the target to the selected file.
  • Down-Arrow: Select only the file directly below the target. This should have no effect if the target was the last file. This should select the first file if there is no target. Sets the target to the selected file.
  • Shift-Up-Arrow: If the most recent selection is a range going down, then remove the target from the selection and then set the target to the one above. If the most recent selection is a range going up or is a single file, then set the target to the one above and then add the (new) target to the selection. If there is no selection, this should select the last file. Alternatively, you can imagine this as undoing the last action, moving the target up, and then reapplying the last action with the new target; however, this idea is not 100% accurate when the last action was Esc.
  • Shift-Down-Arrow: Same as above, except with down and up swapped, all above and below swapped, and first and last swapped.
  • Home: Select only the first file and set the target to the first file.
  • End: Select only the last file and set the target to the last file.

Note that up arrow and down arrow should not wrap around.

Keyboard-Mouse Combinations

These can be given as any combination of a constant value that is distinct from the others on this list and a number representing which file was clicked.

  • Ctrl-#: Add # to the selection list and set the target to #.
  • Shift-#: Add all files between the target and # (inclusive) to the selection list and set the target to #. If there is no target before this operation, this will behave like Blank-#.
  • Blank-#: Set the target to # and select only #. Technically Blank isn't a key but to make matters simple, it's just a placeholder so I don't have to add a third class of combinations just for regular mouse presses.

Challenge Specifications

You will be given input as a positive integer representing the number of files, and a list of any of the combinations listed above, in a reasonable input format that you choose. The output should be a list of which files are selected, with any indexing.

Test Cases

All of these test cases have 10 files. [#] is a mouse press.

Input [1-indexed] -> Output [1-indexed]
Ctrl-A -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Shift-Down-Arrow, Shift-Down-Arrow, Shift-Down-Arrow -> [1, 2, 3]
Shift-Up-Arrow, Esc, Shift-[4], Ctrl-[7], Shift-[9] -> [4, 7, 8, 9]
Down-Arrow, Down-Arrow, Down-Arrow, Shift-Down-Arrow, Shift-Down-Arrow, Ctrl-[8], Shift-[10] -> [3, 4, 5, 8, 9, 10]

Rules and other technical things

  • Standard Loopholes Apply
  • Shortest code wins, but no answer will be accepted
  • You may not open a file explorer and run the commands :P (I think that would end up being longer anyway)
  • No builtin for this exact challenge (I will be very surprised if there is one, unless it's Mathematica)


  • I'm not confident that the explanation / specification is good enough for the Shift Arrow Key combinations; is that clear or do I need to specify it more rigorously?
  • Is anything else unclear?

Please leave an upvote if the challenge makes sense to you and please downvote if anything is unclear.

  • 1
    \$\begingroup\$ "You may not open a file explorer and run the commands" and "No builtin for this exact challenge" - why? This just rules out what could have been an interesting/laughable solution. \$\endgroup\$ – NieDzejkob Nov 27 '17 at 15:37
  • 1
    \$\begingroup\$ @NieDzejkob Yeah but anyone who posts one will probably end up getting a ton of undeserved upvotes having done next to no work. It shouldn't be a huge problem because probably approximately 0 languages have a builtin to do this, but still. \$\endgroup\$ – HyperNeutrino Nov 27 '17 at 15:43
  • \$\begingroup\$ It's kind of implied that there is only one column, but if that's the case that should be explicit as things like Shift-UpArrow function very differently if there are multiple columns. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:55

DNA Quine

Problem Description

Design a quine that outputs its own source code, but encoded into amino acids.
Read your source code in as binary. Each pair of bits now maps to a nucleotide like so:

00 -> A
01 -> C
10 -> G
11 -> T

For example, the ASCII character N has a binary representation of 01001110, so it would produce the nucleotide sequence CATG. A set of three nucleotides produces an amino acid. You can find the charts online, and I can't access imgur, so... yeah.

Anyways, your program must output its own source code as the three letter amino acid names. For example, if your code were 013201323300 in base 4, its nucleotide representation would be ACTGACTGTTAA and its amino acid representation would be ThrAspCysSTP.


Your program must output its representation in amino acids.

Further Rules

All quines must also be valid proteins themselves. This means that:

  • The quine has a number of nucleotides divisible by three
  • The last three nucleotides are either TAG, TAA, or TGA, corresponding to a STP codon
  • No STP codons appear anywhere but the end of the quine.

Apart from that, the standard rules apply.


This is code golf, so the shortest code wins.

Notes/Questions for Sandboxing

Ok, so I get that it's rather short. Is my point clear? Is the scoring section clear? How about loopholes? Should I point out that printing a single STP is not allowed? Would that even be possible?

  • 1
    \$\begingroup\$ You might want to elaborate on "expand it into base 4". Does that mean get each byte's codepoint, concatenate into one big binary integer, and then convert to base 4? \$\endgroup\$ – FlipTack Nov 27 '17 at 20:00
  • \$\begingroup\$ What happens if the number of nucleotide is not a multiple of 3? | The base 4 conversion is indeed unclear. \$\endgroup\$ – user202729 Nov 28 '17 at 1:01
  • \$\begingroup\$ @user202729 if there's a spare nucleotide, it's not a valid program. \$\endgroup\$ – Jakob Lovern Nov 28 '17 at 1:27
  • \$\begingroup\$ So basically "program length must be a multiple of 3". / For example program 00 FF should be 00 00 00 00 11 11 11 11 = AAAATTTT or TTTTAAAA? \$\endgroup\$ – user202729 Nov 28 '17 at 1:52
  • \$\begingroup\$ Yeah, essentially. Except that some code golf languages have special character sets that aren't 8 bits, and some trickster out there might use that. \$\endgroup\$ – Jakob Lovern Nov 28 '17 at 2:10
  • \$\begingroup\$ @JakobLovern Unless there are some computers that can store fractional byte size, that won't be accepted. \$\endgroup\$ – user202729 Nov 28 '17 at 2:53
  • \$\begingroup\$ I have no idea how to convert CATG into amino acids. Challenges should be self-contained. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:46
  • \$\begingroup\$ I suspect most answers will be of the form "1. get string of source code by standard quine technique" and "2. convert string into dna form", so the first part doesn't add anything to the challenge. I'd suggest to change the task to write a program which translates a given string into your DNA format. \$\endgroup\$ – Laikoni Nov 29 '17 at 17:16

Create a Flip-Flop Program

Your challenge is simple: write a full program which alternates between two different outputs upon each run.

Your submission can choose which is printed the first time the program is run, but after that it should alternate between these exact outputs.


  • You cannot assume the filename of your program.
  • The values must be distinct.
  • Creating files is allowed - you are allowed to assume a file such as a.txt does not already exist in the directory.
  • Reading and modifying the source is allowed.
  • This is , so the shortest solution (in bytes) wins! Standard golfing loopholes apply.


  • Should I allow assuming the program's filename at an additional bytecount (length of filename)?

  • \$\begingroup\$ Is it neccessary that the first run always produces the same value? (That makes the problem considerably harder, because it requires detecting the first run.) I agree with the full program restriction here, btw; it avoids a lot of dubious rules-bending answers that change something in the execution state. \$\endgroup\$ – user62131 Jan 10 '17 at 16:58
  • \$\begingroup\$ If you want to be really crazy, you can do something like main(){int n = 1 Then change n in the compiled file return n;} \$\endgroup\$ – SIGSTACKFAULT Jan 12 '17 at 16:12
  • \$\begingroup\$ @FryAmTheEggman is this an explanation of the downvote or was that someone else? \$\endgroup\$ – FlipTack Nov 29 '17 at 8:02
  • \$\begingroup\$ @FryAmTheEggman see update. \$\endgroup\$ – FlipTack Nov 29 '17 at 8:14
  • \$\begingroup\$ Why the full program requirement? As far as I can tell, it will be very hard to do this with just functions. Why disallow something that could give interesting answers? Programs would likely just change their own source code, or read a value from a file and then change it (or append a new one). \$\endgroup\$ – Stewie Griffin Nov 29 '17 at 8:48
  • \$\begingroup\$ Closely related. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 14:39
  • \$\begingroup\$ @AdmBorkBork would you say that it's too similar? \$\endgroup\$ – FlipTack Nov 29 '17 at 16:36
  • \$\begingroup\$ Personally, I think they're distinct enough to not be a duplicate, they're just definitely related. \$\endgroup\$ – AdmBorkBork Nov 29 '17 at 16:41
  • \$\begingroup\$ I didn't downvote since to me this looked fairly good besides what felt like an arbitrary restriction that would just make gaming the challenge easier. Also, I remembered another related challenge, for reference. \$\endgroup\$ – FryAmTheEggman Nov 30 '17 at 0:25
  • \$\begingroup\$ @FryAmTheEggman that's why I recently helped add the stateful tag, all similar challenges involving storing data between runs and self-modifying code are gradually being added there \$\endgroup\$ – FlipTack Nov 30 '17 at 7:29

Thou shall permute!

Given a string of upper and/or lower case letters and/or numbers (or list of characters if you want), and a list of permutation cycles, compute every intermediate step of applying this permutation under the following rules:

  • The space to move letters around is one row above and one row below the input, with the same length available as the string length.
  • In the beginning, top and bottom row are empty, and the middle row contains the whole string
  • A character can only take the spot of another character, if that spot is empty
  • There can only be at most one character in the top row and one in the bottom row at any time
  • You can only move one character in one direction per state change. Directions are:
    1. Out of the middle top or down
    2. Left/Right (any number of steps at once)
    3. Into the middle

Cyclic Permutations

I'm assuming 0 based indexing. A list of cyclic permutations looks like this (I'm assuming list of tuples, but I don't mind if you want something else, as long as it conveys the same idea):


This would mean that:

  • index 0 goes to index 2, index 2 goes to index 3, index 3 goes to index 0
  • index 1 goes to index 4, index 4 goes to index 1


I'm using the -character to show available spots here, you may use a space or any character that can not be contained in the input string, such as #or $.

Given the string test and the cyclic permutations [(0,2)(1,3)], the steps would look as follows:

test  #Start state

-est  # Move index 0 out 

-e-t  # Move index 2 to the other side

-e-t  # Move index 0 to where it needs to go

-ett  # Insert index 0 at index 2

-ett  # Move index 2 to where it needs to go

sett  # Insert index 2 at index 0

s-tt  # Move index 1 out

s-t-  # Move index 3 out

s-t-  # Move index 1 to index 3

s-te  # Insert index 1 at index 3

s-te  # Move index 3 to index 1

stte # Insert index 3 at index 1. Done.

Here is the same example again, but this time using only one long permutation of all characters: [(0,2,1,3)] instead of 2 independent permutations:















  • You will only receive valid cyclic permutations
  • Please indicate if you want 0 or 1 indexed permutations, either is fine
  • You will only receive valid strings up to length 10
  • Characters in the string are not guaranteed to be unique
  • it does not matter which order every permutation is processed as long as they're all processed (that means start and end states are the same, and the above rules are always fulfilled)
  • There will be at least one permutation in the list of permutations
  • All permutations in the list of permutations have at least length 2
  • The maximal length of one permutation is the length of the input string
  • There may be some indices that are not part of any permutation
  • No index is part of more than one permutation
  • You need to output the first step, the last step and all intermediate steps
  • You may have as many trailing newlines and spaces as you want
  • You may output a 2 dimensional array or anything equivalent instead of printing every step, or you can also return a list of all states in the end
  • You can also generate an animation if you like instead of printing sequentially
  • Lowest number of bytes wins
  • Standard loopholes are forbidden
  • You can write a full program or function

Test cases

I implemented a very un-golfed version in python3 here (redirects to repl.it). That code contains 2 functions. find_cycles takes a string and a permutation of that string and computes the cycles to go from one to the other. shuffle does the shuffling. It takes the start string and the cycles. You can use these functions to validate your program.


Find and execute a program from the internet

You have some task to do, but you are too lazy to do it yourself. Your also to lazy to make a program to do it. So you are going to make a program that finds a program to do the task you want.

Select a programming language Q (which must be Turing complete).

Your program will:

  1. Take an input task, as a string, and input, as a string.
  2. Search codegolf.stackexchange.com, using the input string as the query
  3. Select the first question in the search results with an answer which contains a valid Q program. (If there is no such question, the operation of your program may be undefined.) (You may assume that program is in a code block.)
  4. Select either the accepted answer if it contains a valid Q program, or the highest voted answer that contains a valid Q program.
  5. Execute the Q program that that answer contains, using the input from step 1.

Since you are lazy, you want your program to be the shortest program possible. So this is , shortest answer wins!

  • 3
    \$\begingroup\$ What happens if the search result finds your answer? \$\endgroup\$ – Neil Dec 1 '17 at 9:55
  • \$\begingroup\$ @Neil Fixed it. \$\endgroup\$ – PyRulez Dec 1 '17 at 20:30
  • \$\begingroup\$ I don't know enough about the API to say, but can the order of results be changed by changing the search query to only allow questions? It seems like the searching may result in people trying to work around doing some API work, and it will be a pain to check. This isn't really a problem, just something I think you should know before posting. \$\endgroup\$ – FryAmTheEggman Dec 1 '17 at 20:37
  • \$\begingroup\$ @FryAmTheEggman I'm not sure. Think it would be better if I allow people to change the search query to only questions? \$\endgroup\$ – PyRulez Dec 1 '17 at 20:39
  • \$\begingroup\$ I think that would make it easier, but it kind of results in two separate golfing tasks: minimising the search query and minimising the code to parse/execute answers. I'm not sure of a good way to resolve that (or if it is that bad) but it does give me the feeling that it may be better split up in some way. \$\endgroup\$ – FryAmTheEggman Dec 1 '17 at 20:43
  • \$\begingroup\$ @FryAmTheEggman I could allow them to take a search query string template as input (or just say that it doesn't count towards their score). That way, there is no need to golf it. \$\endgroup\$ – PyRulez Dec 1 '17 at 20:45
  • 1
    \$\begingroup\$ What if the result takes no/more than one input? If Q is chosen well enough, you get away with a nop.. so this becomes a quest of finding languages unused on PPCG. What happens if these then get added? \$\endgroup\$ – ბიმო Dec 3 '17 at 3:15
  • \$\begingroup\$ @BruceForte It will be fed into the program via standard input. I said that Q must be Turing complete, which means it must take input. \$\endgroup\$ – PyRulez Dec 3 '17 at 4:51

Information Masking

Email Address Masking:

Only show the first and last characters of the username components of an email address, along with email domain name. Include 5 stars in the middle of the username to mask the length. The username part of the email address may use any of the ASCII characters listed below.


  1. Uppercase and lowercase English letters (a-z, A-Z)
  2. Digits 0 to 9
  3. Characters ! # $ % & ' * + - / = ? ^ _ { | } ~
  4. Character . (dit, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively.
  5. It is provided that email should end with @domainName.com, where the domain name has only alphabetic characters.
  6. It is provided that email address username part have at least 2 characters not starting and ending with a special character.


JackAndJill@gmail.com --> j*****l@gmail.com

Phone number masking:


Mask all the digits in a phone number except the last 4 digits. Each number should be replaced by star(*). Input phone numbers can be with or without the country code. Input Phone numbers can only have +, (, ), - in them along with numbers and spaces. Make sure + is not masked in the output and make sure the number of stars is equal to the number of digits while masking.Phone numbers will always have 10 digits without country code and with the country code, they could be up to 13 digits.


Example1: +1 (333) 444-5678  --> +*-***-***-5678  
Example2: +91 (333) 444-5678 ->  +**-***-***-5678  
Example3: 333 444 5678 --> ***-***-5678  
Example4: (333) 444-5678 ---> ***-***-5678

Program input will start with E: for email and P: for phone numbers, ignore spaces if they are found in the input.

Complete Program Example


E: jackAndJill@gmail.com  
P: +13334445678


E: j*****l@gmail.com  
P: +*-***-***-5678
  • \$\begingroup\$ How does hackAndJill start with a j? \$\endgroup\$ – NieDzejkob Nov 30 '17 at 21:06
  • \$\begingroup\$ Just a typo. Corrected now. \$\endgroup\$ – Siraj Alam Dec 1 '17 at 3:37
  • \$\begingroup\$ The examples show phone numbers of various different formattings what is it? Why are - in the output where in the input were only numbers how does that work? Is input always valid, can input be only a phone number etc. What about email addresses such as user@remote or u@remote.net? \$\endgroup\$ – ბიმო Dec 3 '17 at 3:25
  • \$\begingroup\$ The input number can be in any format as the given in the example. And it is should be output in the form that last phone numbers are shown and then a -, then every 3 numbers are masked as *** and a - after it until the numbers do not end. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 6:41
  • \$\begingroup\$ Email address rules are updated. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 6:45
  • \$\begingroup\$ What is the winning criterion? Code-golf? \$\endgroup\$ – Laikoni Dec 3 '17 at 20:24
  • \$\begingroup\$ Yes, code-golf. \$\endgroup\$ – Siraj Alam Dec 3 '17 at 20:25

Given an Integer array:

  1. Start from the first number (n)
  2. Go forward (n) positions depending on the current position
  3. Delete the current position, the rest of the array fill in to the current position.
  4. Goto step 2 until there are one number remaining
  5. Print that number

The array loops around (the next number after the last number in the array is the first number).

A zero removes itself.

Negative numbers are not allowed as input.

Test Cases

[1] => 1
[1,2] => 1
[1,2,3] => 3
[1,2,2] => 1
[1,2,3,4] => 1
[6,2,3,4] => 4
[1,2,3,4,5] => 5
[0,1] => 1
[0,0,2,0,0] => 0

This is , the shortest answer in bytes wins!

Step-by-step example

 ^          start from the first position
   ^        jump 1 position (value of the position)
[1,  2,3,5] remove number in that position
     ^      take next position of the removed number
         ^  jump 2 positions
[1,  2,3  ] remove number in that position
 ^          take next position (looping on the end of the array)
     ^      jump 1 position
[1,    3,5] remove number in that position
       ^    take next position (looping)
       ^    jump 3 positions (looping on the end of the array)
[1,      5] remove number in that position
         ^  take next position
 ^          jump 5 positions (looping)
[        5] remove number in that position
print 5

Example #2

 ^            start from the first position
         ^    jump 4 positions
[4,3,2,1,  3] remove number in that position    
           ^  take next position
     ^        jump 3 positions
[4,3,  1,  3] remove number in that position    
       ^      take next position
           ^  jump 1 positions
[4,3,  1    ] remove number in that position    
 ^            take next position
   ^          jump 4 positions
[4,    1    ] remove number in that position    
       ^      take next position
 ^            jump 1 position
[      1    ] remove number in that position
print 1

Note: This is my first challenge so any input is welcome.

  • \$\begingroup\$ After the step 2 where is the "pointer"? \$\endgroup\$ – user202729 Dec 10 '17 at 14:40
  • \$\begingroup\$ The third step is worded a bit oddly, but I think I've understood it correctly from the examples. Do you mean that the elements after the deleted element are shifted to fill in the gap? It may be worth having one example written out step by step to make it easier for people to grasp what is happening. \$\endgroup\$ – FryAmTheEggman Dec 10 '17 at 15:13
  • \$\begingroup\$ @FryAmTheEggman I have edited the question to include 2 step-by-step examples. Can you help me word the third step more clearly? Perhaps: 2- jump forward n positions where n is the value of the current position. 3- delete the position you just arrived at. 4- the (new) current position is the next position. repeat step 2. \$\endgroup\$ – workoverflow Dec 10 '17 at 21:18
  • \$\begingroup\$ Problem title ? \$\endgroup\$ – user202729 Dec 11 '17 at 5:52
  • 1
    \$\begingroup\$ That is better, but maybe roll it into one? "Delete the current position, making what was the next position the current position" \$\endgroup\$ – FryAmTheEggman Dec 11 '17 at 5:57
  • \$\begingroup\$ @user202729 Haven't decided yet, Maybe "Football Jersey Josephus" or a variation of Duck, Duck, Goose. \$\endgroup\$ – workoverflow Dec 11 '17 at 7:38

Golf a number

Create a program or function, which when given an input integer, outputs a mathematical expression evaluating to the same value. Expressions which require fewer bytes to represent than the integer itself will achieve better scores!


It is often useful when golfing to compress constant integer expressions by expressing them in the form of an equivalent mathematical expression. 387420489 for example is much more efficiently expressed as 9^9. Similarly 4194303 as 2^22-1

The challenge is, for each integer in the range 1 to 1E6, to golf the number into as short an expression as you can (although any expression which evaluates correctly is acceptable output, see Rules below). The shorter the expression, the better your score; but short programs will also score well so the two need to be balanced!


Input integer as argument or from STDIN

Output as string or equivalent to STDOUT or as function output. Your string can only contain ascii characters [0,1,2,3,4,5,6,7,8,9], as well as those operators defined below, repetitions allowed.

You may use the following mathematical operators any number of times in your string:

() parentheses
^ exponentiation
* multiplication
/ division
\ integer(floor) division - see Test Evaluator
+ addition
- subtraction

NB: division, integer division and multiplication are all evaluated with equal priority, so 3/2\2 = 0 whereas 3\2/2 = 0.5

You may output the input value (if it can't be golfed for example), you do not have to output the perfectly golfed string:

 In: 10000

Out: 10000

However the output must evaluate exactly to the input (assuming perfect precision of floats)


Answers are scored on their compression ratio (how much they golf the input down on average), as well as program size

Program Size: byte count of program (as with normal code golf)

Compression Ratio: golfed Length (white-space ignored) / input Length

Individual Score = (Compression Ratio * 100 - 70)/6 + Log(Program Size, base 10)

Final Score = Mean score for first 10^6 integers

Lowest final score for each language wins!





The main sticking point is scoring how best can you combine 2 metrics into a single score?

The logic so far is that compression ratios will lie in the range 100 - 70 % where 100 is returning the input. Program lengths should be between 2 extremes; returning the input (1 byte) and looking up the input in a hardcoded list (~19,000,000 bytes). This gives the following distribution:

Score table

Actual program length I guestimate will be anywhere in the range 1 to 10000 bytes, hence the log to make the range more manageable. Quick reference; I could probably implement all power golfing (expressing n as a^b) in ~100-200 bytes in VBA. So 10% of that for golfing languages, and who knows what builtins Mathematica has ;).

But implementing more effective algorithms may require a more verbose language, so I think 1 - 10000 seems like a good range to handle in scoring

Open to alternative scoring though, and any required clarifications. Also suggestions what is a good range to test over?

I've suggested 1 to 1E6; The first 1000 integers I don't think are golfable, after that only a few are. So perhaps a greater range of test cases, or ones starting at a larger initial value? What's the biggest range I can feasibly test within say, 10 mins running time max? What's typical algorithm execution times can be expected per digit? I don't want golfers to have to spend too long generating their average score...

Test String Evaluation

  • 1
    \$\begingroup\$ requires fewer bytes to represent than the integer itself. -- but you had said The first 1000 integers I don't think are golfable, so it doesn't work. \$\endgroup\$ – user202729 Dec 11 '17 at 5:58
  • \$\begingroup\$ In your test, 2^13+1808 is longer than 10000. It contradicts your problem statement. Also you don't allow ^ to be used. / Evaluate left to right? \$\endgroup\$ – user202729 Dec 11 '17 at 5:59
  • 1
    \$\begingroup\$ returning the input is 0 byte in most languages, so the score would be log(0) = -Infinity. \$\endgroup\$ – user202729 Dec 11 '17 at 6:01
  • \$\begingroup\$ Related. \$\endgroup\$ – user202729 Dec 11 '17 at 6:17
  • \$\begingroup\$ @user202729 Your 1st point; I did include a sentence you do not have to output the perfectly golfed string in the rules section, but I'll fix the problem statement to match that. Good catch with ^, I'll add that - but a longer expression is supposed to be acceptable. log(0) - well let's hope that's an incentive not to post trivial answers! But seriously, do you think it's worth adding a log(program length +1)? I don't think it is because it adds an additional layer of complexity to the scoring system - and people shouldn't really be entering trivial solutions anyway (I hope) \$\endgroup\$ – Greedo Dec 11 '17 at 10:49
  • \$\begingroup\$ If they do post 0-byte solution and win, it's the fault of your scoring system. For reference, look at the score formula of this challenge. --- You may want to add "you must calculate your score" to the question, like in this challenge. \$\endgroup\$ – user202729 Dec 11 '17 at 12:36
  • \$\begingroup\$ This isn't code-golf - it's code-challenge. \$\endgroup\$ – Mego Dec 11 '17 at 16:30

All possible distributions of different items of a set to an arbitrary number of groups

See Descriptive Real World Example, Rules / Edge Cases or Sample Data for an idea about this or help me by adding a nice sentence explaining it while this is in sandbox.

Descriptive Real World Example:

Ordering a set of x items from a shop what are the possibilities to distribute them among 1 to x orders?

Rules / Edge Cases

  • Identical items are not being distinguished (AB, B == AB, B, compare examples #4, #5 and #6)
  • Order is not important
    • Order of items in order/group: AB == BA
    • Order of orders/groups in distributions: A, B == B, A
    • Order of possible distributions (i. e. lines among output)


I don't really mind the exact format but as it probably makes sense (right?) to tie oneself down to one format I'll suggest the following:

  • Input: Set of items without delimiters. Supported chars: [A-Za-z0-9]
  • Output:
    • Hierarchy: Distributions (Orders (Items))
    • Delimiters:
      • Among distributions in overall output: EOL
      • Among orders/groups in distribution: Comma, Space
      • Among items in orders/groups: None

Sample Data

║ Example │ Input │ Output  │   Output   ║
║   Nr    │       │ line nr │   lines    ║
║   #1    │ A     │    1    │     A      ║
║         │       │    1    │    A, A    ║
║   #2    │ AA    ├─────────┼────────────╢
║         │       │    2    │     AA     ║
║         │       │    1    │    A, B    ║
║   #3    │ AB    ├─────────┼────────────╢
║         │       │    2    │     AB     ║
║         │       │    1    │  A, A, A   ║
║         │       ├─────────┼────────────╢
║   #4    │ AAA   │    2    │   AA, A    ║
║         │       ├─────────┼────────────╢
║         │       │    3    │    AAA     ║
║         │       │    1    │  A, A, B   ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AA, B    ║
║   #5    │ AAB   ├─────────┼────────────╢
║         │       │    3    │   AB, A    ║
║         │       ├─────────┼────────────╢
║         │       │    4    │    AAB     ║
║         │       │    1    │  A, B, C   ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AB, C    ║
║         │       ├─────────┼────────────╢
║   #6    │ ABC   │    3    │   AC, B    ║
║         │       ├─────────┼────────────╢
║         │       │    4    │   BC, A    ║
║         │       ├─────────┼────────────╢
║         │       │    5    │    ABC     ║
║         │       │    1    │ A, B, C, D ║
║         │       ├─────────┼────────────╢
║         │       │    2    │   AB, CD   ║
║         │       ├─────────┼────────────╢
║         │       │    3    │   AC, BD   ║
║         │       ├─────────┼────────────╢
║         │       │    4    │   BC, AD   ║
║         │       ├─────────┼────────────╢
║         │       │    5    │  A, BC, D  ║
║         │       ├─────────┼────────────╢
║         │       │    6    │  B, AC, D  ║
║         │       ├─────────┼────────────╢
║         │       │    7    │  C, AB, D  ║
║         │       ├─────────┼────────────╢
║   #7    │ ABCD  │    8    │  A, CD, B  ║
║         │       ├─────────┼────────────╢
║         │       │    9    │  A, BD, C  ║
║         │       ├─────────┼────────────╢
║         │       │   10    │  B, AD, C  ║
║         │       ├─────────┼────────────╢
║         │       │   11    │   ABC, D   ║
║         │       ├─────────┼────────────╢
║         │       │   12    │   BCD, A   ║
║         │       ├─────────┼────────────╢
║         │       │   13    │   CDA, B   ║
║         │       ├─────────┼────────────╢
║         │       │   14    │   DAB, C   ║
║         │       ├─────────┼────────────╢
║         │       │   15    │    ABCD    ║
  • 1
    \$\begingroup\$ What is the winning criterion of this challenge? Code-golf? Also the current explanation seems more complicated as it needs to be. Only after seeing the examples it became clear that you are asking for set partitions \$\endgroup\$ – Laikoni Dec 20 '17 at 15:09
  • \$\begingroup\$ Possible duplicate of codegolf.stackexchange.com/q/8691/56433 \$\endgroup\$ – Laikoni Dec 20 '17 at 15:12

Show me your core

On many 8-bit machines, it is relatively easy to output the entire core syntax of the built-in language, as everything required is in ROM and most 8-bit machines allow you to PEEK at each location therein, or otherwise easily access the ROM contents.

Here's the complete syntax for a Sinclair ZX81 or Timex TS1000/1500 machine as an example:

 1 PRINT CHR$ 64;CHR$ 65;CHR$ 66;CHR$ 193;CHR$ 193;
 2 FOR I=196 TO 255

Is it as easy to output the core or standard syntax to a screen, console, or window in modern-days languages? How best would I word such a question? And would this make a good challenge?

  • 1
    \$\begingroup\$ What is the "core"? ...... \$\endgroup\$ – user202729 Dec 20 '17 at 15:03
  • \$\begingroup\$ Core syntax, i.e., non-extended PHP, such as stdClass is in the PHP core. Either the question is too ambiguous, or I don't know modern-days programming speak well enough to ask it. \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:08
  • \$\begingroup\$ More precisely, PDOException("blah", 0x00); would not be core in PHP even though it extends the standard Exception because the PDO extension needs to be switched on in your php.ini file; throw and new obviously would be as far as I'm able to work out \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:12
  • 1
    \$\begingroup\$ I don't know PHP so I don't understand that explanation. \$\endgroup\$ – user202729 Dec 20 '17 at 15:12
  • \$\begingroup\$ I only really understand PHP and some 8-bit hl languages and some assembly. Let's try this... if you don't <include xxx.h> in C (where xxx is the header or whatever), what are you left with? Is that even possible. \$\endgroup\$ – Shaun Bebbers Dec 20 '17 at 15:17
  • 1
    \$\begingroup\$ Actually GCC let the program pass with a lot of warnings. \$\endgroup\$ – user202729 Dec 22 '17 at 14:54
  • 1
    \$\begingroup\$ Some similar and related challenges showing that this type of challenge has a lot of difficulty in getting it exactly correct. \$\endgroup\$ – AdmBorkBork Dec 22 '17 at 15:10
  • \$\begingroup\$ Yes there is a lot of difficulty on modern-days tech stacks and such; on 8-bit machines, it's much easier as you only need to find the bit of ROM that holds the syntax and you're half-way there. \$\endgroup\$ – Shaun Bebbers Jan 2 '18 at 9:26

Sight Matrix

I haven't seen this done anywhere yet after a couple of searches, so I might as well post this anyways. If you see this done somewhere else, please tell me and I will delete this post.

The Story

You are a two meter tall sniper fighting in a war-torn area. Your teams have just beaten back the enemy, but the guerillas have an annoying habit of hiding out of sight and waiting patiently to take your unit by surprise, often inflicting heavy casualties. You have been tasked with dealing with these guerillas as a sentry.

The Task


Write a program that, when given a n x n 2D matrix of heights (in meters), outputs a n x n 2D binary matrix with ones being areas that you can see and zeroes being areas that you cannot see.

Input Format

The input will be a two-dimensional array of heights and two numbers signifying where you are standing.

Output Format

The output will be a two-dimensional array of ones and zeroes: ones where you can see and zeroes where you can't see.

Sample input/output


[[120,87,89,93,121], [120,91,83,91,114], [118,121,90,93,97], [124,129,115,120,101], [117,140,138,124,99]] 0 0


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


Last time I checked, people's eyes were on their head. Put that into account when you are writing your code.

This is . Shortest answer in bytes wins. Standard loopholes apply.

Note: this is my first foray into code-golf stackexchange. Please tell me how to improve this or things that I need to add to this answer.

  • 2
    \$\begingroup\$ There have been various questions on line of sight, but right now I think this question would be closed as "Unclear what you're asking" before there was consensus on which was the closest dupe. What are the rules for visibility? You've given my height, but I'm not sure whether it's relevant. You haven't said whether the guerrillas (note: double r) have a height, nor how the terrain is modelled, nor what point in the square I need to see for the square to count as visible. \$\endgroup\$ – Peter Taylor Dec 22 '17 at 13:47
  • \$\begingroup\$ May the input be 1-indexed? \$\endgroup\$ – user202729 Dec 22 '17 at 14:34

Output One More than Int Max

Your job is to create a program or function that will output a whole number (with no trailing decimal point) that is 1 greater than the max number an integer can hold for the language; more or less this:


You are not allowed to use Strings in your solution. Any other type may be used.

Shortest answer in bytes wins.

Note: I know this might be impossible in some languages. I have verified that it is possible in at least one (un-disclosed) language.

Notes on this puzzle

I posted this puzzle recently here and it promptly got closed and deleted (oops). Thankfully, @WheatWizard was kind enough to explain what some of the confusion was. Here where his comments:

I've voted to close this question as unclear. There are a couple of things I find especially unclear, 1) I'm not sure what "the max number an integer can hold for the language" means, it definitely needs a more concrete definition. It seems to presuppose some bounded "integer" type in the language. All the existing answers seem to suppose that long (or equivalent) is not this integer type but that is not at all clear from the question.

2) The requirement "You are not allowed to use strings in your solution" is neither clear nor enforceable. Without a rigorous definition of string there is no way to determine what is a string or not. For example Prolog has a type called "String" but all real string manipulation is actually done on lists of char codes. Are those strings? Prolog also has atoms which behave a lot like strings in many ways, (and act like integers in others) are they strings?

The main thing I would want to see before retracting my close vote/voting to reopen is clear definitions of the terms in question. To be clear that is a very tall order. These terms are not going to be easy to define, let alone define well. I would recommend temporarily moving this question to the sandbox so that you can workshop it a bit.

@Xcali said the following:

To follow on @WheatWizard's comment, what about languages where there's really no type to a variable. For example, in Perl, any single value may be treated as a string or a number at any time

And @Adám:

@CalebKleveter I think you can fix your challenge by removing the prohibition on strings and requiring documentation and/or additional supporting code showing that the produced number cannot be held as any type of integer. Do you want me to edit your post accordingly?

Are there any suggestions on how we could define the things pointed out in these comments? Are there any other issues that should be resolved?

  • \$\begingroup\$ I'm not sure if it's possible to define such things such that it can applies to all languages. You may want to limit the challenge to specific languages, but that will disallow many languages to compete, and some person will get annoyed when their languages can't be used, they may downvote the question. / Original challenge link. \$\endgroup\$ – user202729 Dec 22 '17 at 14:07

Als pr Yrck, I knw hm Hrtio

Here is a link to a text file containing the script for Shakespeare's Hamlet.[to do: provide such a text file, or think of another freely available text input that leads to a wittier title.]

Your task is to write a program that will compress this text, and another that will decompress it to return exactly the original file. Your score is given by C + D + 0.5*F, where C is the size of your compression program, D is the size of your decompression program, and F is the size of the file that your compression program generates, all measured in bytes. The smallest score wins.

Further particulars

Your compression program should take hamlet.txt as input and produce a single file as output, which is to be given as input to your decompression program. You should make sure that the resulting output from your decompression program is identical to the original hamlet.txt file, e.g.

> myCompressor hamlet.txt > compressed
> myDecompressor compressed > output.txt
> diff hamlet.txt output.txt
[no output from diff command means they are identical]

Your programs' only purpose is to compress and decompress the hamlet.txt file - their behaviour on any other input is not part of the challenge. It's fine, for example, if the decompressor always outputs the text of Hamlet regardless of the original input, or if the compressor crashes on any input besides hamlet.txt.

Input and output can be by file I/O or STDIN/STDOUT or any other reasonable method, but the compressor and decompressor should be full programs. They need not be written in the same language.

Your compressor and decompressor must each be completely self-contained. Each must consist of a single file, and that file must be the source code for a programming language as defined here. With the exception of importing libraries, your compressor and decompressor must not open any other files besides their input.

The compressed file may be a text file or a binary file - the only thing that matters is its size in bytes. No information may be transmitted from the compressor to the decompressor by any means other than the content of this file.

You may not use any libraries or built-ins that implement data compression algorithms, such as gzip or bz2, or their corresponding decompression algorithms. This restriction only applies to "off the shelf" implementations - you can use any algorithm you like if you implement it yourself. For details on what counts as a data compression algorithm, see note 1.

If for some reason your language or libraries include a feature that outputs some or all of the text of Hamlet, you may not use that feature.

Although it's not part of the challenge, you are encouraged to explain/demonstrate what happens when your compressor is given some other input besides hamlet.txt, especially if it does something interesting such as produce a garbled Shakespearean version of the input text.

Note 1: For the purpose of this challenge, a data compression algorithm is anything listed in Wikipedia's Category:Lossless Compression Algorithms or Category:Lossy Compression Algorithms, or any of their subcategories. Note that these lists can change over time, and if Wikipedia's editors will allow a new item to be added then that will count as a compression algorithm, even if that happens after an answer using it is posted. This is to prevent the use of obscure algorithms that are not yet listed on Wikipedia. Editing Wikipedia to get around the restriction on off-the-shelf compression is not allowed.

This rule is intended to prevent the use of existing algorithms while allowing all other language features and built-ins. It may be the case that some items on the Wikipedia list are overly broad and end up banning common language features. If this is the case I will add exceptions on a case-by-case basis. This will only be used to permit things that would otherwise be banned, so it won't invalidate existing answers.

Sandbox note: the really tricky thing here is how to prevent trivial solutions that just wrap an existing compression algorithm, without also banning common language features. The above Wikipedia-based definition of a compression algorithm is a bit experimental and I'd welcome feedback on it. My intention is to prevent trivial solutions that just wrap an existing implementation of a compression algorithm, while allowing pretty much anything else.

Another possible approach is simply to allow anything and hope that answers specialised to the input can achieve better scores. That's effectively what I did in Paint Starry Night, but in the end I wish I hadn't, because it turned out that (so far at least) even really clever solutions based on neural nets and genetic algorithms can't come close to the off-the-shelf BPG algorithm. That's the sort of situation I want to avoid for this challenge.

  • \$\begingroup\$ Would compressor, decompressor be acceptable? (only for illustration purposes) \$\endgroup\$ – user202729 Dec 30 '17 at 9:06
  • \$\begingroup\$ @user202729 I don't speak Jelly, but assuming it's not using any built-in compression, that would be fine. (It even says so already in the rules: "It's fine, for example, if the decompressor always outputs the text of Hamlet regardless of the original input".) The thing is that a solution of that form doesn't take any advantage of the discounted scoring for the compressed file, so it would very likely not be optimal. So while it's allowed, it would probably not win. \$\endgroup\$ – Nathaniel Dec 30 '17 at 9:46
  • \$\begingroup\$ Correct, if the text is sufficiently long. The “...» is Jelly string encoding codec using base decompression and some dictionary lookup. \$\endgroup\$ – user202729 Dec 30 '17 at 9:55
  • \$\begingroup\$ @user202729 then it would be fine. (I'm fairly certain the script for Hamlet is long enough - if it isn't, that would be an interesting surprise.) \$\endgroup\$ – Nathaniel Dec 30 '17 at 10:58
  • \$\begingroup\$ @user202729 Though actually, I guess by the letter of what I wrote, it wouldn't be fine, because Jelly's dictionary lookup is presumably explicitly intended as a way to compress text. That's not what I intended the rule to mean. This is pretty tricky - I want to disallow trivial things like just wrapping a bz2 compressor, while permitting pretty much anything else. It doesn't seem easy to do that in a way that avoids loopholes. (Comments on this are welcome from anyone.) \$\endgroup\$ – Nathaniel Dec 30 '17 at 12:46
  • 1
    \$\begingroup\$ You can't disallow "trivial" things, only discourage them. That's not really a problem - the real problem is they get more upvotes than they deserves, and solutions which the OP actually put effort in writing get less upvotes. \$\endgroup\$ – user202729 Dec 30 '17 at 13:02
  • \$\begingroup\$ @user202729 I can't disallow trivial things in general, but I can write the rules in such a way that specific types of trivial solution are not permitted. If I had disallowed built-in compression in paint Starry Night then it would have been a much better challenge (albeit possibly less epic in the long run, since the non-trivial answers made a good effort at keeping up with the trivial ones). Basically I don't want the winning answer to just be a shell script that runs bzip on its input. \$\endgroup\$ – Nathaniel Dec 30 '17 at 13:19
  • \$\begingroup\$ Anyway I've changed the wording of the rule - I'm not sure if the new version will work but we'll see if people have comments. \$\endgroup\$ – Nathaniel Dec 30 '17 at 13:20
  • \$\begingroup\$ Instead of stating something like "If for some reason your language or libraries include a feature that outputs some or all of the text of Hamlet, you may not use that feature." you could actually require the program to work for any input and only use Hamlet to get the scoring, this would elegantly close up that loophole but I'm sure people will find a way around this.. As you noted yourself this is a difficult task to solve. \$\endgroup\$ – ბიმო Dec 30 '17 at 14:00
  • \$\begingroup\$ @BruceForte I think I prefer the direct approach for that point. If I ask it to work for other inputs I open up the quagmire of trying to define what that should mean and how to test for it. However that's achieved I would likely still need the "if for some reason" rule, because there would probably still be ways to take advantage of a built-in database of Shakespeare plays if some language out there happens to include one. I think banning Shakespeare built-ins is unproblematic - my problem is more how to ban bz2 and the like without accidentally also banning common language features. \$\endgroup\$ – Nathaniel Dec 31 '17 at 2:26
  • \$\begingroup\$ "in the end I wish I hadn't" ... Why? What's the difference? \$\endgroup\$ – user202729 Jan 1 '18 at 9:06
  • \$\begingroup\$ @user202729 it would have been a better challenge. The best scoring answers would have been the cleverest ones that took the most effort, and there would be more motivation for people to continue doing cleverer things to beat the lowest score. If that doesn't seem desirable to you then fair enough, but it's what my taste is and it's the kind of challenge I want to design. \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:15
  • \$\begingroup\$ How can you be so sure (without testing it)? bz2 developers definitely put a lot of efforts into writing their lossy image compression algorithms, so they may win. Not to mention that their code are not bytecount-limited. \$\endgroup\$ – user202729 Jan 1 '18 at 9:21
  • \$\begingroup\$ @user202729 I'm not sure what you mean. If you're referring to the Starry Night challenge I can be sure because I have tested it. Just look at the existing answers - some are really really nontrivial and use genetic algorithms, deep neural networks and other clever techniques, whereas others simply wrap an image in BPG or FLIF format and call an existing function to decompress it. There is some golfing and file type knowledge involved in this, but it's trivial compared to the other type of answer. Unfortunately the latter type did win, and that's exactly what I'm trying to avoid this time. \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:29
  • \$\begingroup\$ (The clever answers on Starry Night exist in large part because I offered a series of bounties to answers that passed various milestones without using built-in compression. I could do that again this time, but I have only 2100 rep to give away, and in any case it's much more elegant if the challenge provides that motivation by itself.) \$\endgroup\$ – Nathaniel Jan 1 '18 at 9:36

You must log in to answer this question.

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