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

# Golf me a Bookmarklet Quine

Given a javascript program (or any utf-8 text) of arbitrary length, output it in my simplified version of URI form, like a bookmarklet. You can use https://mrcoles.com/bookmarklet/ as reference. Output should be in the form

javascript:[input with percent-encoding for special characters]

Special characters are any character that is not

• Alphabetic (upper or lower)
• a digit
• the characters .,-,_, or ~ (period, hyphen, underscore, tilde)

Your program "should convert all other characters to bytes according to UTF-8, and then percent-encode those values"w

A percent-encoding mechanism is used to represent a data octet in a component when that octet's corresponding character is outside the allowed set or is being used as a delimiter of, or within, the component. A percent-encoded octet is encoded as a character triplet, consisting of the percent character "%" followed by the two hexadecimal digits representing that octet's numeric value. For example, "%20" is the percent-encoding for the binary octet "00100000" (ABNF: %x20), which in US-ASCII corresponds to the space character (SP). source

Lowercase hex is okay, but uppercase is preferred.

This is code golf, standard loopholes are prohibited, programs should handle input up to 20 lines and output in a single line.

## The Twist (so it's not a duplicate)

If run with no input or just a newline (your choice), the program should output itself in the same format as if the program's source was inputted normally.

## Examples

In                                              Out

[blank]                                         javascript:[the%20program%27s%20source]
g/re/p                                          javascript:g%2Fre%2Fp


## sandbox questions

• What tags does this need?
• Are my examples inconsistent?
• What parts of the challenge are redundant?

Comment: might be too similar to previous mutual quine challenge?

## Collaboration/quasi-quine challenge

Write a valid submission (A) which prints the code for another competitor's valid submission (B). The languages used in A and B must be different.

### Clarifying rules

If B prints the code for a third submission, C, it is not required that A and C be different languages. Similarly, the authors of A and B must be different, but A and C need not be. (More different languages/authors score higher, however.)

The shortest chain is for A to print B and B to print A.

Note that if A prints B, and B prints C, but C is not valid for some reason, then neither A nor B are valid either.

It is acknowledged that the validity of your submission may change over time, due to factors beyond your control. Try not to let this worry you too much. :)

None

## Output

Just the code described above. Nothing extraneous.

## Scoring

Scoring is (A + L) * 100 + C where:

• A is the number of distinct authors that directly or indirect print your solution. So if you are Q, and Z=>X=>Q=>X, your "A" is 2. (Each submission only has one author, the "answerer".)
• L is the number of distinct languages in your quine circle, along the same lines as for authors. (Each submission only has one language. "Distinct" means really different, not just different versions or implementations of the same languages.)
• C is the length of your solution in bytes.

(So, for a given circle of quines, all the submissions will have similar scores, with the length of the submission as tie-break.)

Standard loopholes are forbidden.

• I like it when your score improves if you use more languages. Any reason why you didn't include that? Apr 30, 2020 at 21:51
• Oh, what would an example of that be? I did consider something like having your score improve, the longer the chain is. Like, your score is the sum of the length of all the submissions divideded by the square of the number of participants or something. May 1, 2020 at 2:09
• That would be nice, but I wouldn't know how to balance it well. Just a thought. May 1, 2020 at 17:46
• This seems to me like a chicken-and-egg situation. How could the first posted answer be valid if there are no B answers to print the code for? May 25, 2020 at 15:35
• This is another similar challenge. It had several problems that I think might occur again with your current setup. I'd recommend giving the criticism and answers there a read over. May 25, 2020 at 20:45
• @mathjunkie It wouldn't. I don't think that's inherently problematic, it's just an interesting bootstrapping challenge. May 26, 2020 at 1:00

# Price this word code-golfnumberstring

So, I'm going shopping in the Word Market™. There are shelves of words which I can buy around me, but I only have one dollar bills and the change machines at the market are broken. To add to the problem, there are words with... non-word characters in them. That's no good, I can't buy those... can you help me figure out which words I can buy and which I can't?

So, I can only buy words that consist of only alphabetical characters and are worth a dollar. To determine a word's value, you have to sum the letters in the word where A = 1¢, B = 2¢... to Z = 26¢. I'm too lazy to look at the output and judge whether it is equal to one dollar (100 cents), so you'll need to return a specific value for words equal to a dollar (...or 100 cents) and a specific value for not equal to a dollar (I'm going to stop including this).

I'll also offer a bonus byte reduction: if your code returns whether the word is less than a dollar, equal to a dollar, greater than a dollar, or invalid (e.g. <, =, >, x), your score will be multiplied by 3/4.

SANDBOX NOTE: Is this a balanced bonus value?

## Examples

Word          Non-bonus value     Bonus value

a                  false               <
b                  false               <
printera           false               >
\$word              false               x
printer            true                =


And here's a JavaScript snippet you can use if you want to check for non-bonus validity:

(it's also 52 bytes; you can use it by calling f())

f=s=>([...s].map(x=>a+=parseInt(x,36)-9),a==100),a=0


Anyways, standard loopholes apply, shortest answer in bytes wins (but I'll add shortest answers for esoteric and functional languages)... you get the idea.

• In general, bonuses in code golf are seen as something to avoid May 28, 2020 at 2:45
• Standard Loopholes May 28, 2020 at 2:46
• This challenge doesn't seem interesting to me. We've already have plenty of challenges about summing up characters in a string, and having to determine whether a string contains non-word characters just seem like tacked on challenge that makes the whole thing more cumbersome. May 28, 2020 at 15:40
• What's a bit ironic about this is that after you posted this you went on to write a program that went through words in the English language and summed up their values depending on what character they were, sharpness of a word May 28, 2020 at 20:53
• Never say I like the sharpness challenge either. :P But I do think that that challenge is a bit more interesting, due to the somewhat arbitrary mapping of letter to values. Yours just straight up uses the vanilla alphabetical order. May 29, 2020 at 14:53
• You do have a point; in Jelly or 05AB1E there's probably a builtin that would sum up a string based on values like I want people to do. May 29, 2020 at 21:50

# Magic card trick: Hide information by flipping cards

(This is inspired by a series of questions on puzzles.stackexchange.com: 10, 8, 7)

Fix two integers m and u. Your task is to perform the following magic trick:

• A Magician brings a pack of m distinct cards, and leaves the room.

• In their absence, a volunteer from the audience shuffles the deck and arranges all cards in a line, in any order they want.

• Still in the absence of the magician, their assistant flips u cards. On the table are the n cards, still in the order chosen by the volunteers, but u are face down, leaving only mu cards face up.

• The magician returns, and from the order of the cards alone, knows each card.

### Input:

m - number of cards.

u - number of cards to flip face down.

• You may assume 0 < u < m.

### Output, if the trick is possible for m and u:

f - an mapping assigning to each sequence the order the assistant will create by flipping cards.

• If the trick is to work, this mapping must be bijective.
• Use the integers 1...m (or 0...m−1), or single letters as card values.
• Use any meaningful way to express f: a hash maps, a table, a function.
• Use a fixed placeholder for any face-down cards.

### Output, if the trick is impossible for given values of m and u

This case should be indicated in a meaningful way.

### Example output (m=3, u=1):

Using the digits 0, 1, and 2 as cards, and _ for their flipside:

012 01_
021 0_1
102 _02
120 12_
201 2_1
210 _10


(For these values of m and u, this isn't very impressive as a magic trick, of course.)

### Example output (m=4, u=2):

Using 1, 2, 3, and 4 for the cards and 0 for their flipside, and a JSON representation:

{"1234":"0034","1243":"0043","1324":"0024","1342":"0042","1423":"0023","1432":"0032",
"2134":"0104","2143":"0103","2314":"0014","2341":"0041","2413":"0013","2431":"0031",
"3124":"0120","3142":"0102","3214":"0204","3241":"0201","3412":"0012","3421":"0021",
"4123":"4003","4132":"0130","4213":"0203","4231":"0230","4312":"0302","4321":"0301"}


This is correct because as required, the keys are all permutations of 1234, each value has two cards face-down and the other cards match the original sequence, and each value appears only once.

## Scoring

This is code-golf. Shortest solution wins.

• I think I should not allow all that input/output flexibility and require some fixed format. For example: input is u and a string whose (unique) characters are the decks. Require _ as placeholder. Require a fixed table format. May 29, 2020 at 4:27
• There were some clarity issues I had while reading this, but as is I think this has a much bigger problem. It seems very likely to me that outputs for large m will be prohibitively difficult to verify, given the complexity of the proofs from the related puzzling challenges. There are many ways you could approach this, like upper bounding m, making this a test-battery, or making a code-challenge where the goal is to find the maximum u for the highest m. There are probably other ways to handle this, so these are just some starting ideas. Thanks for using the sandbox! May 29, 2020 at 19:23
• Thank you for the valuable feedback @FryAmTheEggman. The proofs from the linked puzzles are long because they're reasoning & looking for insight. To just verify the list, two steps are sufficient: verify that f*(*x) is obtained from x by replacing u symbols with _, and that f is a bijection and defined for all permutations. Non-golfed solution including full tests . The output will still be huge, no chance of cursory manual verification. I didn't know about alternatives to code-golf, actually! I'll be looking into these. May 29, 2020 at 21:44
• No problem! I do want to clarify though - I was aware of the ability to prove by exhaustion when I posted my first comment. However, I did base my assessment of it being a true problem around you not wanting a completely naive brute force search through each strategy, which I see now wasn't correct, so if you are fine with that then there isn't really a problem. But of course, if you want anything besides those solutions I'd recommend looking into what I suggested, or asking in our chat room for other people's points of view. May 29, 2020 at 22:43

# _

• What kind of numbers can be in the sequence?
– xnor
May 22, 2020 at 10:30
• @xnor Integers, basically.
– user92069
May 22, 2020 at 10:35
• Would the test cases that time out, 1,2 and 7,4, be excluded by "the input will always be provided in a way such that it won't take forever to zero the accumulator"? No product of exclusively odd numbers can end up being divisible by a power of 2. May 23, 2020 at 9:35
• @UnrelatedString Thanks for nothing that; I've removed these test cases.
– user92069
May 23, 2020 at 9:46
• Now this post is zeroed eventually
– l4m2
Jun 5, 2020 at 1:36

# Mobile games money representation

In many mobile clicker games where the player is usually required to tap on the screen to make money (in order to buy upgrades for you to generate money faster), it gets to a point in the game that the money made per second is so big that if represented in its "normal" form, it would clutter the mobile screen. Imagine showing the user that they are making $$\1,000,000,000,000,000,000,000,000\$$ per second in a small mobile phone screen!

From my experience as a regular player of these type of games, I have noticed that most of them represent bigger numbers by using letters. If the number of money per second is a number less than $$\10,000,000\$$ then print the number as is. Otherwise, if the number is in the millions (but $$\ \geq 10,000,000\$$), for example $$\ 102,000,000\$$ it should print $$\102M\$$. If it is in the billions, it should print $$\102B\$$. You should use $$\T\$$ for trillion and $$\Q\$$ for quadrillion.

As you can notice, the next would be quintillion which would also use the letter $$\Q\$$ if followed the pattern. Instead of following this pattern which can be confusing at one point, game developers usually start a new pattern: Quintillion is used with the suffix $$\AA\$$, sextillion is $$\AB\$$, septillion is $$\AC\$$ and so on.

Notice that this pattern would go until $$\AZ\$$ and if the player is making more money than that, it would start from $$\BA\$$, $$\BB\$$, ..., $$\BZ\$$, ...,$$\ZA\$$, $$\ZB\$$, ... , $$\ZZ\$$ which for our problem we will assume is the limit one player can make per second.

Given an integer $$\x\$$ where $$\0 \lt x \leq 999\$$ and a natural number $$\y\$$ where $$\y \gt 0\$$ representing the number of zeroes the number has, output the number in a "mobile game money representation" as described above.

# Observations

• The number of zeroes that $$\y\$$ represent does not include the possible zeroes $$\x\$$ might have! Example: if $$\x = 100\$$ and $$\y = 6\$$, you should output $$\100M\$$ and not $$\1,000,000\$$

# Test Cases (x, y --> game money representation)

100,  6 --> 100M
100,  5 --> 10M
100,  4 --> 1000000
1,   12 --> 1T
10,  12 --> 10T
100, 12 --> 100T
1,   18 --> 1AA
10,  18 --> 10AA
100, 18 --> 100AA


# Meta questions

1. Is this a duplicate? I have looked around but didn't find anything similar.
2. Is the wording confusing? I'm open to recommendations!
3. I haven't written a program yet so the test cases might be wrong (I'll add more later).
4. Pretty much any feedback is appreciated!
• Looks like it needs some test cases with decimal points, e.g. 123, 17 -> 12.3AA. Jun 1, 2020 at 0:20
• Shouldn't 100, 4 become 1M? Jun 1, 2020 at 13:03
• @SurculoseSputum In these games, when the number is small enough (as I said in the second paragraph), if the number is less than 10 million, then it is printed in its "normal" form. The abreviations starts after 10 million. Jun 1, 2020 at 19:33
• Suggest cases where $y$ don't just go the AA
– l4m2
Jun 19, 2020 at 4:24
• Thanks all, I'm pretty busy lately unfortunately. Whenever I get the time I'll try to update the challenge Jun 19, 2020 at 21:59

# Shift the letters, soldier !

posted, finally

• Thank you for sandboxing this. I usually recommend doing so for at least a week, and periodically ask for review in TNB.
Feb 28, 2020 at 9:09
• I think people would be forced to do the bonus in this case because of the -30% margin. I got a 42 without bonus but a 57*0.7=39.9 with bonus in JS. Feb 29, 2020 at 3:16
• Bonuses are discouraged for a variety of reasons. I would strongly recommend either making it mandatory or completely leaving it out. Mar 1, 2020 at 18:58
• The main challenge is add by position, the bonus challenge is minus by position. So it's a good idea to completely leave the bonus out.
– user92069
Mar 2, 2020 at 0:29
• Thanks for the comments, I'll remove the bonus as it will never be balanced enouth to be interesting. I'll add some example as soon as I can. Mar 3, 2020 at 20:02
• I would say that allowing the usage of the ascii range 1 to 255 or a language's code page could allow for some interesting golfs :)
– RGS
Mar 3, 2020 at 20:39
• Use asciii values from 0 to 255 was my original plan, but I'm afraid some interestings languages would be disadvantaged. Also, wouldn't the usage of language's code page be too permissive ? Mar 4, 2020 at 15:51
• @Therandomguy it depends on what you mean by "too permissive". Sometimes it is done, as it may allow some languages to do some funny things. As to the range being from 0 to 255, I don't see it hurting any language at all, but of course I may be missing something :)
– RGS
Mar 4, 2020 at 21:36
• Are you interested in re-posting it?
– user92069
Mar 6, 2020 at 7:38
• This weekend I'll post it, I just need some time creating the examples Mar 6, 2020 at 8:25
• I'd be glad to see it posted in Main!
– user92069
Mar 25, 2020 at 12:19
• Finally posted it in main Jun 3, 2020 at 7:45

# Compute the pointiness, sharpness and smoothness of a letter code-golfkolmogorov-complexity

Inspired by Determine the sharpness of a word.
You are given an uppercase letter of the English alphabet as input. You have to compute (and output) its pointiness, sharpness and smoothness. Since it is difficult to define these objectively, here's a table of the outputs:

            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
pointiness: 2 0 2 0 3 3 2 4 4 2 4 2 2 2 0 1 1 2 2 3 2 2 2 4 3 2
sharpness:  1 2 0 2 2 1 1 0 0 1 0 1 3 2 0 1 0 1 0 0 0 1 3 0 0 2
smoothness: 0 2 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 2 0 1 0 0 0 0 0


Transposed version (first lists the letter, then the pointiness, then the sharpness and then the smoothness) (like a true CGCC user, I transposed it with Jelly and added spacing with Retina):

A 2 1 0
B 0 2 2
C 2 0 1
D 0 2 1
E 3 2 0
F 3 1 0
G 2 1 1
H 4 0 0
I 4 0 0
J 2 1 1
K 4 0 0
L 2 1 0
M 2 3 0
N 2 2 0
O 0 0 1
P 1 1 1
Q 1 0 1
R 2 1 1
S 2 0 2
T 3 0 0
U 2 0 1
V 2 1 0
W 2 3 0
X 4 0 0
Y 3 0 0
Z 2 2 0


Bonus imaginary internet points if you find a language where this is built-in.

This is tagged , so the shortest answer wins.

# Sandbox stuff

• Is this not a duplicate?
• Is the table computed correctly? (the only ones that don't seem certain with the current font are I's pointiness, G's sharpness and S's smoothness)
• After fiddling about a bit, I think this should probably have enough patterns that mindlessly compressing the numbers won't be the best strategy. Still, I could be wrong, but here is what I used to see roughly how long such an approach would be (I encoded each set of values to a base 5 number, then in turn encoded that list of numbers into a base 61 number). Separately, you probably want to include the data in a more copy-pastable way. Jun 3, 2020 at 20:34

# Is this a simple cutting template?

A simple cutting template is a rectangle that can be recursively cut into smaller rectangles using only full-width cuts.

If you prefer a bottom-up description, then:

• A single rectangle is a simple cutting template with 0 cuts.
• Two simple cutting templates of the same width (or length) can be joined along their common side into a larger simple cutting template.

Input: A diagram of a rectangle subdivided into smaller rectangles, or a list of rectangles in some standard format, e.g. position and size.

Output: A truthy value if the diagram is a simple cutting template.

Note that if you take input as a diagram then all of the rectangle edges will use the same character, whearas in the truthy examples below, some of the edges have been replaced with digits to show a possible ordering of cuts while the falsy examples have the smallest portion of the input that is not a simple cutting template marked on them.

####2################
#   2               #
111111111111111111111
#                   #
#                   #
#                   #
111111111111111111111
#     2   2   2 4 4 #
3333332   2   2 4 4 #
# 4   2   2   2 4 4 #
# 45552   2   2 454 #
# 4 6 2   2   2 4 4 #
# 4 6 2   2   2 4 4 #
# 4 6 2   2   2 4 4 #
33333323332   2 4 4 #
#     2   2   2 4 4 #
#     23332   2 4 4 #
#     2   2   2 4 4 #
#     2   2   233333#
#     2   2   2     #
######2###2###2######


-> Truthy

##2#####4############
# 2     4           #
# 2333333333333333333
# 2         6     4 #
# 25555555555555554 #
# 2 6   6     8   4 #
# 2 6   67777777774 #
# 2 6   6         4 #
# 2 6   6         4 #
# 2 6   6         4 #
111111111111111111111
#               2   #
#               2333#
#               2   #
111111111111111111111
#   2             2 #
#   233333333333332 #
#   2 4 4     4   2 #
#   2 4 4555554   2 #
#   2 4 4     4   2 #
####2#############2##


-> Truthy

#####################
#                   #
#                   #
#                   #
111111111111111111111
# 2   4           2 #
# 2   4           2 #
# 2   4           2 #
# 23333333333333332 #
# 2     4   4 6 4 2 #
# 2     45554 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 4 6 4 2 #
# 2     4 6 45554 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
# 2     4 6 4   4 2 #
##2#####4#6#4###4#2##


-> Truthy

#####################
#               # # #
################# # #
#               # # #
#               # # #
#               # # #
?????????############
?     # ?     #     #
?     # ?     #     #
?     # ?     #     #
?     ##?     #     #
?     # ?     #     #
?###### ?############
?     # ? #       # #
?     # ? #       # #
?     # ? #       # #
?###### ?##       ###
? #   # ? #       # #
? ######? #       # #
? #     ? #       # #
?????????############


-> Falsy

?????????????????????
?     # # # # #     ?
?###### # # # #     ?
?     # # # # #     ?
?     # # # # ######?
?     # # # # #     ?
?###### # ##########?
? #   # # #         ?
? ##### # #         ?
? # # # # #         ?
? # # # # #         ?
? # # # # #         ?
? ####### #         ?
? #     # #         ?
? #     ############?
? #     #     #     ?
? #############     ?
? #     #     #     ?
? ##################?
? #         #       ?
?????????????????????


-> Falsy

#####################
#       #   #     # #
################### #
#                 # #
#####################
# #                 #
# ###################
# #   #             #
# ###################
# #   #     #       #
# ###################
# #                 #
# ???????????????????
# ?   #             ?
# ?   #             ?
# ?   #             ?
# ?   ##############?
# ?   #   #         ?
# ?########         ?
# ?       #         ?
##???????????????????


-> Falsy

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

• I think you should include an explicit definition: 'A simple cutting template is a rectangle that can be recursively cut into smaller rectangles using only full-width cuts.' Jun 6, 2020 at 4:06
• @Dingus Thanks for pointing that out, I think I must have accidentally edited it out by mistake when writing the sentence for the output.
– Neil
Jun 6, 2020 at 10:29
• I'd prefer one or two small examples with extra markings and then a list of copy-pasteable test cases. Jun 6, 2020 at 11:13

## Backstory

A doctor in Berlin, after analyzing his medical history, has realized that all of the results of his integral measurement results can be represented in the form of $$\23x+28y\$$, where $$\x\$$ and $$\y\$$ are integers.

However, he could have extended his theory. $$\23\$$ and $$\28\$$ can be replaced by any two coprime numbers, and this theory would still hold. (He didn't have time to write his theory in a paper, that's quite awful.)

Without examples, I'll never be convinced that this nonsensical theory holds!

Given $$\the\ output\ of\ (ax+by)\$$ (let's call it $$\z\$$), $$\x\$$, and $$\y\$$, find the smallest pair of $$a,\ b)\$$ that makes $$\ax + by = z\$$ true. ## Example cases   ## Duplicate of Find the minimum edit distance between two strings ## Partition distance code-golfstring Quoting Anush: I am very glad to provide a service to fill in the terrible gap in edit distance questions which codegolf.se has had. When there are as many edit distance questions as quine questions my job will be done. --Anush ## Task Given a binary string consisting only of 0's and 1's, partition the binary string (divide the string into consecutive substrings), and determine the minimal edit distance in order to transform one piece into another, left to right. You need to output the sum of the edit distances between consecutive blocks. ## Example I'm going to make a reference implementation to find the optimal partitions. But that's after I dump all my ideas, though. 011010110111 We partition the string like this: [011][010][110][111] And then find the cumultative edit distance between each 2 pairs of partitioned strings: [1 1 1] Then, we sum the list of partitions. [3] So 3 is a possible output for this binary string. However, you need to find the minimum edit distance, so this might not be the correct answer.  ## Another example 001001010 We partition this string: [001][001][010] And then find the mimimal edit distance between each piece. [0 1] Therefore, our (non-optimal?) output for 001001010 is 1 ([0 1] summed).  ## Rules • The edit distance between two strings is the minimum number of single character insertions, deletions and substitutions needed to transform one string into the other. • The input is guaranteed to have at least length 3. • The pieces of your partition don't have to be the same length. • What do you mean by "partition the input string"? Can I choose any partition I want as long as it's not all singletons or the entire thing? Or do I have to find one that's optimal in some sense? Why is the all-singletons case disallowed? Is the output the sum of the edit distances between consecutive blocks? From the examples I guess it is but you should say it explicitly. May 31, 2020 at 18:50 • @Zgarb "partition the input string" means divide the input string into (not necessarily equal) consecutive substrings. You need to find one that's optimal, I've emphasized that. I allowed the all-singleton case; I specified that the output is the edit distance sum between consecutive blocks explicitly. – user92069 Jun 7, 2020 at 4:36 • It should still be made clearer that the output is the minimum over all partitions. Jun 7, 2020 at 20:21 # Compute the factorial, on both sides of 0 Why, why, why do factorials stop at zero? (Yes there are actual reasons). Make a factorial function (or full program) that doesn't stop at zero! Your code-golfed program should, given an non-zero integer n (can be positive or negative, the rule still applies), find the product of the range n to -n excluding 0. Graph that at least works for positive numbers ### Sample IO  Input | Output ----------------|------------ 0 | 1 (product of 0 and -0 without 0 / empty product) 2 | 4 (2*1*-1*-2) 3 | -36 (3*2*1*-1*-2*-3) 4 | 576 (4*3*2*1*-1*-2*-3*-4) -4 | 576  Probably not a duplicate, but it might not be that much of a challenge. • Would the input always be positive? Is n=0 a possible input? Jun 11, 2020 at 23:02 • @Bubbler For now I'll say 0 is undefined, might change it later before posting if I have a good idea. Jun 12, 2020 at 13:53 • As it is, isn't this always the factorial of the absolute value of the input squared, then made negative if the input is odd? - except in the edge case for zero? The sign of the input doesn't really appear to matter, which is an odd feeling. Jun 12, 2020 at 16:24 • @FryAmTheEggman Yes, see this graph of the values. Is that a bad thing? Do you have a better suggestion? Jun 12, 2020 at 20:44 • "downvotes mean nothing but rudeness" - I downvoted this because I do not think "compute $|n|!^2 \cdot (-1)^n$" is a good challenge. I can't see how disagreement is rude. The requirements here seem completely arbitrary to me. This will result in the exact same approaches as were used in the factorial challenge. Jun 14, 2020 at 8:27 • I think it is a bad thing in that it becomes dangerously close to a dupe of the factorial problem. I probably wouldn't hammer it immediately, but if most of the responses basically worked for both or many others had the same concern I'd probably close it. I'm not sure of a good way to modify this to be better, so unfortunately I don't have any suggestions at the moment. I will let you know if something occurs to me. Jun 15, 2020 at 20:09 • @FryAmTheEggman I wouldn't consider it a dupe but I wouldn't consider it a good question after all based off of what my pronoun is monicareinstate said. Jun 16, 2020 at 21:47 • If you consider 0 as a valid input, I suggest that its expected output be 1, which corresponds to the empty product (Wikipedia). Jun 17, 2020 at 3:52 • For the interesting-ness, I believe it can be interesting in at least some languages (which IMHO justifies the value of having such a challenge). FWIW, I have two J solutions of equal length, one using the factorial built-in ! and the other not using it. Jun 17, 2020 at 3:53 • I'd likewise close this as a duplicate, but I'm known for having much broader standards than the rest of the community about what questions are closeworthy, so make of that what you will. Jun 18, 2020 at 2:38 • I'll just abandon this, but if @Bubbler wants to post it, they can. Jun 18, 2020 at 21:17 # Default Lightning Strike ## Introduction: Inspired by this reddit question: ELI5: Why does lightning travel in a zig-zag manner rather than a straight line? Although it's more complex than this, in general multiple lightning paths will randomly check its immediate surrounding for the direction with least resistance (based on air pressure, temperature, composure, humility, etc.) and travel in that direction. As soon as one of the paths reaches the ground, that entire path has the least resistance and most (although not all) of the ions will accumulate in that path, causing the lightning flash and thunder. Here a slow-mo video of a lightning strike to get an idea. ## Challenge: Input: An integer $$\h\geq3\$$ and an integer $$\1\leq p\leq\left\lfloor\frac{h}{2}\right\rfloor\$$ Output: Each step of the ASCII animation of a lightning strike, with a cloud to earth height of $$\h\$$ and up to $$\p\$$ paths We start with a lightning ion at the cloud, with a lowercase letter of your own choosing (i.e. b). This ion will travel in a random direction (horizontally, vertically, or (anti-)diagonally), except where this path itself comes from. Every 'tick' it also has a 20% chance of branching out into two paths, as long as we haven't reached $$\p\$$ paths yet. Each of these paths will behave the same. As soon as any path hits the ground based on the height $$\h\$$, all letters of that particular path will become uppercase, and in the final 'tick' after that, only this uppercase path will remain. ## Challenge rules: • Paths can intersect with other paths • Paths can travel upwards beyond the height of our starting point • Output can be in any reasonable format. Could be a list of multi-line strings for each 'tick'. Could be a list of character-matrices for each 'tick'. Could be pretty-printed to STDOUT (with clear non-whitespace separation between each 'tick' - i.e. a single character like a comma or semi-colon, or a line of --- or ___) • Trailing spaces for each line of a tick are optional (leading as well, as long as the lightning bolts are still correct) • If multiple paths strike the ground in the same 'tick', only the first one of those two (or more) paths will become the lightning strike. The order in which paths are created are therefore important, so keep that in mind. ## Examples: This may all sound pretty vague, so here a couple of examples: (I've added trailing spaces for each step with spaces, but you don't necessarily have to do so as mentioned in the challenge rules.) Example 1: $$\h=3, p=1\$$ Tick 1: "b" " " " " Tick 2 (random direction: right): "bb" " " " " Tick 3 (random direction: up-left): "b " "bb" " " " " Tick 4 (random direction: down-left): " b " "bbb" " " " " Tick 5 (random direction: down): " b " "bbb" "b " " " Tick 6 (random direction: up-right): Note that this overlaps with a previous step in this path, which is fine. " b " "bbb" "b " " " Tick 7 (random direction: down-right): " b " "bbb" "b b" " " Tick 8 (random direction: down): " b " "bbb" "b b" " b" Tick 9 (lightning strike): " B " "BBB" "B B" " B" Tick 10 (extra tick to remove all other paths, although there are none right now): " B " "BBB" "B B" " B"  Example 2: $$\h=5, p=2\$$ Tick 1: "b" " " " " " " " " Tick 2 (random direction: down-left): " b" "b " " " " " " " Tick 3 (random direction: down-left): " b" " b " "b " " " " " Tick 4 (random direction: right): " b" " b " "bb " " " " " Tick 5 (random 20% path split; random direction 1: top-right, random direction 2: right): " b" " bb" "bbb" " " " " Tick 6 (random direction 1: top-left, random direction 2: down): " bb" " bb" "bbb" " b" " " Tick 7 (random direction 1: left, random direction 2: down-right): "bbb " " bb " "bbb " " b " " b" Tick 8 (lightning strike of path 2): "bbB " " Bb " "BBB " " B " " B" Tick 9 (extra tick to remove all the other paths, which is path 1 in this case): " B " " B " "BBB " " B " " B"  ## General rules: • This is , so shortest answer in bytes wins. Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call. • Default Loopholes are forbidden. • If possible, please add a link with a test for your code (i.e. TIO). • Also, adding an explanation for your answer is highly recommended. # Sandbox Questions: • Should I perhaps use a different letter of the alphabet per path? • If yes: what would happen when different letter-paths overlap? I assume the top one will be visible per 'tick', but if lightning is struck it should still change it to the underlying letter as uppercase. In either case, you'll have to keep track of each individual path and uppercase only the one that struck the ground (first). • Any additional rules or things that are unclear? • An additional relevant tag? • More examples with more paths and/or larger height? • A different path percentage instead of hard-coded $$\\frac{1}{5}\$$ / 20%. # Sort numbers using as few distinct bytes as possible ## Task Write an algorithm that takes as input an ordered list (array, linked list, etc...) of numbers and outputs an ordered list containing the same numbers sorted by their value (ascending or descending). The numbers may be represented using the most convenient format to you, with the only restriction that there must be a way to encode 256 distinct numbers. You are not allowed to use built-in sorting functions/algorithms. ## Scoring criteria Let $$\c\$$ be the number of distinct bytes in your code* and let $$\s\$$ be the number of bytes in your code*. *Or its UTF-8 representation The score is equal to $$\c^2 + s\$$. The answer with the lowest score wins! Examples (imagine these are sorting algorithms): • ababccbaacbabcba$$\c=3, s=16, score=25\$$ • aAbcd€f$$\c=9, s=9, score=90\$$ • bytes 16 ee 3c 79 ee$$\c=4, s=5, score=21\$$ I'm open to suggestions, especially about the score formula. • I see that this is your first attempt at writing a challenge. Thank you so much for using the sandbox! – Adám Jun 25, 2020 at 22:16 • Please note that it is very hard to write good challenges that restrict solutions from certain things. This is because it is hard to define exactly what is prohibited in every language, and it is also hard to determine if any prohibited feature was used. – Adám Jun 25, 2020 at 22:19 • @Adám So how should I prevent trivial answers? Maybe "built-in sorting functions/algorithms" is a bit vague. Jun 25, 2020 at 23:04 • We don't prevent trivial answers in most cases. Btw, if I accept plain numbers as input, may I assume the input is a list of integers between 0 and 255 inclusive? Jun 25, 2020 at 23:46 • How about this: "You are not allowed to use any built-in function/command that can take an ordered container and output the sorted result. Anything else is OK." Jun 25, 2020 at 23:54 • I think a good solution would be to allow built-in solutions, but to compile (in advance, so that it can be posted very quickly, probably via the "answer your own question" feature) a community wiki answer listing trivial 1-byte solutions. Jun 26, 2020 at 4:17 • @Bubbler Would still be unclear if J's /:~ or /:] were allowed or not. – Adám Jun 26, 2020 at 6:15 • @D.Pardal Why do you want to prevent trivial answers? – Adám Jun 26, 2020 at 6:20 • I wanted to prevent built-in functions because otherwise most answers would be exactly the same as the ones from this question. Maybe the easiest way to solve this would be to replace the task of sorting an array with another. Jun 26, 2020 at 7:15 • Yes. Banning built-in has long been considered a bad idea. Jun 26, 2020 at 11:57 # Fix mispellings code-golfkolmogorov-complexity Wikipedia has a list of common misspellings, and there is also a machine-readable version! Your challenge is to input a string and fix the mispellings in it. The parituclar list we'll be using is https://en.wikipedia.org/w/index.php?title=Wikipedia:Lists_of_common_misspellings/For_machines&oldid=962756669#The_Machine-Readable_List. Note that even if the list changes, you must use this version. Here's a pastebin link: https://pastebin.com/j03aL98d. Each line in the list is in the format INPUT->OUTPUT1, OUTPUT2, OUTPUT3, ... (of course, there may be more or less possible outputs, or even just one). That means that for input INPUT you must output exactly one of the possible outputs OUTPUT.... This is tagged , so the shortest answer wins. # Sandbox stuff Should I add more misspellings to the post, or should I remove them? • Related Jul 2, 2020 at 14:23 • @pppery While the idea is probably related, I don't think the solutions would be related at all. Jul 2, 2020 at 14:26 • What is the input format? A plain English sentence (so we need to handle spaces, punctuation, capitalization), or is a list of words acceptable? How should capitalization be handled (some entries look like Tolkein->Tolkien and UnitesStates->UnitedStates; given unkown->unknown, what is the expected output of unkown, Unkown, UNKown, Tolkein, tolkein, TOLKEIN)? Jul 2, 2020 at 23:19 • @Bubbler The input is a single entry in the list (the part before ->, of course). You do not need to handle capitalization ("tOLKEIN" is not "Tolkein"). (will clarify later). Jul 3, 2020 at 2:11 ## Overlap characters code-golf Put all the characters of a given list, following the order, in a sequence of bits keeping it as small as possible. Rules • Write the bits of each character on a line. • You can overlap bits if they are equal. • You cannot change already written bits. • Extend the line, in both directions, if not all the bits fit in. • Always try to extend as less as possible. Example input :['a','&','1','.'] 0110 0001 // a 0010 0110 // & 001 1000 1 // 1 00 1011 10 // . output :0010011000011000101110 input : "&1a." 0010 0110 // & 0 0110 001 // 1 0 1100 001 // a 0010 1110 // . output : 011000010011000101110  I/O rules • input can be any sequence of single byte elements. • output the resulting sequence of bits in any convenient method, no extraneous bits allowed (0 or 1) # Distributive on myselfcode-golfkolmogorov-complexity • Now that this has been posted to main, could you delete this proposal to create more space for new answers? Sep 25, 2020 at 1:04 # Validating Words in Word Grids A follow on from Generating Word Grids Given a grid of letters, a set of co-ordinates and a dictionary of words, validate that the co-ordinates follow only cardinal direction changes, at least one of the co-ordinates touch an empty space in the centre of the grid, the resulting word is valid given the dictionary (taking into consideration any blank tiles) and return either the grid, with the letters at the co-ordinates removed along with the score of the word, or, if one of the conditions fail, the original grid and a score of -1. ## Details Please detail the format you want to accept coordinates in any reasonable format is acceptable. ## Scoring Letters are worth their values as per Scrabble: 0 points: blank tiles 1 point: E, A, I, O, N, R, T, L, S, U 2 points: D, G 3 points: B, C, M, P 4 points: F, H, V, W, Y 5 points: K 8 points: J, X 10 points: Q, Z  Bonus tiles (indicated by a lowercase letter, or ! for a blank tile) provide a *2 multiplier and stack (eg. if my co-ordinates spell gOLf I would earn (((2+1+1+4)*2)*2), 32 points). ### Examples: Input: 6,4 6,5 5,5 4,5 3,5 3,6 2,6 1,6 UWDESTKP? ItDBaDEdI TERMDYTSR ROANJLEFT EkCI OOsT IPAJPGMNY MZLORITVI GwEGgPUeI MNROYOEER  Output: 9 UWDESTKP? ItDBaD dI TERMDY SR ROANJ FT EkCI OsT IPAJP MNY MZLO TVI GwEGgPUeI MNROYOEER  (spells RIGOLETE, (1+1+2+1+1+1+1)) Input: 0,3 0,4 0,5 0,6 UWDESTKP? ItDBaD dI TERMDY SR ROANJ FT EkCI OsT IP P MNY MZL TVI GwE gPUeI MNROYOEER  Output: -1 UWDESTKP? ItDBaD dI TERMDY SR ROANJ FT EkCI OsT IP P MNY MZL TVI GwE gPUeI MNROYOEER  (spells DEST which doesn't appear in the dictionary) Input: 5,6 4,6 4,7 4,8 UWDESTKP? ItDBaD dI TERMDY SR ROANJ FT EkCI OsT IP P MNY MZL TVI GwE gPUeI MNROYOEER  Output: 12 UWDESTKP? ItDBaD dI TERMDY SR ROANJ FT EkCI IP P NY MZL TVI GwE gPUeI MNROYOEER  (spells MOsT, (3+1+1+1)*2) ## Rules This is so the shortest code in bytes wins. • The order is not important, it can be score then grid, or vice versa. • Any reasonable format can be used for I/O assuming it is consistent. • All standard loopholes are forbidden. ## Questions for meta Things have changed a lot in the time since I originally posted this, so rather than just posting I thought I'd bump for fredback. • What would the best way of using an associated dictionary be, taking it as input? • Obviously the input format for co-ordinates can be more flexible (0-based index, 1-based index, or something) is mentioning this enough? • Grid input format can be flexible too, mentioning this should be enough too? • Any other relevant tags? • This looks pretty good to me. Sep 15, 2017 at 18:20 • Thanks @Pavel, I'll bear that in mind, i'm not sure how much interest there is based off of part 1, but I might still post this in the next week or so :) Sep 16, 2017 at 9:21 # Crazy Blazin' DOM Injection I was instructed to post this code golf challenge here for recommendations on how to modify the challenge. I'd like to tag it. fastest-code grid and browser , but I don't know how to do that here. Code golf challenge listed below. # Introduction This problem is a challenge that has to do with DOM manipulation at scale and overcoming some issues that may be inherent in dealing with the DOM. • This challenge is interesting because limitations push us to think through things differently and lean on the strengths of languages different than what we usually use. • I created this challenge myself based on a real world problem I ran into myself (details can be provided if needed). If this challenge has any relation to a differently know problem, those similarities are coincidental. This challenge will be scored based on fastest execution and fastest algorithm. A multiplier will be given for completing the challege at easy, medium, and hard difficulties. # Challenge You must render one of the challenge levels in a web browser: Through any means available to you interacting through a web browser in code you need to complete the following: 1. Get each table displayed and add a class table-n to each table where n is a zero based index of order of the table on the screen. If a table is nested within a table the parent would be N and the child would be N+1 with the next table being N+2. 2. Get each row displayed in each table and add a class of table-n-row-r where r is a zero based index of rows in the table represented by table-n. 3. Get each cell displayed in each table and add a class of table-n-row-r-cell-c where c is a zero based index of cells in a row represented by table-n-row-r. At the end of the challenge the web page should still be able to be interacted through in the browser, and a call to document.getElementsByClassName('table-n-row-r-cell-c'); should return one and only one cell from the DOM. Any method available to you as valid as long as: 1. Access to one of the difficulty levels has been done through a web browser 2. The URL of the browser and the page displayed doesn't change 3. A call to document.getElementsByClassName('table-n-row-r-cell-c'); returns only one element # Output Examples For this example we're using the easy level as input. The abbreviated output in the DOM should be. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Code Golf Challenge</title> </head> <body> <table class="table-0"> <thead> <tr class="table-0-row-0"> <th class="table-0-row-0-cell-0">1</th> ... </tr> </thead> <tbody> <tr class="table-0-row-1"> <td class="table-0-row-1-cell-0">11</td> <td class="table-0-row-1-cell-1">12</td> ... </tr> ... </table> </body> </html>  There are only <td> and <th> elements used as cell elements for the challenge. As long as document.getElementsByClassName('table-n-row-r-cell-c'); returns an element with this class. We're good to go. # Qualifying Entries All entries that qualify need to have an execution speed of under 40 seconds for any difficulty level. Timing starts when your algorithm starts, but after the page has loaded completely as all elements must be available (the browser spinner has stopped spinning). Calculate the runtime for your method by calling performance.now() before and and after your injection method, and subtracting the first from the second as in the example below. let t0 = performance.now(); doSomething() // <---- The function you're measuring time for let t1 = performance.now(); let totalTime = t1 - t0;  The medium and hard difficulty levels will have their execution time multiplied by 0.50 and 0.25 respectively. None the less, an execution time of less than 40 seconds is needed to qualify. So if the execution time on the medium difficulty was 41 seconds before the multiplier, it does not qualify. # Winner The winner will be determined by the shortest execution time for dynamic injection of these classes and where document.getElementsByClassName('table-n-row-r-cell-c'); can still be executed against the browser console and return an element where n, r, and c are replaced with indexes. • Do you mean that all entries should be written as a JS function so that it can be run inside the browser console? Which browser(s) will you be using to time it (since different browsers may have different support of JS features and the engine optimized in different ways)? Jul 20, 2020 at 2:15 • "scored based on fastest execution and fastest algorithm" is ambiguous, because fastest execution means that a constant factor in the algorithm is important, while fastest algorithm is not. I think you mean simply "fastest execution", since it seems hard to use a big-O notation in this task (should it be a function of table size or entire document size?). Jul 20, 2020 at 2:18 • All entries should be written as a JS function (I think that's the only way to achieve it). However, if there are other ways to achieve this they are welcome, but it still needs to be an active webpage pulled from the internet. So, pulling via wget or curl and manipulating it locally in something like jelly is out of the question unless Jelly can interact with the browser. We can standardize on chrome 83.0.1.x for the web browser, so that it's exactly the same for all. Jul 20, 2020 at 2:18 • It should only be fastest execution then. Let's go with that. Jul 20, 2020 at 2:19 • Also, if a submission works for all of easy/medium/hard, how is it scored? I guess the minimum of (easy time), (medium time / 2), (hard time / 4)? Jul 20, 2020 at 2:23 • If a submission works for all level (qualifies at all levels) it gets scored at the hardest level it qualifies for. Jul 20, 2020 at 2:24 • That sounds like unnecessarily penalizing possibly good submissions because it might run blazing fast on easy but more than 4x slower on hard, giving it a worse score. Jul 20, 2020 at 2:26 • I can agree with that. How do you suggest we even that out? Jul 20, 2020 at 2:27 • Personally, I think it is better to do away with the different difficulty levels. They aren't exactly the same as bonuses in code golf but most of the arguments for why we don't like bonuses apply to these difficulties, too. Jul 20, 2020 at 2:43 • I think this will work: "The submission that handles the highest difficulty within 40 seconds wins, ties broken by the time taken to complete for that test case." If the first part of the sentence is confusing, I mean "a submission that handles hard is better than one that can't". Jul 20, 2020 at 2:45 • I'll get rid of the difficulty levels. Jul 20, 2020 at 2:45 • Actually, Bubbler, what you said makes sense. I'll state it like you said and get rid of the bonus. Jul 20, 2020 at 2:48 • Still getting downvotes on the challenge. I don't know the reason why. Implemented the changes we discussed, but I guess it still doesn't meet standards? (^-^;) Jul 20, 2020 at 11:56 # 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. • If possible, please add a link with a test for your code (i.e. TIO). • Also, adding an explanation for your answer is highly recommended. ## Test 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. ## Task 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? # Task & scoring 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, 2020 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, 2020 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 function (x, mask) local result=list(); for i=1, min(x.length, mask.length) do if mask[i] then result.append(x[i]); end end return result; end  ## Example inputs and outputs // In binary: // f(x, mask) == result 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. // 16-bit variants in hexadecimal: f(BEEF, 1111) == 9 f(DEAD, 8888) == F 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 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, 2020 at 11:07
• Does the two puyo(s) in a pairstick to each other like in tetris? Aug 15, 2020 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, 2020 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, 2020 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.