# Sandbox for Proposed Challenges

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

Sandbox FAQ

## Posting

Write your challenge just as you would when actually posting it, though you can optionally add a title at the top. You may also add some notes about specific things you would like to clarify before posting it. Other users will help you improve your challenge by rating and discussing it.

When you think your challenge is ready for the public, go ahead and post it, and replace the post here with a link to the challenge and delete the sandbox post.

## Discussion

The purpose of the sandbox is to give and receive feedback on posts. If you want to, feel free to give feedback to any posts you see here. Important things to comment about can include:

• Parts of the challenge you found unclear
• Problems that could make the challenge uninteresting or unfit for the site

You don't need any qualifications to review sandbox posts. The target audience of most of these challenges is code golfers like you, so anything you find unclear will probably be unclear to others.

If you think one of your posts needs more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended!

It is recommended to leave your posts in the sandbox for at least several days, and until it receives upvotes and any feedback has been addressed.

## Other

Search the sandbox / Browse your pending proposals

The sandbox works best if you sort posts by active.

To add an inline tag to a proposal use shortcut link syntax with a prefix: [tag:king-of-the-hill]. To search for posts with a certain tag, include the name in quotes: "king-of-the-hill".

Get the Sandbox Viewer to view the sandbox more easily!

# Convert superscript numbers to normal numbers

• Maybe specify exactly what characters will be included in the input? Dec 11 '21 at 22:02
• @emanresuA Done Dec 12 '21 at 0:05

## Rotate two differently cased subwords independently

You have one string made of two subwords in different cases, the upper case first, then the lowercase:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

And you must return each subword cycled by a given increment. (N.b. the letters aren't rotated through the alphabet, but each character is shifted in the word)

The subwords are not always the same length as each other, and are part of the same 'data' structure. If your language cannot store strings, you're permitted to store the 'string' in a single array, e.g. ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

Here are the test cases:

Input Output
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyz'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26 'ABCDEFGHIJKLMNOPQRSTUVWXYZopqrstuvwxyzn'
"ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyz'
"ABCnopqrstuvwxyz", 2 'BCAyznopqrstuvwx'
"AAABBBcccddd", 2 "BBAAABddcccd"
"AAABBBcccddd", 6 "AAABBBcccddd"
"HELLOworld", 5 'LLOHErldwo'
"CODEgolf", 0 'CODEgolf'

Here is an ungolfed example program:

const subWordRotate = (original, rot) => [...original.split(/([A-Z]+)(?![A-Z][a-z]+)/)].map(list => [, ...list].reduce((memo, char, index, input) => {
memo = memo.slice(0, input.length);
memo.splice((index + rot) % (input.length), 1, char);
return memo
}, Array(original.length).fill('')).join('')).join('')

const testCases = [
["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 13],
["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyzabcdefghijklm", 13],
["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 26],
["ABCDEFGHIJKLMNOPQRSTUVWXYZnopqrstuvwxyz", 13],
["ABCnopqrstuvwxyz", 2],
["AAABBBcccddd", 2],
["AAABBBcccddd", 3],
["AAABBBcccddd", 4],
["AAABBBcccddd", 5],
["AAABBBcccddd", 6],
["AAABBBcccddd", 7],
["AAABBBcccddd", 8],
["AAABBBcccddd", 9],
["AAABBBcccddd", 10],
["HELLOworld", 69],
["CODEgolf", 0]
]
testCases.forEach(
if ($key > 3){ ++$virtue;
}
}


(the rhyme is on value-virtue)

• Lines whitout readable characters count as whitespace (the two lines with } in the example)

• How does that example rhyme...?
– Doorknob Mod
Jan 25 '14 at 12:54
• @DoorknobofSnow well, i'm not really a poet, that's why i propose it as a challenge for others :p. if you have a better example i'll replace it Jan 27 '14 at 15:58

# Implement Kalah code-golf

The game of Kalah is a two-player board game in the Mancala family. Your implementation must:

• Identify the active player ("Player 1" or "Player 2")
• Display board state (in format specified below)
• Accept input to allow that player to move (using index system below)
• Announce a winner ("Player N wins")

# Overview

Each player has a line of six spaces, called houses, and one additional space called a store. Each space holds seeds, which move from house to house in a counter-clockwise direction. The objective is to fill your store with seeds.

You must represent the board in the following two-row format with stores offset, where HH is a house and SS is a store:

SS HH HH HH HH HH HH
HH HH HH HH HH HH SS


The top row represents the number of seeds in player #1's spaces, and the bottom row represents the seeds in player #2's spaces. The S in each row is the respective player's store (player #1's is top-left, #2's is bottom right). Single-digit values should include a leading space.

In this challenge, user-input will identify each house numerically. Use a left-to-right, indexed-from-one scheme for both sides:

S 1 2 3 4 5 6
1 2 3 4 5 6 S


Note that the players' stores are not numbered, because seeds placed in the store never move out.

## Rules

Wikipedia has a good summary of the game and its rules:

1. At the beginning of the game, three seeds are placed in each house.

2. Each player controls the six houses and their seeds on his/her side of the board. His/her score is the number of seeds in the store to his/her right. [Clarification: from our perspective, player 1's store is to the left, player 2's store is to the right.]

3. Players take turns sowing their seeds. On a turn, the player removes all seeds from one of the houses under his/her control. Moving counter-clockwise, the player drops one seed in each house in turn, including the player's own store but not his/her opponent's.

4. If the last sown seed lands in the player's store, the player gets an additional move. There is no limit on the number of moves a player can make in his/her turn.

5. If the last sown seed lands in an empty house owned by the player, and the opposite house contains seeds, both the last seed and the opposite seeds are captured and placed into the player's store. [Clarification: moves that end on an opponent's empty house end normally without a capture.]

6. When one player no longer has any seeds in any of his/her houses, the game ends. The other player moves all remaining seeds to his/her store, and the player with the most seeds in his/her store wins.

# Example

(Parenthetical text should not appear in actual output.)

Player 1
0  3  3  3  3  3  3
3  3  3  3  3  3  0
> 2                      (prompt arrow and line break
are purely optional)
Player 2
1  1  0  3  3  3  3
4  3  3  3  3  3  0
> 4

Player 2  (P2 gets a bonus turn from rule #4)
1  0  3  3  3  3  3
4  3  3  0  4  4  1
> 5

Player 1
1  0  3  3  3  4  4
4  3  3  0  0  5  2
> 4

Player 1  (P1 captures P2's seeds in space 1)
6  0  4  4  0  4  4
0  3  3  0  0  5  2
...

Player 2
12  0  0 10  0  1  0
0  0  0  0  0  1 13
> 6

Player 1 wins            (because the non-finishing players gets
all remaining seeds on their side, it's 23-14)


Meta question: Would this be improved by removing some of the rules?

• Do the players run the game once and then take it in turns to take moves, with the process ending only when the game ends? Or do they run the program once per move? Jan 30 '14 at 10:06

[This is the first time I'm using the sandbox. I want to get feedback/suggestions before posting the question.]

Make a spider web (standard, orb type) that fills frame in the ratio of n:m, where n, m are input integers. You may use the example below as a model (but you don't need to use labels).

Your web should have multiple radii, at least 4 of which attach directly to the frame. The remaining radii should attach to the outer outline (perimeter) of the web. The web should have at least 15 radii. The mesh spacing should be more or less uniform spacing (although occasional weaving mistakes" or crossings are encouraged and will receive a bonus).

This is code-golf, so the shortest code (minus bonuses) wins.

Bonuses (to be removed from the number of characters in your code). Bonuses are awarded for the following features that reflect the architecture of an actual web (as opposed to a perfectly symmetric rendering). They are somewhat greater than usual as an incentive for attention to detail and realism.

-mesh spiral instead of concentric circles: 40 pts

-assymmetric web: 31 pts. (e.g. height of capture area greater than width)

-distinct segments between radii (straight or crooked, but not the arc of a circle): 32 pts

-outer and inner outline clearly distinct from the spiral: 41 pts

-irregular outer outline: 20 pts

-2 or more easily observable reverses in spiral: 40

The accept will be awarded on Feb. 20, 2014.

• If there are bonuses then it isn't code-golf, by definition. It's not clear what output formats are acceptable. I'm not sure what you mean by "distinct segments between radii". "2 or more easily observable reverses" seems problematic: the ease of observing reverses is subjective, and might in addition depend on input and/or on the random numbers obtained. The weighting for the bonuses seems very arbitrary: is there any justification for it? Feb 3 '14 at 11:49
• Re: bonuses, I should probably decide on the features I want included in the web, thereby eliminating bonuses altogether. Distinct segments means that there should be 2 straight mesh segments between radius n and radius n+2 (not sure whether this should be required in instructions to be updated.) Will give reverses more thought. Feb 3 '14 at 12:02

## Write a PHP Code Golfer code-challenge

Since my currently daily programming is in PHP, I tend to try the challenges on the site using that language, but frequently I large program because of the verbosity of the language. And then I have to strip it for presentation...

But this is not a tips question, it's an eviscerating challenge.

The objective is to write a program in the language of your choice that takes a PHP file and outputs a golfed valid PHP file with the same functionality.

The scoring will be the average reduction in percent of the result of running the program with 3 selected files (not yet selected, I was thinking of some open source library)

The output file should run on at least 5.4 (so shorthand arrays, function dereference, traits are available)

Since the score is the difference between the ungolfed and golfed files, techniques beyond minifying are encouraged, such as using code subtitution, eval, compression,  (variable variables), dereferencing...

Scoring example: The 3 sources have 450, 1200 and 3500 chars respectively

results lenghts: 250, 1000, 3300
reduction: 200, 200, 200 (44%, 17%, 6%) average: 22%

results lenghts: 350, 1050, 3150
reduction: 100, 150, 350 (22%, 13%, 10%) average: 15%

In this case Answer 1 would win, even tough both answers got the same total reduction (-600 chars)

• It's a specialisation of codegolf.stackexchange.com/q/3652/194 , so would likely be closed as a duplicate. Feb 4 '14 at 22:44
• @PeterTaylor I saw it. is similar, but I include an objetive goal and score. have any idea on how to make it more unique? Feb 5 '14 at 2:43
• "Making it shorter" is too broad, can I just delete some comments? If not, can I only shorten one variable and it's ok. It's not very interesting like this... Feb 5 '14 at 9:56
• @Fabinout the objective is golfing the code. If you only remove some characters, I doubt you'll get a good score Feb 5 '14 at 15:27
• Alright, the criterion is the size of the output source code. good clarification. Feb 5 '14 at 15:55
• Sum the bytes with the percents or separately? Also, no matter what sources you choose, make sure to paste the code into your questions; who knows when the code in the library will change? Feb 6 '14 at 19:11
• i'll edit the bit about scoring (with examples) tomorrow (when i come back to work). I'll post the test sources as a pastebin, but I'll wait to choose them until the question is polished enough and someone consider it interesting enough Feb 6 '14 at 19:34
• Is there anyone more with questions? is still possible that it will be marked as a duplicate? or can i choose the sources and publish it? Feb 13 '14 at 19:22

# Create diagonal code

Your task is to create a program that outputs d=s*sqrt(2).

Specs:

• Your program must be at least 4 lines long;

• d=s*sqrt(2) cannot be hardcoded as is (so using ascii, compression, encoding, etc. is allowed and encouraged);

• For each line of code n, pick up the nth character. The string obtained this way must be a valid program in a programming language of your choice, that must be different from the one you used for the main program. The obtained program must compile successfully, but it can throw errors, exceptions, etc.;

• If at the nth line there is no nth character, you can consider that character as a whitespace or a newline. This cannot be done for the first 4 lines, which must be long at least n non-whitespace characters.

• Your main program must end successfully (no errors, exceptions, etc.);

• Internet access is forbidden;

• Most upvoted answer in 2 weeks wins.

Happy coding!

I was unsure about making this a with several bonuses (polyglot answer, secondary program still valid, etc...).

### Some bonuses for the code-challenge version:

+15 for any other hidden answer;
+5 for every hidden answer that runs and ends successfully, without any problem;
• It's trivial to make the diagonal program be just whitespace (many scripting languages will accept this as a program) or H  (valid program in H9Q+). Feb 26 '14 at 9:26
• Nowhere does it say that the diagonal program must output your magic string: it doesn't even have to execute correctly. Your amendment doesn't really fix things: I can now have the second line be #H, the third be #HH, etc. Feb 26 '14 at 9:37
• Thinking about quines and diagonals (which was the "spirit" of the question), what about a sort of mini-quine? The main program would have to display d=s*sqrt(2) only, and its diagonal must reproduce the code used to display the magic string (no comments allowed). It could be tagged code-golf or code-challenge. Feb 26 '14 at 11:04