title: Printing ascending ASCII, Cops

text:
# Question
Title: Printing ascending ASCII, Cops
This is the cops' thread. The robbers' thread goes here.

Write a program or function consisting only of **printable ASCII characters** (that excludes tab and newline) that outputs at least 5 printable ASCII characters in ascending order (from space to tilde / 32 to 126). Characters can be outputted several times, as long as they are adjacent to each other. A single trailing newline is accepted. You must provide the full output, and for every 6 characters in your code you must provide one character in your code, at the position it appears. If your code has 5 or less characters, then you have to reveal only the length. You shall not reveal more than 1 character per 6 in your code.

So if your code `alphaprinter` outputs the alphabet from a-z, then you need to reveal 2 characters of your code (use underscore for the others), for instance:

```
al__________  // or
__p__p______  // or
__________er

```

Rules / specifications:

* You cannot append trailing white spaces that doesn't have a function.
* You can not use comments (but the robbers can use comments when cracking the code)
* Built-in cryptographic primitives (includes any rng, encryption, decryption, and hash) aren't allowed.
* In languages where the **default** output are like in MATLAB: `ans =`, then that's accepted, as long as it's **clearly stated** and shown that `ans =` is outputted. It should also be clearly stated whether this is part of the "ascending output" or not.
* The output must be deterministic
* Using a non-free language is not accepted
* The output doesn't have to be consecutive characters. Both `abcde` and `abcdg` are valid outputs.
* The characters do not need to be distinct as long as the output contains at least 5 characters. `aaaaa` and `aaacc` are valid.
* Answers that assumes a REPL environment are not considered to be valid programs or functions and are therefore not allowed.
* STDERR is not considered valid output, but data may written to STDERR.

If the revealed characters are underscores, then you must identify it as shown below. In this case, the second and sixth character are revealed underscores, while the others are unknown.

```
_____________
 |   |

```

**Note:** The robbers only need to find a code that produces the same output. The language, the length of the robbers solution, and the position of the revealed characters must also match.

Your score is the number of characters in your code. The winner will be the submission with the lowest score that hasn't been cracked in 7 days. Only submissions that are posted in 2015 (UTC) are eligible for the win. Submissions that are posted later than this are welcome, but can not win.

In order to claim the win you need to reveal the full code (after 7 days).

Your post should be formatted like this (nn is the number of characters):

---

# Language, nn characters

Output:

```
abcdefghijklmnopqrstuvwxyz

```

Code (12 characters):

```
al__________

```

---

If the code is cracked, insert \[Cracked\](link to cracker) in the header. If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

# Answer
## Hexagony, 8 characters, safe

```
_______.

```

prints

```
123456

```

You can try Hexagony online

### Solution

```
`&)!."@.

```

The ``` is just misdirection to make the code look like it requires side-length 3. Unless the interpreter is executed with `-d` the backtick is simply stripped from the source code before determining the layout. Afterwards, the code fits into side-length 2:

```
 & )
! . "
 @ .

```

This moves the memory pointer (MP) around one hexagon of the memory grid, while copying the value to the next edge, incrementing it and printing it.

This is what the memory grid looks like, with the MP starting the marked position:

Initially all edges are zero. The first `&` is a no-op, but `)` increments the edge and `!` prints the `1`. Then `"` moves back to the left (the edge labelled *2*). There, `&` copies a value. Since the edge is currently zero, the left neighbour (in the direction of the MP) will be copied which is the `1` we just printed. `)` increments it, `!` prints the `2`. This continues as long as we're visiting new edges and we print all digits up to `6`. When we hit the edge we started on, `&` will copy the *right* neighbour instead (because the edge value is positive), so the edge becomes `0` again, and control flow jumps to the last row, where `@` terminates the program.

Try it online.
> 6 votes

# Answer
## Perl, 46 characters (safe)

Output:

<pre><code>((()))*++,---../00011123445556667779::;;<<==??@@AAACEFGHHHIKKMMNOOOPPQQQRRSSSVWXXYY[[[\]]]^^^```aaeeffggghjjjnpppqqrttuwxxyzz{{{
</code></pre>

Code:

```
print _______________________________________;

```

I somehow managed to delete the original in the space of a week, but I think this is right:

> `print chr()x(($i=($i*41+7)%97)&3)for(40..123);`
> 13 votes

# Answer
# Brainfuck, 48 characters, cracked by Mitch Schwartz

I made this one for the robbers. It is definitely not going to be the winning submission :)

```
____[_____[_______]__]___[___________]___[_____]

```

This outputs:

```
ABCDEFGHIJKLMNOPQRSTUVWXYZ

```

**Solution:**

> `++++[>++++[>++++<-]<-]+++[>++++++++<-]>++[>+.<-]`

I tested it here.

**Hint:** Don't try to find programs generated by online generators haha. This was handwritten and can only be solved by logical thinking :)
> 11 votes

# Answer
## Noisy 3SP, 89 characters (safe)

```
0 _____________________________ _ _ _ _ _ _ _ _ _ __2_2__________________________________

```

Original program:

```
0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 3 2 2 2 2 0 3 0 1

```

This program prints

```
 !"#$$

```

(note the leading space), and *nothing else!*

Explanation (\*n refers to the nth cell in memory):

```
0 0 0                                Increment *0 to 3 (via the 0s in *0, *1, and *2)
2 (32 times)                         Increment *3 to 32 (via the 0 in *2 and the 3 in *0)
                                      (Note that *3 mod 256 is the character that prints)
0                                    Increment *32 (via the 3 in *0 and the 32 in *3)
3                                    Increment *1 (via the 32 in *3 and the 1 in *32)
                                      (Note that printing is on when *1 mod 2 is 1,
                                       which means " " prints right here)
2 (4 times)                          Increment *3 to 36 (printing '!"#$')
0                                    Increment *36 (via *3) (printing "$" again)
3                                    Increment *1 to 2 (via *36) (printing turns off)
0                                    Increment *36 to 2 (via *3)
1                                    Increment *0 to 4 (via *2)

```

The last two commands turn out to be sufficient to prevent 1 from ever being incremented again on subsequent passes through the program, which means nothing is ever again printed, though it will go on setting all memory addresses from \*36 onward to the value 36 forever.
> 7 votes

# Answer
## CJam, 13 characters

```
_____________
  ||

```

prints

```
7LLMYahnsuv

```

You can try CJam online.

### Solution

```
{`__Jf^er$}_~

```

I thought basing a cop on a generalised quine was pretty clever and novel. The moment I posted this, I realised that `__` and `er` are completely useless, which is why I posted the 8-byte CJam cop for a more competitive score. Pietu cracked that one rather quickly, so I was afraid he'd figure out this one as well. I suppose the unnecessarily convoluted character transliteration saved it.

Anyway, the code takes its own characters (except the `_~`), XORs each one with 19 for obfuscation and then sorts them.

This cop led me to the "discovery" of xorting, although I'm not actually using it here (and it would probably be near impossible to make use of it with a short generalised quine).
> 7 votes

# Answer
# ~~Matlab~~ Octave, 27 characters, safe

### Challenge

Regarding the new language restrictions: It also works in Octave.

```
____________3_3___4_3______

```

Output (in Octave): (`ans =` is not part of the output, the first character of the output is `"`)

```
ans = """""""""""""""""""""""""""""""""""""""""""########$$$$$$%%%%&&&&'''(()))**++,,-../001223456789:;<=>?@BCDFGHJKMNPRTUWY[]_acehjloq

```

Output (in Matlab): (`ans = \n\n` is not part of the output, the output is just the last line)

```
ans =

"""""""""""""""""""""""""""""""""""""""""""########$$$$$$%%%%&&&&'''(()))**++,,-../001223456789:;<=>?@BCDFGHJKMNPRTUWY[]_acehjloq

```

### Solution

> `[fix((0:.07/3:3).^4+34),'']`
> We are basically looking at this function, converted to ASCII values.
> 6 votes

# Answer
# JavaScript (ES6), 60 characters, Cracked by user81655

Not promising to win, but hopefully fun to crack:

```
e_e_______a__a____e___e________e__o___________o______o______

```

This is a function that returns:

```
    :ERacddeeeeeeffiinnnoorrrrst
^^^^ -> 4 whitespaces

```

---

**Edit**

user81655 cracked it character by character:

> `e=e=>{try{a}catch(e){return[...e.toString()].sort().join``}}`
> 6 votes

# Answer
# Fortran, 45 characters, safe

Complete Output:

```
 !"$)0<Ka|

```

Cat attempted to cracked it here

Code (45 characters):

```
pr_gr_m____________________/___3____________

```

Program code:

> `program t;print*,(char(i**3/8+33),i=1,9);end`
> 4 votes

# Answer
# Jolf, 27 characters, Cracked by Adnan

```
________W___________--_____
                         |

```

prints

```
abcdefghijklmnopqrst

```

Interpreter.

Original code:

```
on*2toHEWn)oH+H `pl$--$n}_H
on                          set n
  *2t                        to twenty
     oHE                    set H to the empty string
        Wn)                 while(n){
           oH+H             append to H
                `pl$--$n     get the nth character of the alphabet, decrement n before
                        }   }
                         _H print H reversed

```

Congrats to Adnan! You scare me.

---

Here, you can test your submission, to see how many characters must be removed.

```
setInterval(function(){r=document.querySelector("textarea").value;document.getElementById("output").innerHTML=r.length/6-r.split("").filter(function(x){return x=="_"}).length|0},20)
```

```
*{font-family:Consolas,monospace}textarea{width:100%;resize:none;height:auto;min-height:1.2em;}b{color:red;}
```

```
<textarea>Example Program</textarea><div>You must reveal <b id="output">n</b> characters.</div>
```
> 4 votes

# Answer
# PHP, 46 characters, safe

Source:

```
for(_______________________=________________);

```

Outputs a 84 characters long string:

```
!!"#$%&'()*+,-./0123456789::;<=>?@AABCDEEFGHIIJKLLMNNOPPQRRSTTUUVWWXXYYZZ[[\\]]^^__`

```

**Hint**

> What'd you say? My cousine is involved?

**Revealed code**

> This method is relatively simply as it prints up to *64* characters starting at `chr(32)`. The obscuring part is, that the iterator `i` is not incremented linearly. It's incremented by it's own *cosine* value which will result in repeated and missing characters.
> `for(;$i<64;)echo chr(32+$i+=cos(deg2rad($i)));`
> `for(_______________________=________________);`
> 4 votes

# Answer
# R, 60 bytes, cracked by plannapus

Output:

```
0123456789ABCDEFGHTUVWXYZdefghijklmnopqrstuvw

```

Code:

```
___(_(_:_____________]_____________6]_______s_4_____,___=___

```

I think this will not be so hard. We will see.
> 4 votes

# Answer
## Python 3.4, 127 characters - SAFE

This is my first coppers-post. I think/hope it's not too hard or too obvious.

The obfuscated code:

```
_______inspect__________________getsource_____________________________________________print__________c*s_______________________

```

creates this output (there are 5 spaces at the beginning; total length is 7740 characters):

```
     """"""""""""(((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))**********************...................................................................................................................;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;==============================[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooopppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

```

## Edit 25 sept 2021, the answer in Python 3

```
import inspect;s=sorted(inspect.getsource(inspect.getmodule(inspect.currentframe())));print("".join([c*s.index(c) for c in s]))

```

Try it online!

The code gets the code itself as a string and then repeaths every i-th character i times. Finally the resulting string is sorted.

Funny thing is thus that all the characters of the solution are in the output! ;-)
> 4 votes

# Answer
# 05AB1E, 13 characters, cracked by quintopia

I'm an idiot. I forgot to implement power function (-\_-｡). Here is the obfuscated code:

```
__D____<_____

```

My original code was:

```
99DF2}r<F*}bR

```

Explanation:

```
99DF2}r<F*}bR

99            # Pushes 99
  D           # Duplicates the top item
   F }        # Creates a for loop: For N in range(0, 99)
    2         # Pushes 2 (this will be done 99 times)
      r       # Reverses the stack
       <      # Decrement on the last item
        F }   # Creates a for loop: For N in range(0, 98)
         *    # Multiplies the last two item of the stack, which now looks like
              # [2, 2, 2, 2, 2, 2, 2, 2, ...]. Basically we're calculating 2^99
           b  # Converts the last item to binary
            R # Reverses the last item of the stack

```

This will output:

```
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001

```

Yes, that is 99 zeroes followed by a 1.

---

**Note**, I have a power function implemented right now. So this could be done in six bytes:

```
Y99mbR

```
> 3 votes

# Answer
# Pyth, 17 characters, cracked by Pietu1998

Output:

```
""''''''''''''''''''''0000000000111111111122222222223333333333XXXXXXXXXX[[[[[[]]]]]]

```

Code:

```
___________#____1

```

My solution:

```
Sjkm^dT%"'%#X"291

```

Pietu1998's solution:

```
S`u]G6*T`t"#X0231

```
> 3 votes

# Answer
# MATL, 8 characters, safe

*Stable version of the compiler working in Octave hopefully coming soon. Meanwhile, this GitHub commit works, and in particular runs the original code that produces the indicated output*

*This submission counts as posted on December 28, 2015, 15:30 UTC*

Output:

```
$**0016688??@HHQ

```

Code (8 characters):

```
_:______

```

### Solution

```
6:9tX*Sc

```

What it does:

```
6:9          % numeric vector [6 7 8 9]
t            % duplicate
X*           % Kronecker tensor product
S            % sort in ascending order
c            % convert to char. Implicit display

```
> 3 votes

# Answer
# Mathematica 10.1, 98 characters, safe

Output is here. The entire output has 838,316 characters and a trailing newline.

Code:

```
Print[""<>Chara__________________________________________________________________________________]

```

Yes, this must be run in 10.1. <sub>*(hint)*</sub> The original program:

```
Print[""<>Characters@ToCamelCase@ExampleData@{"Text","DonQuixoteIEnglish"}~SortBy~ToCharacterCode]

```
> 3 votes

# Answer
## CJam, 8 bytes, Cracked by Pietu1998

```
__:_____

```

prints

```
%*;a|~

```

You can try CJam online.
> 3 votes

# Answer
# Malbolge, 254 characters, cracked by Adnan

Code:

```
_____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ __

```

Output:

```
`AB\cd`

```

I kinda cheated by putting a space for every 6th character. Oh well...

---

Adnan's cracked code:

```
('&%: ^"!65 4Xzyx w4-Qs rpo'K mlk"' ~Dfdc ba}v< ::8[Z XnVlq }0/mO ,*MbK JH^6# 4`C|0 ?U=Sw uPsaq L4on2 Mjjh, ged)c '<$$p ]!};Y WiVxS eRQ>= ).K]l Ij"Fh gfedc b,=;z L\q%H X3E2C /ng-k N*KJI 8%6#D ~2^Ai >g<<d tUr`6 oJ"!1 /|{CU f)d>b <A_^! \};Yj yUxTS dtsr` ML

```

The original code:

```
bCBA@ ?>=<; :9876 54321 0/.-, +*)(' &%$#" !~}|{ zyxwv utsrq ponml kjihg fedcb a`_^] \[ZYX WVUTS RQPON MLKJI HGFED CBA@? >=<;: 9y165 43210 /.-,+ *)('& }C#"! ~wv<z \xwvu tsrqp onmlk jihgf e^$ba `_^W\ UyYXW VUTSR QPONM FKJIH GFEDC BA@9] =<;:9 27654 3210) M:

```

I cheated again by using a text-to-Malbolge generator for this code.
> 3 votes

# Answer
## Labyrinth, 5 bytes, Cracked by Adnan

```
_____

```

prints

```
000000

```

---

My original code was:

```
<!!@

```

Note the trailing space.

I suppose I should have gone for more characters and revealed one of the `!`, because Adnan's solution only grows linearly when adding more `!`, while mine grows quadratically.
> 2 votes

# Answer
# CJam, 12 characters, Cracked by jimmy23013

**Output**

```
#$%&'()*+,-./:;<=>?@[\]^_`

```

**Code**

```
_:____#_____

```
> 2 votes

# Answer
<sup>Because I majorly f'ed up my last answer.</sup>

---

# Mouse-2002, 23 chars, *safe*

Code:

```
________9<^___________

```

Output:

```
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`ab

```
> 2 votes

# Answer
## ES6, 17 characters, cracked by Cᴏɴᴏʀ O'Bʀɪᴇɴ

```
__=____=_________

```

This is a function that will return the string

```
11233

```
> 2 votes

# Answer
# PHP, 28 characters

```
<?=________________________;

```

Outputs the string

```
abcdefghijklmnopqrstuvwxyz

```
> 2 votes

# Answer
# JavaScript, 83 chars, Cracked by Martin Büttner

Output

```
Hi~~~

```

Code

```
_=____r____=u____=__s__=_________=__________________u_______A__________e______"_~_"

```

Output is in the JS console of a browser like Chrome/Firefox.
Original code (which *might* be invalid):

```
q=w=e=r=t=y=u=i=o=p=s=d=f=g=h=j=k=l=z=x=c=v=b=n=m="Huh"[0]+"Alarms in here"[7]+"~~~"

```
> 2 votes

# Answer
# MirBSD Korn Shell, 57 characters, safe

Output:

```
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```

Code (57 characters):

> \___________*32\____________127\_____________________echo*$s

Revealed code:

> `local -i1 x=32;while((++x<127));do s+=${x:2};done;echo $s`
> 2 votes

# Answer
# Pyth, 6 characters, cracked by Pietu1998

Code:

```
S_____

```

Output:

```
.0113345678888999

```

You can try Pyth here
> 2 votes

# Answer
# Pyth, 15 characters (safe)

Code:

```
_CM____________

```

Output:

```
"$%'()+-./013456789:;=?BCEFGIKLOPRSTUWXYZ[]^`abcdefghjklmoqsuvxy{|

```

You can try Pyth online.

> I wonder if you can find out the criteria for the characters. :3

Additional hint:

> One could have a computers firm like Captor's Fermium totally messed up on just this one puzzle, and still they wouldn't fully solve it. Even the actor Frump Mise couldn't solve it.

## Original code

> `sCMf%sPT3rCN127`

Explanation:

> `rCN127` generates all numbers from 34 (`CN` = `ord('"')`) to 127. `f%sPT3` finds all the ones that satisfy the following: the sum of the prime factors of `n` is not divisible by 3. `s` concatenates the results. The first hint has the number 3, and it refers to filtering the characters/numbers. The additional hint contains 3 anagrams of `prime factor sum`.
> 2 votes

# Answer
# Octave, 18 bytes:

Output in Octave:

```
ans =  $'())**+,,--../0011233

```

Note that `ans =_` (replace `_` with space) is how Octave prints output by default and is not part of the output string. The output string alone starts with a single leading space like this:

```
 $'())**+,,--../0011233

```

Code:

```
[________:_______]

```

<sub>Disclaimer: If this miraculously should end up being the shortest uncracked submission, I'll award the win to the runner-up. This won't be a winning submission, I just wanted to have some fun too. *And* I figured a relatively short MATLAB/Octave submission could be fun for others. The other one was too hard for me at least.</sub>
> 2 votes

# Answer
# JavaScript ES6, 134 characters

Huh boy, that was fun. Good luck!

```
_=_=_____l____.______.________(___}__;___=______ru____"_____+_[________]______!____]__[_________e________.__U_________)__________\_____

```

Outputs:

<pre><code>((((((()))))))+...000000000000000000002233=>AAAAAAAAAAABBBBBCCCCCCCCCCCCCCCCCCDDDDDDDEEEEEEEEEEEEEEEEEEEFFFFFFFGHIIIIIIIIIIIIIIIIJJJJLLMMNNNNNNNNNNNNNNNNNNNNNNNNNOOOOOOOOOOOOOOOOOOOOOOPRRRRRRRSSSSTTTTTTTTTTTTTTTTTTTTTTTUUUUUUUUUVVVVVVXXY[[[[[[[[]]]]]]]]````ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiinnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu{{{{{{}}}}}}
</code></pre>
> 2 votes

# Answer
## Seriously, 7 bytes, Cracked by Martin Büttner

```
______S

```

Output:

```
   deeknnoow

```

Shouldn't be too difficult, even if the result is not exactly what you'd expect.
> 2 votes

# Answer
# Python 3, 58 characters, cracked by Mitch Schwartz

Code:

```
______________print(_______(_______________________)_____)

```

> import string;print(''.join(sorted(string.printable))\[5:\])

Output:

```
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```
> 2 votes

# Answer
# Ruby, 32 characters, safe

Output (with no trailing newline):

```
!"#$%&'(+,./567;<HKLUVWnouvw

```

Obfuscated code:

```
________{|c|___________________}

```

Revealed code:

> 95.times{|c|c&5\*c\<7&&putc(c+33)}

Explanation:

> Actually pretty straight-forward, just too arbitrary to easily guess or brute-force. For each number c from 0 to 94, bitwise-and c and 5\*c. If the result is less than 7, add 33 and output as an ASCII character.
> 2 votes

# Answer
# Befunge, 11 characters, cracked (in funge-98) by MegaTom

Output:

```
1223788

```

Obfuscated code:

```
________.__

```

All one line, since the rules prohibit newlines. Tested using http://www.quirkster.com/iano/js/befunge.html .

Edit: This is legally cracked since I didn't specify a version, but note that there's a Befunge-93 solution still out there.
> 2 votes

# Answer
## Perl 5, 30 bytes, cracked by Adnan

Code:

```
print_________________________

```

Output:

```
9:;@AFGHLMNRSTYZ_`a

```

Cracked:

Adnan found a trivial crack: obviously, I didn't think this puzzle through well enough. I've composed another instead.
> 2 votes

# Answer
# Python 2, 62 chars, Cracked by Adnan

```
______________________________________________________________
         | |   ||                  |  |  ||

```

It kinda looks like a table.

This outputs the string `abcde`.

Adnan's code:

> `print "ab_c_de___".replace("_","")#___________________________`

My code:

> `f=lamda _,__,___:"abcde"+'f'*sum(_,__,___)*000;print f(1,2,3);`
> 2 votes

# Answer
# Octave, 22 characters, Safe

Code:

```
__A____________A___V__

```

Output:

```
ans = ABCDFGHHIJLMNNOPRSTTUV

```

`ans =` is not part of the output. The output starts with an `A`.

Real code:

> \[(A=66:86)+sin(A),'V'\]

Explanation:

> In Octave, variable assignments can be done in the same line they are used. So, the variable `A` is created starting from `66` (corresponds to `A` in ASCII) to `86` (corresponds to `V` in ASCII). `+sin(A)` creates a small sine wave noise. `'V` converts the vector to chars and adds a `V` at the end. The variable name `A` and the last letter `V` was of course chosen to throw people of track =)

This one was made for the robbers. Hope it's neither too hard nor too easy. Good luck :-)
> 2 votes

# Answer
# Marbelous, 39 characters (safe)

_ is an unknown character: it may or may not be a newline.

* represents a newline character.

```
__^__________*__<___________@___/_*____

```

Output:

```
%,:>?@@BBFFNN^^~~

```

Code:

```
@0^5FF
0101FC
\\<ZEE
<</\+S
@0+Z//
25--

```

Online interpreter. None of the options should be checked.
> 1 votes

# Answer
# Recall, 64 characters

Output:

```
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```

Code:

```
_D_0__0_M__________0__0___0_________Z___0____0_____________M____

```

Pretty straightforward in theory. I made a sandbox here, so you can try things. Keep in mind that infinite loops or deep recursion will crash your tab/browser, so keep a copy elsewhere when trying. You can also download `recall.min.js` from the link in the title and run it with node.js.
> 1 votes

# Answer
# PHP, 68 characters, safe

As usual, don't expect anything short from PHP:

```
______________________________1_________________________________[1_;
 |    |    |           |               |           |    |      |

```

Outputs this 252 character long string:

```
AAAAAAAABCCDDEEEEEEEGIIIIIKLMNNOOOOOOOOOPPPPRSSTTTUUUUUXYYZaaaaaaaaaaaaaabbbbccccccccccccdddddddeeeeeeeeeeeeeffffffggghhhhiiiiiiiiiiiklllllllllllllllmmmmmmnnnnnnnnnnooooooooooooooopppppppppppppqrrrrrrrrrrrrrrsssssssssssssssssstttttttttuuuuuuuuuwxyyyzzz

```

**Hint 1**

> Sometimes you have to "translate" things.

**Hint 2**

> Luckily PHP stores all those helpful "translations" for you internally.

**Revealed code**

> There aren't too many built in functions, that return long strings or arrays with predefined values. One exception is `get_html_translation_table`. I sorted this array and returned the first character after the `&` from all escape sequences, e.g. the *A* from `Ä`. It has a nice distribution which looks random because the amount of entities related to a letter varies a lot.
> `$_=get_html_translation_table(1);sort($_);foreach($_ as$_)echo$_[1];`
> `______________________________1_________________________________[1_;`
> `>| | | | | | | |`
> 1 votes

# Answer
# Milky Way 1.6.1, 24 characters, Safe

Output:

```
jklmnopqrt

```

Code (24 characters):

```
^_"_________________"__!

```

---

### Solution

```
^^"pqrjklmno"C=<<<"t"JG!

```
> 1 votes

# Answer
# PHP, 61 characters

Gonna try again, if that's okay :p I wasn't expecting `range('a','z')` to be particularly well-known, but I should have known better around here ;)

Code:

```
<?p___________++<_______h__________e______1____p_____________

```

Outputs:

```
AAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBCCCCCCCCDDDDDDEEEEEEFFFFFGGGGGHHHHHIIIIJJJJKKKKLLLMMMNNNNOOOPPP

```
> 1 votes

# Answer
# Python 2, 76 characters, Cracked by Adnan

```
print __________h______________________v_____________,___)_________)_______)

```

Outputs

```
BKT]f

```

Full Code

> `print "".join([chr(x) for x in list(reversed(range(32,126)[70:5:-9]))[3:8]])`
> 1 votes

# Answer
# 05AB1E, 7 characters, cracked by quintopia

Obfuscated code:

```
___T___

```

Original code:

```
576T*uH

576      # Pushes 576
   T     # Pushes 10
    *    # Multiply the last two items of the stack
     u   # To uppercase, this just returns 576 in string format
      H  # Convert from hexadecimal to decimal

```

**Note:** I used the uppercase command to convert the int to a string. This however is a bug and has already been fixed.

Output:

```
22368

```
> 1 votes

# Answer
## Seriously, 7 characters, (uncracked and noncompeting)

I was inspired by trying to find an answer to Adnan's latest cop, by how close this number was to their number:

```
___P___

```

Output:

```
22366

```

> 22366 is the 211th triangular number. The original program was `8PτPurΣ` but it is disqualified for containing two non-ASCII characters. It simply takes the 8th prime (23), doubles it (46), finds the 46th prime (211), then pushes the 0-211 range (`ur`) and sums it.
> 1 votes

# Answer
# Marbelous, 19 characters

```
_1
___0
____
_____1

```

Outputs

```
39?E(

```
> 1 votes

# Answer
# Pyth, 6 characters (cracked by isaacg)

Output:

```
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

```

Code:

```
S_____

```

Let's try a simpler one.
> 0 votes

# Answer
## Purple, 31 characters (safe)

```
__A_____________o______b__1___b

```

Full program:

> `a1AbA1iib{bi1b1Bo1aaa1bbab1Bi1b`

Output:

```
abcdefghijklmnopqrstuvwxyz

```

Explanation:

> It's about the shortest way to print the alphabet in Purple.
>
> ```
> 1.  a1A    Set to 1-"a" == -96
> 2.  bA1    Set b to -1 (using the fact that a is always negative)
> 3.  iib{   Set i=i-b, i.e. i+1. This skips over the "{"
> 4.  bi1    Set b = i-1 (the cell before the current command, containing "{")
> 5.  b1B    Set b = 1-"{" == -122
> 6.  o1a    Output 1-a (which will be the current character)
> 7.  aa1    Subtract 1 from a (i.e. move to the next character)
> 8.  bba    Set b=b-a. It will be negative until a==-122, when it will be zero
> 9.  b1B    Set b=1-what b points to. It will be 0 until a==-122, when it will be -96.
> 10. i1b    Jump to 1-b. This goes to line 2 until a==-122, when it jumps outside
>            the program and halts.
> ```
> 0 votes

# Answer
# Unefunge-98, 16

Output:

```
&),/258;>ADGJMPSVY\_behknqtwz}

```

Code:

```
_#_________3____

```
> 0 votes

# Answer
## Perl 5, 31 bytes, safe

Code:

```
print__________________________

```

Output:

```
$%&&'+,,-1223478899:>??@DEEFJKKLLMPQRRSWXXY]^^_

```

Code:

> `print+(chr)x(1.2+cos)for 36..95`
> 0 votes

# Answer
# JavaScript (ES6), 59 characters

Output:

<pre><code>   """'''(((((())))))+++++++++,,,,,,---------...............123:::===>>>???NNNNNNOOO[[[[[[\\\]]]]]]^^^______````````````aaabbbbbbccccccddeeeeeeeefgggggggggggghhhiiiijjjjjjjjjkkklllllllllnnnnnooooooooorrrssstttttttttu{{{}}}
</code></pre>

The first 3 characters in the output are spaces.

Code:

```
(_____________________________________________.join``_____)

```

*Note: The original version of this produced a much greater variation in characters with the exact same code hint, but I thought the output was unreasonably long so I decided that I'd at least give someone a chance at cracking this. :P Good luck!*
> 0 votes

# Answer
# Forth, 29 chars

You're gonna need a very special version of Forth for this one: one that doesn't require newlines after function definitions.

Code

```
_______ __ _________ ____ ___

```

(Yes, that's whitespace, and yes, it has to be there or else one gets `Error: Unknown word`)

Output:

```
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

```

Note the leading space.
> 0 votes

# Answer
# CJam, 9 chars

Code:

```
'_{___2__

```

Output:

```
abcdefghijklmnopqrstuvwxyz

```
> 0 votes

# Answer
# Brainfuck, 51 chars

Code

```
_____[________________]>.>_____[________]>[_______]

```

Output:

```
ABCDEFGHIJKLMNOPQRSTUVWXYZ

```
> 0 votes

# Answer
# Python2, 72 chars

Code:

```
___(___(___(___((_____)_(____)_)______________(______)________________)

```

Full output (63,769,891 bytes) as compressed by `zlib` (use `import zlib; zlib.decompress(...)` to get the actual string, which I recommend writing to a file)
> 0 votes

# Answer
# CLC-INTERCAL 1.-98.-2, 198 bytes, safe.

33 bytes are revealed:

```
__#3__#9__,1_____________________________3__3__-_3__3__________-_33_D_______&_________-_____________-___D_#4__#28D______________-________B#__-_V________________-_V_______________________________U___

```

Output is:

```
!->Ma

```

Should I post shorter one next time?

Try it online!

## Answer

Sorry for irrationally difficult problem.

> `DO#3<-#9DO,1<-#3DO,1SUB#3<-#3~#3DO,1SUB'#3~#3'<-#3~#3DO,1SUB#5<-#338DO,1SUB"&'#3~#3'"<-#27DO,1SUB#4<-#27DO#4<-#28DO,1SUB'#4~#4'<-#4DO,1SUB#6<-"V'#V4'"DO,1SUB#8<-'V"V'#V4'"'DO,1SUB#2<-#333DOREADOUT,1`

### How it works

> `DO#3<-#9` changes meaning of the constant.

> `DO,1<-#3` lets array to have nine item; note previous statement.

> `DO,1SUB#3<-#3~#3` is equivalent to `DO,1SUB#9<-#9~#9`, which is equivalent to `DO,1SUB#9<-#3`.

> `DO,1SUB'#3~#3'<-#3~#3` does `,1SUB#3<-#3`.

> `DO,1SUB#5<-#338` is equal to `DO,1SUB#5<-#18` when `READ`ing `OUT`; this is how Baudot character set works; it cares for only lower five octets.

> `DO,1SUB"&'#3~#3'"<-#27` does `,1SUB#1<-#27`.

> `DO,1SUB#4<-#27` is obvious, as none of those constants are not overloaded yet.

> `DO#4<-#28` now overloads the operand.

> `DO,1SUB'#4~#4'<-#4` now does `,1SUB#7<-#28`.

> `DO,1SUB#6<-"V'#V4'"` is actually `DO,1SUB#6<-#30`.

> `DO,1SUB#8<-'V"V'#V4'"'` does `,1SUB#8<-#31`

> `DO,1SUB#2<-#333` does what it says.

> Finally, output is done by `DOREADOUT,1`.

By the way the reason why an array requires 9 items to output 5 characters is: tail arrays adopt extended Baudot character set. The character set has a concept of "state": uppercase, lowercase, figures, and symbols. When a same value is READ OUT with different state, the different character is READ OUT
> 0 votes

# Answer
# CLC-INTERCAL, 38 bytes, safe.

This is much easier than previous. Six bytes are revealed:

```
____<-___________<-________DO_________

```

Outputs:

```
BCDLX

```

Try it online!

## The answer

> `DO;1<-#1DO;1SUB#1<-#17DOREADOUT;1+#460`

> Please note output is "B" and "CDLX".
> 0 votes

---
Tags: cops-and-robbers
---


title: Primes ’n’ Digits

text:
# Question
Title: Primes ’n’ Digits
This has no practical purpose but it could be fun to golf.

# Challenge

Given a number *n*,

1. Count the amount of each digit in *n* and add 1 to each count
2. Take the prime factorization of *n*
3. Count the amount of each digit in the prime factorization of *n*, without including duplicate primes
4. Create a new list by multiplying together the respective elements of the lists from steps 1 and 3
5. Return the sum of that list

For example, 121 has two `1`s and a `2`, so you would get the following list from step 1:

```
0 1 2 3 4 5 6 7 8 9
1 3 2 1 1 1 1 1 1 1

```

The prime factorization of 121 is 112, which gives the following list for step 3:

```
0 1 2 3 4 5 6 7 8 9
0 2 0 0 0 0 0 0 0 0

```

Note how we did not count the exponent. These multiply together to get:

```
0 1 2 3 4 5 6 7 8 9
0 6 0 0 0 0 0 0 0 0

```

And the sum of this list is 6.

# Test cases

```
1 -> 0
2 -> 2
3 -> 2
4 -> 1
5 -> 2
10 -> 2
13 -> 4
121 -> 6

```

# Notes

* Standard loopholes are forbidden.
* Input and output can be in any reasonable format.
* You should leave ones (or zeros for step 3) in the list for digits that did not appear in the number.
* This is , so the shortest solution in bytes wins.

# Answer
> 1 votes
# 05AB1E (legacy), 5 bytes

```
fS¢>O

```

Try it online!

```
f      list of prime factors (without duplicates) of the implicit input
S      characters, all of the digits
¢      count each of the characters in the implicit input
>      increase each of the counts
O      sum (implicit output)

```

# Answer
> 4 votes
# Jelly,  ~~18~~  17 bytes

-1 byte thanks to caird coinheringaahing & H.PWiz (avoid pairing the two vectors)

```
DF‘ċÐ€⁵
ÆfQÇæ.Ç‘$

```

A monadic link taking a positive integer and returning a non-negative integer.

**Try it online!**

### How?

```
DF‘ċÐ€⁵ - Link 1, digitalCount: number(s)    e.g. [13,17]
D       - to decimal list (vectorises)            [[1,3],[1,7]]
 F      - flatten                                 [1,3,1,7]
  ‘     - increment (vectorises)                  [2,4,2,8]
      ⁵ - literal ten                             10
    Ð€  - map across              (implicit range [1,2,3,4,5,6,7,8,9,10])
   ċ    - count                                   [0,2,0,1,0,0,0,1,0,0]

ÆfQÇæ.Ç‘$ - Main link: positive integer, n   e.g. 11999
        $ - last two links as a monad:
      Ç   -   call the last link (1) as a monad   [0,2,0,0,0,0,0,0,0,3]
       ‘  -   increment (vectorises)              [1,3,1,1,1,1,1,1,1,4]
Æf        - prime factorisation                   [13,13,71]
  Q       - deduplicate                           [13,17]
   Ç      - call the last link (1) as a monad     [0,2,0,1,0,0,0,1,0,0]
    æ.    - dot product                           8

```

# Answer
> 3 votes
# Jelly, 16 bytes

```
ṾċÐ€ØD
ÆfQÇ×Ç‘$S

```

Try it online!

Developed independently from and not exactly the same as the other Jelly solution.

**Explanation**

I'm gong to use `242` as an example input.

```
ṾċÐ€ØD     Helper link
Ṿ          Uneval. In this case, turns it's argument into a string.
           242Ṿ → ['2','4','2']. [2,11] → ['2', ',', '1', '1']. The ',' won't end up doing anything.
    ØD     Digits: ['0','1',...,'9']
 ċÐ€       Count the occurrence of €ach digit in the result of Ṿ

ÆfQÇ×Ç‘$S  Main link. Argument 242
Æf         Prime factors that multiply to 242 → [2,11,11]
  Q        Unique elements → [2,11]
   Ç       Apply helper link to this list → [0,2,1,0,0,0,0,0,0,0]
     Ç‘$   Apply helper link to 242 then add 1 to each element → [1,1,3,1,2,1,1,1,1,1]
    ×      Multiply the two lists element-wise → [0,2,3,0,0,0,0,0,0,0]
        S  Sum of the product → 5

```

# Answer
> 2 votes
# APL (Dyalog), ~~43~~ 41 bytes

```
⎕CY'dfns'
+/×/+/¨⎕D∘.=⍕¨(⎕D,r)(∪3pco r←⎕)

```

Try it online!

**How?**

`r←⎕` \- input into `r`

`3pco` \- prime factors

\- unique

`⎕D,r` \- `r` prepended with `0-9`

`⍕¨` \- format the factors and the prepended range

`⎕D∘.=` \- cartesian comparison with every element of the string `0123456789`

`+/¨` \- sum each row of the two tables formed

`×/` \- multiply the two vectors left

`+/` \- sum the last vector formed

# Answer
> 1 votes
# Pip, 44 bytes

```
Y_N_.aM,tT++o>aTa%o{a/:olPBo}$+y*Y_N JUQlM,t

```

Takes input from command-line argument. Try it online!

# Answer
> 1 votes
# Python 2, ~~136~~ 127 bytes

```
lambda a:sum(''.join(u(a)).count(`i`)*-~`a`.count(`i`)for i in range(10))
u=lambda a:[`j`for j in range(2,a)if a%j<1>len(u(j))]

```

Try it online!

# Credits

---
Tags: code-golf, primes, factoring
---


title: Longest Uncommon Substring

text:
# Question
Title: Longest Uncommon Substring
For the purposes of this challenge a *substring* \\$B\\$ of some string \\$A\\$ is string such that it can be obtained by removing some number of characters (possibly zero) from the front and back of \\$A\\$. For example \\$face\\$ is a substring of \\$defaced\\$

\\$ de\color{red}{face}d \\$

This is also called a *contiguous* substring.

A common substring of two strings \\$A\\$ and \\$B\\$ is a third string \\$C\\$ such that it is a substring of both \\$A\\$ and \\$B\\$. For example \\$pho\\$ is a common substring of \\$photochemistry\\$ and \\$upholstry\\$.

\\$ \color{red}{pho}tochemistry\\ u\color{red}{pho}lstry \\$

If we have two strings \\$A\\$ and \\$B\\$ an *uncommon* substring of \\$A\\$ with respect to \\$B\\$ is a third string \\$C\\$, which is a substring of \\$A\\$ and has no common substring of length 2 with \\$B\\$.

For example the longest uncommon substring of \\$photochemistry\\$ with respect to \\$upholstry\\$ is \\$otochemis\\$. \\$otochemis\\$ is a substring of \\$A\\$ and the the only nonempty common substrings of \\$otochemis\\$ and \\$upholstry\\$ are size 1 (\\$o\\$, \\$t\\$, \\$h\\$, and \\$s\\$). If we added any more onto \\$otochemis\\$ then we would be forced to permit a common subsring of size 2.

## Task

Given two strings \\$A\\$ and \\$B\\$ output the maximum size an uncommon substring of \\$A\\$ with respect to \\$B\\$ can be. You may assume the strings will only ever contain alphabetic ASCII characters. You can assume \\$A\\$ and \\$B\\$ will always be non-empty.

This is so answers will be scored in bytes with fewer bytes being better.

## Test cases

```
photochemistry, upholstry -> 9
aaaaaaaaaaa, aa -> 1
aaaaabaaaaa, aba -> 5
babababababa, ba -> 2
barkfied, x -> 8
barkfield, k -> 9
bakrfied, xy -> 8

```

# Answer
> 7 votes
# 05AB1E, ~~11~~ 8 bytes

```
ü«å_γO>à

```

Try it online! or Try all cases!

**Explanation:**

The longest uncommon substring is the longest sequence of adjacent length 2 substrings of \\$A\\$ that are not substrings of \\$B\\$.

```
ü«        # length 2 subtrings of A
  å       # for each substring: is it a substring of B?
   _      # logical negation
    γ     # split into list of equal adjacent elements
     O    # sum each section
      >   # increment each sum
       à  # take the maximum

```

# Answer
> 7 votes
# Python 3, 58 bytes

```
f=lambda a,b,s=1:a>''and+max(f(a[1:],b,a[:2]in b or-~s),s)

```

Try it online!

# Answer
> 5 votes
# Jelly,  ~~11 10~~  9 bytes

-1 using ovs's observation.

```
;Ɲẇ€ṣ1ẈṀ‘

```

**Try it online!**

---

#### 10 byter

```
Ẇ;ƝẇƇ¥ÐḟṪL

```

**Try it online!**

### How?

```
Ẇ;ƝẇƇ¥ÐḟṪL - Link: A, B
Ẇ          - sublists of A (from shortest to longest)
      Ðḟ   - filter discard those for which:
     ¥     -   last two links as a dyad, f(substringOfA, B):
 ;Ɲ        -     length 2 sublists of substringOfA
    Ƈ      -     keep those (pairs) for which:
   ẇ       -       is this pair a sublist of B?
        Ṫ  - tail -> longest uncommon substring
         L - length

```

# Answer
> 3 votes
# JavaScript (ES6), 63 bytes

Expects `(B)(A)`.

```
b=>g=([c,...a])=>a+a&&Math.max(g(a)-1,g=!b.match(c+a[0])*-~g)+1

```

Try it online!

### Commented

```
b =>             // main function taking the 2nd string b
g = ([           // g = recursive function taking the 1st string as:
  c,             //   c = next character
  ...a           //   a[] = array of remaining characters
]) =>            //
  a + a &&       // stop if a[] is empty (and return a zero'ish value)
  Math.max(      // otherwise, take the maximum of:
    g(a) - 1,    //   - the result of a recursive call, minus 1
    g =          //   - the updated value of g, which is:
      !b.match(  //     - 0 if b contains c + a[0]
        c + a[0] //     - g + 1 otherwise
      )          //   NB: all recursive calls have already been processed
      * -~g      //   when this part of the code is reached; so it's OK
                 //   to re-use g as a counter (initially zero'ish)
  )              // end of Math.max()
  + 1            // increment the result to make it 1-indexed

```

# Answer
> 3 votes
# Retina, ~~33~~ 32 bytes

```
(?=(..).*¶.*\1|.*$).
;¶
P`.+
\G.

```

Try it online!

-1 thanks to Neil.

Takes the strings \\$A\\$ and \\$B\\$ separated by a line feed for the input.

First, a Replace stage looks for each character in \\$A\\$ that when combined with the next character forms a pair that can be found in \\$B\\$ (`(..).*¶.*\1` in the lookahead), as well as every character of \\$B\\$ (`.*$` in the lookahead). Each of those characters is replaced by a semicolon followed by a line feed. This breaks \\$A\\$ into pieces that are uncommon with respect to \\$B\\$ and \\$B\\$ into individual characters, except with `;` in place of the last character of each piece. Each piece is on a separate line.

Next, a Pad stage matches each whole line, and pads all of them to the longest length present.

Finally, a Count stage matches each character in the first line (because `\G` makes the matches have to be consecutive, and `.` does not match line feeds), and produces the number of such characters.

# Answer
> 2 votes
# Japt, 13 bytes

Just can't seem to do better than 13.

```
ä@VèZÃôÎmÊÍÌÄ

```

Try it

```
ã2 ô!øV ñÊÌÊÄ

```

Try it

```
ä@VèZÃôÎmÊÍÌÄ     :Implicit input of strings U & V
ä                 :Consecutive pairs of U
 @                :Map each Z
  VèZ             :  Count the occurrences of Z in V
     Ã            :End map
      ô           :Split on elements with
       Î          :  A truthy sign (i.e., 1)
        m         :Map
         Ê        :  Length
          Í       :Sort
           Ì      :Last element
            Ä     :Add 1

```

```
ã2 ô!øV ñÊÌÊÄ     :Implicit input of strings U & V
ã2                :Substrings of U of length 3
   ô              :Split on elements
    !øV           :  Contained in V
        ñ         :Sort by
         Ê        :  Length
          Ì       :Last element
           Ê      :Length
            Ä     :Add 1

```

# Answer
> 2 votes
# Python 3, 80 bytes

```
f=lambda b,a,*r:{*zip(a,a[1:])}&{*zip(b,b[1:])}and f(b,*r,a[1:],a[:-1])or len(a)

```

Try it online!

Yes! Longest continuous substring again.

# Answer
> 2 votes
# Brachylog, 18 bytes

```
⟨s{s₂ᶠ¬{∋~s}}⟩ᶠlᵐ⌉

```

Takes a list containing strings \\$A\\$ and \\$B\\$ as input; produces the longest length as output. Try it online!

### Explanation

Implements the spec pretty directly:

```
⟨            ⟩      "Sandwich" construction:
 s                  The output is a substring (C) of the first string in the input (A)
  {         }       which satisfies this predicate with respect to the second string (B):
   s₂ᶠ               The list of all length-two substrings of C
      ¬{   }         does not satisfy this predicate:
        ∋             There exists an item in the list
         ~s            which is a substring of B
             ᶠ     Find all substrings that satisfy the sandwich predicate
              lᵐ   Length of each
                ⌉  Maximum

```

# Answer
> 2 votes
# , ~~156~~ ~~107~~ ~~105~~ 99 bytes

Or **\>=4.1, 85 bytes** by replacing two `function` appearances with `\`s.

```
function(x,y,r=rle(!sapply((1:nchar(x))[-1],function(k)grepl(substr(x,k-1,k),y))))max(0,r$l[r$v])+1

```

Try it online!

Port of @ovs's answer.

# Answer
> 1 votes
# Jelly, 12 bytes

```
ẆẆḊƇẇ€SʋÐḟẈṀ

```

Try it online!

## How it works

```
ẆẆḊƇẇ€SʋÐḟẈṀ - Main link. Takes A on the left, B on the right
Ẇ            - All contiguous substrings of A
       ʋÐḟ   - Keep substrings S for which the dyadic link f(S, B) is 0:
 Ẇ           -   Substrings of S
  ḊƇ         -   Remove singleton lists
     €       -   Over each substring:
    ẇ        -     Is B a contiguous substring?
      S      -   Sum
          ẈṀ - Get the maximum length

```

# Answer
> 1 votes
# Pip, 19 bytes

```
U#MX J(_.BNIbMPa)^0

```

Takes the two strings as command-line arguments. Try it here! Or, here's a 20-byte version in Pip Classic: Try it online!

### Explanation

Based on ovs's 05AB1E answer:

```
U#MX J(_.BNIbMPa)^0
             MPa     Map this function to each pair of characters in a:
       _.B            Concatenate them together
          NIb         Return 1 if that string is not in b, 0 if it is
     J(         )    Join the resulting list of 1s and 0s into a single string
                 ^0  Split it on 0s
  MX                 Take the maximum (i.e. the longest run of 1s)
 #                   Get its length
U                    Increment

```

# Answer
> 1 votes
# Vyxal, 14 bytes

```
K'2lv∑⁰vca¬;tL

```

Try it Online!

A bit messy.

```
K              # Substrings
 '         ;   # Filtered by...
         a¬    # None of...
  2lv∑         # Substrings of length 2
       vc      # Are contained in...
      ⁰        # The second input
            t  # Get the last (and longest) element
             L # Get its length

```

# Answer
> 1 votes
# Attache, 37 bytes

```
${#Last[{_&Has\`@&1\y==[]}\x]}:Slices

```

Try it online!

## Explanation

```
${#Last[{_&Has\`@&1\y==[]}\x]}:Slices
${                           }           a function taking inputs x and y
                              :Slices    ...where x = Slices[x] and y = Slices[y]
        {                }\x             all members _ of x where
                   \y                     |the elements of y which
               `@&1                       | |have a char at index 1 (i.e., length >= 2)
         _&Has\                           | |and are contained in _
                     ==[]                 |is the empty list
   Last[                    ]            obtain the last such member
  #                                      and return its length

```

## Golfing Process

**41 bytes:** `${#({None[_&Has,{#_>1}\y]}\x)[-1]}:Slices`

**41 bytes:** `${#Last[{None[_&Has,{#_>1}\y]}\x]}:Slices`

**40 bytes:** `${#Last[{None[_&Has,{_@1}\y]}\x]}:Slices`

**39 bytes:** `${#Last[{None[_&Has,`@&1\y]}\x]}:Slices`

**38 bytes:** `${#Last[{#(_&Has\`@&1\y)<1}\x]}:Slices`

# Answer
> 1 votes
# K (ngn/k), 38 bytes

```
{#*((1&/^(2'y)?2')')#,/(''|1+!#x)[;x]}

```

Try it online!

Takes `A` as `x` and `B` as `y`.

* `,/(''|1+!#x)[;x]` generate all substrings of `A`, with the longest first
* `(...)#` filter, keeping only those items where `(...)` has `1`s
    + `((...)')` apply the code in `(...)` to each item in the list being filtered
    + `2'` take 2-length substrings of the current item
    + `(2'y)?` retrieve their indices in the 2-length substrings of `B` (returning `0N` (null) if it is not present)
    + `1&/^` keep items where none of their 2-length substrings are present in `B`
* `#*` return the length of the first (longest) uncommon substring

# Answer
> 0 votes
# Python 3, ~~144~~ 124 bytes

Naive approach, much room for golfing.

```
lambda a,b,l=len,r=range:max(l(c)for c in(a[x:y]for y in r(l(a)+1)for x in r(y))if all(c[n:n+2]not in b for n in r(l(c)-1)))

```

Try it online!

# Answer
> 0 votes
# C++ (gcc), ~~119 bytes~~ 116 bytes

```
int f(char*a,char*b){char*c=b,s=0,l=0;for(;a[1];*a++?l=l>++s?l:s:0)for(b=c;b[1];)*a-*b++|a[1]-*b?:s=*a=0;return-~l;}

```

Try it online!

I used ovs' characterization of longest uncommon substring as the longest sequence of adjacent length 2 substrings of \\$A\\$ that are not substrings of \\$B\\$ (plus 1).

I only use `C++98`. The function takes two C-strings as input and modifies the first one. ~~I chose not to abuse the `?:` feature in `gcc`, but that would save at least 1 byte.~~ Following ceilingcat's comments, I guess it doesn't hurt to use non-standard code (using `?:`, UB with bitwise OR `|`). This saves 3 bytes.

### Explanation

```
int f(char* a, char* b) {               // Take two C-strings as input
  char* c = b;                          // Remember the start of b
  char s = 0;                           // Current sequence length
  char l = 0;                           // Longest sequence length

  for (; a[1]; ++a) {                   // Iterate until before last character
    for (b = c; b[1];) {                // Similar
      if (*a != *b++ or a[1] != *b) {   // Compare pairs of characters
      }
      else {
        s = 0;                          // Reset current sequence length
        *a = 0;                         // Flag to indicate sequence reset
      }
    }
    if (*a) {                           // Check if sequence is reset
      ++s;                              // Increment current sequence length
      l = l > s ? l : s;                // Update maximal sequence length
    }
  }
  return l + 1;                         // Increment to get substring length
}

```

# Answer
> 0 votes
# Charcoal, 18 bytes

```
Ｉ⊕Ｌ⌈⪪⭆Φθκ¬№η⁺§θκι0

```

Try it online! Link is to verbose version of code. Explanation: Based on @ovs' approach.

```
       θ            Input A
      Φ             Filter out
        κ           First character
     ⭆              Map over characters and join
             §θκ    Previous character
            ⁺       Concatenated with
                ι   Current character
         ¬№         Is not found in
           η        Input B
    ⪪            0  Split on `0`s
   ⌈                Longest string of `1`s
  Ｌ                 Length
 ⊕                  Incremented
Ｉ                   Cast to string
                    Implicitly print

```

---
Tags: code-golf, string
---


title: Simulate my pill box

text:
# Question
Title: Simulate my pill box
I have a small pill box of \\$n\\$ slots. (Think of it as a linear one like the image below, but not necessarily having 7 slots.)

Each slot has at most one pill. Every day, I take one of two actions: take one pill from the pill box, or refill the pill box. The order of taking a pill alternates between left-to-right and right-to-left on each refill, **except** when the pill box was totally empty before the refill, in which case I always take the next pill from the left. The pill box is initially filled, and I initially take pills from the left. (I never try to take a pill from an empty box or refill a full box.)

Believe me, I take pills exactly as I describe here IRL. If you wonder why: I alternate directions as a simple way to prevent a pill from being too long in the pill box, and I just forget directions when the pill box is totally empty :P

Example with 5 slots:

| Action Number | Action | State of slots | Direction |
| --- | --- | --- | --- |
| 0. | Initial: | `[1, 1, 1, 1, 1]` | (order: -\>) |
| 1. | Take pill: | `[0, 1, 1, 1, 1]` | (-\>) |
| 2. | Take pill: | `[0, 0, 1, 1, 1]` | (-\>) |
| 3. | Take pill: | `[0, 0, 0, 1, 1]` | (-\>) |
| 4. | Refill: | `[1, 1, 1, 1, 1]` | (\<-) |
| 5. | Take pill: | `[1, 1, 1, 1, 0]` | (\<-) |
| 6. | Take pill: | `[1, 1, 1, 0, 0]` | (\<-) |
| 7. | Take pill: | `[1, 1, 0, 0, 0]` | (\<-) |
| 8. | Refill: | `[1, 1, 1, 1, 1]` | (-\>) |
| 9. | Take pill: | `[0, 1, 1, 1, 1]` | (-\>) |
| 10. | Take pill: | `[0, 0, 1, 1, 1]` | (-\>) |
| 11. | Take pill: | `[0, 0, 0, 1, 1]` | (-\>) |
| 12. | Take pill: | `[0, 0, 0, 0, 1]` | (-\>) |
| 13. | Take pill: | `[0, 0, 0, 0, 0]` | (-\>) |
| 14. | Refill: | `[1, 1, 1, 1, 1]` | **(-\>)** |
| 15. | Take pill: | `[0, 1, 1, 1, 1]` | (-\>) |
| 16. | Refill: | `[1, 1, 1, 1, 1]` | (\<-) |
| 17. | Take pill: | `[1, 1, 1, 1, 0]` | (\<-) |
| 18. | Take pill: | `[1, 1, 1, 0, 0]` | (\<-) |
| 19. | Take pill: | `[1, 1, 0, 0, 0]` | (\<-) |
| 20. | Take pill: | `[1, 0, 0, 0, 0]` | (\<-) |
| 21. | Take pill: | `[0, 0, 0, 0, 0]` | (\<-) |
| 22. | Refill: | `[1, 1, 1, 1, 1]` | **(-\>)** |
| 23. | Take pill: | `[0, 1, 1, 1, 1]` |  |

Inputs to your program or function:

* \\$n\\$, the size of the pill box.
* The list of my actions. You may choose any two distinct, consistent values to represent "take pill" and "refill".

The output is the list of the state of my pill box after each action. You may choose to include or exclude the initial state. You may also choose any two distinct, consistent values to represent a slot being full or empty.

If you encode "take pill" and "refill" as numbers 1 and 0 respectively, the input to your code for the above scenario would be

```
5, [1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1]

```

and the expected output is the list of arrays on the right side (you don't need to output the "order"), with or without the zeroth row.

Standard rules apply. The shortest code in bytes wins.

# Answer
# 05AB1E, 18 bytes

Takes input as a string of digits where `1` encodes *take pill* and `0` encodes *refill*.

-1 byte thanks to Kevin Cruijssen.

```
ηε0¡€g¤IL‹s5¡θgGR

```

Try it online!

I initially thought we are supposed to just generate the final state, which is why this program iterates over the prefixes. (But that might not even be a bad approach)

```
ηε                   # for each prefix of the input:
  0¡                 # split it on "0"
    €g               # take the length of each segment
       ¤             # take the last number (number of uses since last refill)
                     # this leaves the full list on the stack
        IL           # push the range [1 .. size of pill box]
          ‹          # element-wise less than
                     # this creates a list [0, ..., 0, 1, ..., 1] with the remaining number of pills
           s         # swap to the list of lengths
            5¡       # split the list in the register on 5 (direction resets)
              θg     # take the length of the last part
                GR   # reverse the list 1 times less than than this

```
> 5 votes

# Answer
# Vyxal, ~~30~~ 20 bytes

```
$(n[¥↳£¹|‹]:×*¹↳¥ßṘ,

```

Try it Online!

It's slightly satisfying using two different overloads of the same element.

```
$(                   # Iterating over the list of instructions
  n[                 # If it's truthy (refill)
    ¥↳               # Bitshift the current value by the register
                     # Iff the register is 0, and the current value is 1, the result is truthy.
      £              # Store this to the register
       ¹             # Refill, pushing original input
        |‹]          # Otherwise decrement (take a pill)
           :         # Duplicate
            ×*       # Get that many asterisks
              ¹↳     # Align
                ¥ßṘ  # If the register is truthy (we're taking pills from the left) reverse
                   , # Print.

```

Older version, where I was a big brain and tried to store the whole box:

```
1£ƛ1;?(n[:T¥ßṘt0Ȧ|:a¬¥¬∨£ƛ1;]…

```

Try it Online!

```
1£                             # Store 1 to register (direction)
  ƛ1;                          # Array of length n, filled with 1
     ?(n                       # For each item in the list of refills...
        [                      # If it's truthy (Take pill)
         :T                    # Get the truthy indices
           ¥ßṘ                 # Reverse if direction is left
              t                # Get the last one (first empty pos if left, last if right0)
               0Ȧ              # Assign 0 to this index
                 |          ]  # Else (Refill)
                        £      # Set the register (direction) to...
                  :a¬          # Whether the current array is all falsy
                       ∨       # Logical or with...
                     ¥¬        # The opposite current value of the register
                               # If any values are truthy, the register (direction) flips
                               # Otherwise, it becomes 1 (left)

                         ƛ1;   # Refill (fill with 1s)
                             … # Whichever action we took, print the current array

```
> 4 votes

# Answer
# JavaScript (V8), 80 bytes

```
(n,x,d)=>x.map(i=>'.'.repeat(i?--w:(d=w&&!d,w=n))[d?'padEnd':'padStart'](n),w=n)

```

Try it online!
> 3 votes

# Answer
# Ruby, ~~78~~ ~~76~~ ~~74~~ 73 bytes

```
->n,m{b=*i=0;(b+m).map{|a|a<1?b=[1**i=b.max*~i/n]*n:b[i]=0&i+=i/n|1;p b}}

```

Try it online!

### Explanation

For input, the 'take pill' and 'refill' actions are encoded as `1` and `0`, respectively. Output is a series of arrays in which `1` indicates a full slot and `0` an empty slot. The initial state is included.

The initial state is created by adding a refill step to the start of the action list. The direction of movement is embedded in the slot index `i`. If we are moving left to right then `i` is non-negative (array indices \\$0, 1, 2, \ldots\\$). If we are moving right to left then `i` is negative (array indices \\$-1,-2,-3,\ldots\\$), that is, we read from the end of the pillbox array.

```
->n,m{                      # n = size of pillbox, m = list of actions
  b=*i=0;                   # initialise slot index i to 0 and pillbox b to [0]
  (b+m).map{|a|             # for each action, beginning with extra refill step (overloaded b)
    a<1?                    #   if refilling
      b=[1**i           ]*n #     fill (overwrite) the pillbox with n pills
            i=b.max*~i/n    #     if the pillbox is empty (b.max = 0), set i to 0, otherwise (b.max = 1) set i to -1|0 if previously moving right|left
    :                       #   else
      b[i]=0&               #     take pill from slot i and...
      i+=i/n|1;             #     add 1|-1 to i if moving right|left
    p b                     #   print the pillbox
  }
}

```
> 3 votes

# Answer
# Python 2, ~~89~~ 88 bytes

```
n=input()
i,s=0,1
while 1:i,s=[0,i+1,i/n or-s,s][input()::2];print([0]*i+[1]*(n-i))[::s]

```

Try it online!

thanks to @ovs for -1 byte

# Python 3, 100 bytes

```
n=int(input())
i,s=0,1
while 1:i,s=[0,i+1,i==n or-s,s][input()>"0"::2];print(([0]*i+[1]*(n-i))[::s])

```

Try it online!

take the actions in the form of individual inputs

## How it works :

* `n` store the length of the box, `s` the side from which the pill have to be taken (`1` for left and `-1` for right) and `i` the number of the pill

at each loop :

* if the `input()` returns `1` (take a pill): then `i,s=[0,i+1,i==n or-s,s][input()::2]` will assign `i` to `i+1` and `s` will stay inchanged
* if the `input()` returns `0` (refill): then `i,s=[0,i+1,i==n or-s,s][input()::2]` will assign `i` to 0 and `s` to either `-s` or `1` dependig if the box is empty (`i==n`)
* `print([0]*i+[1]*(n-i))[::s]` will then print `i`missig pills and `n-i` pills in the order defined by `s`
> 3 votes

# Answer
# JavaScript (ES6),  ~~78~~  76 bytes

*Saved 2 bytes thanks to @l4m2*

Expects `(n)(array)`. Returns an array of strings. The initial state is included.

```
n=>a=>[d=0,...a].map(c=>a=c?a.replace(d||/1(?!1)/,0):'1'.repeat(n,d=!d|!+a))

```

Try it online!

### Commented

```
n =>              // n = number of pills
a =>              // a[] = array of actions, re-used as the box string
[ d = 0,          // prepend a 'refill' directive
                  // and initialize the direction to 0 (right to left)
  ...a            // leave all other actions unchanged
].map(c =>        // for each action c:
  a =             //   update a:
    c ?           //     if this is a 'take pill' action:
      a.replace(  //       replace in a:
        d ||      //         either the first '1' (if d = 1)
        /1(?!1)/, //         or the last '1' (if d = 0)
        0         //         with '0'
      )           //       end of replace()
    :             //     else:
      '1'.repeat( //       generate a string consisting of ...
        n,        //       ... '1' repeated n times
        d = !d |  //       and update the direction to:
            !+a   //         - 1 (L -> R) if d = 0 or the box is empty
      )           //         - 0 (R -> L) if d = 1 and the box is not empty
)                 // end of map()

```
> 2 votes

# Answer
# Python 2, 105 bytes

```
n=input();k=[1]*n;d=0
for i in input():exec(i*"k[d]=0;d+=[1,-1][d<0]#"+"d=-(d>0)*any(k);k=[1]*n");print k

```

Try it online!

Geez. Need to find a better way to inverse the direction.

-22 thanks to @Jakque
> 1 votes

# Answer
# , ~~250~~ ~~202~~ ~~198~~ 197 bytes

```
import std.array,std.algorithm;U[]f(T,U)(T b,U A){U[]r=[[1].replicate(b)];T d=1,p;foreach(a;A){U P=r[$-1].dup;if(a*P.sum){P[p]=0;p+=d;}else{P=[1].replicate(b);d=a?1:-d;p=d>0?0:b-1;}r~=P;}return r;}

```

Try it online!
> 1 votes

# Answer
# Zsh, 109 bytes

```
a=({1..$1})
$a(){<*&&r+=\|tac||r+=\|sort;>$a}
0()rm `eval ls$r|head -1`
for x;$x&&(eval \<$^a';s+=$?;';<<<$s)
```

Attempt This Online!

This seemed like a good way to go about it, until I re-read the challenge and it was more complicated than I thought (it started as a 40-byte answer... for a totally different challenge). A proper rewrite would surely be half the length.
> 1 votes

# Answer
# Pip, 37 bytes

```
Ft0.bP[Yt?yR`\b1`s#(i:1Ny&!i)XaRVy]@i

```

Takes the steps as a string of 1s (take pill) and 0s (refill box); outputs the pillbox as a string of 1s (pills) and spaces (empty slots). Try it online!

### Explanation

It's easier to store the pillbox in a consistent order and conditionally reverse it when printing. Arguments are size of pillbox (integer) and actions (string of 1s and 0s).

```
Ft0.bP[Yt?yR`\b1`s#(i:1Ny&!i)XaRVy]@i
                                       a,b are cmdline args; s is space; i is 0; y is ""
                                       We're going to store the pillbox in y and the
                                       direction in i (0 = LTR, 1 = RTL)
Ft                                     For each action t in
  0.b                                  the input actions with a 0 prepended (so that the
                                       box is "refilled" as the first step):
       Y                                Set y to the following quantity:
        t?                              If t is truthy (1, take pill):
          yR                             The pillbox string, replacing
            `\b1`                        regex matching the first 1
                 s                       with a space
                                        Otherwise (0, refill box):
                    i:                   Set i to
                      1Ny                 Number of pills left in the box
                         &                Logical AND
                          !i              Logical negation of previous i value
                  #(        )            Length of the above (always 1)
                             Xa          string-repeated (size of pillbox) times
      [                           ]     Put the new value of y in a list with
                               RVy      its reverse
                                   @i   Index into the list using i (i.e. reverse iff i=1)
     P                                  Print

```
> 1 votes

# Answer
# Charcoal, 40 bytes

```
Ｎθ≔⁰ηＦ⁺RＳ«≡ιR«≔∧η¬ζζ≔θη»≦⊖η≔⭆θ‹κηε⟦⎇ζε⮌ε

```

Try it online! Link is to verbose version of code. Uses `R` for refill and `P` (or anything else really) for pill and outputs a string of `0`s and `1`s for each state. Explanation:

```
Ｎθ

```

Input `n`.

```
≔⁰η

```

Start with `0` pills.

```
Ｆ⁺RＳ«

```

Loop over the commands, but with an extra Refill action. This saves me from having to explicitly initialise the direction.

```
≡ιR«

```

If this is a refill action, then...

```
≔∧η¬ζζ

```

Flip the direction, unless there are no pills, in which case reset the direction.

```
≔θη

```

Refill the pills.

```
»≦⊖η

```

Otherwise, decrement the number of pills.

```
≔⭆θ‹κηε

```

Generate a string of full and empty slots.

```
⟦⎇ζε⮌ε

```

Output the string or its reverse depending on the current direction.
> 1 votes

---
Tags: code-golf, array
---


# Question
Title: Minimally prepend numbers to get a symmetric Young diagram
## Background

A **Young diagram** is a diagram that represents a nonincreasing sequence of positive integers using left-justified rows of squares. As an example, `5, 4, 1` is drawn as

```
OOOOO
OOOO
O

```

A Young diagram is said to be **symmetric** if it is identical to its transpose (reflection along the NW-SE diagonal). The above diagram of `5, 4, 1` is not symmetric, since its transpose represents `3, 2, 2, 2, 1` instead:

```
5 OOOOO    3 OOO
4 OOOO     2 OO
1 O     => 2 OO
           2 OO
           1 O

```

A symmetric example is that of `4, 2, 1, 1`:

```
OOOO
OO
O
O

```

## Challenge

Given a nonincreasing sequence of positive integers, add as few numbers as possible to the front of it so that its Young diagram becomes symmetric. If the input is already symmetric, your code is expected to output it as-is. You may take input and give output in reverse order (numbers in increasing order; e.g. `[1, 1, 2, 2] -> [1, 1, 2, 2, 4, 6]`).

Standard rules apply. The shortest code in bytes wins.

## Test cases

```
[1] -> [1]
[2] -> [2, 2]
[3] -> [3, 3, 3]
[1, 1] -> [3, 1, 1]
[2, 1] -> [2, 1]
[3, 1] -> [4, 3, 3, 1]
[2, 2, 1] -> [5, 4, 2, 2, 1]
[3, 2, 1] -> [3, 2, 1]
[4, 2, 2] -> [4, 4, 2, 2]
[4, 2, 1] -> [6, 5, 4, 4, 2, 1]
[4, 4, 3] -> [4, 4, 4, 3]
[5, 4, 1] -> [6, 5, 5, 5, 4, 1]
[4, 2, 1, 1] -> [4, 2, 1, 1]
[2, 2, 1, 1] -> [6, 4, 2, 2, 1, 1]

```

# Answer
# 05AB1E, ~~25~~ ~~24~~ ~~21~~ 19 bytes

```
g+àLZиæé€ì.ΔDÅ10ζOQ

```

Brute-force approach. Times out for most inputs.

-2 bytes thanks to *@ovs*.

Try it online or verify some of the shorter test cases.

## Previous answer: 05AB1E (legacy), ~~25~~ 24 bytes

```
Å1ζO©[DN(.£I®gN-£Q#>}N£ì

```

Port of *@gsitcia*'s Python answer, so make sure to upvote him/her as well!

-1 byte by switching to the legacy version of 05AB1E. The original program was `Å10ζO©[D¾.$I®g¾-£Q#>¼}¾£ì`, with the following differences:

1. -1 byte: `0ζO` (zip with 0 filler; sum) is replaced with `ζO` (zip with default space filler; sum), since the legacy version will ignore these spaces when summing;
2. -1 byte: The `¾` are replaced with `N` and the `¼` has been removed, because `N` can be accessed outside of loops in the legacy version, which will reset to `0` in the new version;
3. +1 byte: `.$` wasn't a builtin yet in the legacy version, so we'll have to use `(.£` instead (`.$` is a\[b:\];  is a\[-b:\], and `(` negates the integer first).

Try it online or verify all test cases.

**Explanation:**

```
g              # Get the length of the (implicit) input-list
 +             # Add it to each value in the (implicit) input-list
  à            # Pop and leave the maximum
   L           # Create a list in the range [1,max(input)+length(input)]
    Zи         # Repeat each integer this max amount of times
      æ        # Get the powerset of this entire list
       é       # Sort it by length
        €ì     # Prepend each in front of the (implicit) input-list
.Δ             # Find the first list which is truthy for:
  D            #  Duplicate the current list
   Å1          #  Map each integer in the list to a list of that many 1s
      ζ        #  Zip/transpose this list of lists,
     0         #  with 0 as filler to make it a rectangle
       O       #  Sum each inner row
               #  (we now have the reflection of the list)
        Q      #  Check if the duplicated current list is equal to its reflection
               # (after we've found a result, output it implicitly)

```

```
Å1             # Map each integer in the (implicit) input-list to a list of that many 1s
  ζ            # Zip/transpose this list of lists,
               # with a space as default filler to make it a rectangle
   O           # Sum each inner row, ignoring the spaces
               # (we now have the reflection of the input-list)
    ©          # Store this list in variable `®` (without popping)
[              # Start an infinite loop:
 D             #  Duplicate the current list
  N(.£         #  Remove the last 0-based loop-index amount of values from this list
      I        #  Push the input-list
       ®g      #  Push the length of list `®`
         N-    #  Decrease it by the 0-based loop-index
           £   #  Only leave that many leading items from the input-list
            Q  #  If both lists (®[cv:] and input[:len(®)-cv]) are now equal:
             # #   Stop the infinite loop
 >             #  If not, increase all values in the list by 1
}              # After the infinite loop:
 N             # Push the (0-based) loop-index we ended at
  £            # Only leave the index amount of values from the list
   ì           # And prepend it at the front of the (implicit) input-list
               # (after which this is output implicitly as result)

```
> 5 votes

# Answer
# Jelly, 21 bytes

```
+L}Rṗ⁸;€b1ZƑ$Ƈ
0ç1#Ḣç

```

Try it online!

A full program taking a list of integers as its argument and printing the shortest list satisfying the requirements. The TIO link includes all test cases.

## Explanation

### Helper link

Left argument is the number of additional digits to prepend, right argument is the original list

```
+               | Add:
 L}             | - Length of original list
   R            | Range 1..this
    ṗ⁸          | Cartesian power with number of new digits
      ;€        | Prepend each to the original list
        b1ZƑ$Ƈ  | Convert to unary and test whether unchanged by transposition

```

# Main link

```
0ç1#           | Starting with zero, identify how many additional digits are needed to make the list meet the requirements
    Ḣ          | Head
     ç         | Then call the helper link again one last time

```

---

# An alternative Jelly answer uses less brute force, 21 bytes

```
b1S+⁹ḣɗⱮṀŻ$;€⁸b1ZƑ$ƇḢ

```

Try it online!
> 4 votes

# Answer
# JavaScript, 110 bytes

```
f=(a,l,g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i})=>g(c=b=[...a],b=[g(a,c)])|b==c+''?c:f(a,-~l)

```

```
f=(a,l,g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i})=>g(c=b=[...a],b=[g(a,c)])|b==c+''?c:f(a,-~l)

console.log(JSON.stringify(f([1])));
console.log(JSON.stringify(f([2])));
console.log(JSON.stringify(f([3])));
console.log(JSON.stringify(f([1, 1])));
console.log(JSON.stringify(f([1, 2])));
console.log(JSON.stringify(f([1, 3])));
console.log(JSON.stringify(f([1, 2, 2])));
console.log(JSON.stringify(f([1, 2, 3])));
console.log(JSON.stringify(f([2, 2, 4])));
console.log(JSON.stringify(f([1, 2, 4])));
console.log(JSON.stringify(f([3, 4, 4])));
console.log(JSON.stringify(f([1, 4, 5])));
console.log(JSON.stringify(f([1, 1, 2, 4])));
console.log(JSON.stringify(f([1, 1, 2, 2])));
```

First, function `g` try to calculate transpose of some given input.

```
g=a=>{for(i=j=k=l;j||=k=--i&&l;b[l-i]||=!j*k)k-=a[--j]<i}

```

Although there is only a variable `a` before the fat arrow, it actually takes 3 parameters:

1. The length `l`
2. The input array `a`
3. The output array `b`

It returns the transpose via modify variable `b` in-place.

It assumes `a` have `l` elements (as if there are some `l`s padded at the end of `a`). And try to calculate `a`'s transpose. When `b` is given an non-empty array, `g` keeps values already in `b` as is, and only calculate the remaining values.

So, we can use this function to:

1. `g(a,c=b=[...a])` will try to append some values to input, so it at least `l` elements in it, and the largest value is `l`. And `c` is the calculate result.
2. After that, `g(c,b=[])`will transpose `c`.
3. Finally, we test `b==c+''`: It will be true only if `c` is identical to its transpose.
4. We return `c` if it is identical to its transpose, or reject `c` and try a larger `l`.
> 3 votes

# Answer
# Ruby, ~~92 ... 85~~ 82 bytes

```
f=->l,*r{l==(0...l[0]).map{|x|l.count{|y|y>x}}?l:f[*r+(1..l.sum).map{|q|[q+1]+l}]}

```

Try it online!

# Non-recursive version, 85 bytes

```
->l,*r{l,*r=r+(0..l.sum).map{|q|[q+1]+l}until(0...l[0]).map{|x|l.count{|y|y>x}}==l;l}

```

Try it online!

### How?

This explanation refers to the non-recursive version, which is functionally identical to the recursive one.

Sheer brute force:

```
->l,*r{

```

We must check all sequences, starting with the original: `r` is the list of sequence we haven't checked yet.

```
l,*r=r+(0..l.sum).map{|q|[q+1]+l}

```

This will be executed after each check: since the sequence is not symmetric (or not a Young diagram), we create a new list of sequence which can extend this one by adding one number at the beginning. The maximum possible value is the sum of the sequence + 1 (empirical evidence). The minimum is set to 0, this will generate a lot of non-Young diagrams, but those will be discarded by the check.

```
until(0...l[0]).map{|x|l.count{|y|y>x}}==l;

```

We've found the sequence if for any number `x` between 1 and the maximum value in `l`, the xth element of `l` is the number of elements of `l` that are greater or equal to `x`. If the first element of `l` is not the maximum, then the size of the sequence won't match (this will exclude all non-Young diagrams).

```
l}

```

Finally, return the sequence we have found.
> 3 votes

# Answer
# 05AB1E, 22 bytes

```
∞εLyã}€`ʒIÅ¿}.ΔDāδ@øOQ

```

Try it online! or Try all cases!

```
∞ε   }          # for y in [1, 2, ...]
  L             #   take the range [1, ..., y]
   yã           #   all y-tuples of these numbers
      €`        # flatten the result by one level
        ʒ   }   # filter; keep only those lists
         IÅ¿    #   that end with the input

.Δ              # find the first list y that
  Dāδ@øOQ       #   (is a symmetric Young diagram)
   ā            #   push range [1, ..., len(y)]
    δ@          #   (<=) - table
      øO        #   sum the columns, the result is a list giving the count of numbers >= n for each n
  D     Q       #   is this equal to y?

```
> 3 votes

# Answer
# BQN,31 25 bytesSBCS

```
∧∘⊒⌾/{⊑⊸≡¨⊸/≠⊸+⊸∾⟜¨↑}

```

Try it here.

How it works:

`∧∘⊒⌾/` is a helper function for the transpose. It works by taking the Indices `/`, then the Occurrence Count , sorts  the result, then finally because of the modifier Under  — which conceptually means apply the function on the right, then the one on the left, then undo the one on the right—it takes the inverse of Indices.

To visualize an example:

```
    / 5‿4‿1
0‿0‿0‿0‿0‿1‿1‿1‿1‿2

    ⊒ 0‿0‿0‿0‿0‿1‿1‿1‿1‿2
0‿1‿2‿3‿4‿0‿1‿2‿3‿0

    ∧ 0‿1‿2‿3‿4‿0‿1‿2‿3‿0
0‿0‿0‿1‿1‿2‿2‿3‿3‿4

    /⁼0‿0‿0‿1‿1‿2‿2‿3‿3‿4
3‿2‿2‿2‿1

```

And then the main part:

```
{⊑⊸≡¨⊸/≠⊸+⊸∾⟜¨↑} # a 1-modifier where Transpose is  and input is
                ↑  # list the prefixes of transposed input
               ¨     # for each prefix in the list:
        ≠⊸+          #   add its length to itself
           ⊸∾⟜      #   and join to the input
      ⊸/             # filter by:
  ⊸≡¨               #   whether each element is equivalent to its transpose
 ⊑                   # select first result

```
> 3 votes

# Answer
# Python 3.8 (pre-release), 142 bytes

```
lambda L:(Z:=[len([0for i in L if i>j])for j in range(L[0])])*0+min(K[:n]+L for n in range(1+len(Z))if(K:=[i+n for i in Z])[n:]==L[:len(Z)-n])

```

Try it online!

Ungolfed:

```
def f(L):
  Z = [0]*L[0]
  for i in L:
    Z[:i] = [j+1 for j in Z[:i]]
  # Z is now transpose of L
  for n in range(1+len(Z)):
    K = [i+n for i in Z]
    # K is the start of the transpose of (L with n elements prepended)
    if K[n:]==L[:len(Z)-n]: # the overlapping parts must be equal
      return K[:n]+L

```
> 2 votes

# Answer
# JavaScript (ES6), 117 bytes

```
f=(a,n)=>(g=(i,a,n)=>n?i>n?0:g(i,[i,...a],n-i)||g(i+1,a,n):i--?a.map(v=>t-=v>i,t=a[i])|t?0:g(i,a):a)(1,a,n)||f(a,-~n)

```

Try it online!

### How?

Starting with \\$n=0\\$, we prepend each non-increasing integer partition of \\$n\\$ to the input list and test whether one of the resulting lists is a symmetric Young diagram. We recursively increment \\$n\\$ until a solution is found.

For instance, the test case `[5, 4, 1]` is solved with \\$n=16=6+5+5\\$, leading to `[6, 5, 5, 5, 4, 1]`.

### Faster version (120 bytes)

This version will never generate a partition with a term less than the leading term of the input list. This allows it to solve `[9, 2]` (suggested by Wheat Wizard) almost instantly.

Try it online!

### Commented

```
f = (a, n) => (       // f = main function taking the input list a[]
  g = (i, a, n) =>    // g = helper function computing the partitions
                      //     and looking for a symmetric Young diagram
    n ?               // if n is not 0:
      i > n ?         //   if i is greater than n:
        0             //     invalid partition: abort
      :               //   else:
        g(            //     first recursive call:
          i,          //       pass i unchanged
          [i, ...a],  //       prepend i to a[]
          n - i       //       subtract i from n
        ) ||          //     end of recursive call
        g(            //     second recursive call:
          i + 1,      //       increment i
          a,          //       pass a[] unchanged
          n           //       pass n unchanged
        )             //     end of recursive call
    :                 // else (n = 0 or undefined):
      i-- ?           //   decrement i; if it was not 0:
        a.map(v =>    //     for each value v in a[]:
          t -= v > i, //       decrement t if v is greater than i
          t = a[i]    //       starting with t = a[i]
        ) | t ?       //     end of map(); if t is not 0:
          0           //       this is not a symmetric Young diagram
        :             //     else:
          g(i, a)     //       process recursive calls until i = 0
      :               //   else:
        a             //     success: return a[]
)(1, a, n)            // initial call to g
|| f(a, -~n)          // if no solution was found, try again with n + 1

```
> 1 votes

# Answer
# Wolfram Language (Mathematica), ~~87~~ ~~86~~ ~~76~~ 72 bytes

```
l&@For[i=0,t@@(l=Join[l=#;i+t@i++,#])!=l,]&
t=Tr@UnitStep[l-#]&~Array~#&

```

Try it online!

The helper function `t` returns the first `#` rows of the transpose of the Young diagram of `l`.

```
main function:
   For[i=0,                             ,]  start from i=0 (#extra rows)
                      l=#;  t@i             first i rows of transposed input
                          i+                shift right by i
                 Join[           ,#]        prepend to input
           t@@(l=                   )!=l    transpose equal to itself?
l&@                                           (yes): return
                              i++             (no) : increment i and retry

t:
Tr@UnitStep[l-#]                                count entries of l >= i
                &~Array~#                       for i=1..first argument

```
> 1 votes

# Answer
# Brachylog, 21 bytes

```
~a₁.R⁰l⟦₅{{<.∧R⁰∋}ᶜ}ᵐ

```

Try it online!

My first Brachylog program, so it can probably be improved a lot.

## Explanation

```
~a₁.R⁰l⟦₅{{<.∧R⁰∋}ᶜ}ᵐ
                       The input
~a₁                    is a suffix of
   .                   the output,
    R⁰                 aka R⁰.
      l                The output's length,
       ⟦₅              range from 0 to that-1,
         {         }ᵐ  map:
          {      }ᶜ      count all possible outputs of this predicate:
                           The number
           <               is less than
            .              the output
             ∧             and
              R⁰           R⁰
                ∋          contains
                           the output.
                       this has to be equal to the output.

```
> 1 votes

# Answer
# Charcoal, ~~43~~ 35 bytes

```
ＷＳ⊞υＬι§ΦＥ⊕⌈υ⁺Ｅι⁺ιＬΦυ›νμυ⬤ι⁼λＬΦι›νμ⁰

```

Try it online! Link is to verbose version of code. I/O is as a Young Diagram using `-`s as the fill character. Explanation:

```
ＷＳ⊞υＬι

```

Input the diagram.

```
Ｅ⊕⌈υ

```

For each possible number of rows from `0` to the length of the first row (inclusive)...

```
⁺Ｅι⁺ιＬΦυ›νμυ

```

... calculate the transpose of that number of columns, concatenating with the original input.

```
§Φ...⬤ι⁼λＬΦι›νμ⁰

```

Print the first symmetric result.

Example: At each stage, an `i`-by-`i` square is prefixed to the original input (marked by `#` signs) and then extended by transposition (marked by `=` signs). The first symmetric result is then the one with `3` prefixed rows.

```
                                        #####===
                                ####=== #####==
                        ###===  ####==  #####==
                ##===   ###==   ####==  #####==
        #===    ##==    ###==   ####==  #####=
-----   =----   ==---   ===--   ====-   =====
----    =---    ==--    ===-    ====    ====
-       =       =       =       =       =
0       1       2       3       4       5

```
> 1 votes

# Answer
# , ~~116~~ 106 bytes

```
function(x,u=function(a,b)colSums(outer(b,1:a,`>=`)),y=x){while(any(y-u(max(y),y)))y=c(u(F<-F+1,x)+F,x);y}

```

Try it online!

Uses strategy copied from Neil's answer \- upvote that one!
> 0 votes

---
Tags: code-golf, math, integer, integer-partitions
---