# 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

To post to the sandbox, scroll to the bottom of this page and click "Answer This Question". Click "OK" when it asks if you really want to add another answer.

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
• Comments addressing specific points mentioned in the proposal
• 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!

# Pwning Passwords code-golf

Alice decided to improve the security of her website by sending first five characters of an SHA-1 hash to Bob's Leaked Password Detection Service. However, she made two mistakes that let Eve decode the passwords: sending passwords over HTTP and checking the password after each character of a password is typed. Eve asked you for help in decoding the passwords, however she cannot really program, so needs your help in implementing password cracking algorithm as a computer program or function.

Eve eavesdropped the requests for following hashes from Alice.

516B9
379FC
19C2A
9D4E1
08506
F808E
A7F93
5BAA6


How could you decode this password? Well, you can brute-force all lowercase letters. In this case the only letter whose hash starts with 516B9 is p. The hash of letter p is 516B9783FCA517EECBD1D064DA2D165310B19759.

Knowing that the password starts with p, you can brute-force the second character. In this case, the only possible character is a. The hash of pa is 379FC0D5299A71AC0F171FBB5AFB262829B4E765

You can continue to brute-force letters one by one to figure out the password was password (5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8). Well, that was simple.

Not all passwords are that simple however. Consider the following requests:

4DC7C
A84FD
467D7
BD79D
12D83


First three characters of this password are simple: rxr (467D7856C648A79A096D339A2CE5FC929658967D).

With the fourth character it gets more complicated. BD79D matches for rxrf (BD79DEC8435B8BA509A25F419F31CC2ACDE2FF0A) and rxrp (BD79DC20901B11468F8369B5B0D15894F3D96A5E). There is an ambiguity, but as it turns out, it can be resolved by trying both ways. If you assume the password starts with rxrp there is no valid letters to continue with. However, if you assume the password starts with rxrf, then it's possible to append a, resulting in rxrfa (12D83D3A429CD7D64E9A532C05C2C00C35032A94), which is a valid solution.

All passwords will be composed entirely out of lowercase letters. You can assume all inputs have a solution and there are no inputs that could possibly resolve to multiple passwords (for instance ["4DC7C", "A84FD", "467D7", "BD79D"] is an invalid input because it can match both "rxrf" and "rxrp").

There are no case requirements on the input. Your program is allowed to assume the input is lowercase. Your program is allowed to assume the input is uppercase.

The program must not take longer to execute than 24 hours for a 25 characters long password.

It is allowed to use external libraries or language built-in functions for computation of SHA-1 hash.

# Example Input and Output

This is a JSON.

[
{
"input": [
"516B9",
"379FC",
"19C2A",
"9D4E1",
"08506",
"F808E",
"A7F93",
"5BAA6"
],
"output": "password"
},
{
"input": [
"07C34",
"593B7",
"0262F",
"CED65",
"23612",
"4EF76",
"B7A87"
],
"output": "letmein"
},
{
"input": [
"84A51",
"87DDA",
"83F67",
"E6FB0",
"5157D",
"82CD7",
"6F655",
"43426"
],
"output": "codegolf"
},
{
"input": [
"7A81A",
"DB3D4",
"FE05B",
"E7280",
"32726",
"30AE9",
"2C61A",
"A9E46",
"15D98",
"F780A",
"3E949",
"F4BF2",
"6A5C4",
"C4554",
"FA2EA",
"48A40",
"5DD7F",
"5284E",
"C0B8D",
"20D59",
"9184C",
"32AD9"
],
"output": "onetwothreefourfivesix"
},
{
"input": [
"84A51",
"87DDA",
"26CA7",
"9D925",
"08A23",
"BE075",
"3179A",
"5D904",
"54C70",
"47790",
"5D3B5",
"0E4CE",
"004C7",
"EC8A8",
"131A6",
"7F47F",
"41BC6",
"FCF07",
"D62BD",
"DD14F",
"6A141",
"EE184",
"595F8",
"9D303",
"BFD36"
],
"output": "correcthorsebatterystaple"
},
{
"input": [],
"output": ""
},
{
"input": [
"4DC7C",
"A84FD",
"467D7",
"BD79D",
"12D83"
],
"output": "rxrfa"
},
{
"input": [
"4DC7C",
"A84FD",
"467D7",
"BD79D",
"7B743"
],
"output": "rxrpa"
}
]

• I wonder whether MD5 might be preferred over SHA1 - as in, more likely to exist in the language without having to load external libraries?
– mkst
Jun 18 '20 at 16:25
• Languages without a hashing builtin or library would have effectively two challenges: implementing the hash and doing the key part of the challenge. There are already challenges for MD5, SHA-1, and SHA-256 e.g. codegolf.stackexchange.com/questions/81195/implement-sha-256. I see two resolutions to this: 1. not count byte count of the hash; or 2. use a simple hash, such as the digits after the decimal point in the square root of the sum of code points Jun 18 '20 at 22:19
• You could allow a black-box function as input that computes the SHA256 hash to make this more competitive for languages without builtins. Jun 24 '20 at 2:32

# Posted at Baba if you, flag is win

• There are a lot of possible rules (I think a little less than 2^9, as for each X and Y either X is Y or X is not Y, and there are 3*3=9 (X, Y) choices). Is there any documentation on what's the behavior of each rule combination? // i.e., even in this simplified version there are still a lot of fuzzy details on how the rules behaves. Jun 22 '20 at 15:04
• @user202729 , Thank you for your input. I’ll take out the clause about “no non-core packages” as suggested. In terms on the moves after win, I think the easiest thing will be to say that one can assume the input sequence to end on a winning move. If a longer sequence is given, that’s undefined behaviour and the program can do whatever. Jun 22 '20 at 16:55
• @user202729 Finally, I admit I'm not certain what is your source of confusion. The rules work just like in the main game (with the caveat of everything is stop), and I've specified a lot of tricky cases both in this post and in the accompanying GitHub repo. Arguably, the code on GitHub specifies the problem precisely (as it is an execution of it). I've also added test cases to allow one to check the behaviour. I'm not sure what else could I do? Jun 22 '20 at 17:00
• Now that this has been posted to main, could you delete this proposal to create more space for new answers? Sep 25 '20 at 1:05
• The default for kolmogorov-complexity is that the exact, constant string must be output, so I suggest no leading spaces allowed. Some languages can't output in certain forms (e.g. printing) without a trailing newline, so I'd say it's okay (instead of "print this logo", I'd suggest saying "output this logo exactly as the following string") Jun 27 '20 at 7:45
• Now that this has been posted to main, could you delete this proposal to create more space for new answers? Sep 25 '20 at 1:04

# Migrate Try it online! to CommonMark

Try it online! generates old-style MarkDown code blocks which indent all lines with 4 spaces and then optionally precedes the block with a language comment.

Furthermore if the code block can't be parsed by old-style MarkDown (e.g. it has a leading newline, common in Retina answers), then it instead uses a <pre><code> block, with HTML escapes for all nonprinting characters.

Your program or function must take a whole TIO post, and change its code block into CommonMark style.

Examples:

# [Python 2], 16 bytes

<!-- language-all: lang-python -->

print "Python 2"

[Try it online!][TIO-kdaf9y51]

[Python 2]: https://docs.python.org/2/
[TIO-kdaf9y51]: https://tio.run/##K6gsycjPM/r/v6AoM69EQSkAzFcwUvr/HwA "Python 2 – Try It Online"


becomes

# [Python 2], 16 bytes

 python
print "Python 2"


[Try it online!][TIO-kdaf9y51]

[Python 2]: https://docs.python.org/2/
[TIO-kdaf9y51]: https://tio.run/##K6gsycjPM/r/v6AoM69EQSkAzFcwUvr/HwA "Python 2 – Try It Online"


which displays as

# Python 2, 16 bytes

print "Python 2"


Try it online!

while

# [Retina 0.8.2], 13 bytes

<pre><code>
Retina 0.8.2
</code></pre>

[Try it online!][TIO-kdafdbm1]

[Retina 0.8.2]: https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d
[TIO-kdafdbm1]: https://tio.run/##K0otycxL/P@fKwjMUDDQs9Az@v8fAA "Retina 0.8.2 – Try It Online"


becomes

# [Retina 0.8.2], 13 bytes



Retina 0.8.2


[Try it online!][TIO-kdafdbm1]

[Retina 0.8.2]: https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d
[TIO-kdafdbm1]: https://tio.run/##K0otycxL/P@fKwjMUDDQs9Az@v8fAA "Retina 0.8.2 – Try It Online"


which displays as

# Retina 0.8.2, 13 bytes


Retina 0.8.2


Try it online!

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

# Where are the traps? code-golfnumbersequence

### Background Partially copied from my related challenge

The trapped knight sequence is a finite integer sequence of length 2016, starting from 1, and has the following construction rules:

1. Write a number spiral in the following manner:
17 16 15 14 13 ...
18  5  4  3 12 ...
19  6  1  2 11 ...
20  7  8  9 10 ...
21 22 23 24 25 ...
1. Place a knight on 1.
2. Move the knight to the grid with the smallest number it can go that has not been visited before, according to the rules of chess (i.e. 2 units vertically and 1 unit horizontally, or vice versa).
3. Repeat until the knight gets stuck.

It is known that the sequence ends at 2084 where the knight is trapped. But here is a twist. Suppose a knight can step back to the previous grid whenever it is stuck, and choose the grid with the next smallest number possible. By doing so, the sequence can be further extended until it is stuck again at 2720. Then, the knight steps back and choose another path, which further extends the sequence until it is stuck again at 3325...

Then, we call these numbers at which the knight is being trapped "traps". So we now know that the first few traps are at 2084, 2720, 3325, ... and it continues to infinity.

### Challenge

Write a shortest program or function, receiving an integer $$\N\$$ as input, output the first $$\N\$$ traps in the extended trapped knight sequence.

### Values

The first 100 terms of the sequence are as follows.

  2084,   2720,   3325,   3753,   7776,   5632,   7411,   8562,  14076,   8469,
9231,  22702,  14661,  21710,  21078,  25809,  27112,  24708,  19844,  26943,
26737,  32449,  31366,  45036,  37853,  37188,  43318,  62095,  67401,  68736,
70848,  62789,  63223,  69245,  85385,  52467,  71072,  68435,  76611,  84206,
81869,  70277,  81475,  83776,  70767,  84763,  99029,  82609, 103815,  86102,
93729, 100614, 108039,  82111,  99935,  85283, 109993, 119856, 119518, 116066,
109686,  92741, 124770,  92378, 104657, 125102, 107267, 107246, 117089, 117766,
99295, 121575,  98930, 117390, 123583, 112565, 122080, 111612, 111597,  97349,
105002, 130602, 133509, 153410, 127138, 143952, 153326, 157774, 122534, 136542,
163038, 134778, 140186, 162865, 171044, 159637, 171041, 174368, 184225, 152988


### Winning Criteria

The shortest code of each language wins. Restrictions on standard loopholes apply.

# Convert LifeOnTheEdge to LifeOnTheSlope

Your task here is to take a LifeOnTheEdge pattern and convert it to LifeOnTheSlope.

A LifeOnTheEdge pattern is composed of these four characters: |_L . A pattern corresponds to a certain arrangement of "on" edges in a square grid. The pattern is placed in the grid first with the characters in the cells, and each of the four letters specifies the state of the edges on the left and the bottom of that cell. | means the edge on the left is on, _ means the bottom edge is on, L means both of them are on and   means neither of them are on.

For example the following LifeOnTheEdge:

|_L
|


translates to:

. . . . .
|   |
. ._._. .
|
. . . . .


Your task is however convert it to LifeOnTheSlope. LifeOnTheSlope is a LifeOnTheEdge equivalent but only uses three symbols: /\ . You should rotate the pattern 45-degree clockwise, for example the above example translates to:

/

/\/
\


# Sandbox

I'm not sure if I described the problem clearly. Improvements on the wording and other things?

• Nice challenge! The task is clear, I just think you may specify if and how leading/trailing newlines/spaces are allowed, for example in the example there may be a trailing space. And also.. Are the set of characters strictly fixed? People usually ask for free sets, for example some values [1,2,3,0] instead of |_L but since this is ascii-art I think it's fine to have a fixed set. Let's see if anyone else has any opinion. Aug 2 '20 at 12:35
• @AZTECCO For the second question I'm fine with both options. This convertion is a thing that annoys me in my CA exploration.
– null
Aug 2 '20 at 12:38

# Identify the tonic from a key signature

## Objective

Given a key signature in major, output its tonic.

## Input

An integer from -14 to +14, inclusive. Its absolute value is the numbers of flats/sharps. Negative number represents flats, and positive number represents sharps. Note that theoretical keys are also considered.

## Mapping

Note the use of Unicode characters ♭(U+266D; music flat sign), ♯(U+266F; music sharp sign), 𝄪(U+1D12A; musical symbol double sharp), and 𝄫(U+1D12B; musical symbol double flat).

-14 → C𝄫
-13 → G𝄫
-12 → D𝄫
-11 → A𝄫
-10 → E𝄫
-9 → B𝄫
-8 → F♭
-7 → C♭
-6 → G♭
-5 → D♭
-4 → A♭
-3 → E♭
-2 → B♭
-1 → F
0 → C
1 → G
2 → D
3 → A
4 → E
5 → B
6 → F♯
7 → C♯
8 → G♯
9 → D♯
10 → A♯
11 → E♯
12 → B♯
13 → F𝄪
14 → C𝄪

Output must be a string. Whitespaces are permitted everywhere.

## Rule

• Invalid inputs fall in don't care situation.
• "Or a sequence of bytes representing a string in some existing encoding"? (I think this should be the default, but I don't remember seeing any meta post about it) Aug 4 '20 at 6:06

# Source Code Byte Frequency - Posted here

Changes from the original idea:

• Without the requirement of fixed representation of the result (percentage and trimming).
• With constraint: source code must be at least 1 byte long
• Changed from character to byte, plus removing the constraint of SBCS languages only.
• This may qualify for the quine tag but I'm not so sure about that Aug 4 '20 at 6:40
• Trimming the output may be difficult for some languages, maybe you could also allow fractions, or require that the output is only accurate to x decimal places? Something to consider when writing a challenge is if a rule actually contributes to the problem or is just an accessory of sorts (here I think the main problem is finding the proportions, and rounding is an accessory) Aug 4 '20 at 6:47
• @golf69 I'm also not sure about quine... About the trimming, my intention on the trimming and percentage format was to add a little bit of "work" that the program should do and make the frequencies a bit more different/challenging. Do you think I should drop the trimming part from the challenge? Aug 4 '20 at 9:05
• I do think so, yes (also it might be better received that way) Aug 4 '20 at 17:21
• I do not think the average person who does not use this site will know what a SBCS is, so it is probably still worth explaining. Alternatively, I think it would be cleaner to just require that the input be a byte and the output reflects the frequency of that byte. That way you don't eliminate multibyte languages from using it to their benefit, and I don't think it allows any "cheating." Aug 4 '20 at 21:52
• Sounds okay to me. I agree that it is better to avoid elimination of multi-byte languages. Aug 4 '20 at 22:03
• The thing I try to avoid is to get a lot of 0 bytes answers (for languages that print 0 as default). So I want to add a task that the program should do, like printing in percentage format. So the question is, before I reduced the trimming task, if this is enough to achieve that. Aug 5 '20 at 9:06
• Posted here with some changes listed in this edited answer. Aug 9 '20 at 16:50

# Simulate simple Bloons Tower Defense!

For those who are unaware of this legendary series of video games, here is a link.

## The task

You are going to be given an integer number and type of bloon wave and two integers describing the damage and pierce (max amount of bloons you can damage in one attack) of each attack. Your task is to output in how many attacks can you destroy the bloon wave.

## Bloon types

For simplicity, there will be no special properties like fortified, regrow, camo e.t.c. White bloons will also not be present as, without special properties, they are the same as black bloons

Name - health - what it pops into
BAD   - 20000 - 3x DDT and 2x ZOMG
ZOMG - 4000  - 4x BFB
BFB   - 700   - 4x MOAB
MOAB - 200   - 4x Ceramic
DDT   - 350   - 6x Ceramic
Ceramic - 60    - 1x Rainbow
Rainbow - 1     - 2x Zebra
Zebra   - 1     - 2x Black
Black   - 1     - 2x Pink
Pink    - 1     - 1x Yellow
Yellow  - 1     - 1x Green
Green   - 1     - 1x Blue
Blue    - 1     - 1x Red
Red     - 1     - Nothing!


## I/O

Input: A string describing the type of bloon, and three integers: the amount of bloons in the wave, attack damage and attack pierce

Output: An integer describing how many attacks are needed for destroying the whole wave.

## Examples

Note: If there is not enough pierce n to attack the whole wave, then only the first n bloons are attacked

Input: Rainbow 3 2 10
Starting: 3x Rainbow
Attack 1: 12x Black
2: 20x Yellow 2x Black
3: 10x Blue 10x Yellow 2x Black
4: 10x Yellow 2x Black
5: 10x Blue 2x Black
6: 2x Black
7: 4x Yellow
8: 4x Blue
9: Done!
Output: 9


This is the 4/0/x Sniper Monkey:

Input: BFB 1 30 1
1: BFB(670)
2: BFB(640)
...
13: BFB(10)
14: 4x MOAB(180)
15: 1x MOAB(150) 3x MOAB(180)
...
19: 1x MOAB(30) 3x MOAB(180)
20: 4x Ceramic(60) 3x MOAB(180)
21: 1x Ceramic(30) 3x Ceramic(60) 3x MOAB(180)
22: 3x Ceramic(60) 3x MOAB(180)
...
27: 1x Ceramic(30) 3x MOAB(180)
28: 3x MOAB(180)
...
69: 1x Ceramic(30)
70: Done!


This is codegolf, so lowest byte-count wins

• This is extremely complicated. I feel like this will be in unanswered for a while. Aug 10 '20 at 17:04
• In the second example, how is ceramic destroyed without giving out any lower class bloons? Aug 11 '20 at 0:31
• +1 because btd is awesome lol. However this is a very complicated challenge, even for people who know how the mechanics work. It might be better if you limit the problem to 1 pierce only Aug 18 '20 at 23:34
• or you could even do a challenge that simply requires calculating the RBE for a bloon wave, that could still be an interesting challenge Aug 18 '20 at 23:35
• actually RBE calculating is probably a bit too simple Aug 19 '20 at 0:02

# Solve the Halting Problem for Oneplis

Oneplis is a "very simple esolang" (I don't want to count this one toward my esolangs) made by me which only have three commands. As you can probably see from the name, it is a subset of 1+, along the lines of Befinge.

The three commands are:

• 1, which pushes 1. (Obviously!)
• +, which pops the top two numbers and pushes their sum. (Obviously!)
• #, pops a number n and jumps to the instruction after the nth (0-based) #.

Oneplis is almost certainly a (very limited) push-down automaton, since it's impossible to decrement a number and impossible to retrieve elements arbitrary deep in the stack! Oh, and the only way to read a number is with #, which cannot handle arbitrarily large numbers!

This is , so shortest code wins! Your output should be truthy for halting, and falsy for non-halting. You can use any set of five characters for the instructions. Don't care if it jumps to a non-existence # or trying to execute + when there are <2 numbers on the stack.

## Test cases

11+ -> True
1##1# -> False
1## -> True
11+1+###11+# -> True
11+##1#1 -> False


# Sandbox

• Test cases?

• Shall I require the answers to deal with errors?

• For "nth #", is it 1- or 0-based? (I guess it's 0-based, but you need to be explicit on it anyway.) Aug 20 '20 at 9:39
• @Bubbler Uh, ok. It's 0-based in 1+, but 0-based indexing does not make any sense in this challenge anyway, it's impossible to push 0... Should I change it to 1-based?
– null
Aug 20 '20 at 9:42
• I don't think it's that nonsense, as the only effect is that all instructions between first and second #s are unreachable. Aug 20 '20 at 9:47
• @Bubbler Oh, okay then. So if no one objects I'll post this to main.
– null
Aug 20 '20 at 10:15
• if you don't plan to require answers to deal with errors then also mention that they don't need to worry about popping from an empty stack Aug 20 '20 at 11:20
• Or: errors terminate the program. Aug 24 '20 at 13:29
• @user253751 Yes, that's also good. Although, I prefer it this way.
– null
Aug 24 '20 at 13:43

# Noncommutative Quineoid Triple

This is the hard mode of Quineoid Triple

Write three different programs such that all of the following properties hold:

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

Where:

• $$\ f(g) \$$ is the output obtained from feeding the program text of $$\g\$$ into program $$\f\$$
• $$\ -x \$$ is the program text of $$\x\$$ in reverse (reversed in terms of either raw bytes or unicode codepoints)
• $$\ \epsilon \$$ is the empty string / an empty output

# Rules and Scoring

• This is , so the shortest program length total, in bytes wins.
• 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 anything other than program text of one of the three programs is undefined.

Sandbox note: This is partially inspired by There's a fault in my vault!, which I thought had some interesting ideas in it. This is my effort to frame those ideas in a clearer fashion.

# Cops/Robbers: Create a weak block cipher

In cryptography, we often use block ciphers, which are a form of keyed encryption. More specifically, for a plain text string $$\s\$$ and a secret key $$\k\$$, we design an encryption function $$\E(s, k)\$$ and a decryption function $$\D(\hat{s}, k)\$$ such that if we encrypt and then decrypt the text with the same key, we get back our original text. That is, we have $$\D(E(s,k),k) = s\$$ for all possible strings $$\s\$$ and $$\k\$$.

One security property a good block cipher has is that it is resistant against key-recovery attacks. This means that if we have the ability to run $$\E(s, k)\$$ and $$\D(\hat{s}, k)\$$ for various choices of $$\s\$$ and $$\\hat{s}\$$ and collect pairs of encrypted and decrypted text we cannot tell what the key is.

In this challenge, you will design a simple block cipher that is intentionally vulnerable to a key recovery attack, and challenge others to try and exploit it.

## The Cops' Challenge

1. Design a block cipher. Design an encryption function $$\E(s,K)\$$ and decryption function $$\D(\hat{s},k)\$$ that take strings (or your language's closest equivalent) of a fixed length $$\16\$$ bytes and a key of fixed length $$\16\$$ bytes and outputs a string of length $$\16\$$ bytes. Your $$\E\$$ and $$\D\$$ functions must have the property that $$\D(E(s,k),k) = s\$$ for all 16-byte strings $$\s\$$ and $$\k\$$.1 The functions must be deterministic (not use any randomness) and pure (not rely on any outside state). Your $$\E\$$ and $$\D\$$ must work within the integer/float precision of your language. Specifically, you may not treat floating point as if it's arbitrary precision, nor may you assume integers of arbitrary size if your language utilizes fixed-size integers.
2. Implement a secret key-recovery attack on your block cipher. Write a program that makes calls to $$\E\$$ and $$\D\$$ for a secret, unknown key $$\k\$$ and fully recovers the key by observing properties of the input/output pairs. The key must be recovered with probability $$\1\$$ - you may not rely on probabilistic approaches.2 You must treat $$\E\$$ and $$\D\$$ as black boxes, from which you can only observe their input and output. This means you must not utilize runtime introspection, timing information, or other side effects of the implementation. You must only pass full $$\16\$$ byte strings to $$\E\$$ and $$\D\$$, and not any other type. This means you may not rely on special objects with overloaded operators or similar to glean information about how the input is processed by $$\E\$$ and $$\D\$$. Your attack may be adaptive, in that it decides which strings to pass in based on outputs to previous strings. To enforce a practicality limit, your attack must work for a combined total of strictly less than $$\2^{16}\ = 65536\$$ calls to $$\E\$$ and $$\D\$$ for any key $$\k\$$. If the block cipher you design has the property that for keys $$\k_1\$$ and $$\k_2\$$ that $$\E(s,k_1)=E(s,k_2)\$$ and $$\D(s,k_1)=D(s,k_2)\$$ for all $$\s\$$, then we call these keys functionally identical, and your attack may recover any functionally identical key to the original.

That's it! You will reveal both the encryption and decryption functions $$\E\$$ and $$\D\$$, and challenge the robbers to find your key recovery attack (or possibly a different one).

Clearly, the challenge is to design your $$\E\$$ and $$\D\$$ to look secure, but they have some catastrophic weakness that allow you to recover the key with very few calls. Another approach is to 'trapdoor' the function in some way only known to you. In the spirit of Kerckhoffs's principle, you are encouraged to post a short explanation of what your $$\E\$$ and $$\D\$$ do, especially if they are written in an esoteric language.

You may use cryptographic functions if you wish, but using them presents several practical problems. Hashing functions are designed to be one way and your are unlikely to be able to design both an encryption and decryption function that utilizes them. Symmetric ciphers have both encryption and decryption, but is unlikely to allow the key recovery attack outlined here.

If no-one mounts a successful attack in 7 days, you may post your key recovery attack and mark your answer as safe, which prevents it from being cracked. Note your submission can still be cracked until your reveal your attack.

Your answer is invalid if you do not follow the rules set above. Your answer can be declared invalid even after it is marked safe, if it turns out your revealed attack does not obey the rules.

The shortest safe submission, calculated as the sum of the bytes of the two functions $$\E\$$ and $$\D\$$, wins. Your functions must be named.

## The Robbers' Challenge

1. Find a vulnerable answer. That is an answer, which hasn't been cracked yet and which isn't safe.
2. Crack it by designing a key recovery attack. Your attack must follow the rules outlined in the cops section. To recap, this means:
• The total number of calls to $$\E\$$ and $$\D\$$ with the key $$\k\$$ must be strictly less than $$\2^{16}\$$
• You must only pass $$\16\$$ byte strings to $$\E\$$ and $$\D\$$, and must have the key $$\k\$$ initially be unknown
• The attack may be adaptive but must work to recover any 16 byte key $$\k\$$ (or a functionally identical key)
• You must treat $$\E\$$ and $$\D\$$ as black box, and may not use runtime introspection, timing information, etc.

If you've found such a attack, post an attack on the robber's thread linking back to the answer. If possible, you should post a link to an online interpreter which allows others to run your attack for various keys $$\k\$$. You are encouraged to post how your answer works, and the maximum number of calls your approach makes to $$\E\$$ and $$\D\$$. If your attack does not recover the key, but instead a functionally identical one, explain (briefly) why they are functionally identical.

You must not crack your own answer.

The user who cracked the largest number of answers wins the robbers' challenge. Ties are broken by the sum of bytes of cracked answers (more is better).

## Example #1

### Python 3, 133 bytes (cop)

E=lambda s,k:''.join(chr((ord(c)+ord(d))%256) for c,d in zip(s,k))
D=lambda s,k:''.join(chr((ord(c)-ord(d))%256) for c,d in zip(s,k))


Try it online!

My program computes the sum of $$\s_i\$$ and $$\k_i\$$ for each $$\i\$$.

### Python 3, cracks xxx's answer

leaked_key = E('\0'*16,k)
print('key = %s' % leaked_key)


Try it online!

My crack completes in $$\1\$$ call and uses that fact that $$\0 + k = k\$$.

## Example #2

### Python 3, 147 bytes (cop)

def E(s,k):
o=''
V=[*range(256)]
j=0
for i in range(16):
j+=V[i]+ord(k[0])
j%=256
V[i],V[j]=V[j],V[i]
o+=chr(ord(s[i])^j)
return o
D=E


Try it online!

My program uses a complicated thing.

### Python 3, cracks yyy's answer

leaked_key = ''
for c in range(256):
if E('f'*16,chr(c))==E('f'*16,k):
leaked_key = chr(c)+'x'*15
break

print('key = %s' % leaked_key)
assert E('abcdabcdabcdabcd', leaked_key) == E('abcdabcdabcdabcd', k)
assert D('abcdabcdabcdabcd', leaked_key) == D('abcdabcdabcdabcd', k)


Try it online!

They only ever use the first byte of the key, so we can just bruteforce the first byte and pad with anything to get a functionally identical key. This involves a maximum of $$\256\$$ calls to $$\E\$$ with the secret key.

1. This means that if your language uses null-terminated strings, such as C, then you should be using memcpy-type operations instead of string operations. Since the input length is fixed as 16 bytes, this should be no issue.
2. This requirement forbids most kinds of Birthday attack.

# Questions to sandbox users:

• I know this is a lot to take in. Is it clear?
• Can anyone think of a trivial way to trapdoor $$\E\$$ and $$\D\$$ with eg. a hashing function? I don't think it's possible, but I could be wrong.
• I love this idea! I think it's written in a pretty clear way, I think you could trivially trapdoor E and D, by doing something like if (s == hash("sixteen_byte_str")) return k, but disallowing cryptography functions should fix that Sep 7 '20 at 14:06
• @RedwolfPrograms Glad you think it's clear! Out of curiosity, if you wrote that as your encryption function, how would you write the corresponding decryption function? Sep 7 '20 at 22:58
• Something like if (ŝ == k) return hash("sixteen_byte_str"), you'd just need to ensure there's no way it could be confused with a value that legitimately encrypts to k (which would be easily doable by replacing it with whatever hash("sixteen_byte_str") would typically encrypt to). Using crypto functions to trivially win a CnR challenge is practically a loophole, and is likely to be downvoted anyway. (Btw, when I write x == hash("sixteen_byte_str"), I mean hash(x) == "sixteen_byte_str") Sep 8 '20 at 1:51
• Actually, wait, I'm being stupid. I think there's no way to not have it return hash(x) == "sixteen_byte_str" in one of the two functions, so there doesn't appear to be a trivial way to trapdoor it. I'd still disallow crypto in case someone uses some sort of fancy asymmetric thing, but I can't figure it out if there is. Sep 8 '20 at 12:08

# Take 6!

A good card game is a wonderful thing. I got me a nice fresh set of Take 6! Too bad though, I have no-one to play with. And so I turn to you!

## The Game

The game is played with a set of 104 cards, numbered 1 to 104 inclusively. Each card has a number of 'cows' attached. Here's a quick Python function to calculate the number of cows:

def cows(card):
out = 1
if(card % 5) == 0:
out += 1
if(card % 10) == 0:
out += 1
if(card % 11) == 0:
out += 4
if(card % 5) == 0:  # C-c-c-combo
out += 1
return out


Therefore, there is a total of

• 1 card with 7 cows (number 55)

• 8 cards with 5 cows (the other multiples of 11: 11, 22, 33, 44, 66, 77, 88, 99)

• 10 cards with 3 cows (multiples of ten: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

• 9 cards with 2 cows (other multiples of five: 5, 15, 25, 35, 45, 65, 75, 85, 95)

• 76 cards with 1 cow (all other cards)

The game is played by up to 10 players.

Each player is given 10 cards. 4 cards are placed on the table as the starts of 'rows'. Then 10 turns of play take place. Then, results are calculated.

### A turn

Each player selects one of their remaining cards. At the same time, they reveal their selected cards.

Going in the order of lowest card number, the player whose card it is must place it into a row according to rules:

1. If there is a row with the top card of a lower number than the player's and no such row with a lower number exists, their card must be placed at the end of the row. If their card is the sixth in a row, they take the first 5 cards and put them on their result pile, leaving theirs as the new start.

2. If no such row exists, they must pick one of the rows, take all the cards there to their result pile, and leave their card as the new start.

Examples:

row tops: 10 20 30 40

played: 25

must be placed on the row with a 20, creating the configuration 10 25 30 40 with a possible cow gain

row tops: 10 20 30 40

played: 9

pick any row, creating for example 10 20 9 40, but guaranteed to gain cows

### Counting

The sum of cow values of the cards in a player's result pile is their score. The lower the score the better.

Scores may be added up over several games, creating an overall score for a match.

## Bots

Bots will be standalone programs. Everything belonging to a bot will be placed in a single directory, the name of the directory will be used as the name of the bot. A launch script named launch (may be the entire bot) must be provided. If necessary, a compilation script named build may be provided. Both scripts shall be placed directly in the bot's directory and should use shebangs to specify how they are to be run.

Bots shall not interfere with other bots, the controller, or the git repositories used.

The bots will have the option of storing extra information in files in their own directory. It will be wiped when a fresh series is being run (such as after adding a new bot).

An override input format may be provided. I intend to use StringTemplate for this, I'll write up some details when working on the controller. The default format will have all messages newline-terminated.

Once launched, the bot will be first given their cards, as a list of card numbers, where the numbers may or may not be ordered.

The default format will be

cards 0 1 2 3 4 5 6 7 8 9


No response is expected.

For each round, the bot will be prompted with the current state of the grid, that is the number of cards in each row, the sum of cows in each row and the top number card in the row.

The default format will be

count 1 2 3 4

cows 5 6 7 8

top 11 20 22 35


The bot shall answer with the number of one of its remaining cards.

The list of all the cards used by all bots in the round will be given to each bot. Not that this includes the bot's own card. The order of bots in this message will be consistent within a game.

The default format will be

used 0 1 2 3 4 5 6 7 8 9


No response is expected.

If the placement rule 2. has to be invoked, the bot will receive a message containing the board state at the time when it needs to pick a row

The default format will be

pickrow

count 1 2 3 4

cows 5 6 7 8

top 11 20 22 35


The bot shall respond with the number of the row it wishes to take. The rows will be 0-indexed for this.

If the bot's move results in a gain of result cows, it will be informed of which cards and how many cows it has gained (note that the lower the number the better).

The default format will be

cardgain 1 2 3 4 5

cowgain 6


No response is expected.

At the end, all bots will be shown their score as well as all the scores of others, in the order consistent with the used cards message.

The default format will be

score 30

others 0 1 2 3 4 5 6 7 8


No response is expected.

If the bot makes an invalid move, it will be delivered a special message informing it of such. From that point the bot's current game is over. It gets 100 points of penalty.

The default format will be

invalid


A timely shutdown is expected.

The bot may of course try to save information to its private file at any time, including at the end.

After the final message, the bot shall terminate in a timely manner.

Scoring will be added up over many games, number depends on how fast the games end up running, but at least 100 sounds reasonable to me.

Bots will be placed in a separate github repository TODO for easy setup and reseting. Bots that need a compilation script but don't have one will be given one.

## Controler

Work has started at https://github.com/MrRedstoner/Take6KOTH

The controller will be designed to run in Java 1.8+, using the Process API to launch bots.

# Notes:

While the number of bots is too low, it will be padded to 10 by using multiples of primitive bots. The tournament style once 11+ submissions exist is for now playing all subsets of size 10.

I intend to write up at least a few primitive bots, to get the games going. Something like using cards in the order they were given, or randomly. These will also demonstrate the custom input functionality. Maybe even one that uses external input, to let me play for fun!

Limits for execution time, storage of data etc. are not given at this time. If bots start to behave excessively limits may be added.

Sandbox notes:

Any better idea for tournament?

Should bots be given the names of their competitors as well? Currently leaning towards yes.

Planned tags:

• Even though most people can read python, you should still include a written description of how the cows are counted. As it is, your program counts twice for it being divisible by 5 in the case of 55, is that intentional? Sep 18 '20 at 18:13
• @FryAmTheEggman it is indeed intentional, it's a combo for a reason :D. The result also matches what wikipedia describes about the game. Should have some more to edit soon so I'll make the change then. Sep 18 '20 at 18:16
• But when do you take 720?? /s
– Jo King Mod
Sep 21 '20 at 9:39

# Output all of printable ASCII using all of printable ASCII

Posted

• "Irreducible" isn't really an observable requirement; I'd recommend looking into using pristine-programming to make it an objective criterion.
– hyper-neutrino Mod
Oct 12 '20 at 18:31
• What do you mean by "observable"? "irreducible" simply means you can't purely remove characters (not purely substrings) from the program and have it still work (not merely not error). That's pretty objective, is it not? Oct 12 '20 at 18:39
• Actually, yes it seems you're right, I was probably thinking of some other common criteria that isn't valid. Otherwise challenge looks good, doesn't seem to be a duplicate. I would say this isn't kolmogorov complexity since it's not constant but it is restricted source albeit not in the common usage.
– hyper-neutrino Mod
Oct 12 '20 at 18:48
• Can my program contain additional non-ASCII bytes?
– Adám
Oct 12 '20 at 19:00
• @Adám yes, in the post it says "Your program, and its output, can contain any additional non-printable-ASCII bytes (bytes, not characters) if you like, such as newlines". "non-printable-ASCII" includes "non-ASCII" Oct 12 '20 at 19:01
• Ah, I see. Maybe clarify that you mean both non-[printable-ASCII] and [non-printable]-ASCII.
– Adám
Oct 12 '20 at 19:03
• Perhaps subtract 95 from each score so that scores look more reasonable Oct 13 '20 at 10:51
• @Lyxal my reasoning for not doing that was because I suspect most answers will be quite a lot longer in order to make sure they're irreducible, it would complicate things, and IMO it doesn't really matter if they're that length Oct 13 '20 at 10:55

# Round a Matrix

Your input is a 2d array of nonnegative floats A. It can be supplied in whatever format is most acceptable for your language. It can have any dimensions.

Let r and c be the 1d arrays of row and column sums of A respectively, rounded to the nearest integer, with the rule that 0.5 is rounded up to 1.

Your task is to output a 2d array of nonnegative integers B such that |b_{ij} - a_{ij}| < 1 for all i and j, and also the row and column sums of B are equal to r and c respectively.

In other words, B is obtained by rounding each element of A up or down, in such a way that the row and column sums are preserved.

There may be many possible solutions. In this case, you only need to output one of them.

If there is no solution, your program's behaviour can be undefined.

Example:

 A = 1.2 3.4 2.4
3.9 4.0 2.1
7.9 1.6 0.6


in this case, the row sums are [7.0, 10.0, 10.1] and the column sums are [13.0, 9.0, 5.1] so after rounding these, you get r = [7 10 10] and c = [13 9 5]. One acceptable solution is

 B = 1   3   3
4   4   2
8   2   0


This is code golf, so the shortest code wins.

## Motivation

I am also interested in what clever algorithms people can come up with. I guess the most obvious is just to do a random search, but that can take a very long time, even if the array is only 10x10 or so.

## Questions

• Is it clear? Please can you edit it if it's not in the right format?
• Has it appeared here before? (I don't think so, because I was searching Stackoverflow for a while in order to come up with a solution to this.)
• Is there always a solution under the conditions given here?
• Would it be better in some other format than code golf?
• Should the condition |b_{ij} - a_{ij}| < 1 be |b_{ij} - a_{ij}| <= 1?
• Since you want optimal, interesting solutions, rank by time complexity. You'll get fewer answers, but they will be more optimal than a direct brute force approach. Oct 22 '20 at 6:53
• The suggestion of using complexity isn't often a good one - most challenges here that try to do that wind up closed or unanswered. It would be much simpler to go by execution time for some number of test cases that you pick. For the actual question, I think you should explicitly say that r and c are computed by summing and then rounding (assuming that is the correct order) as it isn't precisely clear from what you have right now. Oct 22 '20 at 20:34

# The Fibonacci Rectangular Prism Sequence (posted)

• There are the square roots of A127546. It looks like there are ways to generate this sequence shorter than just generating Fibonacci numbers and adding their squares. So, this doesn't strike me as a duplicate but an interesting challenge in its own right. I'd recommend removing the square-root step from the challenge and just asking for the sum of the three squares, which is a whole number. This might also allow for more interesting recursive solutions. You should include test cases, perhaps something like the first 15 elements of the sequence and maybe one big one.
– xnor
Oct 27 '20 at 0:39

### Example game

The winning numbers are as follows

• [2, 18, 1, 15, 7]

Four people bought tickets with the following prices and numbers

• $6, [9, 5, 6, 15, 22], one match, score of 4, weight of 24 •$2, [2, 25, 17, 7, 7], two matches, score of 16, weight of 32. Notice how only the second 7 counts, order matters
• $67, [11, 16, 9, 20, 16], no matches, score of 1, weight of 67 •$1, [12, 19, 6, 25, 2], no matches because the 2 is in the wrong spot, score of 1, weight of 1

The total pool is $76,$68.4 after we take our cut, which is then sent out based on the weights. The sum of all weights is 124.

• First ticket gets 24/124, $13.24 • Second ticket gets 32/124,$17.65
• Third ticket gets 67/124, \$36.96
• Fourth ticket gets 1/124, a whole 55 cents
• I think you should explain that the winning numbers are not necessarily distinct in rule 2, instead of leaving it until the examples. Likewise, you should state the 'order matters' rule earlier. Jan 12 '21 at 11:57
• @Dingus I added those clarifications to rules 1-3. Thoughts? Jan 15 '21 at 23:46
• Looks good to me. Jan 16 '21 at 5:02

# Is each bracket matched?

Given a string consisting only of the characters ()[]{}, determine if each type of bracket is matched--that is, every ( corresponds to one later ), every [ corresponds to one later ], and every { corresponds to one later } (and vice-versa).

Pairs are allowed to overlap: ([)] is just as valid as ([]).

Output one consistent value for one classification and anything else for the other, or following your language's truthiness semantics (inverted if you want).

## Test cases:

Matched:

()
[]
{}
()[]{}
()()([])
{[][}]
{{{}}}
([{}]){([]})
[(()())(((())))(]()(()))


Not matched:

(
]
{{}
[)
(()())((((()))))(()()(())(())))
{}{}{)
[())[])]
)(


## Meta

• Does this admit a variety of interesting solutions?
• Would it be better to add <> as a bracket type? Have fewer bracket types? Arbitrarily many?
• I'm writing this up entirely because I'm surprised it hasn't been asked yet, so although I have looked, this might still be a duplicate.
• Although I don't think it's necessarily unclear, I feel like the specification could be worded better.
• very closely related Jan 28 '21 at 2:46
• @Lyxal indeed lol Jan 28 '21 at 3:31

# Is this a valid Irish word?

In Irish, most consonants are divided into broad (velarized) and slender (palatalized) variants, and the orthography marks them with neighboring vowels, which are similarly divided. This gives rise to the caol le caol agus leathan le leathan (slender with slender and broad with broad) rule – a medial sequence of consonants must have the same class of vowel on either side: in leabhar, bh is surrounded by two broad vowels, so it is broad as well, and in cailín, l is surrounded by two slender vowels, so it is slender. a, o and u are broad and e and i are slender (similar with the vowels with the fada: á ó ú é í); ae is also considered broad.

Given a word, output whether it follows this rule.

## Input

You may assume that the input has only the following characters with their uppercase variants:

aábcdeéfghiílmnoóprstuú
AÁBCDEÉFGHIÍLMNOÓPRSTUÚ


## Tests

Valid:

deartháireacha
madra
nuachtán
gaolta
ceannasaithe
snámhann
fómhair
laethanta
béar
Bealtaine
hAoine
ball
tree
ggg


Invalid:

codegolf
delta
alishanoi
ABI
anseo
breithlá


(Note that anseo and breithlá are Irish words, but they happen not to follow this rule. You should still output a falsy answer for them for the sake of simplicity.)

• Jebus, I haven't heard "slender with slender and broad with broad" in a couple of decades, that gave me a flashback! You note that "anseo" ("here", for the benefit of the non-Gaeilgeoirí) doesn't follow the rule but you should probably specify the expected output for it - I'd suggest against special-casing it and having it be invalid. Jun 2 '19 at 19:51
• This needs a much better definition of what is a broad consonant versus what is a slender consonant, unless I'm not understanding the challenge. Jun 3 '19 at 12:56
• @AdmBorkBork as I understood it, broad and slender consonants are indistinguishable in writing, the point is to detect consonants that would have to be both at the same time. Jun 13 '19 at 4:49
• I'd suggest listing their uppercase variants
– l4m2
Jun 25 '19 at 15:52
• 'in leabhar, bh is surrounded by two broad consonants, so it is broad as well, and in cailín, l is surrounded by two slender consonants'. Did you mean 'vowels' instead of 'consonants' here? Feb 8 '21 at 5:06
• Yes, that should have been 'vowels'.
– bb94
Feb 8 '21 at 19:14
• I still have no idea what the types of consonants and vowels are. Feb 9 '21 at 2:12
• This looks like a good challenge to me, to make it more understandable I would just explicitly list the sets of broad vowels, slender vowels, and consonants. (Rather than "here are all the characters: aábc..." have "here are all the broad vowels:aAáÁ...", "here are all the slender vowels:...", "here are all the consonants:...")
– Leo
Feb 10 '21 at 5:42
• Also, you should clarify what should happen if the word does not contain a sequence of consonants surrounded by vowels (e.g. "ball", "thx", "tree")
– Leo
Feb 10 '21 at 5:44
• "thx" is assumed to never be passed in as input. "ball" and "tree" would return true, because there's no contradiction between broad and slender vowels around consonants that can occur here.
– bb94
Feb 12 '21 at 6:09

# Count strictly overlapping substrings code-golfstringcountingsubsequence

Posted

• Is it correct that 1 is never a valid result?
– Adám
Jan 28 '21 at 17:04
• @Adám yes; do you think I should add that? Jan 28 '21 at 17:04
• Probably a good idea.
– Adám
Jan 28 '21 at 17:05
• You need test cases with longer bs that can overlap themselves in multiple ways.
– Adám
Jan 28 '21 at 17:27