# 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.

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

## 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]

# Finding Points in Convex Hulls

Convex hulls are notoriously hard to deal with, so today's challenge will deal with a relatively simple premise: given a convex hull defined by a set of points, and an additional point, find whether the additional point lies in the hull.

Now, for some definitions

1. The convex hull of a finite set X, a subset of R^n, is the set of convex combinations of points of $X$.
2. A convex combination of points x1,x2,...,xn is a point of the form a1x1+a2x2+...+anxn such that all ai>=0 and the sum of all of the ai is 1.

# Input/Output

The input is rather flexible, as long as it contains the appropriate information to express the convex hull and additional point.

An example of a valid input format to express the convex hull represented by (0,1,2),(4,3,2),(8,8,8) and the point (5,5,5) is

([(0,1,2),(4,3,2),(8,8,8)],(5,5,5))


The output is a truthy/falsy value, depending on whether the point is contained in the hull.

# Remarks

There are a lot of packages and libraries that deal with convex hulls, such as scipy.spatial. Such libraries/packages are explicitly banned. Libraries that facilitate matrix computations, such as numpy, are permitted.

The winning criterion is .

There is no limit on the number of dimensions the points can lie in, as long as they all lie in the same number of dimensions.

# Test Cases

I will be using the following tio link for testing the validity of solutions.

Some smaller test cases:

([(1,1)],(1,1)) - True
([(1,1)],(1,2)) - False
([(1,1,1),(3,3,1)],(2,3,1)) - False
([(1,1,1),(3,3,1)],(2,2,1)) - True
([(0,0),(3,3),(0,6)],(2,4)) - True
([(0,0),(3,3),(0,6)],(1,1)) - True
([(0,0),(3,3),(0,5)],(2,4)) - False


# Questions for Sandbox

Is code golf the best criteria for this? That might encourage brute force searches on every combination of points... any suggestions?

• You mention R^n but all the examples use Z^n (which is much easier to work with computationally). Please clarify the expected input. Also, what about libraries for linear programming? – Peter Taylor Apr 1 '19 at 10:03
• @PeterTaylor I was thinking of making it R^n only, since one can bash out the answer if it is in Z^n. And, linear programming libraries probably also should be banned. – Don Thousand Apr 1 '19 at 13:08
• I'm not sure how easy it is to bash out the answer. The weights could be rational, and it's not obvious to me that the denominators can be bounded because the entire system can be translated. – Peter Taylor Apr 1 '19 at 20:35
• @PeterTaylor Hmm, I'll think about how to revise this. – Don Thousand Apr 1 '19 at 22:05

This is a post to pre-test for a duplicate question before I spend the time to finish the full post and add test cases.

So, have we ever had a question for a "snake rotation" of a matrix:

    +--------------+
1  2  3  4  5|
+------------  |
|10  9  8  7  6|
|  +-----------+
|11 12 13 14 15
+--------------+

+--------------+
-->  13 14 15  1  2|
+------------  |
| 7  6  5  4  3|
|  +-----------+
| 8  9 10 11 12  -->
+--------------+


The ascii walls are there only for clarity. Actual input/output would be normal matrices

# Reverse RegEx

Take a regex a as input, output a regex b such that, for each string x, x matches a iff x.reverse matches b

Sample Input    Sample Output
/abcd/          /dcba/
/[^abc]/        /(?!a)[^bc]/
/[^abc]/        /[^abc]/
/(.)abc\1$/ /^(.)cba\1/ /$1/            /10% of $10/ /\123/ /S/  Shortest code win TODO: List of allowed RegEx features, mainly if (?<=xxx) is allowed • What's the regex flavor/set of allowed features/inputs? Is it for a full or partial match? – feersum May 10 '19 at 9:07 • @feersum Allowed features need discuss. To be a full match ^ and $ can be added – l4m2 May 10 '19 at 9:21
• Why is test case /[^abc]/ there twice? Or is it to give two different example outputs? Since just outputting /[^abc]/ for input /[^abc]/ would be fine. Also, I'm not too familiar with this Regex syntax, but how does /$1/ work, since $ is the end of the match? And why is it /10% of $10/ reversed? – Kevin Cruijssen May 10 '19 at 9:27 • @KevinCruijssen twice to show that same input may lead to different output. /$1/ and /10% of $10/ both match nothing – l4m2 May 10 '19 at 9:32 • "both match nothing" Ah ok.. I falsely assumed the regex would match something. So incorrect (but still valid) regexes are also allowed as input. Maybe it's a good idea to add some comments to the sample outputs, like /10% of$10/ can be anything as long as it doesn't match anything (and maybe put the /(?!a)[^bc]/ or /[^abc]/ for the same input on one line. – Kevin Cruijssen May 10 '19 at 9:37
• You should more rigorously explain what x.reverse means, from the examples it looks like you mean the order of letters is reversed, but some people might be confused. – FryAmTheEggman May 11 '19 at 21:28

I've decided to leave this very open ended, so that I can write it based on community input. There are a lot of questions in the bottom. All feedback is appreciated, even minor suggestions/comments. :)

Did you know WordArt is still a thing in MS Word? Let's parse it!

(I'll remove the Swag format)

The challenge will contain a test battery with X jpg.files each with a word or sentence shown in WordArt. Your task is to parse as many as you can. The winner will be the submission that correctly parses the most images, with date stamp being the tie breaker.

### Sandboxing:

• Good idea or not?
• Should there be many different styles, or should I stick to one? Colors? Shade/mirroring?
• How many test cases?
• Is jpg the best format (it was used in the Upgoat/Downgoat challenge)
• Should I have a more refined scoring mechanism? It's hard to mix two quantities into one score.
• Should I stick to just letters / alphanumeric / all printable ASCII / multiple lines? Long sentences or single words?
• Orientation? Waves? Circular?
• Resolution?
• Builtin functions?
• Should I require a complete match of images, or character by character?
• Nice challenge! 1 WordArt is a completely objective (good) definition. 2 Some of the questions was mainly for the problem of the challenge being "too hard", so if you want any answer at all you should simplify those. (somehow most PPCG users are lazy). 3 Format is not a very important problem (conversion is easy), but just to be sure, use a lossless format. – user202729 Nov 7 '17 at 16:48
• There is another problem of the font used. – user202729 Nov 7 '17 at 16:49
• The challenge is supposed to be hard. Scoring based on the success rate would be useless if not. But it's of course possible to change the scoring, and make the test cases easier. – Stewie Griffin Nov 7 '17 at 17:00
• 1. optical-char-recognition. 2. Upgoat/Downgoat used JPG because it used photos. IMO it's preferable in general to allow any raster image format, because otherwise you pretty much force people to use languages with library support for image decoding. 3. The "Swag" example is ambiguous: is it "Swag Swag"? 4. If you want to refine the scoring mechanism, I would do it as the sum of Levenshtein distances from the correct results. But the big problem with scoring test-battery is the tension between keeping the tests secret (to prevent overfitting) and public (for objective scoring). – Peter Taylor Nov 8 '17 at 7:25
• 3. I can avoid the Swag-type format. Are the other formats unambiguous? 4. I can either show all the possible formats, and say that I will use words that are say 4-15 characters, or maximum 15 characters per example. I can then pre-select the input list, and provide a hash that ensures I won't change the input list after answers are posted. People can then try their code on some random strings of their own choosing on various formats and approximate their results, while the final score is made public later...? – Stewie Griffin May 22 '19 at 6:43
• Thanks for the link to the other challenges, they are useful as references when writing this challenge. Do you think this is different enough by the way? – Stewie Griffin May 22 '19 at 6:58

# Challenge

You will be given an input represented by x, which is a string containing at least 3 characters. It will consist only of the standard numeric characters, 0 through 9. Your job is to find and output how many right triangles can be formed with the given numbers.

# Rules

• Numbers must be kept in the order they were given in. No mixing them up!

• The numbers for each right triangle must be consecutive.

• The order of numbers has to be a first, b second, and c third, and must satisfy the formula a² + b² = c². a can be greater than or less than b, as long as it satisfies the formula.

• Decimal points may be added between any numbers.

• Decimals require one or more numbers to be placed before them, e.g. .5 cannot be used as a number but 0.5 and 12.5 can.

• Decimals with at least 4 digits after the decimal point truncated to the third digit, e.g. 1.2345 would truncated to 1.234 and 1.9999 would be truncated to 1.999.

• Numbers can be used more than once in 2 or more different triangles, but cannot be used multiple times in the same triangle.

• Multiple representations of the same value can count multiple times.

• Repeating zeros are allowed, e.g. 000.5 counts as a number.

• All possible combinations must be taken into account for your program to be valid.

# Example Inputs and Outputs

Input: 345
Output: 1
This can be split into 3, 4, and 5, which, of course, form a right triangle.

Input: 534
Output: 0
While this does include the necessary numbers to form a right triangle, they are not in the correct order. It has to follow the formula a² + b² = c², but in this case it follows c² = a² + b². The order of numbers cannot be changed from the original input, so in this case no right triangles can be formed.

Input: 3415
Output: 0
This does contain a 3, 4, and a 5, which can form a right triangle, but they are not consecutive; there is a 1 splitting the 5 from the 3 and 4.

Input: 5567507
Output: 1
Because decimals can be added anywhere, it can be changed to 55.67.507, which allows splitting it into 5, 5.6, and 7.507 to form a right triangle. Remember that decimals are truncated to the third digit after the decimal point, which is how we get 7.507.

Input: 345567507
Output: 2
The first right triangle is formed by 3, 4, and 5. The second one is formed by 5567507 (read the previous example for explanation). Numbers can be used more than once, so the first 5 was used in the first and second triangles.

Input: 51125
Output: 0
Because of rule 5, you cannot use .5, 1, and 1.25. An integer is required before .5 for it to work.

Input: 051125
Output: 0
Unlike the previous example, there is a number before the first 5, so it is now legal to use 0.5, 1, and 1.25.

Input: 121418439
Output: 2
The numbers 12 and 14 would form a right triangle where side c has a length of approximately 18.43908891458577462000. Because long decimals are truncated to the third digit after the decimal point, we would be left with 18.439. This fits in with the original input, 121418439. Additionally, 1.2, 1.4, and 1.843 counts as a separate combination, thus giving us our second right triangle.

Input: 10011005
Output: 8
Numbers count separately if they're represented in different ways, so this allows for (1, 00, 1), (1.0, 0, 1), (1, 0, 01), (1, 0.01, 1), (1, 0.01, 1.0), (1, 0.01, 1.00), (1.0, 0.1, 1.005), and (1, 00.1, 1.005).

This is code golf, so shortest answer in bytes wins. Good luck!

• So if I understand correctly we do the following things: get all substrings of the input; get all 3-part partitions of each substring; insert a comma at each possible position in each possible partition; check any combination of three in order is approximately truthy for $a^2+b^2=c^2$ (approximately, because the decimals have been truncated, so aren't exactly a right triangle in some cases). Do I understand this correctly? – Kevin Cruijssen May 8 '19 at 7:07
• @KevinCruijssen almost correct, except you must find all combinations both with and without decimals at any given location. So it's not necessarily just adding a decimal point at every possible place; it's checking the results that would occur both by adding and not adding a decimal. – Pika the Wizard of the Whales May 8 '19 at 14:19
• "Numbers can be used more than once." - Could you provide some examples of this or otherwise clarify what you mean? – Beefster May 10 '19 at 19:52
• @Beefster see the fifth example: one of the 5's is used to form two different right triangles. – Pika the Wizard of the Whales May 10 '19 at 19:57
• Perhaps a better way to explain it would be something like "Right triangles that only use a subsequence of the digits can overlap with other triangles made from the same sequence of digits" or "You do not need to use all the digits for a single triangle and you may re-use digits that were used in previous triangles". What confused me about the way it's currently written is that it could be taken to mean that you can re-use a digit for the same triangle, so 125059 could be split into 12, 22, 25.059. – Beefster May 13 '19 at 22:45

abcdefghijklmno
pqrstuvwxyz{|}~

¡,,#$%⅋,)(*+'-˙/ 0ƖᄅƐㄣϛ9ㄥ86:;>=<¿ @∀qƆpƎℲפHIſʞ˥WNO ԀQɹS┴∩ΛMX⅄Z]\[^‾ ,ɐqɔpǝɟƃɥᴉɾʞlɯuo dbɹsʇnʌʍxʎz}|{~  The rest of the characters are kept as-is(yes, the unprintable characters are in the ASCII character set). The characters that are larger than 0x7f will be mapped back by subtracting the character code by 128. If you are using a character that is larger than 256, modulo the character's character code by 128 before checking the availability. ## Rules • No standard loopholes, please. • Input and output will be taken with our standard input methods. • If you force Jono 2906 to change a key on their keyboard (allowing typing your specified character), you will get a penalty of +2 bytes for every key you add. • I don't think I quite follow. Are we given a character as input and need to output the upside-down version? – AdmBorkBork Aug 27 '19 at 14:06 • (1) I still find the question confusing even as to the basic functionality required. The "Input/Output" section seems to me to say that it's a Kolmogorov problem, but the "Rules" section talks about input. (2) If a character remapping is involved, the question should list Unicode codepoints for the characters in question, and should list test cases with Unicode codepoints. (3) Is the last rule saying that the program must work as is and after mangling? Or is it just a gimmick ("Post your code upside down, but it only has to work the right way up")? – Peter Taylor Aug 28 '19 at 8:39 • "The rest of the characters are not kept as-is(yes, the unprintable characters in the ASCII character set)." should this not be there? As for that entire paragraph, if I understand correctly: unprintable characters < 33 (as well as 127) will be kept as is; printable ASCII characters displayed will be converted to upside down; other printable ASCII characters and any character above 127 will be modulo-128 before doing the same check. – Kevin Cruijssen Aug 28 '19 at 9:24 • As for the last rule: we can only use those upside down characters in our source code, and when converting it to regular it should also work? So both programs ABC and ∀qƆ should work exactly the same? – Kevin Cruijssen Aug 28 '19 at 9:25 ## Wrong position I typr re;atively accuratrly, but so,etimes I made a whole nlock of text illegible by shifting a key right. So I need a program that corrects my text back to its original meaning. ## Rules • You have to left shift on a standard English QWERTY keyboard. • Whitespace do not count for the procedure before left-shifting and are kept as-is in a standard left-shifting procedure. If the key is the leftmost letter/symbol on a keyboard(i.e. The ~key, Q key, A key, Z key.), the key is kept as-is. If you reach a control character while left-shifting (Caps lock and Shift), their effects will not be triggered and the character before left-shifting is kept. • This is a contest; the shortest answer wins. • Both the input and the output shall be given via our default methods. ## Representation of a subset of the QWERTY keyboard that you will need The two lines connected are possible values of the key: shifted/unshifted. ~!@#$%^&*()_+
1234567890-=

QWERTYUIOP{}|
qwertyuiop[]\

ASDFGHJKL:"
asdfghjkl;'

ZXCVBNM<>?
zxcvbnm,./

(Space)
(Space)


## Input

The input will always be a non-empty string conforming the rules above.

## Output

The output will be the input string corrected to the originally intended meaning.

## Examples:

Yjod ,sfr yjr, imjsppu/ -> This made them unhappy.
vpfr hp;g -> code golf


## Feedback

I think this is not a duplicate; however, is any part of this challenge unclear or needs improvements?

• I think you are mixing up left and right. Clearly, ~, Q, A and Z are leftmost keys, NOT rightmost. And your examples appear to be left-shifting, not right-shifting. – wastl Sep 7 '19 at 11:27
• "I think this is a duplicate" - so why sandbox it? Or did a not go missing in editing? – Peter Taylor Sep 9 '19 at 8:36
• Thank you. Predominantly my mouse was not working again, I didn't get around to fix this. – user85052 Sep 9 '19 at 8:56
• "sonetimes" and "vlock" are shifted the wrong way. – Hiatsu Sep 9 '19 at 16:20

# Path to Path Rearrangement

In the xkcd comic "Map of the Internet", a special fractal path was used, similar to this:

0  1  14 15
3  2  13 12
4  7  8  11
5  6  9  10


Ascii art version:

-0---1  14---15--16 19--20---21
|   |       |   |       |
3---2  13---12 17---18 23---22
|           |           |
4   7---8   11 30---29 24---25
|   |   |   |   |   |       |
5---6   9---10 31  28--27---26
|
58---57 54---53 32  35--36---37
|   |   |   |   |   |       |
59  56---55  52 33---34 39---38
|           |           |
60---61 50---51 46---45 40---41
|   |       |   |       |
63---62 49---+---47 44--43---42
\|/


This path, known as the Hilbert curve, has some interesting properties. Among other things, it can be flipped diagonally without changing most of those properties.

-0   3---4---5  58--59---60  63->
|   |       |   |       |   |
1---2   7---6  57---56 61---62
|           |
14---13  8---9  54---55 50---49
|   |       |   |       |   |
15  12--11---10 53--52---51   48
|                           |
16---17 30---31--32--33 46---47
|   |           |   |
19---18 29---28 35---34 45---44
|           |   |           |
20  23---24  27 36  39---40  43
|   |   |   |   |   |   |   |
21---22 25---26 37---38 41---42


Your task is to apply this transformation. Given a space on one path, find the corresponding location on the other. For example, the fourth space in the top path is located at (0, 2), which is the 14th space along the second path, so the correct output for 4 is 14.

As with similar challenges, this can be done as:

• An infinite sequence along the second path of the corresponding locations along the first path
• A function/program that takes a numbered position on the first path and returns the distance to that point on the second path.
• A function/program that takes a numbered position on the first path and returns all path 1 positions along path 2 to the point specified.

The first 64 terms of this sequence (zero indexed, add one to each for one indexed) are:

0 3 2 1 14 15 12 13 8 11 10 9 6 7 4 5 58 57 56 59 60 63 62 61 50 49 48 51 52 55 54 53 32 35 34 33 46 47 44 45 40 43 42 41 38 39 36 37 26 25 24 27 28 31 30 29 18 17 16 19 20 23 22 21


This is code golf, so shortest code in bytes wins.

## Meta Questions

• Do I need a better description of the paths?
• Is the challenge itself clear?
• Any other issues I should fix before posting?
• The default output formats for sequence challenges can be found in the tag wiki – Jo King Sep 10 '19 at 4:03
• (1) Related. (2) I don't find "Find the location along the second path of a point on the first path" at all clear. It seems to be talking about output in 2D. I think it would be clearer to say "Given an index on the first path, output the index of the same coordinate on the second path". And then give a worked example (e.g. 4 vs 14). – Peter Taylor Sep 10 '19 at 10:53

# Is this number part of a Collatz Prime sequence?

Each step of a Collatz Sequence can be summarized as:

$$p_{2} = \frac{3*p_1+1}{2}$$

Where p1 is the input number, and p2 is the output number.

You task is to find where both the input and output are primes.

Here are some test cases:

1  -> (3*1+1)/2 = 4  : false
3  -> (3*3+1)/2 = 5  : true
5  -> (3*5+1)/2 = 8  : false
7  -> (3*7+1)/2 = 11 : true
11 -> (3*11+1)/2= 17 : true
15 -> (3*15+1)/2= 23 : false
91 -> (3*91+1)/2=137 : true
97 ->(3*97+1)/2 = 146: false


Output should be some truthy value, and false may be an error.

• What is the definition defining? Is $p$ a Collatz prime iff it's a prime and $\frac{3p+1}2$ is a prime? If $p$ a Collatz prime iff it's a prime and $\frac{2p-1}3$ is a prime? Or is a prime Collatz if either of those conditions hold? – Peter Taylor Sep 13 '19 at 10:56
• @PeterTaylor are they not the same thing? – Pureferret Sep 13 '19 at 11:09
• Alternative phrasing: which of $p_1$ and $p_2$ are you calling a Collatz prime? – Peter Taylor Sep 13 '19 at 11:11
• @PeterTaylor I mean $p_1$ – Pureferret Sep 13 '19 at 11:22
• So neither the input prime nor the Collatz prime need to be prime? – Jonathan Frech Sep 17 '19 at 7:56
• "Input MAY be non-prime, in which case the output is always false (see 15)" -- did you specifically define this behavior or why is the above the case? – Jonathan Frech Sep 17 '19 at 8:00
• @JonathanFrech I'm (personally) only interested in going from prime to prime, but I wanted to define the haviour for non-prime input. When I say 'may be non-prime' I mean, it should be able to handle it, it's an allowed/expected input but not one that gives a True output. – Pureferret Sep 17 '19 at 10:55
• To me it feels like an unnatural extra constraint. – Jonathan Frech Sep 17 '19 at 12:54
• @JonathanFrech it's just defining how to behave with certain inputs. – Pureferret Sep 18 '19 at 9:12
• Citing Exceptional edge cases; such out-of-place definitions are generally frowned upon. – Jonathan Frech Sep 18 '19 at 9:56
• @JonathanFrech I've changed the initial ask, and now it shouldn't be an exception – Pureferret Sep 18 '19 at 10:23
• Cf. A158709. – Jonathan Frech Sep 18 '19 at 10:53

## Maximize the Hello, world's in code permutations

In this task you should output this exact string: hi orb (because Earth is a sphere). However, here is the catch: you must output as many hi orb's as possible in all of your code permutations. Identical permutations do not count(e.g. aa's permutations count as one permutation)

Say you have a program abc that outputs this string. You should try your best to make acb, bac, bca, cab, and cba (i.e. the permutations of abc) also output this exact string.

## Rules

• Input/output must obey our standard methods.
• Your score is simply the factorial of the length of your code. You shall also present the following score: The score is counted in the negative of the length of your source code divided by the number of permutations that your code generates; (expression: -(source length/permutations).) Of course you want to keep your score as low as possible.
• All comment characters in your language are disallowed, in order to avoid collapsing into a radiation-hardening challenge.
• If you are using the filename as data, the filename must also count in the permutations.
• The source code length should be <1000. (Don't ask why, it's just an attempt of avoiding abusing the source code length.)

## Feedback

• Is it detailed enough?
• Is the input/output rules clear enough?

I don't think this is a duplicate because nobody has asked a question tagged with both permutation and hello-world. However, I worry that this challenge will collapse into a radiation-hardening challenge if you comment out a single character and then make sure that this will produce the same result, therefore making it a flavored version of this question and close to a duplicate.

• Can't you just extend your score by increasing your byte counnt, as long as you have some commented out part or no-op? – Jo King Sep 19 '19 at 8:50
• Unneccecary NOPs are disallowed, and at least 1 permutation of your code must only contain relevant code and nops. is rather vague, since no-ops aren't really defined, nor is this challenge really that possible to increase score if you don't have no-ops, otherwise it will turn into a duplicate of the normal Hello World question – Jo King Sep 19 '19 at 9:25
• This reminds me of a challenge I sandboxed a while ago, but deleted since it was clear it would produce only trivial answers – Jo King Sep 19 '19 at 9:27
• code-golf scoring usually has lowest score (=code length) wins. If you break with that convention, you should mention it in the rules. I think a big problem with this is that for any non-trivial answer (Like H in HQ9+), the proof of correctness of the score is almost impossible, because unlike radiation-hardening, the amount of variants increases factorially instead of linearly with the code length. – AlienAtSystem Sep 19 '19 at 11:52
• Hmm, it is okay, I will make the score negative then. I believe a program running the permutations of a string (not counting repeated ones) and evaluating them to check the result will be sufficient. Hmm, that's why the submittor needs to golf their code: to allow others to check their answers. – user85052 Sep 19 '19 at 12:09
• That's where it's unfeasible: The highest-scoring answer in the challenge you linked has 96 bytes. That's 9.9*10^149 permutations to check if they output the correct result. Even assuming your implementation is the fastest possible, that would take years, just for that single answer. You can't brute-force determine the score, but using mathematical trickery to try and calculate the score by hand will be arduous and prone to errors. – AlienAtSystem Sep 19 '19 at 13:10
• I don't think the limitations you have put are going to prevent this from falling apart. For example, this Pyth program works for any permutation of the code where only characters after the third " are permuted. Completely filling up the code allowed will achieve a score exceedingly close to zero. I don't think that is what you want, but I'm not really sure you can fix it (like what happened to Jo King), sorry. – FryAmTheEggman Sep 19 '19 at 18:38
• @FryAmTheEggman this particular snippet fails the rule that all code needs to be relevant. However, even if we tighten the rule to all code being life and necessary, that is, in one permutation, all code is executed, and a deletion of any statement resulting in the code not outputting "Hello World" any more, you can still cheese the challenge by bloating the code. The only way to stop that would be to change the scoring method to also use the factorial of the byte count, but then A) HQ9+ is unbeatable and B) It's a math challenge because you have to calculate the amount of viable permutations – AlienAtSystem Sep 20 '19 at 10:06
• Instead of helo word, wouldn't it make more sense to just use a different phrase like greeting earthlings or something along those lines? I agree with @AdmBorkBork that helo just looks weird. I do think it shouldn't be hello world to prevent builtins, so helo word is already better, but it still looks weird and will raise questions for sure.. – Kevin Cruijssen Sep 20 '19 at 12:38
• I don't understand the scoring. If we're scored only on the factorial of the length of code, why does it matter how many permutations output hi orb? I would figure that the number of ways that is output should factor into the scoring somehow... – AdmBorkBork Sep 20 '19 at 14:11

# The Celestial Bureaucracy king-of-the-hill

Posted

• This sounds like a lot of fun. When the exam is asked, is it possible to know which bot gave the exam? – Pureferret Sep 18 '19 at 11:58
• You are given the ID of the bot via the parameter for ask, which allows you to identify if you've interacted with that bot before and if it's the Jade Emperor (because his ID is always -1). You won't get the name - if you want to identify the bot, you'll have to analyse its question and answer pattern. – AlienAtSystem Sep 18 '19 at 12:08

# Creep Spread Territorial Control (WIP)

(probably)

Blah blah blah flavor blah blah blah something about Starcraft blah blah blah

# Gameplay

## Initial State

There is a 150x150 grid of square cells with approximately 7500 random cells missing in a symmetric Perlin noise pattern. There are four creep spread factions competing for dominance of this territory beginning as a single cell 10 cells in from a corner of the grid (one faction per corner). Each faction starts with 50 energy. The board does not wrap around at the edges.

## Expansion

Each turn, each faction earns 1 point of energy for each controlled cell plus 20 base energy. This energy is used for expansion. How much a cell costs to expand to depends on how many cells controlled by the same faction are in the Moore neighborhood of the target cell.

• 0 neighbors: cannot expand to this cell
• 1 neighbor: 50 energy
• 2 neighbors: 20 energy
• 3 neighbors: 12 energy
• 4 neighbors: 8 energy
• 5 neighbors: 5 energy
• 6 neighbors: 3 energy
• 7 neighbors: 2 energy
• 8 neighbors: 1 energy

There is no limit to how many cells can be expanded to in one turn other than energy costs. All expansions occur simultaneously. If two or more factions attempt to claim the same cell on the same turn, the one with the most neighbors of its own faction will claim the cell. If there is a tie, none of the factions claim that cell. Players whose expansions failed due to competition will not be refunded. Factions may expand onto each other's territory, stealing ownership of the cell.

## Game End

The game lasts 10,000 turns or until there is only one faction remaining, whichever happens first. The winner is the faction with the most owned cells. Ties are broken by remaining energy.

The overall winner will be resolved with a randomized pool where each bot plays an equal number of games followed by 12 games of the top 4 contenders. (one for each possible corner positioning)

# Coding

Write a bot that plays this game

• Bots must be deterministic. As a way to provide localized pseudorandomness, a random integer between $$\0\$$ and $$\2^{32}-1\$$ will be passed to the bot, which will be seedable in the controller.
• Bots have perfect information of the current state of the board, which turn it is, and their own energy, but not the energy of other players.
• Bots may not remember anything between turns, but may initialize constants and utility functions at the beginning of each game.

The list of desired expansions is ordered. As soon as an invalid expansion target cell is encountered (whether by cost or lack of same-faction neighbors) in this list, the rest of the list will be ignored and a warning will be logged.

• So if I build at 0,1 and 1,0 on the same turn while having a cell at 0,0, the cost would be 2000, yeah? Are failed expansions refunded? Also, I think having a source of randomness would be good. – Veskah Sep 13 '19 at 17:40
• @Veskah, that would cost 2000, correct. I'll add some rules about when failed expansions are refunded. – Beefster Sep 13 '19 at 19:38
• Suggestions: 1. Maybe allow expanding to own territory too? Could be used as a defensive mechanism when you can predict that you are going to be attacked. (should be thought about, could be bad) 2. Maybe set a limit on how many cell expansions can happen per turn to avoid exponentially expansion? I'm thinking that a bot which gains some advantage might get unstoppable when it is unlimited. – Night2 Sep 14 '19 at 7:33
• 3. More clarification in rules about expansions, for example if player 1 and 2 have a tie on this turn for cell X and they both go for it, but player 1 also goes for a neighbor of cell X in same turn, will player 1 win? (@Veskah mentioned another scenario too) 4. I would suggest using JavaScript so more people can write and run the code (anyone with a browser can do it), also a controller with some helper functions could be nice, for example a function which returns expansion cost for a cell in an optimized way to avoid tens of different implementations for same common action. – Night2 Sep 14 '19 at 7:39
• 5. "Bots have perfect information of the current state of the board.", does this include current energy value of other players? – Night2 Sep 14 '19 at 7:45
• @Night2 1 Interesting. It seems a bit fiddly. 2 This should actually come out to a quadratic expansion rate since where you can expand to is derived from perimeter, which grows linearly. 3 All expansions are resolved simultaneously (as in Conway's Game of Life), so player 1 does not win that tie. 4 Javascript is the likely plan since I intend to have a significant graphical component. 5 I'll have to think about it. That could be rather interesting as 'private' information. – Beefster Sep 15 '19 at 3:00
• 6. Proposal to spice things up: board is randomly generated, with some cells being unavailable for expansion. Uniform random, Perlin/Simplex noise, cellular automaton-based cave generation, etc. 7. Will the bots have access to the turn counter? 8. Maybe rotate and/or mirror the board provided to the bots so that each bot starts at, for example, the top-left corner from its perspective? – Alion Sep 15 '19 at 10:36
• 9. Allow bots to pre-calculate some data on load or game start. This will allow people to speed up their bots. Especially useful if you end up implementing 6. – Alion Sep 15 '19 at 10:47
• @Alion 6 That sounds pretty interesting. I'll probably expand the board slightly in that case. 7 Yes, they'll know what turn it is. 8 I don't think that adds much. I'm probably going to have to make copies of the board every turn anyway to make it impossible to cheat on accident though... 9 Seems reasonable. – Beefster Sep 16 '19 at 0:39
• "Bots must be deterministic. As a way to provide localized pseudorandomness, a random integer ... will be passed to the bot, which will be seedable in the controller.". Why not make a custom random function available or override the default random generator and make the controller generate and handle the seeds? For example in JavaScript users can still use the normal Math.random(), but you can use this to make it deterministic: davidbau.com/archives/2010/01/30/… – Night2 Sep 21 '19 at 11:21
• @Night2, yeah. I'll probably do that since I'm going to have to use an RNG library anyway. – Beefster Sep 22 '19 at 2:32

# Turing-complete regex subset

It's widely known that a programming language is one iff it's capable of addition of natural numbers and primality testing. In practice, this criterion has a high accuracy for distinguishing Turing-complete languages too.[citation needed]

## Cops' challenge

Choose any of the programming languages available on tio.run. Write a regex that will define a subset of this programming language. The subset must still match the definition, though ideally this should be far from obvious.

Write two programs in this language that match this regex:

1. Take two natural numbers, a and b, as input. Output a + b. The program must work for 0 ≤ a + b < 215.
2. Take a natural number n as input. Output whether the number is prime. The program must work for 0 ≤ n < 215.

The behavior outside of this range is undefined. This means that you can output the correct answer, a cute cat ASCII art, an error, an invalid answer, invoke nasal demons, or anything else you can, or cannot, imagine.

Regex come in multiple flavors. Choose one. You can choose any flavor available on regex101, or Retina.

• the programming language and regex flavor you chose
• the regex delimiter and flags you chose (for example: //gm; does not apply to Retina)
• the regex you wrote and its byte count
• the byte counts of your two programs

## Robbers' challenge

Write two programs that prove the subset to be a valid programming language. The rules that apply here are the same that apply to the cops. Additionally, your programs must not exceed the cops' in length.

# Meta questions

The above will be posted as the cops' thread, with the robbers' thread simply linking to it.

• Any improvements to challenge structure? I've never done this before.
• Do you see any loopholes that need addressing?
• Are the allowed regex flavors reasonable?
• Duplicates?
• I think this is a duplicate of codegolf.stackexchange.com/questions/136150/… – pppery Sep 22 '19 at 18:11
• @pppery Hmm. These are definitely pretty similar. On the other hand, regexes might allow more interesting answers. – NieDzejkob Sep 22 '19 at 18:25
• I'm not convinced this is a dupe since most of the interesting work here is in selecting the regex rather than in choosing a sequence, though I think the other challenge is cleaner. I think the optimal scoring regex will usually be to make an "unhash" that produces the appropriate programs. Unfortunately I don't have any suggestions at the moment to help fix that, but if you can then I think this is alright. – FryAmTheEggman Sep 22 '19 at 18:32
• @FryAmTheEggman I can't see what you mean by "unhash" here. Could you elaborate? – NieDzejkob Sep 22 '19 at 18:36
• Consider this program which performs the first task. The regex that matches only programs like this would be short but but not very informative. I think doing this but making guessing the magic number arbitrarily hard would usually be the best approach in a given language. – FryAmTheEggman Sep 22 '19 at 18:43
• @FryAmTheEggman Like, /^\.vC\d+$/? I think that making it complicated enough would take quite a lot of bytes. – NieDzejkob Sep 22 '19 at 19:02 • The point is that the number could be manipulated, so I could pad my program arbitrarily until I got a number that let me write a regex like ^...(2|10|76|345?)*$. That's neither very long nor easy to crack. – FryAmTheEggman Sep 22 '19 at 19:06
• I like the idea of the challenge but I feel including the bit about Turing completeness is a bit of a red herring, it only really distracts from the challenge. – Wheat Wizard Sep 22 '19 at 21:30
• To elaborate the particular part I like is regex selection part. I do agree that my challenge is a bit cleaner otherwise. – Wheat Wizard Sep 22 '19 at 21:31

• I'd recommend removing the text with a strikethrough; I think it is just confusing. "Accurate to 6 significant digits" isn't a very good validity criterion since it would require testing each and every possible input the program could handle. I'd recommend saying it has to be that accurate for your test cases but not be hardcoded for them, or something like that. – FryAmTheEggman Sep 19 '19 at 19:33

# Byte-sized Huffman Coding (WIP)

Huffman codings are a method to compress data with certain frequency properties, usually text. Normally, these operate on bits rather than bytes, but this challenge will instead operate on whole bytes instead. Since you wouldn't get any benefit otherwise, you can represent multiple consecutive characters with a sequence of one or more bytes, for instance '. ' (a period followed by a space) could be represented by byte 1, 'The' could be represented with byte 2, and 'Ishmael' could be represented by a 255 then a 7 (among many other sequence codings).

# Challenge

Create a program that compresses a plain-text version of a work of literature by returning a byte-wise Huffman coding table and a sequence of bytes that represents the text with that table.

## Rules and Assumptions

• You may assume that the text is written in English and uses only printable ASCII characters plus space, newline, and tab.
• It must be a proper Huffman coding; no mapping may be the prefix of another.
• Not all Huffman sequences need to be mapped to a particular character sequence; you could, for instance, not have 7 mapped to anything or not have 255, 39 mapped to something, but have every other 1 and 2 byte sequence mapped to something.
• The returned coding table must be able to encode every possible sequence of valid characters (as per the first assumption above). The simplest way to do this is to make sure that every individual character is mapped to a Huffman byte sequence.
• It can be possible to encode a body of text multiple ways using the returned encoding table. If both ca and at are mapped to byte sequences, cat could be encoded two ways. This is totally fine.
• Case must be preserved.
• Runs do not need to be deterministic, i.e. two runs of the same program with the same input could produce different Huffman tables and compressed output.
• Your program must return a result within a reasonable amount of time to be considered a valid solution. (If you want a hard limit, I'll say 5 minutes on a 2GHz Intel dual-core i5 with 16 GB RAM running Windows 10)

## Scoring

Your results will be run against a corpus of (TBD) 12 publicly available literary (and non-fiction) works. For each work of literature, your score will be the size, in bytes, of the compressed text, plus the total length of all text strings mapped to a byte sequence in the Huffman-coding table. Your overall score is the total score across all 12 works.

### Literature list

• The King James Bible
• Hamlet by William Shakespeare
• Dracula by Bram Stoker
• Frankenstein by Mary Shelley
• On the Origin of Species by Charles Darwin
• Moby-Dick by Herman Melville
• Little Women by Louisa May Alcott
• Tom Sawyer by Mark Twain
• Pride and Prejudice by Jane Austen
• The Hound of the Baskervilles by Arthur Conan Doyle
• < Something that entered the public domain in 2019 because it was published in 1923 >
• < Something written in the last 20 years willingly released into the public domain or with a Creative Commons license that allows derivative works >

### Sandbox

At least one of the last two literary works should preferably be written by a female author to hopefully make writing styles diverse enough to make hard-coded Huffman tables ineffective. Each work should be comparable in length to the other works.

Links to these books (in plain text) would be appreciated. Substitution suggestions are welcome.

I'm considering using something like the Weissman Score relative to gzip for the scoring method so that performance is factored into the score, but I'm concerned about reproducibility of time since that tends to vary even on the same machine due to caching and OS scheduling.

• If you want to vary writing styles, is there a non-fiction work that only contains the allowed characters? – trichoplax Sep 24 '19 at 23:21
• @trichoplax The most notable non-fiction book I can think of for that would be "On the Origin of Species" by Charles Darwin. I've also thought about throwing in the King James bible. Maybe I could bump up the total to 12 works. I also probably will drop War and Peace because the plain text version I found was machine converted and has issues. – Beefster Sep 25 '19 at 15:21
• Regarding plain text books, have you checked Project Gutenberg? They have plaintext versions of many of their books. – AdmBorkBork Sep 25 '19 at 18:35
• I have no idea how much sample text is a good amount for this challenge (number of books, length of books) but it's probably worth doing some kind of rough check that there is enough text to give variation between answers (no optimal solution) while still being little enough text that running in a reasonable time is realistic (doesn't require weeks of work before an answer is efficient enough to meet the time restriction). Maybe others can suggest good ways of approximating this? – trichoplax Sep 25 '19 at 20:16
• @trichoplax so basically you suggest sampling out, say, a few chapters instead of the whole book and then reducing the required runtime? I'm open to that, especially since the word count difference between Hamlet and the Bible is so big. The interesting thing about the Bible is that it has a ton of different authors, so it would almost be better to have the first chapter of each book instead of inserting, say, the entirety of Genesis. – Beefster Sep 26 '19 at 4:41
• I couldn't guess at this point whether more text or less text would be better, and I don't have a way of estimating, just wondering if anyone else does. – trichoplax Sep 26 '19 at 7:32
• I see no problem with 5 minutes as a rough time limit. I'd lean towards a time limit that allows someone to write a quick answer and then improve on it gradually, to encourage more participants. How long that needs to be for the text you settle on I don't know. As long as you're confident an optimal solution can't be found, you could just time a naive approach and then choose a time that doesn't exclude that. Then you can get lots of early answers to get the competition going, but still have open ended improvement over the long term – trichoplax Sep 26 '19 at 7:38
• Not to say that this isn't an interesting challenge as it is but I do wonder if it wouldn't be more interesting without requiring that we use Huffman Encoding? – Shaggy Sep 27 '19 at 22:21
• For the tiebreak, what does code with the fewest bytes mean, given that we're outputting a county assignment? – xnor Oct 7 '19 at 22:24
• @xnor - I modified the scoring mechanism to not require tie breaks. Thanks to this modification, I expect the code submissions to be much more interesting. – Dustin G. Mixon Oct 8 '19 at 17:06
• I like your new assignment score and no longer having a code golf tiebreak.The leave-one-out looks kind-of complicated and might take a long time to run-- is there a way to simplify it? The challenge looks a lot more intimidating that when I last commented, though the idea looks the same. I guess you want to make sure people actually write code that kind-of generalizes rather than possible finding an assignment by hand. Maybe also consider something with the standard deviation in assignment place of the max-min ratio so there's also an incentive to try to balance populations in the middle? – xnor Oct 8 '19 at 22:48
• @xnor - Great points, thanks! I simplified things by cutting the number of leave-one-out instances by a factor of 10. (I selected these 10 counties based on political geography considerations.) I also toned down the math speak to make the challenge less intimidating. I thought about standard deviation instead of max-min, but max-min is closer to how we enforce one person, one vote in practice. – Dustin G. Mixon Oct 9 '19 at 2:20

I came across this little web game Drench Its a fairly mindless game , I wrote a small JS snippet to play this game for me in the background of my browser, it cycles through and clicks on the 6 possible moves

let ind =0;
let games =0;
let wins =0;
let lastMoves = "";
setInterval(function(){
if (jQuery('.moveNum').text() != lastMoves) {
lastMoves = jQuery('.moveNum').text();
ind++;
ind = ind%6;
jQuery('.pbutton:nth('+ind+')').click();
} else {
games++;
if ((jQuery('.moveNum').text()*1)) {wins++;}
jQuery('#myCanvas').click();
}
},200);
`

This Strategy wins about 3% of the time My question is, is there a more optimal strategy that will allow me to win a greater % of the time (without looking at the board)?

• Hi and thanks for using the sandbox! Though this is a bit unusual for this site, I think your question is on-topic, just far too broad. "Can I do better" just isn't something you can really ask on the SE network. I think the best way for you to move forward is to fully explain the game in the body of your post, and then score submissions based on their win percentage. – FryAmTheEggman Sep 21 '19 at 19:37
• I really like the idea though - I think win% is the way to go – simonalexander2005 Sep 23 '19 at 15:20
• Make this a code-challenge? To verify, you can run it for, for example, 500 times and calculate the winning percent? – null Oct 13 '19 at 8:49
• Coded this up in p5.js, you can play it here hoppingmad9.github.io/dench Happy to convert it to pure js if needed and could add an interface to get the board state and input moves. – Sam Dean Oct 18 '19 at 12:14
• oops, well I guess the code golf version can be called "Dench" not "Drench". I thought "Dench" was a weird name – Sam Dean Oct 18 '19 at 15:29
• Probably needs a time limit for each turn to prevent people trying every single possibility of moves – Sam Dean Oct 25 '19 at 15:39