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

# How wide is this string?

Given a unicode string in any standard encoding of choice, determine how many columns wide it is.

To keep this challenge relatively simple, use the following rules for character widths:

• Tab characters align to the nearest multiple-of-8 column
• CJK characters are 2 columns wide.
• For the purposes of this challenge, you may assume all characters in Unicode Planes 2 and 3 (U+20000-3FFFF), plus codepoints U+3400-9FFF are CJK characters.
• CJK characters outside these ranges may be treated as either 1 or 2 columns wide.
• Combining diacritics (U+0300-036F), control characters (U+00-1F, U+7F-9F), and the zero-width space (U+200B) are all 0 columns wide.
• All other officially zero-width characters may be treated as either 1 or 0 columns wide.
• You may assume that there are no newlines or carriage returns.
• You do not need to handle escape sequences.
• You may assume all other characters are 1 column wide.
• For any character the standard says has a specific width, you may use that width instead.

Shortest code wins.

# Tumbling 2x2 in a Matrix

## Challenge:

Input: A rectangular integer matrix that's at least 2x2 in size. Output: A 2D integer array, of the result after the top-left 2x2 block has tumbled down.

For example: Let's say we have the following 3x5 matrix as input:

[[ 4, 7,12],
[11, 2, 5],
[ 7, 3,15],
[21,10, 1],
[12, 6, 6]]


The 2x2 block is [[4,7],[11,2]], which will act as if it was tumbling down from a stairs (in a top-left to bottom-right direction). Here this process step-by-step:

[[ 4, 7,  ],
[11, 2,  ],
[--,  ,  ],
[  ,  ,  ],
[  ,  ,  ]]

[[  ,  , 4],
[  ,11, 7],
[--, 2,  ],
[  ,  ,  ],
[  ,  ,  ]]

[[  ,  ,  ],
[  ,11, 4],
[--, 2, 7],
[  ,--,  ],
[  ,  ,  ]]

[[  ,  ,  ],
[  ,  ,  ,11],
[--,  , 2, 4],
[  ,--, 7],
[  ,  ,  ]]

[[  ,  ,  ],
[  ,  ,  ,  ],
[--,  , 2,11],
[  ,--, 7, 4],
[  ,  ,--]]

[[  ,  ,  ],
[  ,  ,  ,  ],
[--,  ,  ,  , 2],
[  ,--,  , 7,11],
[  ,  ,--, 4]]

[[  ,  ,  ],
[  ,  ,  ,  ],
[--,  ,  ,  ,  ],
[  ,--,  , 7, 2],
[  ,  ,--, 4,11]]


Doing so, it will add it's values to the other cells in its path. So here is the same step-by-step process with the other numbers added in the cells:

[[ 4, 7,12],
[11, 2, 5],
[ 7, 3,15],
[21,10, 1],
[12, 6, 6]]

[[ 4, 7,16],
[11,13,12],
[ 7, 5,15],
[21,10, 1],
[12, 6, 6]]

[[ 4, 7,16],
[11,13,16],  // Note that the 13 and 5 remain the same, because the cells of the tumbling
[ 7, 5,22],  // block haven't moved from the previous to this step
[21,10, 1],
[12, 6, 6]]

[[ 4, 7,16],
[11,13,16,11],
[ 7, 5,24, 4],
[21,10, 8],
[12, 6, 6]]

[[ 4, 7,16],
[11,13,16,11],
[ 7, 5,24,15],  // Note that the 24 and 8 remain the same, because the cells of the tumbling
[21,10, 8, 4],  // block haven't moved from the previous to this step
[12, 6, 6]]

[[ 4, 7,16],
[11,13,16,11],
[ 7, 5,24,15, 2],
[21,10, 8,11,11],
[12, 6, 6, 4]]

[[ 4, 7,16],
[11,13,16,11],
[ 7, 5,24,15, 2],
[21,10, 8,11,13],  // Note that the 11 and 4 remain the same, because the cells of the tumbling
[12, 6, 6, 4,11]]  // block haven't moved from the previous to this step


## Challenge rules:

• I/O is flexible. You may take the input as integer-matrix, integer list with loose dimension-inputs, as a list of strings, etc. Output can modify the original input, return a new matrix, print space/newline delimiter to STDOUT, etc.
• You may optionally take the dimensions as additional input.

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

## Test case:

Input:
[[ 4, 7,12],
[11, 2, 5],
[ 7, 3,15],
[21,10, 1],
[12, 6, 6]]
Output:
[[ 4, 7,16],
[11,13,16,11],
[ 7, 5,24,15, 2],
[21,10, 8,11,13],
[12, 6, 6, 4,11]]


TODO: More to come.

# Sandbox questions:

I might change the tumbling process a bit later on, since I'm not too happy about the current one. I still want the tumbling 2x2 down the matrix, but I might make the way the other values changes a bit different. This is just an initial idea.

• Any missing tags?
• Any missing rules?
• Any suggestions on how to change the output without changing the core part of the tumbling top-left 2x2 block?
• Any suggested test cases?

# Trapping a Jogger

A person starts jogging to the right from his house on a busy street.

t=0
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - G - - - G
>


He travels 1 hectometer every minute, so he is 11 hectometers away from his house after 11 minutes:

t=11
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - R - - R - - - G
>


Since this is a busy street, there are walking signals that occasionally turn red. In this example, the signals at 5, 8, and 12 units from home alternate colors every 2, 10, and 4 minutes (this would not be a fun road to drive on). The signals are red (signal stop ✋) for the same duration that they are green (signal go 🏃).

Our jogger doesn't want to wait long, so he instantly turns around when he reaches a stoplight that is red, even if it will turn green within the next minute.

t=12
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - R - - - R
>

t=12.001
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - R - - - R
<

t=13
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - R - - - R
<


This can cause the jogger to reverse direction again, making for a potentially long outing.

t=16
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - R - - - G
<

t=16.001
0 1 2 3 4 5 6 7 8 9 A B C
⌂ - - - - G - - R - - - G
>


View the rest of the sequence using a visualizer.

Given the cycle intervals and positions of a list of streetlights, determine the time until the jogger returns to his house (at distance 0) or runs to the right of the rightmost streetlight.

The streetlights at time t=0 will all have just turned green.

The n cycle intervals shall all be integers at least 2. The n positions of the streetlights may be taken as either (sorted) absolute distances from home or the distance from that streetlight to the previous. In the example, this would be either [5,8,12] or [5,3,4].

## Example cases

positions
intervals
output

5,8,12
2,10,4
38

10
20
11

10
6
20

2,8
8,6
40

2,8
7,6
16

1,2,3,4,5,6
6,5,4,3,2,1
16
$$$$


# International "Hello, World!" (WIP) code-challengestring

(Please note the special scoring for this challenge)

This code-golf question has over 900 answers and all of them print "Hello, world!" in English! If we can use hundreds of different programming languages to print that message, why can't we use hundreds of different natural languages to express that message?

Your task is to beat the answers of the Hello, world! challenge ("HW" challenge from now on) in different natural languages, as determined by the length ratio of the English string "Hello, world!" and the string in the natural language you pick. For example, I could pick Portuguese, hence I will have to print "Olá, mundo!" which has a length ratio of 11/13.

• if your natural language has capitalization, you must respect the original capitalization.
• if your natural language has punctuation, you must respect the original punctuation.

Then you pick the programming language you are going to write your code in. For example, I could pick Python. And you write your program. My program could be print("Olá, mundo!"), with a standard code-golf score of 20.

You then look for the best submission in the HW challenge with the same programming language you chose, let's say it has score S. (We probably need a leaderboard for challenge HW to make this step easier.) My score would then be (20/S)/(11/13).

Does this make any sense? Any preliminary feedback?

• It's hard to define whether the grammar of the output is correct in the chosen language, especially for those who don't know the language.
– user92069
Jul 29 '20 at 9:46
• @user92069 why do I need to define if the grammar is correct? "Hello, world!" doesn't look grammatically very correct either.
– RGS
Jul 29 '20 at 22:36

# Extract an integer from another

This is a somewhat interesting problem I ran into while nanboxing: given two integers, compute their bitwise-AND and concatenate the resulting "substrings" into a new integer.

More precisely: you are provided two integers as input — an input integer and a bitmask. As output, you should produce the bitwise-AND of the two such that, given a mask with $$\n\$$ set bits, the corresponding bits from the input are grouped together in the first $$\n\$$ bits of the resulting integer.

The following pseudocode is one way to implement the function:

-- x and mask are lists of booleans
local result=list();
result.append(x[i]);
end
end
return result;
end


## Example inputs and outputs

// In binary:
f(1011, 1111) == 1011 // Select entire number
f(1010, 1010) == 11   // Select bits 1 and 3, and concatenate them
f(11001100, 01100110) == 1010 // Concatenate substrings [1:2] and [5:6]
f(11111111, 10101010) == 1111 // Concatenate bits at odd indices.

f(BEEF, 1111) == 9
f(1337, FF00) == 13
f(CODE, 7777) == 82E

// Two 64-bit variants (in hex):
f(400921FB54442D18, CODE601F15DABE57) == 111DE42C8
f(FFFE0000004010CC, 8003000000000000) == 6


## Specific rules

• Standard loopholes, default IO, etc. apply where not overridden.
• Input and output values must fulfill $$\x \in \{b_{set}, b_{unset}\}^{n}\$$ for some $$\b_{set} \neq b_{unset}, n \in \mathbb{N}_{\geq 16}\$$ of your choice. In other words:
• You must support integers of at least 16 bits in your representation, but you may otherwise arbitrarily constrain their size - i.e. to 32-bit integers. You may also accept integers of any length through lists, arrays, strings, etc.
• The "set" and "unset" values do not need to be of the same type or length, but they must be constant and distinct.
• Most "linear" representations for integers are valid: integers, vectors, arrays, strings, etc.
• This is , so the shortest answer in bytes wins.
• Have fun!
• Is this the PEXT BMI2 instruction? (also, possible duplicate: codegolf.stackexchange.com/q/37167) Jul 30 '20 at 13:00
• @mypronounismonicareinstate After reading the referenced challenge I think this is indeed a duplicate of that. The required algorithms are identical and other requirements seem to not affect this too much. Aug 3 '20 at 4:07
• @mypronounismonicareinstate I've given it a read, and it definitely is the same challenge, bar minor cosmetic differences. Of course, the search did not find it when I tried searching for it... Aug 3 '20 at 11:46

Write an ASPIF (clasp's ASP input format) program to find a maximum cap set (https://en.wikipedia.org/wiki/Cap_set) for 4 dimensions.

Share the code you used to generate the ASPIF rather than ASPIF itself. This may be an ASP program.

Winner is smallest word-count (according to wc) in ASPIF format. For ASP, you can get this by running something like:

clingo capset.asp --mode=gringo | grep -v "$$^1 0 1 [0-9]\+ 0 0$$\|$$^4$$" | wc -w


(note the grep is for excluding unary rules and #show directives neither of which are necessary for solving. The output of this is still a valid clasp program)

I have an example for four dimensions (but I have a better one I won't share right away because I'm curious to see what other people get).

feature(number, (one; two; three)).
feature(color, (red; green; purple)).
feature(shape, (oval; diamond; squiggly)).
dimension(D) :- feature(D, _).
card(c(N,F,C,S)) :-
property(c(N,F,C,S),number,N) :- card(c(N,F,C,S)).
property(c(N,F,C,S),color,C) :- card(c(N,F,C,S)).
property(c(N,F,C,S),shape,S) :- card(c(N,F,C,S)).

{in_capset(X) : card(X)}.
:~ in_capset(X).[-1,X]

settable(D, A, B, C) :-
feature(D, A); feature(D, B); feature(D, C); A != B; A != C; B != C.
settable(D, A, A, A) :- feature(D, A).

:- in_capset(X); in_capset(Y); in_capset(Z);
settable(D, A, B, C) :
dimension(D), property(X, D, A), property(Y, D, B), property(Z, D, C);
X < Y; Y < Z.

#show in_capset/1.


This grounds to an ASPIF program with 9296 "words"

• 4D cap set is already known and has a pattern which was found in a challenge of mine, so it might be too trivial. Why not ask to take n as input and solve for n dimensions (without time and memory limit)? Aug 7 '20 at 3:32
• Also, most people here are not familiar with ASP or ASPIF. It would be helpful if you include relevant links, so we can do some research before tackling the challenge. Aug 7 '20 at 3:34

# Mega Man

My first polyglot challenge, enjoy!

## Validness of a program

In this challenge, a "program" doesn't take an input. This challenge doesn't care of any output, though.

An invalid program, either:

• Doesn't compile, or

• Compiles, but the program doesn't halt when executed.

A program is valid otherwise.

## The 6 Robot Masters

A robot master is a valid program. Their language can be chosen freely, not necessarily all same or all distinct.

There are 6 Robot Masters in total, namely Cut Man, Elec Man, Ice Man, Fire Man, Bomb Man, and Guts Man.

(Yeah, I wanted to include Time Man and Oil Man as well, but that would make this challenge too hard.)

## Weapons

The robot masters have their distictive weapons. (This doesn't mean the robot masters' source code acts as their weapon, though.) A weapon is an operation on a string.

• Cut Man's weapon, Rolling Cutter, leaves the target source's first half characters only, rounded down. Example: Hello, world!Hello,

• Elec Man's weapon, Thunder Beam, eliminates all whitespaces. Example: Hello, world!Hello,world!

• Ice Man's weapon, Ice Slasher, turns all uppercase ASCII letters small. Example: Hello, world!hello, world!

• Fire Man's weapon, Fire Storm, turns all lowercase ASCII letters capital. Example: Hello, world!HELLO, WORLD!

• Bomb Man's weapon, Hyper Bomb, eliminates the target source's first word. The behavior on the surrounding whitespaces is implementation-defined. Example: Hello, world!world!

• Guts Man's weapon, Super Arm, doubles all characters. Example: Hello, world!HHeelllloo,, wwoorrlldd!!

## Objective

When a weapon is applied to a robot master's source code, if and only if it hits their weakness, the resulting code must be a valid program in the robot master's language.

• Rolling Cutter is the weakness of Elec Man.

• Thunder Beam is the weakness of Ice Man.

• Ice Slasher is the weakness of Fire Man.

• Fire Storm is the weakness of Bomb Man.

• Hyper Bomb is the weakness of Guts Man.

• Super Arm is the weakness of Cut Man.

Every other combination is not a weakness and must result in an invalid program. This includes a weapon applied to its owner.

# Scoring

This is a code golf. The score is the sum of the byte counts of all 6 source codes. The answer with the least score wins.

• I find the organisation of the text quite confusing. If I've understood correctly (and I had to read it several times), the challenge boils down to this: write 6 programs, each of which is only valid when one of the weapons is applied to it. Is that right? Since the programs aren't required to implement the weapons, I don't really understand why each robot master is associated with a program. Lastly, do you mean 'execute' rather than 'compile'? Aug 17 '20 at 8:28
• @Dingus Well, it was pretty hard to make a reference to the game. I've clarified the 'compile' and 'execute'. The challenge boils down to, Write 6 programs, each of which is valid and also valid when a weapon is applied, but is invalid when any other weapon is applied. Aug 17 '20 at 9:42
• Ahhh, that makes more sense - I wasn't aware of the game (living under a rock, maybe). Perhaps you should include some more context about it. It seems a bit strange that hitting a weakness results in a valid program (would have expected the opposite), but the description is clear enough. I would suggest a small tweak to 'if and only if it hits their weakness, the resulting code must still be a valid program'. Aug 17 '20 at 10:20
• About 'compile', I meant in the bullet points where you define what an invalid program is. Many languages are not compiled languages. Aug 17 '20 at 10:23

# [PuyoPuyo] How long is my combo?

Context:

PuyoPuyo is a puzzle game where you and your opponent pile up colored slimes (called puyo) in a vertical (13*6 cells) grid. A puyo is one-cell big, but they come as pairs in the screen. Puyo pairs fall from the top to the bottom of the grid, and you can move and rotate them the Tetris way. The list of possible puyo pairs is the cartesian product of {'red','blue','green','yellow'} with itself. The pair sequence for a game is randomly generated for both players at the start of a round, and will be the same for both of them.

If four puyo (or more) of the same color are next to each other (in line, in square, Z-, S-, T-, J- or L-shaped), they disappear, awarding you points and making all the above puyo to fall. If when those puyo fall, they make another group of four (or more) they will disappear too, awarding you with more points than the first group: it is called a two-hit combo.

When a combo stops, whatever its length (1-hit or more), you will send damage to your opponent. The bigger the combo, the more damage is sent. Those damage are called ojama puyo, grey slimes that disappear only when a group disappears next to it. If your third column from the left is filled before your opponent's is, you lose. So to kill your opponent, you must manage to fill its screen before they fill yours.

Challenge:

With a given sequence of puyo pairs associated with their drop locations, output the length of the combo that has been made by this player. Shortest code in any language wins.

Input:

List of puyo pairs and their drop locations:

• 'r1b1r1r2y2r3...'
• '001000013102...'
• [('red','1','blue','1'),('red','1','red','2'),('yellow','2','red','3'),...]
• any sensible way you want, provided you detail how it works

Details:

• This list will never contain any "column number" outside of [1;6] (or [0;5], if 0-indexed) nor a puyo of a color outside of {'red','blue','green','yellow'} (or any set used for your interpretation).
• This list will always contain at most one combo sequence.
• This list will never contain unusable data, like two colors in a row, or two column indices in a row.
• If both puyo of a pair are dropped on the same column, the first one to come is on the top of the pair (in the example #1, red is dropped on the top of the blue on the column 1).
• Puyo will never remain floating in the grid, but will fall to the lowest available cell of the column they are in, even if the paired puyo has stopped in its column (tl;dr puyo pairs split).

Output:

A single integer indicating the length of the combo.

Test cases:

Test case #1

Input
y1r1

Output
0


Test case #2

Input
r1r2g3r3g3g2g1r2

Output
2


Test case #3

Input
y1r1r2r3g2g3r2g3y2y3g3g3y1y1

Output
3


Test case #4

Input
b1b1r2b2g3g3r2r3y4y5b6b6b5y5g4b5y4g3b6b6

Output
1


Test case #5

Input
y1b2b3b3b5b5y6b6b4b4

Output
1


Test case #6

Input
y1r1r2r3g2g3r2g3y2y3g3g3y1y1

Output
3


Test case #7 (click me!)

Input
b1b2g3r4g5y6y1y2b3g4r5g6y1b2g3r4g5y6r1r2g3r4r5y6r1b2b3y4r5y6b1y2y3r4r5g6r1b2r3y4g5g6y1g2r3b4b5b6b1g2g3r4r5g6b1b2r3y4b5r6g1y2b2y3y4g4g5g6g5g6

Output
17


Test case #8 (click me!)

Input
r1r2r5r6g1r2r5g6g1y2y5g6g1y2y5g6y1g2g5y6y1b2b5y6r1b2b5r6b1r2r5b6b1y2y5b6b1y2y5b6y1r2r5y6y1r2r5y6r3r4

Output
4


Standard Loopholes apply.

NB: for purists, I know that the 13th row is supposed to be invisible and that puyo that are in that column are not considered 'linked' to nearby puyo, but I figured this challenge was hard enough as-is.

@Sandbox please comment! I'd love to hear your thoughts about such a challenge. I will finish setting it up soon, adding some extra resources about the game (like this one). Questions:

• Should I reverse the "top / bottom" puyo of a pair rule? The way it is now, it forces to parse input as pairs. If it is reversed, golfers can take puyo one by one and sort it all by columns, making the challenge easier.
• What tags should it enter with?
• I will make other test cases soon enough, but should I include a as a file (via pastebin)?
• "The combo"? Will there be only one combo? Aug 15 '20 at 11:07
• Does the two puyo(s) in a pairstick to each other like in tetris? Aug 15 '20 at 11:07
• Thanks for your comments @user202729, I'll be editing the challenge soon. This challenge will let you assume there will only be one combo. And puyo pairs are broken upon drop if need be, so that every single puyo cannot be floating in the grid. Aug 18 '20 at 11:51

# Sort until overflow - POSTED HERE

• Now that this has been posted to main, could you delete this proposal to create more space for new answers? Sep 25 '20 at 0:37

# Quineoid Triple Uniqueness Optimization

This is a variant of Quineoid Triple with the same requirements but different scoring.

Write three different programs such that when any one program is provided as input to one of the other two, you get the source of the remaining program as output. More explicitly, given programs $$\A\$$, $$\B\$$, and $$\C\$$, where $$\f(g)\$$ denotes the output obtained from inputting the text of program $$\g\$$ into program $$\f\$$, all of the following must hold:

• $$\ A(B) = C \$$
• $$\ A(C) = B \$$
• $$\ B(A) = C \$$
• $$\ B(C) = A \$$
• $$\ C(A) = B \$$
• $$\ C(B) = A \$$

# Scoring

The goal is to have the three programs be as different as possible.

Your score is the sum of:

• Number of unique bytes found in program $$\A\$$, but not $$\B\$$ or $$\C\$$
• Number of unique bytes found in program $$\B\$$, but not $$\A\$$ or $$\C\$$
• Number of unique bytes found in program $$\C\$$, but not $$\A\$$ or $$\B\$$

The theoretical maximum score is 256.

• Standard quine rules apply.
• Each program can be in any language. Any number of them may share languages or each may use a different language.
• Use any convenient IO format as long as each program uses a consistent convention.
• Functions are allowed, as this counts as "any convenient IO".
• The result of feeding a program its own source code is undefined
• The result of feeding anything other than program text of either of the other two programs is undefined.
• Byte encoding should be taken into account for languages with dedicated codepages.

SANDBOX: this is kind of -ish. Should I call it a bowling challenge?

# Modular Chain Compression

A common trope in some kolmogorov-complexity challenges is to use repeated application of the modulo operator in order to compress large integers or string hashes into some range. For example, we can squash the numbers $$\13,4,16\$$ into $$\0,1,2\$$ by taking each number mod $$\7\$$ and then mod $$\3\$$. We call this sequence the modular chain $$\7,3\$$. In general, reducing a number $$\k\$$ by the modular chain $$\n_1,n_2,\ldots,n_i\$$ is equivalent to evaluating

$$(((k\ \text{mod}\ n_1)\ \text{mod}\ n_2)\ \ldots\ )\ \text{mod}\ n_i$$

In this challenge, you will be challenged to compress an arbitrary set of integers in this way. We say the length of the modular chain is the number of elements in the chain (not the number of bytes).

## Input

You are given a fixed set of $$\100\$$ random 32-bit integers. Here they are:

2997344323
2062352342
1953414591
... (more on the actual post) ...


## Output

Via whatever means necessary (brute-force, mathematics, etc) design a modular chain to compact these numbers into a small a range as possible. The modular chain must have a distinct output for each input number.

## Scoring

In code-golf challenges, a modular chain is usually desirable if it achieves two things:

• It compacts the input numbers or hashes into a small range.
• It is short.

In this spirit, your score is the sum of the maximum output number of your modular chain and the length of your modular chain for the given input numbers.

Note an optimal modular chain could compress the input numbers into the range $$\0 \ldots 99\$$ with a single modulo operation, making the theoretical minimum score $$\99 + 1 = 100\$$.

The lowest scoring answer wins. You are encouraged (but not required) to post any code, mathematical background etc. that helped you design your modular chain.

• Length in modulo operations or bytes? Aug 25 '20 at 9:41
• @user253751 The number of operations. Clarified. Aug 25 '20 at 10:28

# The fastest code to find a subset-sum

Given k sorted integers from low to high, output n permutations of those integers with sum as close as possible to m but not exceeding m. The output needs to be sorted from highest to lowest sum.

### Input

k integers, n, m - as described above. All the k integers and m are positive 31-bit integers. Now since this is NP-complete problem, both k and n are small integers, 20 at most.

### Output

One row for each premutation, with integers sorted from high to low. Also, the rows need to be sorted from highest to lowest sum

# The fastest code wins

For the performance test, we will use the below input:

• k = [67, 613, 2111, 2179, 2203, 2269, 3433, 3583, 4219, 5011]
• m = 14,213
• n = 10
• 1) You might want to provide multiple test cases, so that the submissions don't use an algorithm that is fast only in some of them and very slow in the others. 2) For fair evaluation of speed, you need to run all submissions on your machine, so you need to provide some information about your machine's OS, RAM, CPU (also GPU if you want to allow using it). 3) Is the sum of all k integers guaranteed to be positive 31-bit integers? Otherwise we might face overflows during calculation. 4) I think you mean subsets instead of permutations. Aug 28 '20 at 4:42

## [Unnamed]

This challenge is based on a somewhat unusual premise; the goal is to create a rectangular program (box) which is as large as possible, where each row and column will be a solution to a different challenge on this site.

For example, a 3×4 box might look like this:

abcd
:-]
1234


As all solutions will be read from left to right or top to bottom, this would expand into seven programs:

abcd
:-]
1234
a 1
b:2
c-3
d]4


For an answer to be valid, each one of these must be a valid solution to a different challenge on this site, in the same language. The box may be padded by whitespace, but must be rectangular (x groups of y bytes, separated by newlines). This is code bowling, so the longest answer in bytes wins.

• Solutions cannot contain newlines (because otherwise they would be two separate rows/columns)
• Yes, it will be possible to trivially get very high scores with some languages (like unary), but as with most challenges it's a competition within each language
• Solutions do not have to be original, but ones copied from other answers should link to them
• Unary won't be able to compete because the number of challenges on our site is lower than most Unary programs. It will be very hard to compete even in golfing languages, as the answerer will need to manually find the appropriate challenge to use. I don't really think a challenge that makes use of "all challenges on our site" is fun. Sep 10 '20 at 1:40
• @Bubbler Yeah, now that I think about it I agree. I still like the concept, maybe there's something similar that might actually be fun. Sep 10 '20 at 2:37
• Maybe you could select a subset of challenges - something like what was done for this challenge? Sep 17 '20 at 11:43
• @Dingus Good idea! I'll see if I can fix a few other things, too. Sep 17 '20 at 12:39

Targeted sum and difference of a sequence

You are given two things: a target integer(not necessarily positive) n, and a sorted list/array/etc. of non-negative integers a. (The list will have at least two elements). Your goal is to choose one element of a as your total, and then one by one, take elements of a, and either add or subtract them from your total. Print out all possible combinations(duplicates can be removed, but it is optional) of [a_1]±[a_2]±[a_3] or return them as a list/array/etc. .

In other words, find all solutions to n=[a_1]±[a_2]±[a_3]. The first element of a is not guaranteed to be a_1, nor is the second element guaranteed to be n_2.

Test cases:

n = 10, a = [1,2,3,4] :  10 = 1+2+3+4 and 2+1+3+4 ...
# The output should be 1+2+3+4(and 4+2+3+1, and every combination like that)
n = 1, a = [2,3]: 1 = 3-2, so 3-2.
# (-2+3 wouldn't work, since it is strictly addition or subtraction of positive integers).
# -2 isn't a part of [2,3]. You should think of the steps as [a_1]±[a_2]±[a_3].
# n = -5, a = [0,5,1]. -5 = 0-5, and nothing else.
n=95, a = [50,50,5]. 95 = 50+50-5, 50-5+50. (A second 50+50-5 is optional)


Criteria: Shortest code wins

Meta:

Is this clear enough(and what should I do to make this more clear)? Also, has this been done before? Finally, should I remove the restriction on the first number being positive?

Thank You!

• What do you mean by "The first element of a is not guaranteed to be a_1"? Sep 11 '20 at 7:01

A centered hexagonal number is a centered figurate number that represents a hexagon with a dot in the center and all other dots surrounding the center dot in a hexagonal lattice.

Illustration of initial terms:

                                 o o o o
o o o        o o o o o
o o      o o o o      o o o o o o
o    o o o    o o o o o    o o o o o o o
o o      o o o o      o o o o o o
o o o        o o o o o
o o o o

1      7          19             37


Write a function that takes an integer $$\n\$$ and returns "Invalid" if $$\n\$$ is not a centered hexagonal number or its illustration as a multiline rectangular string otherwise.

Sample Output :-

hexLattice(1) ➞ " o "
// o

hexLattice(7) ➞ "  o o  \n o o o \n  o o  "
//  o o
// o o o
//  o o

hexLattice(19) ➞ "   o o o   \n  o o o o  \n o o o o o \n  o o o o  \n   o o o   "
//   o o o
//  o o o o
// o o o o o
//  o o o o
//   o o o

hexLattice(21) ➞ "Invalid"


Rules

Shortest Code Wins!

• I like the challenge concept! Usually, we advise against input validation; that is, rather than outputting "Invalid", solutions should assume the input is valid, though if you do that this challenge is almost a duplicate and so I think in this case it could make for an interesting challenge to leave it in.
– hyper-neutrino Mod
Sep 23 '20 at 13:11
• Another thing is usually we encourage flexible input/output formatting; in this case, in addition to a multiline string, I would also allow a list of strings or a matrix of characters as output, and rather than strictly outputting "Invalid", I would suggest allowing solutions to state any reasonable parameters for how they'll indicate invalid input.
– hyper-neutrino Mod
Sep 23 '20 at 13:13
• Related-ish. There are several other hexagon related challenges but this was the only one I could find that required computing the centred hexagonal numbers. Sep 24 '20 at 18:58

# Word Length-Sum Multiples

• Now that this has been posted, I've edited it down to save space and I'd recommend you delete the proposal Sep 25 '20 at 0:15

# Double Prime Words

• tags would be decision-problem, code-golf, primes, I think? Sep 8 '20 at 19:07
• I think if and only if x is prime should be if and only if n is prime? Sep 8 '20 at 19:08
• Additional exampleː Is this word a double primeː Hello Worlds aardvark aalii Aani Sep 10 '20 at 12:36
• @Xwtek Is that 4 separate examples, or 1 long example? Sep 10 '20 at 15:09
• Now that this has been posted, I've edited the post down to save space and I'd recommend you delete this proposal Sep 25 '20 at 0:19

# $$\d\times n\$$ dimensional word matrices [WIP]

Given two positive integers $$\n\$$ and $$\d\$$, and a list of words $$\a\$$, produce a $$\d\$$-dimensional matrix $$\m\$$ with each dimension having length $$\n\$$, filled with letters, that contains the words from $$\a\$$ placed such that they form a directly adjacent contiguous path through the dimensions.

For example, given $$\d = 1\$$, $$\n = 3\$$ and $$\a = \$$['cat'] output one of:

cat


or

tac


Given $$\d = 2\$$, $$\n = 3\$$ and $$\a = \$$['cat', 'hat', 'mat'] output something similar to:

cat
hat
mat


Given $$\d = 3\$$, $$\n = 3\$$ and $$\a = \$$['low', 'complexity'] output something similar to:

coq
igw
typ

kmc
xeo
buf

kpr
dll
scm


or, if it's easier to visualise in an array structure:

[
[
['c', 'o', 'q'],
['i', 'g', 'w'],
['t', 'y', 'p'],
],
[
['k', 'm', 'c'],
['x', 'e', 'o'],
['b', 'u', 'f'],
],
[
['k', 'p', 'r'],
['d', 'l', 'l'],
['s', 'c', 'm'],
],
]


Which contains low at nested indices $$\m[2][1][2]\$$, $$\m[1][1][2]\$$, $$\m[0][1][2]\$$ and complexity at $$\m[0][0][0]\$$, $$\m[0][0][1]\$$, $$\m[1][0][1]\$$, $$\m[2][0][1]\$$, $$\m[2][1][1]\$$, $$\m[1][1][1]\$$, $$\m[1][1][0]\$$, $$\m[0][1][0]\$$, $$\m[0][2][0]\$$, $$\m[0][2][1]\$$.

I'd like to add some more complicated examples beyond three dimensions here.

TODO

## Rules

• Unused spaces should be filled with randomly selected letters.
• There will always be enough space in the dimensions provided to allow the words to be added without re-using letters.
• There is no requirement to ensure the words don't also appear elsewhere in the grid, so for example if the filler letters happen to spell one of the provided words, that is acceptable.

## Questions for meta

• This seems fun to me, any thoughts?
• Is it too easy/hard?
• Any other tags that are relevant?
• As a follow up, I'd like to have a nested matrix provided and have programs solve it - but that might be better as a fastest-code challenge - is this a reasonable precursor?
• Is d^n large enough to contain all the words without sharing letters? Jul 23 '20 at 8:18
• Yeah, you won't have to be concerned with that, I'll add that to the rules. Jul 23 '20 at 8:21

# Terminal Punch Card

moved because apparently it's not clear enough.

So back in the day, computers didn't have fancy keyboard and mouse inputs, and didn't have your fancy screens. Instead they had punch cards.

Punch cards punchers punched (try saying that 10 times fast) a hole out of a card to represent a 1-bit, and left it filled to represent a 0-bit. The cards were some number of holes wide, with each hole representing a bit in a byte.

Recently, you discovered an old mainframe at your local university that accepted punch cards that were 8 holes wide. For this challenge, you will be given data as an input, and your job is to punch a punch card to the terminal output, like this:

Hello, World!

: *  *   :
: **  * *:
: ** **  :
: ** **  :
: ** ****:
:  * **  :
:  *     :
: * * ***:
: ** ****:
: ***  * :
: ** **  :
: **  *  :
:  *    *:


The input will be a string or bytes representing the punched data payload. The output data must include rows, which start and end with a :, and have 8 bits between them, represented as a   for 0, or a * for 1. There must be one row for each byte of data.

Here's the catch: The punch card puncher only punched one hole at a time, so in your program, must print (or add to the output string) only one character at a time.

Example of unacceptable method call:

# binary is some string with the binary bits.
print(":" + binary.replace("0", " ").replace("1", "*") + ":")


Acceptable method call:

for bit in binary:
print(bit == "1" ? "*" : " ", "")


Also acceptable method call:

output = ""
for bit in binary:
output += bit == "1" ? "*" : " "


The challenge is code golf, so least number of bytes wins. Standard rules/loopholes are in effect.

• A word about catches before we even discuss observability and clarity issues: Catches are rarely a good idea for two reasons. The first is that challenge writers frequently add catches because they somehow feel their challenge is deficient or too easy and want to salvage it somehow. This coping mechanism usually fails, they are better off writing a new challenge.
– Grain Ghost Mod
Oct 4 '20 at 12:17
• Note also there are already comments here regarding observability, assuming language features, and assuming implementation details Oct 4 '20 at 12:19
• The second, which I think is more relevant to you, is that structuring your challenge with a catch is often confusing. You have already written what is a complete challenge, but then in the last 10% or so the whole task changes. Some people don't read the whole challenge once they think they have it, miss the last bit or become frustrated when things are pulled out from under them. Regardless of how you feel about these people, It is really just better to phrase your challenge in a straight forward and upfront way. Nothing should seem tacked on if you can avoid it.
– Grain Ghost Mod
Oct 4 '20 at 12:21
• One way you could easily make your catch observable is to take a string and an index and output the character at that index. Of course answerers can just produce the entire string and index it, but they could already do that with your existing version (probably, it's a little unclear).
– Grain Ghost Mod
Oct 4 '20 at 12:26

# Socially distanced seating

Lord Lloyd Warbler wants to minimise the harm to his theatre's seating capacity for his hit show, Birds, of maintaining social distancing.

The social distancing rules in Westendland are:

• Groups may sit together without distancing
• Between groups there must be at least 2 empty seats along the row, and 1 empty row in front and behind.
• The closest diagonal permitted is a knight's move - only 1 horizontal space empty.

Diagrams:

 A _ _ B

A
_
B

A _ _
_ _ B


Given a list of group sizes and the theatre size (rows and columns), can you pack them all into the theatre? Groups can sit in any contiguous (connected) arrangement of seats.

## Sample tests

(Rows, cols), [groups] -> canFitBool
(1,1), [1] -> true
(2,2), [1,1] -> false
(2,3), [1,1] -> true   // knight's move
(5,2), [4,4] -> true   // 2x2 in rows a,b, gap in c, 2x2 in d,e


## questionmarks

• Should I just provide a list of cases of varying difficulty? Like, some of these could be pretty difficult.
• Is the knight's move rule too complicated?
• Is the contiguous rule too permissive, and therefore complicated? It could mean some edge cases are possible if you have a weird shaped group. Could make it rectangular blocks only?
• Groups can sit in any contiguous (connected) arrangement of seats You need to decide, and specify in the text, if contiguous means 4-connectivity (up, down, left, right) or 8-connectivity (diagonals count as connected too) Oct 4 '20 at 12:17

# Count the strokes of an ASCII character

## Objective

Given a printable ASCII character (0x21 – 0x7E), count its strokes (as handwritten), then output it.

Note: The strokes are based on how I write the characters. Those with potential controversy are marked * below.

## Mapping

       ! → 2  " → 2  # → 4  $→ 2* % → 3* & → 1* ' → 1 ( → 1 ) → 1 * → 3* + → 2 , → 1 - → 1 . → 1 / → 1 0 → 1* 1 → 1* 2 → 1 3 → 1 4 → 2 5 → 2 6 → 1 7 → 2* 8 → 1* 9 → 1 : → 2 ; → 2 < → 1 = → 2 > → 1 ? → 2 @ → 1 A → 3* B → 2 C → 1 D → 2 E → 3* F → 3 G → 2 H → 3 I → 3* J → 1* K → 2* L → 1 M → 4* N → 3* O → 1 P → 2 Q → 1* R → 2 S → 1 T → 2 U → 1 V → 1 W → 1 X → 2 Y → 2 Z → 2* [ → 1 \ → 1 ] → 1 ^ → 1 _ → 1  → 1 a → 1 b → 1 c → 1 d → 1* e → 1 f → 2 g → 2* h → 1 i → 2 j → 2 k → 2 l → 1 m → 1 n → 1 o → 1 p → 1 q → 1 r → 1 s → 1 t → 2 u → 1 v → 1 w → 1 x → 2 y → 2 z → 2* { → 1 | → 1 } → 1 ~ → 1  ## Rule • Every character outside of U+0021 – U+007E falls in don't care situation. • There's no requirement for the *s, because people have to follow your specification anyway. If there's a way to solve this beyond simple compression, then this challenge will be good. Oct 15 '20 at 6:29 • Can we take input as an ASCII codepoint? Oct 15 '20 at 16:11 • Also can I just say how the hell do you write Q with only one stroke? Oct 15 '20 at 16:17 • Does "don't care" mean "assume we won't be given this" or "it doesn't matter what you output"? Oct 15 '20 at 16:17 • @pxeger ASCII codepoint is acceptable. "Don't care" means both. For the Q, the tail bisects the bowl, so it can be written in one stroke. Oct 15 '20 at 21:06 # Position my geohashes ## The Challenge This is the reverse challenge of Geohash my positions. Given a Geohash string of length 8, convert it to a latitude and a longitude. The conversion is done by the following algorithm, using u09tunqu as an example input. • For each character of the Geohash string, find its 0-indexed position in the map 0123456789bcdefghjkmnpqrstuvwxyz. • u09tunqu becomes 26 0 9 25 26 20 22 26 • Convert each integer into a binary string of length 5. • 26 0 9 25 26 20 22 26 becomes 11010 00000 01001 11001 11010 10100 10110 11010 • Join the binary strings together. • 11010 00000 01001 11001 11010 10100 10110 11010 becomes 1101000000010011100111010101001011011010 • Separate the odd positions in the joined binary string from the even positions. These represent the longitude and latitude, respectively. • 1101000000010011100111010101001011011010 becomes 10000001101000011011 (odd positions: longitude) and 11000101011111001100 (even positions: latitude). • The latitude should be somewhere in the range (-90, 90). Narrow down the range, based on the first character in the latitude binary string. If the first character is 0, the latitude should converge to the lower half of this range, i.e. (-90, 0). If the first character is 1, the latitude should converge to the upper half of this range, i.e. (0, 90). • The 1st character in 11000101011111001100 is 1, so the new range becomes (0, 90). • The remaining characters in the binary string are to be processed in the same way, where 0 represents the lower half of the new range and 1 represents the upper half of the new range. • The 2nd character in 11000101011111001100 is 1, so the new range becomes (45, 90). • The 3rd character in 11000101011111001100 is 0, so the new range becomes (45.0, 67.5). • The 4th character in 11000101011111001100 is 0, so the new range becomes (45.0, 56.25). • The 5th character in 11000101011111001100 is 0, so the new range becomes (45.0, 50.625). • The 6th character in 11000101011111001100 is 1, so the new range becomes (47.8125, 50.625). • ... • The 20th character in 11000101011111001100 is 0, so the final range becomes (48.85826, 48.85843). • The final latitude is the midpoint of the final range. • (48.85826, 48.85843) becomes 48.85835 • Repeat the same process for the longitude, starting from the range (-180, 180) • 10000001101000011011 becomes 2.29460 • Output the final latitude and longitude. • u09tunqu becomes 48.85835, 2.29460 ### Input A string of length 8, consisting only of the characters 0123456789bcdefghjkmnpqrstuvwxyz. ### Output Two signed floats in the ranges (-90.0, 90.0) and (-180.0, 180.0) representing the corresponding latitude and longitude. ## Test cases u09tunqu → (48.85835, 2.2946) dr5r7p62 → (40.68933, -74.04459) stq4s8cf → (29.97525, 31.13783) 75cm2txp → (-22.9519, -43.21043) usdkfsq8 → (71.17089, 25.78302) zzzzzzzz → (89.99991, 179.99983) 00000000 → (-89.99991, -179.99983) ezs42s00 → (42.60507, -5.60286) 7zzzzzzz → (-0.00009, -0.00017)  ## General remarks # AOG Day 6: Filtering the Playlist I promise the next one will be better You've sent the invitations for the party (and made the postperson do a whole lot more work than they should have, smh), made the decorations as interesting as possible (who doesn't love a painstakingly written quine) and made sure that the event won't kill anyone (at least, not due to COVID). The next thing that needs to be planned is the music. Now, of course, you could go ahead and create a YouTube playlist by hand, but that's way too tedious and, well, predictable. Instead, you've decided to write a program that randomly chooses songs from the music genre (I know...very efficient isn't it). But of course, there's just one problem with that plan: there's a very small chance that a song selected at random might just ruin the party vibes for everyone (even though people such as myself would consider it a Christmas miracle, others would probably see it as a lame stunt and potentially leave the party). Thankfully, the magic of code allows us to check the html of the YouTube video before hand to tell if it is indeed a rickroll. ## The Challenge Given a YouTube link as input (not shortened, but a full standard link), retrieve the title and description of the video and output whether or not it is a rickroll. In order for a video to be considered a rickroll, it must have either the unbroken phrase Never Gonna Give You Up or Rickroll in the title or description. ## Test Cases Under construction • How about checking the top 5 comments for the unbroken phrase Never Gonna Give You Up or Rickroll as well? Would that make it inconsistent? Nov 12 '20 at 13:25 # English Stroke Count Alphabet In a Chinese glossary/index for any given book, to find terms that are contained within the book and because Chinese doesn't have an alphabet like in English, they are sorted by stroke count instead. (一畫 = 1 stroke，二畫 = 2 strokes，三畫 = 3 strokes，四畫 = 4 strokes，and so on) An English glossary, having an alphabet, is naturally sorted alphabetically. For this challenge, we flip that idea to the Chinese manner. And we'll follow some Chinese writing rules to help determine stroke order for the alphabet below. Take 口 (kou) for example, a simple square. You'd think it is 4 strokes, but it is actually 3. The 1st being the left vertical line, the 2nd being the top horizontal and right vertical in one fluid stroke, and the 3rd being the lower horizontal line. This pattern, among others, holds relatively true across Chinese characters. For sake of simplicity though, and for some diversity in the English Stroke Count Alphabet, this will be the primary pattern used. First, I need to define stroke count for each letter. For sake of simplicity, and somewhat subjectively, I'll use the characters as they appear below. If there are any arguments why a letter should have a different stroke count, please make your case, but in order to promote diversity in stroke counts, I made some personal judgment calls. These stroke counts could easily change with different fonts. 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 3 3 1 2 4 3 2 3 3 1 3 2 4 3 1 2 2 3 1 2 1 2 4 2 3 3 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 2 2 1 2 2 2 2 2 3 2 3 2 3 2 1 2 2 2 1 2 2 2 4 2 2 3 Letters with equal stroke counts should retain the original alphabetic order as before. So the English Stroke Order Alphabet is as follows. (If I made an error, please say as much, there are a lot of examples that I might have to adjust) C J O S U D G L P Q T V X A B F H I K N R Y Z E M W c o s a b d e f g h j l n p q r t u v x y i k m z w The Challenge Given a non-empty string input containing a sentence/series of words, or a list of words, organize all words according to this new English Stroke Count alphabet. Output can be either a string, or a list of properly words is a single string of properly organized words, including duplicates should they exist. Note 1: If upper and lowercase for the same letter have the same stroke count, uppercase letters take precedence. • "Cousin" precedes "cousin" • "father" precedes "Father" (because lowercase f is 2 strokes, while the uppercase is 3) • "Stop" precedes "soap" (while the o would precede t in stroke count, uppercase S precedes lowercase s) • KO precedes kO (K precedes k) • kO precedes ko (O precedes o) Note 2: I've intentionally avoided weird words in input. Inputs such as "WeIrD", "COVID-19". Input will never include any numbers, punctuation, or special characters. Input / Output "It was the best of times it was the worst of tImes" / "of of best the the tImes times It it worst was was" ["When", "life", "gives", "you", "lemons", "make", "Lemonade"] / ["gives", "Lemonade", "lemons", "life", "you", "When", "make"] [The, journey, of, a, thousand, miles, begins, with, one, step,] / [of, one, step, The, a, begins, journey, thousand, miles, with] "English Stroke Count Alphabet" / "Count Stroke Alphabet English" "A man a plan a canal panama" / "canal a a panama plan A man" "Carry on my wayward son" / "Carry on son my wayward" "Close our store and begin destroying every flower green house just lose no people quietly rather than using vexing xrays yesterday it killed my zoo wombat" / Same as input (If you can write a better sentence than above, I'd be much appreciated.) ["May", "the", "Force", "be", "with", "you"] / ["be", "the", "you", "Force", "May", "with"] [Im, going, to, make, him, an, offer, he, cant, refuse] / [cant, offer, an, going, he, him, refuse, to, Im, make] "jello Jello JellO JEllo JELlo JELlO JELLO" / "JellO Jello JELLO JELlO JELlo JEllo jello" "We suffer more often In imagination than IN reality" / "often suffer reality than In IN imagination more We" "Code Golf and Coding Challenges" / "Code Coding Challenges Golf and" ["Do", "or", "DO", "not", "there", "is", "no", "try"] / ["or", "DO", "Do", "no", "not", "there", "try", "is"] "Failure the best teacher is" / "best teacher the Failure is" "Can you tell that I am a Star Wars fan" / "Can Star a am fan tell that you I Wars" [enough examples no more words] / [enough examples no more words] • If I is 3, then surely i is 4, no? Similarly for J vs j. – Adám Nov 2 '20 at 21:32 • You should be more lenient about input. E.g. allow a list of words. – Adám Nov 2 '20 at 21:34 • "Uppercase letters take precedence when determining stroke counts, should they be equal." means there's just a single case-sensitive alphabet. It'd be more interesting if uppercase matching lowercase on stroke counts would only be used as a tie breaker. – Adám Nov 2 '20 at 21:37 • @Adám As per point 1, I can see the argument. I can make that change, but it'll likely take a second to get all of the examples in line. Point 2, that input format seems adequate. Point 3, I think I know what you mean. And I'm pretty certain that that's what I was intending, but I had poor wording. Nov 2 '20 at 21:49 • No rush. I recommend sandboxing for at least one week. – Adám Nov 2 '20 at 21:52 • You should add KD vs kO and kO vs ko to the examples for Note 1. – Adám Nov 2 '20 at 21:53 • I'm not sure what you mean by "that input format seems adequate", but please familiarise yourself with this. – Adám Nov 2 '20 at 21:55 • @Adám I'd like to add one thing about how stroke count works in Mandarin. 口 (kou) in Mandarin appears to be a square, and you'd think it has 4 strokes, but it actually has 3. The 1st stroke is the left vertical line, the 2nd stroke is the top horizontal and right vertical line, and the 3rd and final stroke is the bottom horizontal line. These patterns hold fairly true across Chinese characters. In the case of the letter i, I actually see 3 strokes instead of your suggested 4. The 1st being the slight horizontal tick and vertical line, the 2nd being the bottom line, and the 3rd for the dot. Nov 2 '20 at 21:57 • I see, but then J should be 1, no? 一丿 – Adám Nov 2 '20 at 21:59 • @Adám Correct, I wasn't necessarily thinking of that when I made the challenge, but I'll add the explanation and make the edit. Nov 2 '20 at 22:02 # Make a die of given number of faces ## Objective Given an integer $$\n\$$ greater than 3, identify an $$\n\$$-sided die with the "greatest" symmetry, then decompose $$\n\$$ to numbers of faces grouped up to the symmetry, and then output the decomposition. ## Symmetry A die can have one of the following symmetries, from the greatest and with descending order: • $$\I_h\$$, icosahedral symmetry • $$\O_h\$$, octahedral symmetry • $$\T_d\$$, tetrahedral symmetry • $$\D_{ph}\$$, $$\p\$$-fold prismatic symmetry, in ascending order on $$\p\$$, where $$\p\$$ is an odd prime number Note that every other symmetry is redundant. ## Faces A die of each symmetry can have the following faces: • For a die of symmetry $$\I_h\$$: • Optionally $$\12\$$ faces, those from a dodecahedron • Optionally $$\20\$$ faces, those from an icosahedron • Optionally $$\30\$$ faces, those from a rhombic triacontahedron • Optionally $$\60\$$ faces, those from a deltoidal hexecontahedron • Zero or more sets of $$\120\$$ faces, those from a disdyakis triacontahedron • For a die of symmetry $$\O_h\$$: • Optionally $$\6\$$ faces, those from a cube • Optionally $$\8\$$ faces, those from an octahedron • Optionally $$\12\$$ faces, those from a rhombic dodecahedron • Optionally $$\24\$$ faces, those from a deltoidal icositetrahedron • Zero or more sets of $$\48\$$ faces, those from a disdyakis dodecahedron • For a die of symmetry $$\T_d\$$: • Optionally $$\4\$$ faces, those from a tetrahedron • Optionally $$\6\$$ faces, those from a cube • Optionally $$\12\$$ faces, those from a triakis tetrahedron • Zero or more sets of $$\24\$$ faces, those from a tetrakis hexahedron • For a die of symmetry $$\D_{ph}\$$: • Optionally $$\2\$$ faces, those from base faces of a $$\p\$$-gonal prism • Optionally $$\p\$$ faces, those from side faces of a $$\p\$$-gonal prism • Optionally $$\2p\$$ faces, those from a $$\p\$$-gonal bipyramid • Zero of more sets $$\4p\$$ faces, those from a $$\2p\$$-gonal bipyramid Note that faces from the Catalan solids that are not mentioned here are redundant. ## Rules • The input and output format doesn't matter. Possible choices of output format include: • A list, sorted or unsorted • A multiset • Invalid inputs fall in don't care situation. Especially, integers that are 3 or less. ## Examples • For $$\n=4\$$, the die has $$\T_d\$$ symmetry, so $$\n\$$ decomposes to $$\(4)\$$, with the die being a tetrahedron. • For $$\n=5\$$, the die has $$\D_{3h}\$$ symmetry, so $$\n\$$ decomposes to $$\(2,3)\$$, with the die being a triangular prism. • For $$\n=6\$$, the die has $$\O_h\$$ symmetry, so $$\n\$$ decomposes to $$\(6)\$$, with the die being a cube. • For $$\n=7\$$, the die has $$\D_{5h}\$$ symmetry, so $$\n\$$ decomposes to $$\(2,5)\$$, with the die being a pentagonal prism. • For $$\n=8\$$, the die has $$\O_h\$$ symmetry, so $$\n\$$ decomposes to $$\(8)\$$, with the die being an octahedron. • For $$\n=9\$$, the die has $$\D_{3h}\$$ symmetry, so $$\n\$$ decomposes to $$\(3,6)\$$, with the die being a truncated triangular bipyramid. Note that the die won't have $$\D_{7h}\$$ symmetry because $$\D_{3h}\$$ is greater. • For $$\n=10\$$, the die has $$\T_d\$$ symmetry, so $$\n\$$ decomposes to $$\(4,6)\$$, with the die being a chamfered tetrahedron. Note that this is different than the usual d10, which is a pentagonal trapezohedron. • For $$\n=11\$$, the die has $$\D_{3h}\$$ symmetry, so $$\n\$$ decomposes to $$\(2,3,6)\$$. • For $$\n=12\$$, the die has $$\I_h\$$ symmetry, so $$\n\$$ decomposes to $$\(12)\$$, with the die being a dodecahedron. Note that due to the greater symmetry, dodecahedron supersedes rhombic dodecahedron and triakis tetrahedron. • For $$\n=100\$$, the die has $$\T_d\$$ symmetry, so $$\n\$$ decomposes to $$\(4,24,24,24,24)\$$. Note that this is different than usual Zocchihedron, which has prismatic symmtery. Note that, if $$\p\$$ and $$\p+2\$$ are twin primes, $$\p+2\$$ will always decompose to $$\(2,p)\$$. ## Ungolfed solution ### Haskell This implementation mimics the ReadP parser. import Control.Monad type DResult = [([Int], Int)] type DParser = DResult -> DResult returnD :: Int -> DResult returnD n = [([],n)] pfail :: DParser pfail _ = [] get :: Int -> DParser get m results = do (ns, n) <- results guard (m <= n) return (m:ns, n - m) many :: DParser -> DParser many p results = let results2 = p results in case results2 of [] -> results _ -> results ++ many p results2 optional :: DParser -> DParser optional p results = p results ++ results run :: DParser run = filter ((0==) . snd) (<++) :: DParser -> DParser -> DParser (<++) p q results = case p results of [] -> q results results2 -> results2 decomposeDph :: Int -> DParser decomposeDph prismFold = run . optional (get 2) . optional (get prismFold) . optional (get (2*prismFold)) . many (get (4*prismFold)) decomposeTd :: DParser decomposeTd = run . optional (get 4) . optional (get 6) . optional (get 12) . many (get 24) decomposeOh :: DParser decomposeOh = run . optional (get 6) . optional (get 8) . optional (get 12) . optional (get 24) . many (get 48) decomposeIh :: DParser decomposeIh = run . optional (get 12) . optional (get 20) . optional (get 30) . optional (get 60) . many (get 120) decomposeDie :: Int -> [Int] decomposeDie n = fst . head$ foldr (<++) pfail (decomposeIh : decomposeOh : decomposeTd : map decomposeDph [3,5..]) (returnD n)


# Topologies on Rational Numbers (WIP)

## Objective

Construct a subset $$\P\$$ of $$\\mathbb{Q}\$$ such that:

• $$\P\$$ is neither open nor closed in $$\\mathbb{Q}\$$ as a subspace of $$\\mathbb{R}\$$, and

• $$\P\$$ is open but not closed in $$\\mathbb{Q}\$$ as a subspace of $$\\mathbb{R}_l\$$.

Or, in other words, construct a subset $$\P\$$ of $$\\mathbb{Q}\$$ such that:

• There exists $$\p \in P\$$ such that, there doesn't exist an open interval $$\p \in (a,b) \subset \mathbb{R}\$$ such that, $$\\mathbb{Q} \cap (a,b) \subset P\$$.

• For every $$\p \in P\$$, there exists a half-open interval $$\p \in [a,b) \subset \mathbb{R}\$$ such that, $$\\mathbb{Q} \cap [a,b) \subset P\$$.

• There exists $$\p \in \mathbb{Q} \setminus P\$$ such that, there doesn't exist a half-open interval $$\p \in [a,b) \subset \mathbb{R}\$$ such that, $$\\mathbb{Q} \cap [a,b) \subset \mathbb{Q} \setminus P\$$.

## Notes and Rules

• Note that $$\P\$$ is necessarily infinite, and thus cannot be represented as an associative container. One way of representing $$\P\$$ is to have a function $$\f : \mathbb{Q} → \mathbb{Z}_2\$$ that halts for every input, where $$\\mathbb{Z}_2\$$ is the set of the boolean values. Then $$\p \in P\$$ shall satisfy iff $$\f(p)\$$ is true.

• The representation of $$\\mathbb{Q}\$$ must be exact. Thus you cannot have floating-point values as an input. Though native rational-number arithmetic will be preferred, you may use two arbitrary-length integers as an input. In this case, the fraction is assumed to be irreducible and to have a positive denominator. Otherwise, the fraction falls in don't care situation.

• Invalid inputs fall in don't care situation.

## Example

An example of such $$\P\$$ is:

$$\mathbb{Q} \cap ((0,1) \cup [2,3))$$

Work in progress due to a trivial example.

• Is there a way you can frame this question without topology? At the moment I think participation would be very low due to the high background knowledge demanded. Nov 10 '20 at 9:58

# Find the longest streak of Fibonacci numbers on the Ulam spiral

## Fibonacci numbers

Fibonacci numbers are a sequence where each element is the sum of the previous two elements. In the original Fibonacci sequence, the first two number are 1. So the sequence goes: 1, 1, 2, 3, 5, 8, 13, 21, .... For the challenge, we will accept any two numbers as the two starting numbers of the series.

## Ulam spiral

The Ulam spiral is an arrangement of natural numbers. The spiral goes counter-clockwise and starts with the numbers 1, 2, where the 2 is right of the 1. For this exercise, only the shape of the spiral is relevant.

Find the length of the longest streak of generalised Fibonacci numbers (with any two starting numbers) following the Ulam spiral in a given array of integer numbers.

## Example

The following 5x5 array has two generalised Fibonacci sequences: one of length 4 (in blue + yellow: 138, 81, 219, 300) and one of length 8 (in green + blue: 24, 57, 81, 138, 219, 357, 576, 933). The answer is thus 8.

## Rules

• Your program should at least support arrays up to 65535 * 65535 in size and array elements with values up to 4,294,967,295.
• Invalid input (non-square arrays, float or negative elements, non-arrays, etc.) may lead to unpredicted output, errors or (un)defined behaviour.
• Default I/O rules apply and default loopholes are forbidden.

on question 1; see comments below

• This is , so the shortest answer in bytes wins.

on question 2; see comments below

• This is , so the fastest answer wins.
• Fastest code is measured in average user time over 5 different, undisclosed input matrices of sizes 100, 1000 and 10,000, each run 3 times on my late 2013 MacBook Pro with 2,3 GHz quadcore Intel i7 CPU and 16 GB of RAM.

## Review questions

• I plan on publishing this question twice: one time as a codegolf and one time as a fastest-code. See the last section of my question. I think this challenge has interesting but very different optimization strategies for speed and size. Is this be something that would be frowned upon by the CGSE community?
• Is the challenge clear enough as stated?
• Should I add more/larger test cases? Or a test case generating Python script?

# Isomorphic Modular Arithmetic

For this question, we define $$\U(n)\$$ as the group consisting of a number below $$\n\$$ that is coprime to n (1 included but 0 doesn't) and multiplication as group operator.

Your task is to print every integer (so it's an infinite loop, but there should be output during looping) and group it into lines so that:

1. The line consists of a sequence of sorted number so that the $$\U\$$ group based on each number is isomorphic
2. The output itself has to be sorted based on the first number on each line
3. Every number have to be eventually outputted given enough time.

A pair of groups $$\(X,\times_A)\$$ and $$\(X,\times_B)\$$ is called isomorphic if there is a pair of functions $$\f : X\to X\$$ and $$\g:X\to X\$$ so that:

$$\ f(g(x)) = x = g(f(x)) \text{ (i.e. they are inverses)} \$$

$$\ f(x) \times_B f(y) = f(x \times_A y) \$$

$$\ g(x) \times_A g(y) = g(x \times_B y) \$$

The shortest code wins.

## Example

U(2) consists of only one element 1. U(3) and U(4) is isomorphic because both contains only 2 elements (former 1, 2 and latter 1, 3. 2 is excluded because 2 divides 4) and the table of multiplication is identical aside of replacement of 2 and 3. Less trivially U(8) and U(12) is isomorphic, but not U(5) the elements of U(8) is 1,3,5,7 the elements of U(12) is 1,5,7,11 the elements of U(5) is 1,2,3,4 Look at the table of multiplication:

    U(8)          U(12)          U(5)
1 3 5 1       1  5  7 11     1 2 3 4
1 1 3 5 7    1  1  5  7 11   1 1 2 3 4
3 3 1 7 5    5  5  1 11  7   2 2 4 1 3
5 5 7 1 3    7  7 11  1  5   3 3 1 4 2
7 7 5 3 1   11 11  7  5  1   4 4 3 2 1


By replacing 1 <-> 1, 3 <-> 5, 5 <-> 7, 7 <-> 11, the table of multiplication for U(8) and U(12) is identical. U(8) and U(5) is not, as n * n = 1 for any n in U(8), but 22 = 4 and 11 = 1 in U(5). If there is such a pair f : U(8) -> U(5) and g : U(5) -> U(8), then g(22)=g(4) <=> g(2)g(2)=g(4) <=> 1 = g(4) <=> g(1) * g(1) = g(4) <=> g(11) = g(4) <=> f(g(11)) = f(g(4)) <=> 1*1=4 <=> 1=4, which is a contradiction.

Even less obviously U(7) and U(9) are isomorphic, the multiplication table is:

   U(7)           U(9)
1 3 2 5 4 6   1 2 4 5 7 8
3 2 6 1 5 4   2 4 8 1 5 7
2 6 4 3 1 5   4 8 7 2 1 5
5 1 3 4 6 2   5 1 2 7 8 4
4 5 1 6 2 3   7 5 1 8 4 2
6 4 5 2 3 1   8 7 5 4 2 1


Aside of swapping the row and column (has been done) and relabeling, the multiplication table is identical, So, they are symmetric

Output for 2-15

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

• Your opening sentence doesn't quite define a group. Do you mean a group generated by the coprime and multiplication? It seems like the most logical choice.
– Grain Ghost Mod
Nov 24 '20 at 14:55
• I am starting to doubt that since the result is always isomorphic to the integers under addition, and completely ignores n. Do you maybe mean the group generated by the coprime and multiplication on the cyclic group of order n? This makes more sense, but not a whole ton of sense. I think if you explained the output requirements more directly it would be easier. As it stands I do not understand them at all.
– Grain Ghost Mod
Nov 24 '20 at 15:19
• @WheatWizard I mean group generated by coprime and multiplication on the cyclic group of order n Nov 25 '20 at 10:43
• You still haven't actually changed the problem statement.
– Grain Ghost Mod
Nov 28 '20 at 21:04

This is just a general idea, I don't know how you would go about scoring it or what the goal would be, but I think it would be fun to see stuff like oop in haskell.

• Reminds me of infix expression in Factor (it's funny because Factor is a stack-based language) Nov 29 '20 at 23:03

## Golfing on a Budget

Every answer should take a positive number as input, and print/return every number in reverse down to zero (inclusive), in any reasonable format. For example:

10    -> "10 9 8 7 6 5 4 3 2 1 0"
8     -> [8, 7, 6, 5, 4, 3, 2, 1, 0]
1000  -> [["1", "0", "0", "0"], ["9", "9", "9"], ["9", "9", "8"], ...]


## The requirements

Every program has $100 to spend. The cost of each byte is determined by $$\2^{t-1}\$$, where $$\t\$$ is the number of times the byte has appeared in previous programs in addition to the current one. For example, assuming it's the first program, x->x++ would cost$10. Each - and > are $1, and each x and + are$2.

• In some sense, doesn't this become a contest of speed to solution? The earlier I post, the lower my score. It also severely advantages certain languages that don't use ASCII. Dec 3 '20 at 4:17
• Also, what's the criteria for winning? What is the reason for the \$100? Dec 3 '20 at 4:25
• @Xcali This is currently a very rough idea, so I didn't have any winning criterion decided on yet. What I was trying to do was make it so that it would be harder to come up with valid answers as time went on, but I think the execution ended up really bad here. Dec 3 '20 at 4:27