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

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

## I'm sorry, Code Golf

This challenge is inspired by a series of Garfield-inspired artwork in which Garfield is depicted as a horror creature, stalking his owner, Jon. Commonly referred to as "Creepy Garfield", the line "I'm sorry, Jon" can be found in one of the earliest Creepy Garfield images, created by DubbleBaby.

After being used over and over again by the Code Golf community, our beloved Jimmy has transformed - no longer bound to his weak, mortal body. He has become the embodiment of spaghetti code, the ascii manifestation of hours-long debugging sessions.

Take 3 ordered numerical inputs and output Jimmy's body

Inputs

Input is received in the form x y z where:

x is the number of left limbs (integer between 1 & 10)
y is the number of right limbs (integer between 1 & 10)
z is the number of heads (integer between 1 & 10)

----Sample Input----
2 8 1

Meta Note: I don't think increasing the possible amount of body parts will influence the solutions but please let me know if you think they should be higher.

Body Parts

Left Limb =     /
Right Limb =    \
Filler Limb =   |
Body Piece =    0

Body Generation Rules

1. Left limbs must be attached to the left side of a body piece
(excl rule 3)
- Correct:  /0
- Incorrect: /<o>
- Incorrect: 0/
- Incorrect: /0\0\

2. Right limbs must be attached to the right side of a body piece
(excl rule 3)
- Correct: 0\
- Incorrect: <o>\
- Incorrect: \0

3. Limbs must not touch
- Correct: /00\
- Incorrect: /0\/0\

4. An external body piece without a limb must have a | in its place
- Correct: /0|
- Correct: |0|
- Correct: /00\
- Incorrect: /0
- Incorrect: 0\

5. Heads must be between body pieces (horizontally not vertically)
- Correct: 0<o>0
- Incorrect: 0<o><o>0
- Incorrect: 0<o>

6. All lines must be aligned centre
- Correct:      /0\
/0<o>0|
/0\

- Incorrect:    /0\
/0<o>0|
/0\

7. The bottom line of Jimmy's body must always contain a left and right limb
- Correct:      /0\
/0<o>0|
/0\

- Incorrect:    /0\
/0<o>0\
/0|

8. Jimmy's body must be whole and cannot be separated into sections
- Correct:    /0\
/0<o>0|

- Incorrect:    /0\   /0\   |0<o>0|

- Incorrect:      /0\

/0<o>0|

Examples

Input:
2 8 2

Sample Output:

/0<o>0<o>0\
|0\
|0\
|0\
|0\
|0\
|0\
/0\

OR

/0\
|0\
|0<o>0\
|0\
|0\
|0<o>0\
|0\
/0\

## Rules & Win Conditions

1. You may receive the stated input via any method into a program or function.
2. You may display the output in any clear and discernible way.
3. Your output must obey all Body Generation Rules.
4. The previous 3 rules must be followed for all 1000 combinations of inputs.
5. Standard loophole rules apply.

As this is , least amount of code in bytes wins.

• I don't like bonuses in code golf in general, and this one doesn't even affect the score so it's just an invitation to distract from the challenge – trichoplax Jul 16 '19 at 20:36
• (1) Whenever you see a bandwagon, run the other way. It's better to ask an interesting question than the nth variant on a theme. (2) That aside, there's no clear explanation of what the input is. Where are the values of that enum? – Peter Taylor Jul 17 '19 at 10:53
• @PeterTaylor (1) This challenge doesn't exist to hop on the bandwagon. I thought that generating an eldritch-like stick figure would be neat. If you don't think this is an interesting question, I'd love to hear your feedback on that. (2) I've amended the input section to be a bit clearer but I'm not sure what I was missing in the first place. – BDM Jul 17 '19 at 21:13
• What's missing is an explanation of the interpretation of the numbers. The input section defines the range of legal inputs but not the meaning of the inputs. – Peter Taylor Jul 17 '19 at 21:33
• @PeterTaylor Ah I understand now. Hopefully my recent edit solves this. – BDM Jul 17 '19 at 21:44
• Somewhat related ... I think?! – Shaggy Jul 21 '19 at 21:23

# String attractors

Let $$\S$/extract_tex] be a string of length $$\n\$$. An attractor of $$\S\$$ is a subset of indices $$\A \subset \{0, \ldots, n-1\}\$$ such that every nonempty contiguous substring $$\S[i \ldots j]\$$ of $$\S\$$ has an occurrence $$\S[i' \ldots j']\$$ whose index set $$\[i' \ldots j']\$$ intersects $$\A\$$. A minimum attractor is one with minimal size. Minimum attractors can be used to implement very efficient string compression algorithms. In this challenge, your task is to find a minimum attractor for a given string. # Example Consider the string acabaccabc. Using 0-based indexing, one of its attractors is $$\A = \{2,3,5,8\}\$$. This graphic shows the positions of $$\A\$$: acabaccabc ^^ ^ ^ For example, the occurrence of the substring ac in the beginning doesn't intersect $$\A\$$, but there is another occurrence after the first b that does. It turns out that no attractor of size 3 exists for this string, so $$\A\$$ is a minimum attractor. # Specifications Your input is a nonempty string of lowercase ASCII characters. Your output is a minimum attractor for this string, in any reasonable format. You can use either 0-based or 1-based indexing. There may be several choices for the minimum attractor. In that case you may return any one of them, but only one. The lowest byte count wins. # Test cases These are 0-indexed and show one possible output. a -> [0] aaa -> [0] ababab -> [0,1] qgqqgq -> [1,2] abcbacaa -> [1,3,5,6] abcdefgh -> [0,1,2,3,4,5,6,7] jejjeeje -> [2,3,5] sttststt -> [1,5] ykkkkvyk -> [0,2,5] assassins -> [0,2,6,7] acabaccabc -> [2,4,6,8] ssssssjjjsjj -> [5,8] hrhrhhrhhhrr -> [3,7,10] fubuaabubuau -> [0,1,4,6,10] jjaahajjhahaaahjjh -> [2,6,8,11,14] • It took me a few tries to understand the first paragraph. I think it is explained well, but I may just have been unfamiliar with the language. Adding an explanation of "occurrence" may help? – FryAmTheEggman Jul 18 '19 at 20:34 • The formal definition in the first paragraph is clear if you are used to such an academic style, though it might unnecessarily hard to grasp for users with no such background. It might be worthwhile to start with an informal explanation before giving the concise formal specification. E.g. something like this: Consider the following game: You are given a string like acabaccabc and need to defend it against attacks by marking some of its characters. An attack is a continuous substring of the given string, e.g. ca, and it is defended if one of the occurrences of the substring has (1/2) – Laikoni Jul 28 '19 at 18:43 • a character that was marked by you. In the given example, ca occurs two times and covers the characters at positions 1,2 and 6,7 (with positions starting with 0). Thus, at least one of the positions 1,2,6 or 7 would need to be marked to defend the attack. Your goal is to find a marking such that the string is defended against any attack. Furthermore, you want to mark as few characters as possible. (2/2) – Laikoni Jul 28 '19 at 18:43 Posted here # Check If A Binary Search Tree Is Balanced Now posted on CodeGolf.StackExchange.com: Write The Shortest Program To Check If A Binary Tree Is Balanced • Looks like a nice challenge! I think you should specify what representations of a binary tree are accepted. There is certainly the representation as a list (where the children of the entry at index r are at 2*r and 2*r+1), but there might also be other native representations. – flawr Aug 5 '19 at 6:44 • Now that you've posted this, please edit it to be only a link to the main challenge and then delete your post to help keep the Sandbox tidy. Thanks! – AdmBorkBork Aug 7 '19 at 14:28 Posted to PPCG. Thx for the votes! # Nearest Primes Converted String Inspired by this SO question. ## Challenge: Given a string input, convert each of its characters to its integer code-point, and then get the nearest prime $$\p\leq c\leq P\$$ (where $$\c\$$ is the code-point of the given characters, $$\p\$$ is the nearest prime below it, and $$\P\$$ the nearest prime above it), after which we convert that prime back to a character. For example: Input: test It's code-points: [115, 101, 115, 116] The primes $$\[p, P]\$$: [[113,127],[101,101],[113,127],[113,127]] The nearest prime of the two: [113,101,113,113] Output: qeqq ### But wait What happens when the nearest prime is an unprintable character, like 127 for character y? In that case we'll.. I have multiple things in mind. Will decide later how to deal with them. I might restrict it to printable ASCII only or printable unicode values only. Will edit this information later in after making some example implementations myself. ## Challenge rules: • I/O can be in any reasonable format. Can be a string, list/array/stream of characters, input one by one through STDIN, etc. Taking the characters already as code-points is not allowed, unless your language has no other choice! • If the distance between the current code-point and its two nearest primes below and above are equal, we'll use the lowest prime of the two (i.e. f with a code-point of 102 and the prime above/below it being 101 and 103, both with a distance of 1, will become 101 (e). ## General rules: • This is , so shortest answer in bytes wins. Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call. • Default Loopholes are forbidden. • If possible, please add a link with a test for your code (i.e. TIO). • Also, adding an explanation for your answer is highly recommended. ## Test cases: Input: Output: test qeqq TODO: More to come. • looks good. This challenge is closely related to this one, but I'm curious as to where else this will go; I've enjoyed many of your challenges. – Giuseppe Aug 7 '19 at 19:34 • As it stands, I would VTC this as a dupe of the challenge @Giuseppe linked as it just requires wrapping those solutions in converting to codepoints, mapping and converting back to codepoints. That that would be trivial in some languages but less so in others is what might stay my dupe-hammer. If and how you decide to handle unprintables, though, could well change my opinion. – Shaggy Aug 7 '19 at 21:18 • And, without having tried to come up with to restrict the characters in the output, I think the only feasible way to do so would be to restrict it to printable ASCII as, off the top of my head, the only way I can think of to restrict it to printable UTF would be through the use of some sort of lookup table, which, in my book, would make this a chameleon challenge. – Shaggy Aug 7 '19 at 21:21 • @Shaggy Yeah, I indeed thought the same thing as your second comment, which is why I hadn't decided anything yet. And I agree with your VTC comment. I've looked at some of the implementations of that challenge, and putting a convert from/to string around it works as is. If you have any suggestions on how to change this challenge, feel free to let me know. I will see if I can come up with something myself as well to change it. If not, I'll just delete it. – Kevin Cruijssen Aug 8 '19 at 7:15 # Find the Lowest Common Ancestor of Two Nodes In A Binary Tree Any two separate nodes in a binary tree have a common ancestor, which is the root of a binary tree. The lowest common ancestor(LCA) is thus defined as the node that is furthest from the root and that is the ancestor of the two nodes. The following are binary trees and the lowest common ancestors of the some of their nodes. The LCA of 13 and 15 is 14. The LCA of 47 and 49 is 48. The LCA of 4 and 45 is 40. The LCA of 13 and 14 is 14. Challenge Write the shortest program possible that accepts as input the root of a binary tree and references to any two nodes in the binary tree. The program returns a reference to the LCA node of the two inputted nodes. Restriction The binary tree does not have nodes with parent field references in any form. You may not use parent field references in your program. Input The root of a binary tree and references to any two nodes in the binary tree. This may be in the form of a reference to the root object or even a list that is a valid representation of a binary tree. Output Returns a reference to the node that is the LCA of the two inputted nodes. Definition of a Binary Tree A tree is an object that contains a value and either two other trees or pointers to them. The structure of the binary tree looks something like the following: typedef struct T { struct T *l; struct T *r; int v; }T; If using a list representation for a binary tree, it may look something like the following: [root_value, left_node, right_node] • I mostly like your binary tree questions, but it would be nice if your definition was more inclusive of languages without the concept of pointers. Something like 'input will be a tree where a tree is either something containing a number and two other trees, or else something representing nothing. A tree must not be ambiguous'. This would include strings like [5[][7[6[][]][8[][]]], where a tree is [number tree tree] or [] as well as the usual standard binary tree structures and lists – Jo King Aug 9 '19 at 6:45 # A Picture is Worth a Thousand Words The average word is four characters/bytes long. So a picture, according to the old saying, is worth 4 kilobytes. But how complicated can that picture get? Using any language or length of code you want, generate an image exactly 4,000 bytes in size with the highest possible entropy. You may use any standard image format. Your score will be the compression ratio when your image is compressed as a .zip file. For example, an image that compresses to 2,000 bytes will score 2, but if it expands to 4,100 bytes it will score 0.9756. Lowest score wins. • What image formats are allowed? – wastl Aug 13 '19 at 2:41 • @wastl All of them. – Purple P Aug 13 '19 at 3:19 • should the program output to a file or can it print a list of bytes? – SuperStormer Aug 13 '19 at 12:20 • Interesting challenge. .zip is a file format, not a compression method, though. You'll need to specify what compression method is used -- DEFLATE, LZMA, etc. -- because that could drastically affect the scoring. – AdmBorkBork Aug 13 '19 at 12:51 • @SuperStormer It shouldn't matter as long as you upload the image file. – Purple P Aug 13 '19 at 15:03 • @AdmBorkBork How about gzip? I would specify version 1.6 because that's what I have. – Purple P Aug 13 '19 at 15:04 • If you say something like gzip 1.6 using DEFLATE with default settings that should probably suffice. – AdmBorkBork Aug 13 '19 at 15:58 • I didn't test this but I feel that any uncommon image format of raw data will have the optimal score (assume the compressor is smart enough to store without compression) – user202729 Aug 16 '19 at 4:42 ## Black Hole Evaporation Background: In empty space, occurring all the time, there are pairs of particles that appear and then, usually soon after, cancel each other out. At a certain distance from a Black Hole, it's possible that a pair of particles might spontaneously appear and, if the distance is just right, one of the particles will fall into the Event Horizon while the other escapes off into space, never getting a chance to cancel each other out. The exit of those particles is Hawking Radiation. Eventually, this process causes the entire Black Hole to evaporate away. Challenge Given a string of numbers, emit the negative of the single digit number closest to, in front of, the infinity symbol ∞ (the event horizon), and continue emiting it until there are no digits left in front of the infinity symbol. Then print the rest of the string masking each character uniquely and different from the masked character (burst of energy that might take place at the final instant), excluding any infinity symbols. Test cases Input: Output: 111∞4567 -1 -1 -1 jkl; 3∞ -3 3-145∞962 -5 -4 1 -3 ™©® 4-567-9∞1-23 9 -7 -6 5 -4 😐😈😎😻 2-1∞ 1 -2 34∞67∞89 -4 -3 9876 -123∞456 -3 -2 1 ♫♪# 6-6∞6 6 -6 ä 48120∞ 0 (or -0) -2 -1 -8 -4 ---5∞555 5 オゼヰ Challenge rules • Anything after the first infinity symbol can be ignored as it has fallen into the Black Hole and we know nothing more about it anyway until after evaporation, where the information is a bit scrambled. • The code should only expect numbers, negations, and infinity symbols. No decimal points or other symbols. The input can be an array, list, etc..., but each character must be separate, including the negation and infinity characters. • A negation only applies to the single digit immediately after it. See the test cases above. • You may mask the remaining characters after evaporation with any character set of your choice, as long as the resulting character is different from the masked character, and each character in the resulting output is unique. For languages limited to smaller character sets (or type constraints), characters may repeat after each possible unique character has already been utilized in the output. • You may use the '_' symbol instead of the '∞' symbol. General rules • This is , so shortest code in bytes in its respective language wins. • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN (with the specification above)/STDOUT, functions/method with the proper parameters and return-type, full programs. • Default Loopholes are forbidden. • If possible, please add a link with a test for your code (TIO). • I'm thinking of expanding this to all alpha numeric characters. – ouflak Aug 7 '19 at 19:04 • What does it do if there is a single number after the infinity symbol? – TheOnlyMrCat Aug 8 '19 at 6:53 • I'll update the rules and the test cases. Curiously, I already sort of demonstrated that case by having nothing after the infinity symbol. Nice catch. – ouflak Aug 8 '19 at 6:55 • If 121 remains after evaporation, is reversing that string an acceptable scrambling? – Adám Aug 8 '19 at 7:21 • Any particular reason to use ? Adding Unicode into the mix is an unnecessary complication for many languages. Maybe allow substituting _? – Adám Aug 8 '19 at 7:22 • @Adam, "If 121 remains after evaporation, is reversing that string an acceptable scrambling" Absolutey! Our understanding of what happens to the information after Black Hole evaporation is still under much debate. It is entirely possible that the result of scrambling might result in the same information. We just don't know. – ouflak Aug 8 '19 at 7:46 • @Adam, "Any particular reason to use ∞? Adding Unicode into the mix is an unnecessary complication for many languages." Yeah I thought about that. It can even be excluding factor, which I don't like. I really want that infinity symbol though.... I'll have a think about it, but any suggestions like yours are welcome. – ouflak Aug 8 '19 at 7:49 • @Adam, "If 121 remains after evaporation, is reversing that string an acceptable scrambling?". After re-reading through the Information Paradox, I think the answer is 'no'. '121' should definitely end up different. I'll have to find some way to re-word the challenge, and I can be talked out of this. This requirement seemed rather innocent, but as I'm trying to code this up in my head, it can get complicated. – ouflak Aug 8 '19 at 8:01 • The connection between the background and the task is not very clear. The comment about information suggests that you have a much clearer idea which you haven't included in the question. There's no need to overload the question with back story, but a link to a more detailed explanation might make it feel less arbitrary. – Peter Taylor Aug 8 '19 at 8:23 • @PeterTaylor, I've been mulling over your comment and I'm not sure what to include. Links to the Information Paradox or Hawking Radiation, or both? – ouflak Aug 8 '19 at 8:41 • Probably both. AIUI, the infinity symbol represents the event horizon, the symbols to the left represent virtual pairs which become Hawking radiation, the symbols to the right represent the captured information, the emission of the inverted symbols to the left corresponds to the emission of Hawking radiation, and the shuffling of the symbols to the right corresponds to the information paradox. (I'm not sure without checking some reference why there's anything left to the right after evaporation). It would be good to sketch the correspondences and have some "Further reading". – Peter Taylor Aug 8 '19 at 8:46 • @PeterTaylor, Ok thanks. The final stage of evaporation might release a detectable packet of energy (which has yet to be seen or is even theoretically certain), so that's kind of what that represents. There might be something left over afterwords, or maybe not. When I get the chance, I'll edit some links in and parenthesize some metaphors in there as well. – ouflak Aug 8 '19 at 8:55 • @ouflak Regarding you can use it but allow substitution. Btw, _ is the infinity symbol in the J language. – Adám Aug 8 '19 at 9:27 • @Adám, What about, "If your language has a built-in substitute for ∞, you may use that. If your language can't use Unicode, or use it efficiently, you may use the '_' symbol instead." Does that sound fair and inclusive enough? – ouflak Aug 8 '19 at 10:03 • @ouflak What if your language's infinity is inf? That's three symbols, so it complicates matters a lot. "use it efficiently" is unclear? Does that include causing higher byte count? How about just: You may use the _ symbol instead of . – Adám Aug 8 '19 at 10:06 ## Up side down keyboard Jono 2906 wants you to create a translator from plain Australian to up-side-down text after inventing a keyboard dedicated to typing up-side-down text, since they still want to demonstrate that their keyboard is powerful after failing to program in their keyboard. However, they want your implementation to be typed with their own keyboard, since they also want to get used to programming using their keyboard. ## Input/Output The whole ASCII character set mapped to their up-side down variation (the up-side down " is a double ,): !"#%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[$^_
abcdefghijklmno
pqrstuvwxyz{|}~

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. – Post Rock Garf Hunter 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. – Post Rock Garf Hunter 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? – HighlyRadioactive 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

# Create a safe crossing.

Given a string/number/array of any two distinct characters make the "squarest" 2D array that allows "someone" to cross from left to right or top to bottom "stepping" only on whichever character you have chosen as your stepping stone

### or

Make the "squarest" array possible that contains a complete row or column of stepping stone characters. (clearer but takes away the fun story-ness)

"squarest" meaning smallest difference between the dimensions of the 2D array.

## Input

• A string/number/array of your choosing consisting only of your two chosen distinct characters. So no error checking needed. Allow true/false values if input is array?
• input will have at least 1 stepping stone character so that a valid solution is always possible 1 by x or x by 1
• a minimum length of x? needed? might make it easier if there's some weirdness with very short arrays in the algorithms people come up with
• the last row can be incomplete to allow for prime number length inputs and to more easily allow non trivial 1xX/Xx1 answers

## Output

The output should be the dimensions of the array

• and specify the row or column to use?
• print your 2D array so that the path can be seen graphically?

## Test Cases

100100100 -> 3x3 array

100
100
100

11111000 -> 4x2 or 3x3 - 3x3 is squarer so is correct

1111    111
1000    110
00

11000011000101001001 -> 5x4

11000
01100
01010
01001

1000000000000 -> 12x1 - trivial as only 1 stepping stone

100000000000

010111 -> 3x2 or 2x3 - either acceptable as both are only "1" away from square

010    01
111    01
11

## Issues

• allow diagonal crossings? does that make it a lot harder?
• need a lot more test cases I think?
• input spec
• output spec
• better/more tags?

# ASCII Sum of your code

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

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

## Example

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

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

Now, sum everything into a meaningless very useful value

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

Here it is, Hello, world! returns 1193 !

## Rules

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

# Feedback

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

# It's slashing time

(Inspired by Seven Slash Display)

You're lying in bed, awake. Sleepily, you turn your head to the alarm clock and read what time it is. Since you're lying down, the clock is facing diagonally, making it difficult to read. You decide to write a program to help you out (hey, you're awake anyway).

Given a "slashed" seven-segment display, output what time it is in 24-hour format.

/\
/\
/\  /
\ \
. \/
/\ .
/
\/

2:03

You can choose where to place the : between the numbers (for example, evenly spaced as above or left-aligned as below, etc.), but the : must be present.

Some further examples:

\
\
/\
/\
/ . /
\/\.
\  /
\

15:31

\
\/\
\
\
\.
\.

1:14

Here are the precise digit shapes:

/\
\ \
\/

\
\

/\
/
\/

/\
/\
/

\
\/\

/
\/\
/

/
\/\
\/

/\
\

/\
\/\
\/

/\
\/\
/

## Rules & Standard I/O boilerplate

• The time will always be valid. For example, you'll never receive something like 30:25 or 7:99 or the like.
• You're allowed to pad the input with whitespace however necessary (e.g., padding it to always be a rectangle with trailing spaces).
• Input always a valid time? Can we shift the dots? – Veskah Oct 29 '19 at 19:01
• 2 in 2:03 is not aligned with other digits :( – tsh Oct 31 '19 at 8:53
• @tsh Indeed it wasn't. Thanks for the correction! – AdmBorkBork Oct 31 '19 at 15:11

# Room volume as a function of paint on the walls/ceiling

Task: Write a function that will take in the size of a room (height, width, and length) and a number of paint layers (given that the layers are of a consistent thickness) and return the area of free space in the room after that many layers of paint are applied.

Requirements:

• Return the final area left in the room after the paint layers are added
• should be able to run on a room of any size
• The answer must account for the decreasing area in the room as each layer is applied.
• number of layers and paint layer thickness should both be inputs
• must account for walls and ceiling
• standard loopholes are disallowed

The winner is determined via byte count

• How thick is each coat of paint? Also, do you mean return the volume of free space in the room? – girobuz Nov 14 '19 at 4:30

# Substitute Unprintable ASCII Characters

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

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

## Input

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

## Output

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

In other words:

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

## Tests

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

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

## Rules

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

## Scoring

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

## Test-Case Generator

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

Try it online!

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

List of integers to pairs ?? Any suggestions for the title ??

Write a function or a full program taking a list of non negative integers numbers L that outputs a pair of numbers [X , Y] such that X %( Y + i ) == L [ i ] .

Output specifications

• You can output X Y in any order, just indicate it and be consistent.
• X Y are also unsigned integers, obviously Y must be greater than 0 to avoid modulo 0 errors.
• If your language doesn't support 0 indexed list you can consider X %( Y + i ) == L [ i + 1 ] ?? Any suggestions how to handle this ??

Example

[ 1, 2, 3 ] => [ 11, 2 ]

11 %( 2 + 0 ) = 1
11 %( 2 + 1 ) = 2
11 %( 2 + 2 ) = 3

[ 10, 2 ] => [ 98, 11 ]

98 %( 11 + 0 ) = 10
98 %( 11 + 1 ) = 2

# Test cases

[ input ] , [ output ] pairs

[ 0, 1, 2 ] ,  [ 5, 1 ]
[ 1, 2 ] ,  [ 5, 2 ]
[ 1, 2, 3 ] ,  [ 11, 2 ]
[ 1, 2, 3, 4, 5 ] ,  [ 59, 2 ]
[ 4, 3, 2, 1, 0 ] ,  [ 9, 5 ]
[ 6, 12, 18 ] ,  [ 3318, 18 ]
[ 27, 18, 9 ] ,  [ 279, 28 ]
[ 3, 9, 27 ] ,  [ 4059, 26 ]
[ 2, 4, 8, 16 ] ,  [ 8584, 14 ]
[ 0, 0, 0, 0, 0, 0 ] ,  [ 60, 1 ]
[ 1, 1, 1, 1 ] ,  [ 61, 2 ]
[ 120, 20 ] ,  [ 12220, 121 ]
[ 10, 2 ] ,  [ 98, 11 ]
[ 9, 8, 7, 0 ] ,  [ 1339, 10 ]
[ 0, 1, 4, 9, 2, 10, 4, 15, 10, 5, 0, 16, 12, 8, 4, 0, 22, 19, 16, 13 ] ,  [ 100, 10 ]
[ 9, 99, 90, 81, 72, 63, 54, 45, 36, 27 ] ,  [ 999, 99 ]

# Rules

• Input/output can be given by any convenient method.
• You can print it to STDOUT or return it as a function result.
• Either a full program or a function are acceptable.
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.

• For the testcases I think you can omit the outer parenthesis and the trailing comma. Furthermore I'd talk about nonnegative integers instead of unsigned integers. – flawr Nov 17 '19 at 16:44
• But I have another question: Is this problem always solvable? – flawr Nov 17 '19 at 16:44
• @flawr thanks I'll fix then. For the second question Idk.. Numbers increase extremely, I made a program for solving the problem and also a program to do the reverse(X,Y to list) I may do some test for each X,Y to a certain number.. – AZTECCO Nov 17 '19 at 17:48
• I don't think [0,0,1,1] has a solution (consider the parity of X) cc @flawr – H.PWiz Nov 17 '19 at 17:53
• @H.PWiz sadly yes – AZTECCO Nov 17 '19 at 18:45
• @flawr and H.PWiz so if it's not always solvable do I have to delete this challenge? – AZTECCO Nov 17 '19 at 18:47
• I dunno, you could guarantee that the input is solvable. Or you could ask a different (harder) question instead: "Is there a solution?" – H.PWiz Nov 17 '19 at 19:06

# Create a block maze solver AI

A block maze is a maze in which goal is to complete a pathway by adding blocks.

It starts like this :

#..#.
#...#
..###
.#...
.#..#

# is a block (which can be crossed). . is empty space (which cannot be crossed).

The goal is to connect top-left corner S to the bottom-right corner E. Diagonals are not allowed.

S....
.....
.....
.....
....E

One possible solution for the example above is to add three blocks like this :

#..#.
#...#
#####
.#..#
.#..#

Think about a man who want to cross a river with crocodiles . using huge stone blocks #.

The task is to create a program that take a grid as input and return a solution as output.

## Scoring

The sum of all blocks required to solve all solutions in a 1.000 test case file I will provide.

The winning program is the one that use the fewest blocks to solve all mazes.

## Rules

• All grids are 25 x 25.
• Start / end points are always top-left / bottom-right corners. There is always a block on those points.
• There is always one guaranteed solution (which can be found by filling all empty spaces)
• Program must be entirely deterministic; pseudorandom solutions are allowed, but the program must generate the same output for the same test case every time. If two programs take the same number of steps (e.g. they both found the optimal solutions), the shorter program will win.

The program should return the solution as a sequence of blocks x-y coordinates (the coordinates of blocks to add to solve maze) in the format of your choosing :

11-3;15-6;19-12

## Meta

• I cannot think of a simple algorithm that returns an optimal (best possible) solution in a reasonable time. I expect programs to use some heuristics to get non-optimal/near-optimal solutions. I made the grids 25 x 25 to make it challenging enough and prevent simple solutions like brute force.
• Is this a duplicate? There is lot of related questions but I couldn't find anything related to block maze.
• The tags are . Anything else?

EDIT : as AlienAtSystem pointed out in comments, there is an optimal algorithm for all cases. I made some tests: even a slightly modified Dijkstra's algorithm will work (it will find shortest path in a short time). I will not post this challenge as it is trivial. I leave it here in case someone else would have same idea.

• By fewest total steps, do you mean cumulatively? – Corsaka Nov 20 '19 at 10:07
• I mean the sum of all blocks. If solution for maze01 use 4 blocks and solution for maze02 use 5 blocks, it is 4+5 = 9 blocks in total. The lowest is the best. Someone who has 7+1=8 blocks will win. I have edited answer. – tigrou Nov 20 '19 at 10:37
• You should allow people to have any output format as long as it has x first, y second. None of the mazes are duplicate. I can't think of any other tags. This should be good to post. – Corsaka Nov 20 '19 at 10:49
• Should we add a test suite of some sort? Or how are you going to verify the score of a submission? But in general the challenge looks clear. A few questions: I assume there are some test cases among the 1000 requiring us to go right/up for the optimal solution, instead of only going left/down? Are the input-characters strict, or could we also use for example 012 for @.x respectively as integer-matrix? One other relevant tag: [path-finding] – Kevin Cruijssen Nov 20 '19 at 13:25
• @KevinCruijssen I am planning to provide a program to validate solutions. right/up : some mazes might be shorter to solve that way but it is not allowed. The goal is go from top-left to bottom-right (not to cross from left to right). character set : programs should use the same characters as the test file. Anyway, using 012 might be a good idea (I might update the test file with such chars). There is no @ character in the test file since the start / end position are always the same. – tigrou Nov 20 '19 at 14:31
• @tigrou Ah ok, so @ is not part of the input. In that case a binary-matrix with just 0s and 1s would be a suitable input format I guess. As for the right/up: I meant it for an input like this pastebin. With this maze you could walk from the top-left to bottom-right with just 2 x insertions (at the _ positions), but you'd have to travel up and left in the path from the top-left to bottom-right. But if I understand correctly we only travel right and down, so this would be the solution (with 4 insertions at _) instead? – Kevin Cruijssen Nov 20 '19 at 18:38
• @KevinCruijssen : both solutions you posted are valid. You can go up / down / left right at any moment. – tigrou Nov 20 '19 at 18:42
• I can think of an algorithm that should be optimal for all test cases. This could result in the tie-breaker problem if other people realize it, too. – AlienAtSystem Nov 22 '19 at 6:32
• @AlienAtSystem : optimal algo : is it because of my test cases (which have some flaws) or the maze challenge in general ? – tigrou Nov 22 '19 at 8:20
• @tigrou In general. It can be translated into a shortest path challenge over a considerably smaller graph. While A* wouldn't work on that one, other algorithms will. This wouldn't be short in terms of bytes, although I suspect not that much compared to other approaches, given that some part tasks need to be done by everyone. – AlienAtSystem Nov 22 '19 at 9:35
• I think you don't need to give up entirely right away. While this doesn't work as test-battery challenge because it's too easy to get everything right, it should be good for posting as generic code golf. – AlienAtSystem Nov 22 '19 at 13:36

## A Spherical Die

### Inspiration

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

### Assumptions

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

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

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

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

### The Challenge

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

Input

A co-ordinate on the sphere.

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

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

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

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

for clarity:

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

Output

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

Usual exclusions etc. apply.

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

## OEIS A125959

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

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

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

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

None

# Output

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

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