# 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 requires more feedback, but it's been ignored, you can ask for feedback in The Nineteenth Byte. It's not only allowed, but highly recommended! Be patient and try not to nag people though, you might have to ask multiple times.

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!

# Navigate the city

The government of your country has just completed a city designed to accommodate a few hundred thousand people. It has all sorts of facilities including roads, restaurants, malls, houses, etc. You have been invited to test the road system, but you are completely unfamiliar with it, so you need a GPS. Your challenge is to make one.

## Description of the city

Note: when I say "a x a grid", I mean that there are a horizontal roads and a vertical roads within the grid.

To make the challenge easier (because of course making a GPS is difficult in itself), the city is fixed. The city's road system is based on a very rigid grid. This grid is pictured further below.

The grid has a size of 15x15 and the roads are labeled as [r/c num][dir] where "r/c num" is the row/column number (whether it is a row or column depends on the direction of the road) and "dir" is the direction. If the road runs from west to east, "dir" is E, and if it runs from north to south, "dir" is S. For instance, "1E" is the first row of the grid, while "12S" is the twelfth column of the grid. Each row and column of the grid has a length of 14km (1km between each intersection).

The Central Business District (CBD) is the 5x5 sub-grid situated in the middle of the grid. Due to the traffic parameters set below, it is important for your GPS to route the user away from the CBD if it is not necessary to pass through that district. Note that the CBD includes the borders of the 5x5 sub-grid.

At each intersection, there is a traffic light. The amount of time to wait is as follows:

• there is a "base time" which is 400 if the intersection is in the CBD, and is the row position of the intersection (row 1 column 2 would be the intersection between 1E and 2S) times the column position otherwise;
• the waiting time to turn left is equal to the base time;
• the waiting time to go straight is equal to the base time, multiplied by 2;
• the waiting time to turn right is equal to the base time, multiplied by 3.

The times above are measured in seconds.

In addition to the standard grid of roads, there is an expressway circling the inner part of the city. It passes directly over parts of the 4E, 4S, 12E and 12S roads in such a way that it forms a square. In both directions, there is an innovative exit/entry elevator at each place where there would be an intersection if you took the 4E, 4S, 12E or 12S road rather than the expressway. It is positioned in such a way that you can skip the traffic light for that intersection and get going, and in addition to that you can turn your car around in whichever direction you would like and go that way. I know it sounds rather confusing, but in essence you can exit at any intersection and go whichever way you wish, with the distances still being measured in kilometers in all cases. Note that the elevator is instantaneous (once again, not very realistic, but who uses elevators for cars on the main road anyway?). Upon entering the expressway, you can go in either direction. On the expressway, there are no at-grade intersections, so the traffic is free-flowing, and there are no waits at traffic lights or any other obstruction. Entry onto the expressway is done at any intersection involving the 4E, 4S, 12E or 12S road. Cars entering the expressway do not need to wait at a traffic light before doing so. Once again, the way in which the entry elevator is designed ensures that all distances are still measured in kilometers. This means that you can drive 1km from an intersection, enter the expressway there, and drive 3km on the expressway, with the total distance being 4km.

The city sets speed limits as follows:

• 30 for all roads within the CBD;
• 60 for all standard roads outside the CBD;
• 120 for the expressway.

These speeds are measured in kilometers per hour.

## Picture of the grid

Everything inside, and including, the bold black outline, is the Central Business District. The blue outline represents the expressway.

## Challenge

Write a GPS which takes in a start intersection and end intersection, and attempts to output the fastest route from the start to the end. The "intersection" must be an intersection between two roads and can be specified in whichever reasonable input format you would like. You could take the row and column, the names of the two roads, etc. as long as it's reasonable.

Your output should be a list of directions in whichever reasonable output format you would like. Each direction should specify the direction to turn (straight, left, right, and for the expressway, enter/exit), the road to turn on and the number of "kilometers after the previous direction" to wait before executing this direction. For instance, "After 7km, exit the expressway onto 12E (East)". If the direction is to be executed while on the expressway, it must not take intersections into account. Your program may optionally decide to omit directions telling the user to "continue straight", but it may not omit any other direction. As shown above, directions telling the user to enter or exit an expressway must specify the direction to head upon entry ("enter the expressway (South)", for instance). You may direct the user in any direction from the starting intersection, and arrive at the end intersection from any side. It should also tell the user for how long he or she will have to drive, down to the second, and, optionally, the distance he or she will have to drive, which is necessarily measured in kilometers.

Your GPS may assume that the user will always be driving at the speed limit. It may also assume that the start and end are different.

## Scoring

There are 225 x 224 = 50400 ways to choose start/end pairs. Your GPS will be scored based on the sum of the amounts of time it takes to drive from the start to the end, for each pair of start/end points. The GPS with the smallest total is the winner.

In the unlikely event of a tie between two or more submissions, length of code shall be the tiebreaker.

No test cases because there is never a single route for any start/end pair.

The tags for this challenge are , , and .

# Play chess (KOTH)

Your task is to write a chess engine that will compete with other submissions in a chess tournament. Well, almost. Since writing a full engine can be a bit tedious, you only need to write the evaluation function.

An evaluation function takes a chessboard as input and returns how "favorable" the position is. If white is winning, the evaluation function should return a large positive number. If black is winning, a large negative number. If the situation is tied, a number close to zero.

Chess engines then simulate different possible games to some depth and choose the moves that lead to the best result.

A classic evaluation function is as follows:

• Set r=0
• For every white pawn, add 1. For every black pawn, subtract 1.
• Same for knights and bishops, except add or subtract 3.
• For rooks, use 5
• And for queens, use 9

This evaluation function only takes into account material advantage; that is, just the raw amount of different pieces. More complicated evaluation functions may consider the position of individual pieces, what kind of structures do the pawns form etc.

Your task is to write an evaluation function in C in at most 150 bytes. The evaluation function takes as input 7 bitboards. A bitboard is a 64-bit integer that assigns one bit to every square of the chessboard. The first bitboard has a bit set for every piece in the chessboard. The second one encodes the owner of the piece. The remaining bitboards have a bit set for every pawn, knight, bishop, rook and queen respectively. There is no bitboard for the king, since you can calculate it using the first and last 5 bitboards. Your function will return a signed integer.

For your convenience, I've aliased __builtin__popcount to p and uint64_t to q, and also included every standard header. You should name your function e.

Note that a slow evaluation function means that the engine won't be able to search as deep as with a fast one.

# Meta

• Is 150 bytes a good number?
• Almost tempted to not alias the popcount... would have interesting results
• How will this be KOTH if nobody actually competes in a game of chess? Jan 24 at 20:38
• @thejonymyster You write the evaluation function. A chess bot with your evaluation function competes (rest of the bot is standardized). Jan 24 at 20:39
• Oh, interesting! Jan 24 at 20:40
• @thejonymyster counts how many bits are set in a number. It's massively useful here, since the board data is in 64-bit integers. Jan 24 at 20:50

# Count the ways to transform (2)

Your input is a matrix (2d array) of positive integers. For example:

$$\begin{matrix} 1 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 2 & 1 & 4 & 5 \\ \end{matrix}$$

A semi-continuous transformation of this matrix is a rearranging of elements that preserves immediate neighbors. For example, we can swap the $$\2\$$ in the bottom left, and the $$\1\$$ in the top left corner.

$$\begin{matrix} 2 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 1 & 1 & 4 & 5 \\ \end{matrix}$$

This is fine, because every number has the same neighborhood counts. That is, we can make a sorted list of numbers and their neighbors, and verify the they are the same:

$$\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 2,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,5 \\ 4 & 1,5,7 \\ 4 & 1,5,5 \\ 5 & 3,4,4,6 \\ 6 & 5,5,7 \\ 7 & 4,6 \end{matrix}$$

Here is another example.

$$\begin{matrix} 2 & 1 & 1\\ 1 & 3 & 1\\ 1 & 1 & 4\\ \end{matrix}$$

Let's make a neighbor list. Note that we are gonna have duplicate entries (which is fine)

$$\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,1 \\ 1 & 1,2,3 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 1,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,1 \\ 4 & 1,1 \\ \end{matrix}$$

Now, can we swap the top left $$\2\$$ and the bottom left $$\1\$$? It may look fine at first glance, but we must be careful! By swapping those two elements we would create a $$\1\$$ which has neighbors $$\2,3,4\$$, which didn't exist in the first input.

Just to demonstrate, here is the matrix after this non-semi-continuous transformation:

$$\begin{matrix} 1 & 1 & 1\\ 1 & 3 & 1\\ 2 & 1 & 4\\ \end{matrix}$$

And here is the neighbor list:

$$\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,1 \\ 1 & 1,1,3 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 2,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,1 \\ 4 & 1,1 \\ \end{matrix}$$

Which is has changed after the transformation, ergo the transformation is non-semi-continuous (on this input).

To clarify, semi-continuity is a property of a transformation on some specific matrix.

Your code will take a matrix as input and output the number of (unique) semi-continuous transformations. Two transformations are different if the output is different. So for example swapping two identical numbers is the same as the identity transform (doing nothing).

Or in other words: Your code will take a matrix and return the number of matrices with those dimensions that have the same neighbor-list.

# Trap the persistent hero in a maze

Last time a challenger tried to thwart your evil magical deeds, they got trapped in a maze that you created to be as small as possible, giving up only a few steps from the exit. Now there is another hero on the way. If it ain't broke, why fix it, so you ask the magic ball about the moves the hero will make in the maze. There are good news, and bad news.

The good news is that the hero's moves are still predictable. There is a list of moves, which determine how the hero moves in an intersection. The bad news is that the hero is persistent, never really giving up. What this means is that the list of moves repeats forever.

# TODO Explanation of the move list and rules

Your task is to write a program that traps the hero in the maze. You may assume that the input has a solution.

Count count count..

Posted

• what about something like [1,[2,5,10]] Jan 26 at 13:56
• @thejonymyster count 1 to .. [2,5,10]->8 result is 7, ok I got it.. There's no test cases involving sorted lists, thanks Jan 26 at 13:59
• actually i was being stupid, but im glad you found use in it :D +1 btw Jan 26 at 14:08
• @thejonymyster glad you raised a doubt here on the sandbox ;) Jan 26 at 14:12

# Intro

Given a number of sides $$\a\$$ and a side length $$\b\$$, generate an $$\a\$$-sided polygon with side length $$\b\$$. The fill value will be the alphabet going clockwise. If there are not enough letters, wrap around.

# Test cases

3 4

A
H B
I   C
G F E D

4 4

ABCD
L  E
K  F
JIHG
$$$$

• This seems like it'd immediately run into problems with, say, a pentagon. But I digress, this is intriguing Jan 25 at 14:51
• Good idea, it's just that I'm unsure as to how one might handle a heptagon, or dodecagon, for instance. And do we have to loop back to the beginning of the alphabet once we have exhausted the entirety of the alphabet? For instance, a square with a side length of 10? Jan 25 at 17:55

## Shuffle up a list

Given two lists $$\A\$$ and $$\B\$$, with no repeats in elements and so that the elements of $$\B\$$ are identical to the elements of $$\A\$$ except for the order they are in, we say $$\B\$$ is an $$\n\$$-well-shuffled list of $$\A\$$ (where $$\n\$$ is a nonnegative integer) if:

• For any $$\(a_1, a_2, \cdots, a_n) \in A^n\$$, $$\a_1\$$'s position in $$\A\$$ is $$\\neq\$$ its position in $$\B\$$, $$\a_2\$$'s position in $$\A\$$ is $$\\neq\$$ its position in $$\B\$$, ... and $$\a_n\$$'s position in $$\A\$$ is $$\\neq\$$ its position in $$\B\$$
• For any $$\(a_1, a_2, \cdots, a_n) \in A^n\$$, if $$\a_i\$$ precedes $$\a_j\$$ for some $$\(i, j) \in [1, n]^2\$$ in $$\A\$$, then $$\a_i\$$ follows $$\a_j\$$ in $$\B\$$

Your task is to take two nonnegative integers $$\m, n\$$ as input and return how-many $$\n\$$-well-shuffled lists of lists of length $$\m\$$ there are.

# Climbing the Bookshelf code-golf

Climbing the Bookshelf

• Can we please have the option to output 0-indexed? Jan 25 at 15:48
• @ThisFieldIsRequired No, sorry. Jan 25 at 17:19

# Is it an action?

Today, you will solve an abstract algebra challenge.

Consider a set $$\G\$$, which, to simplify things, is a finite subset of $$\\mathbb{Z}\$$ containing $$\0\$$. It has a binary operation $$\*\$$, which for our example will be $$\+\$$, but your program should be able to handle any binary operation. If $$\G\$$ is closed under $$\*\$$, i.e. $$\g * g' \in G \forall g, g' \in G\$$, there is associativity with regard to $$\*\$$, there is a unique element in $$\G\$$, which we will note as $$\1_G\$$, such that $$\1_G * g = g * 1_G = g \forall g \in G\$$, and there exists a unique $$\g^{-1} \in G \forall g \in G\$$ such that $$\ g * g^{-1} = g^{-1} * g = 1_G \$$, then $$\G\$$ is a group.

Consider a set $$\X\$$, which is also a finite subset of $$\\mathbb{Z}\$$. Then $$\\circ: G \times X \to X\$$, where $$\G\$$ is a group, is an action if:

• $$\1_G \circ x = x \forall x \in X\$$, and
• $$\g \circ (g' \circ x) = (g * g') \circ x \forall g, g' \in G, x \in X\$$ (associativity).

## Challenge

Your task is to write a program or function which takes in the following:

• $$\G\$$, a finite subset of $$\\mathbb{Z}\$$ that includes $$\0\$$;
• $$\X\$$, also a finite subset of $$\\mathbb{Z}\$$, but not necessarily the same as $$\G\$$;
• a binary operation $$\*\$$ that operates within $$\G\$$ and that makes $$\(G, *)\$$ a group, which can be taken in any reasonable manner you would like, such as taking it as a function with two parameters, and
• an "application" $$\\circ\$$ from $$\G \times X\$$ to $$\X\$$, which can be taken in any reasonable manner you would like.

For the purposes of this challenge, $$\1_G\$$ is always $$\0\$$.

This program should then output true if $$\\circ\$$ is an action and false if not. You may use any two distinct values for true and false.

The shortest code, measured in bytes, wins.

### Test cases.

$$\G = \{0, 1, 2\}\$$

$$\X = \{1, 2, 3\}\$$

$$\*\$$ defined by $$\g * g' = (g + g') mod 3\$$

$$\\circ\$$ defined by $$\g \circ x = g + x\$$

Output: false because:

• $$\1_G\$$ is 0;
• then $$\1_G \circ x = 0 \circ x = 0 + x = x\$$;
• but $$\(1 * 2) \circ 2 = 0 \circ 2 = 2 \neq 1 + (2 + 2) mod 3 = 1 + (2 \circ 2) = 1 \circ (2 \circ 2)\$$, thus $$\\circ\$$ is not associative.

$$\G = \{0, 1, 2\}\$$

$$\X = \{0, 1, 2\}\$$

$$\*\$$ defined by $$\g * g' = (g + g') mod 3\$$

$$\\circ\$$ defined by $$\g \circ x = (g + x) mod 3\$$

Output: true because:

• $$\1_G\$$ is 0;
• then $$\1_G \circ x = 0 \circ x = (0 + x) mod 3 = x mod 3 = x\$$ (because $$\x < 3\$$);
• and $$\\circ\$$ is associative (proof not provided)

## Workout Numbers

I work out semi-regularly, but haven't the faintest clue what I'm doing. On weight machines, I never plan how many reps to do in advance, instead pursuing a dynamic goal based on how much I feel up to:

• The bare minimum is $$\5\$$ reps, but I usually do at least $$\8\$$.
• However, I feel more satisfied with $$\10\$$, $$\12\$$, or $$\15\$$.
• If I don't have $$\20\$$ in me, there's no way in hell I'm doing $$\16\$$!

A Workout Number is a positive integer which is either a multiple of $$\5\$$, or a multiple of $$\4\$$ which does not have an absolute difference of $$\1\$$ with any multiple of $$\5\$$.

This is a standard challenge. You may choose to implement one of these three options:

• Take a positive/nonnegative integer $$\n\$$, and output the $$\n\$$th Workout Number, 0- or 1-indexed.
• Take a positive integer $$\n\$$, and output the first $$\n\$$ Workout Numbers.
• Take no input and output the sequence of Workout Numbers indefinitely.

The first 100 Workout Numbers are:

5,8,10,12,15,20,25,28,30,32,35,40,45,48,50,52,55,60,65,68,70,72,75,80,85,88,90,92,95,100,105,108,110,112,115,120,125,128,130,132,135,140,145,148,150,152,155,160,165,168,170,172,175,180,185,188,190,192,195,200,205,208,210,212,215,220,225,228,230,232,235,240,245,248,250,252,255,260,265,268,270,272,275,280,285,288,290,292,295,300,305,308,310,312,315,320,325,328,330,332


### Sandbox questions

• Is this too trivial? The sequence is just positive integers congruent to one of $$\\{0, 5, 8, 10, 12, 15\}\$$ mod $$\20\$$.
• Would it be more interesting taking an additional input?:
• An integer $$\k\$$ for which the sequence consists of multiples of $$\k\$$ and multiples of $$\k-1\$$ not adjacent to multiples of $$\k\$$
• A list of integers $$\k_1...k_i\$$ which, in order, populate the sequence with their multiples not adjacent to numbers already in the sequence
• Subject to the constraint that they are given in descending order?
• Pairwise coprime?
• Could this variant work better as a ?
• Better name? Too much context? I need to spend five minutes actually learning how to exercise effectively?
• the "dynamic goal" thing made me think it was going to be a challenge about determining how much excersize youd be doing in a given section, the sequence thing seems way out of left field and the requirements to be a workout number arbitrary, even in relation to the lore Feb 3 at 4:43

# Quicksand

In this challenge, you take a positive integer as input, which represents the height of a sand pile, located at (0,0) on an infinite square grid. For example, if our input is 123, the sand grid looks initially like this:

$$\\begin{matrix} 0 & 0 & 0 \\ 0 &123& 0 \\ 0 & 0 & 0 \end{matrix}\$$

Now, piles of sand are unstable, so they topple if their height is 4 or greater. When sand piles topple, they send sand equally in all four directions, but due to the quantum nature of sand, the amount sent is an integer. Or in other words, if there is a pile of height n, it sends sand as follows:

$$\\begin{matrix} 0 & \lfloor\frac{n}{4}\rfloor & 0 \\ \lfloor\frac{n}{4}\rfloor & n\mod 4 & \lfloor\frac{n}{4}\rfloor \\ 0 & \lfloor\frac{n}{4}\rfloor & 0 \end{matrix}\$$

This means that sandpiles evolve step by step. For example, if we have this initial position, here's how the sandpiles evolve.

$$\\begin{matrix} 0 & 0 & 0 & 0 \\ 0 & 0 & 6 & 0 \\ 0 & 2 & 7 & 0 \\ 0 & 0 & 0 & 0 \end{matrix}\$$

$$\\begin{matrix} 0 & 0 & 1 & 0 \\ 0 & 1 & 3 & 1 \\ 0 & 3 & 4 & 1 \\ 0 & 0 & 1 & 0 \end{matrix}\$$

$$\\begin{matrix} 0 & 0 & 1 & 0 \\ 0 & 1 & 4 & 1 \\ 0 & 4 & 0 & 2 \\ 0 & 0 & 2 & 0 \end{matrix}\$$

$$\\begin{matrix} 0 & 0 & 2 & 0 \\ 0 & 3 & 0 & 2 \\ 1 & 0 & 2 & 2 \\ 0 & 1 & 2 & 0 \end{matrix}\$$

Now, since all the sandpiles have less than 4 sand, this sand grid is stable.

# Rules

Your task is to take an positive integer $$\i\$$ as input, and output the eventually stable grid that the following initial position evolves to:

$$\\begin{matrix} 0 & 0 & 0 \\ 0 & i & 0 \\ 0 & 0 & 0 \end{matrix}\$$

(Note that the grid is still infinitely big)

The output format should be the following: "width;data", where width is an odd number representing the width a square that bounds the eventually stable arrangement (width doesn't have to be the smallest possible). Next is the raw data, which is just the square section of the grid flattened, and the numbers are represented with digits "0123"

• by "IO format" do you mean input or output? if its input, i dont understand why youd take the ending width as an input. great pun btw Feb 3 at 4:46

## Word Guess KOTH

Inspired by Wordle and Evil Wordle.

A King of the Hill game where you must write a bot which acts as both Guesser and Judge of a word guessing game. Each bot will play a match against all the other bots. Each match will consist of 10 rounds alternating between judge and guesser. A bot's score for the match is the number of guesses the opponent made minus the number of guesses it made. Higher is better. Bot with the highest average [or total?] score is KOTH.

The game is as follows:

1. The Judge and Guesser are both provided with the same dictionary of N letter words.
2. The Judge selects an answer from the dictionary.
3. The Guesser makes a guess. The candidate word must be contained in the dictionary.
4. The Judge is given the guess, and provides a score according to the following rules.
• The score is a string of N characters from the set ['G','O','B'], corresponding to the guessed letters

• A 'G' indicates that the guessed letter is correct for that position. Great
• A 'O' signifies that the guessed letter is in that answer but not that position. Out-of-place.
• A 'B' indicates that the guessed letter is not in the answer. Bad.
• If a letter appears in the guess more than once, there will never be more non-'B' results than instances of that letter in the answer.

• for example if the answer is 'ruler' and the guess is 'belle', the score will be 'BOGBB'.
1. Steps 2 and 3 continue until the score is all 'G's.
2. The the number of guesses is added to the Judge's score and subtracted from the Guesser's.
• Note that the judge is free to modify the answer after each guess, as long as the new answer is consistent with all the previous guesses.

An example scoring function in Python is:

def count_score(truth, trial):
score = [None]*len(truth)
allow = truth
for index,value in enumerate(trial):
if truth[index]==value:
score[index]='G'
allow=allow.replace(value,'',1)
for index,value in enumerate(trial):
if not score[index]:
if value in allow:
score[index]='O'
allow=allow.replace(value,'',1)
else:
score[index]='B'
return ''.join(score)


Entries must provide a bot command that can be called from the command line and prints the required outputs to stdout, separated by newlines.

For all the use cases below, codex is a filepath to a dictionary of legal words, and token is a string used by a bot to maintain state. It must not be empty. The token generated in any round is passed back to the same bot in the following round. The opponent bot will never see your token. Tokens are not retained from one round to the next.

arguments --> results

codex "judge" --> token Judge initialization. Returns a token.

codex "judge" token trial --> token score Judge will score the trial word. score is constructed according to the rules above.

codex "guess" --> token trial Guesser makes initial trial guess.

codex "guess" token score - token trial Guesser gets score from previous guess. Returns new trial guess.

Example Bot:

import random,sys,re

def begin_offer(codex):
words = [l.strip() for l in open(codex)]
return [random.choice(words)]

def score_trial(token, trial):

def first_guess(codex):
words = sorted([l.strip() for l in open(codex)])
guess = words[0]
return (guess, guess)

def later_guess(codex, prior, score):
words = sorted([l.strip() for l in open(codex)])
index = words.index(prior)

for place,value in enumerate(score):
if value != 'G':
while words[index][place]==prior[place]:
index+=1
break
guess = words[index]
return guess,guess

if __name__ == "__main__":
codex,style,*extra = sys.argv[1:]
if style == 'judge':
if not extra:
result = begin_offer(codex)
else:
result = score_trial(*extra)
elif style == 'guess':
if not extra:
result = first_guess(codex)
else:
result = later_guess(codex,*extra)

print("\n".join(result))



Match Runner (in progress)

import sys,subprocess
return [bites.decode('ascii').strip() for bites in reply.split()]

if __name__ == "__main__":
judge,guess = sys.argv[1:]

for round in range(10):

print(trial)

reply = subprocess.check_output([judge, "words.txt", "judge", judge_token, trial])

print(score, "\n")
if score == 'GGGGG':
print("{} guessed {}'s word in {} rounds".format(guess, judge, round+1))
break

reply = subprocess.check_output([guess, "words.txt", "guess", guess_token, score])

print(round+1)

• I wrote up all the sample code for this before I found this related post where the comments suggest a similar KOTH Feb 4 at 8:00
• Question: Is EVERY string of N characters allowed to be returned by your function? Feb 4 at 10:10
• @StackMeterPlus no, see steps 1-3 Feb 4 at 14:23
• Although it's not an exact dupe, this feels quite similar to some other KotHs that are based around guessing numbers or playing games like hangman. Feb 4 at 19:56
• Step 2 may be misleading and suggest that there is a slight chance of guessing the word in the first guess. In the adversarial Wordle I know (by qntm) the underlying word is chosen only after the guess, along with returned score (so that they are consistent). This way there is no way to guess a word in the first try (for a reasonable Judge). Or maybe current formulation is intentional? Feb 5 at 19:45
• (Because I suspect a lot of people are going to use regex) can we take other bracket pairs and what formats are acceptable for string output? Feb 5 at 4:25
• wdym by other bracket pairs? Feb 5 at 4:28

# Very simple auto battler

There are two players. Each player has a team of between 0 and 5 members. Each member has two relevant statistics: an attack score and a health score. These range from 1 to 50.

Until at least one team runs out of members, you need to battle the lead member of each team against each other. (You can decide whether this is the first or last member of the team.) The two attacks are simultaneous, so it's possible that both members can defeat each other. Each attack reduces the foe's health by the user's attack. Once a team member's health is reduced to zero (or less) then it faints and takes no part in the rest of the battle.

If both teams simultaneously run out of unfainted members then the result is a draw otherwise the team that still has unfainted members wins.

Your task, given two teams in a reasonable format, e.g. list of tuples of (health, attack), is to write a program or function that outputs which (if any) team will win, using one of three specific values of your choice, e.g. -1, 0 and 1, or A, B and D. (Please describe the mapping of values in your answer.)

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

Sample team generator and battler

# Interpret Subleq code

## Background

Subleq is a language that has only one 3 argument instruction. The instruction has three operands A B C. When executed it subtracts the contents in address A from address B; stores the result in address B; if the result is less than or equal to 0 it goes to address C. -1 in a position has special meaning. -1 in A will read the ASCII value of then next character of input into B; if no more input then goto 'C'. -1 in B will send the ASCII character in A to output. -1 in C will exit the program instead of going to an address.

Given input and Subleq code, output the results from running the Subleq code.

An interpreter built in Excel is here.

## Test Cases

For the test cases below, any input to the Subleq is before the '/', code is after. Code is represented by decimal numbers.

### Hello, World!

Input=>
/
12 -1 13
1 0 6
3 2 -1
4 4 0
72 101 108 108 111 42 32 87 111 114 108 100 33
Output
Hello, World!


### !I!n!s!e!r!t! !i!n!b!e!t!w!e!e!n!

Input->
1 2 3 4 5 6/
2 -1 33
-1 8 -1
8 -1 0
8 8
Output
!1! !2! !3! !4! !5! !6!


## Meta

• What am I leaving out?
• Is there a better way of handling the input to the Subleq code?
• Does it need more/better examples?

# Generate all groupings

• Related Feb 8 at 19:20
• Can we output in reverse order? This order feels a bit unnatural Feb 9 at 9:31

# Bigger regex?

• anttiP you can clear this post now buddy Feb 13 at 23:42
• Are duplicate prime numbers allowed? (is 36 = 3#3 3#-1 or 36 = 3#1 3#1 valid?) Feb 18 at 11:07
• i guess i could allow duplicate prime no.'s. Which do you think benefits the challenge more @AnttiP? Feb 18 at 11:09
• Allowing duplicates makes the challenge a bit easier, since you don't have to simplify the exponents. Basically without duplicates there are two parts to the program, one is the recursion part (factor to primes and recurse) and the other one is the simplification. If duplicates are allowed, then simplification is not necessary so the answers will be shorter. Personally I slightly prefer allowing duplicates, since the answers would be a bit more "focused". But I think if you allow duplicates then you should also allow a 0 exponent. Feb 18 at 11:30
• I think the challenge should be ready to be posted. Feb 18 at 11:49

# Play 1D minesweeper

• What should I output?
– tsh
Feb 18 at 4:00

# Page Selector

• Personally, I think that the last two examples (from a UI standpoint) should be < 1 2 3 [4] 5 ... 11 > and < 1 ... 6 [7] 8 ... 11 >. Regardless, you should clarify if there is some priority for how numbers should be distributed (e.g. should the center have more numbers?) Feb 22 at 19:11
• Slightly related codegolf.stackexchange.com/questions/147318/goto-the-nth-page
– tsh
Feb 23 at 2:39
• Adding to AnttiP's comment, a worked out example or examples would be nice. Feb 23 at 6:39
• @AnttiP Good point, clarified slightly. Feb 23 at 15:06
• What should be the output for 11 6 7? < 1 ... 6 [7] ... 11 > or < 1 ... [7] 8 ... 11 > or something else? (this should be clarified in the specs) Feb 23 at 19:43
• @pajonk Clarified. Feb 28 at 13:48
• Ok, what about 11 6 6? (That problem with specs was intended in my previous comment) Feb 28 at 19:32
• @pajonk Added (and updated specs) Mar 3 at 1:31

# Can the Tune be Played?

I changed the question slightly from when it was posted on the Sandbox.

• I don't get it. Could you explain in detail eg. the [1, 3, 2] is valid - the notes would be played in the order [3, 1, 2] statement? Feb 27 at 16:35
• I might change the wording because I think I have explained it in a confusing way. A more mathematical explanation is: if you shift back each number n in a list by n spaces, do any of the numbers end up in the same space? If so, the list is invalid. So: shifting 1 back by 1 space, it ends up at position -1; shifting 3 back by 3 spaces, it ends up at position -2, and shifting 2 back by 2 spaces, it ends up at position 0. Since none of these are the same position, the list [1, 3, 2] is valid. Feb 27 at 16:46

# Social distance the graph

Given a connected, undirected graph like so, where various nodes are connected to each other:

Select as many nodes as possible such that no two selected nodes are adjacent.

^ made by clumsy by-hand greedy algorithm, tell me if I stuffed this up. The red ones are the selected ones.

You should output the maximal number of points for which this is possible.

You can take the graph in any reasonable form - as an adjacency matrix, a list of edges, a list of nodes, etc.

The graph will have at least one edge, and no more than one edge connecting two points.

## Testcases

-> 2
-> 3
-> 5
-> 5

• This is called the maximum independent set problem, though I like the social distancing name Mar 6 at 16:20
• What are the assumptions on the graph we can make? E.g. will the graph be connected, without self-loops, without multiple edges joining same vertices, with at least one edge? Mar 6 at 17:01
• @pajonk You can assume all of those. Mar 6 at 18:47
• Could you please edit all of that into the question? I bet there will be a question about it when it gets posted (especially connectivity, less confident about self-loops) ;-) Mar 6 at 18:54
• @pajonk Already did. Mar 6 at 18:55
• Alright, sorry, I missed the "connected" added at the beginning. Mar 6 at 18:58
• Could you clarify that in your example the red ones are the one's you selected, not the purple ones? I had to work out which was which. Also, why are some of the nodes in the diagrams bigger than others? Mar 8 at 20:57
• For the second test case, would it be possible to rearrange the nodes so the lines don't all cross in the same place? Just for the avoidance of doubt to make it clearer Mar 8 at 20:58

# Reveal all clues of Black Box

Black Box is a board game, Your task is to reveal all clues.

## What is black box

Black box is a board game with hidden atoms, Your task is given input, All atoms, reveal all clues.

## I/O

### Input

The atoms can be any 1-char that is not newline (Used for separator) Like this.

O....
...O.
..O..
.....
....O


### Output

When the code reveals all clues (See Below) the output of The given input above can be:

 HRHH1
H     1
R     H
H     H
2     R
H     H
H2HRH


or

[["H", "R", "H", "H", "1"], ["1", "H", "H", "R", "H"], ["H", "R", "H", "2", "H"], ["H", "2", "H", "R", "H"]]


Ignore the number, This doesn't mean anything, the number can be non-unique

### Hit

Atoms interact with rays in three ways. A direct impact on an atom by a ray is a "hit".

.........
.........
.O.....O.
.........
.........
...O.....H 1
.........
.......O.


Thus, ray 1 fired into the box configuration at left strikes an atom directly, generating a "hit", designated by an "H". A ray which hits an atom does not emerge from the box.

## Deflection

The interaction resulting from a ray which does not actually hit an atom, but which passes directly to one side of the ball is called a "deflection". The angle of deflection for this ray/atom interaction is 90 degrees. Ray 2 is deflected by the atom at left, exiting the box as shown.

    2
.........
.........
.O.....O.
.........
.........2
...O.....
.........
.......O.


### Reflection

The final type of interaction of a ray with an atom is a "reflection", designated by an "R". This occurs in two circumstances. If an atom is at the edge of the grid, any ray which is aimed into the grid directly beside it causes a reflection.

.........
.........
.O.....O.
.........
.........
...O.....
.........
.......O.
RHR
354


Rays 3 and 4 at left would each generate a reflection, due to the atom at the edge. Ray 5 would be a hit on the atom.

### Double deflection

The other circumstance leading to a reflection is when two deflections cancel out. In the grid at left, ray 6 results in a reflection due to its interaction with the atoms in the grid.

   6

R
.....
..O.O
.....
.....
.....


### Detour

Rays that don't result in hits or reflections are called "detours". These may be single or multiple deflections, or misses. A detour has an entry and an exit location, while hits and reflections only have an entry location for a hit, and a single entry/exit location for a reflection.

  8   8
.........
.........
.O.....O.
.........9
.........
...O.....
.........9
.......O.


Of course, more complex situations result when these behaviors interact. Ray 8 results in two deflections, as does ray 9.

Some rays travel a twisted course, like ray 1 at left.

 .........
.........
.O.....O.
.........
1.........
...O.....
.........
.......O.
1


Notice that this complex set of five deflections above looks exactly like a single deflection, as shown by ray 2 at left. Things are not always as simple as they seem within a black box.

 .........
.........
.........
.....O...
1.........
.........
.........
.........
1


Reflections and hits can be more complex, too. Ray 2 gets deflected by the first atom, reflected by the next two atoms and again deflected by the original atom, yielding a reflection.

.O...
.....R 2
.....
.O.O.
.....


Ray 3 below gets deflected by the first atom, then by the second atom, and then hits the third atom, yielding a hit.

   ...O.
O....
.....
3 H.....
...O.


## Test cases

O....
...O.
..O..
.....
....O
->
HRHH1
H     1
R     H
H     H
2     R
H     H
H2HRH

O
->
H
H H
H

OOO
O O
OOO
->
HHH
H   H
H   H
H   H
HHH

..O..
O...O
..O..
->
HRHRH
R     R
H     H
R     R
HRHRH

...
...
...
->
123
4   4
5   5
6   6
123

....
O...
...O
....
->
H1HH
R    1
H    R
R    H
2    R
HH2H


## Meta:

• Any feedback?
• I think I would first explain what Black Box is and then specify the task and I/O. Right now the Input and Output sections are hard to grasp without context and one needs to go back to those sections after reading specs. Feb 25 at 19:29
• I'd use a capital O in your demos, rather than a #. It makes it visually clearer, imo. Feb 26 at 1:29
• @wizzwizz4 Ok, I will do later Mar 9 at 21:01
• @wizzwizz4 It's a bit ugly because the clues are letters, I will rollback if someone doesn't like this. Mar 9 at 21:09

# Negative of an ASCII photo

• interesting challenge although this might be a dupe im not sure Mar 14 at 2:38
• @DialFrost I had a browse and couldn't find one, but obviously if it is I won't post Mar 14 at 2:45
• ah ic although u might wanna state that the negative photo has to be of same "size" as the original one as suggested by ur ["#",""] and ["","#"] but i dont know if it rly matters Mar 14 at 2:47

# Smallest Bit Rotate

For a given positive integer, try to find out the smallest possible rotate result by rotating it 0 or more bits.

For example, when the given number is 177, whose binary representation is $$\10110001_{(2)}\$$:

• $$\ 10110001_{(2)}=177 \$$
• $$\ 01100011_{(2)}=99 \$$
• $$\ 11000110_{(2)}=198 \$$
• $$\ 10001101_{(2)}=141 \$$
• $$\ 00011011_{(2)}=27 \$$
• $$\ 00110110_{(2)}=54 \$$
• $$\ 01101100_{(2)}=108 \$$
• $$\ 11011000_{(2)}=216 \$$

27 is the smallest rotate result. So we output 27 for 177.

## Input / Output

You may choose one of the following behaviors:

• Input a positive integer $$\n\$$. Output its smallest bit rotate as defined above.
• Input a positive integer $$\n\$$. Output smallest bit rotate for numbers $$\1\dots n\$$.
• Input nothing, output this infinity sequence.

Due to definition of this sequence. You are not allowed to consider it as 0-indexed, and output smallest bit rotate for $$\n+1\$$.

## Test cases

So, here are smallest bit rotate for numbers $$\1\dots 100\$$:

 1  1  3  1  3  3  7  1  3  5
7  3  7  7 15  1  3  5  7  5
11 11 15  3  7 11 15  7 15 15
31  1  3  5  7  9 11 13 15  5
13 21 23 11 27 23 31  3  7 11
15 13 23 27 31  7 15 23 31 15
31 31 63  1  3  5  7  9 11 13
15  9 19 21 23 19 27 29 31  5
13 21 29 21 43 43 47 11 27 43
55 23 55 47 63  3  7 11 15 19
`

## Notes

Meta:

• This is not A331856.
• Any duplicate?
• Clear enough?
• You may want to specify explicitly, that rotation preserves leading zeros. Mar 16 at 12:18
• @pajonk What do you mean by preserve leading zeros? Although I wrote $00011011_{(2)}$, it has nothing different than $11011_{(2)}$. I just wrote it like that so lines are aligned.
– tsh
Mar 16 at 12:35
• I mean that rotating further results in $00110110$ not $10111$. To put it in other words, that rotating by n bits happens all at once, not one-by-one. Mar 16 at 13:09