# Question
Title: Reversed Engineered from Uniqueness (Cop's Thread)
Given the output of the cop's program (`o`), the byte-count (`n`) and the number of unique bytes (`c`) used, come up with a corresponding piece of code that is `n` bytes long with `c` unique bytes which matches the cop's output `o`.

---

# This is the ***cops thread***. Post solutions that are to-be-cracked here.

# The ***robbers thread*** is located here.

---

Cops should post solutions like this:

```
#[Language], `n` Bytes, `c` Unique Bytes (c*n points) [Cracked](Link-To-Crack)

    [Output]

---

(Optional spoiler)

```

---

# Rules

* You may not take any input for your program.
* The program must use at least 1 byte, but cannot exceed 255 bytes.
* The output itself is also limited to 255 bytes.
* The program must have consistent output results when executed multiple times.
* If your submission is not cracked within 7 days, you may mark it as "safe".
    + When marking it safe, post the intended solution and score it as `c*n`.
    + Only mark an answer as "safe" if you *really* want the +15 for an accepted answer; it's more fun to see how long you can go.

# Winning

* The uncracked post with the lowest `c*n` score, wins the cop's thread.
* This will be decided after 10 safe answers, or a few weeks.

# Caveats

* If you feel cocky, you may tell the user the algorithm using a ***spoiler*** tag.

---

Uncracked Submissions:

```
fetch("https://api.stackexchange.com/2.2/questions/147635/answers?order=desc&sort=activity&site=codegolf&filter=!.Fjs-H6J36vlFcdkRGfButLhYEngU&key=kAc8QIHB*IqJDUFcjEF1KA((&pagesize=100").then(x=>x.json()).then(data=>{var res = data.items.filter(i=>!/^#.*cracked/im.test(i.body_markdown)).map(x=>{const matched = /^ ?#{1,3} ?(?:(?:(?:\[|<a href ?= ?".*?">)([^\]]+)(?:\]|<\/a>)(?:[\(\[][a-z0-9/:\.]+[\]\)])?)|([^, ]+)).*[^\d](\d+) ?\[?(?:.*(?:byte|block|codel)s?)(?:\](?:\(.+\))?)? ?(?:\(?(?!no[nt][ -]competing)\)?)?/gim.exec(x.body_markdown);if(!matched){return;}return {link: x.link, lang: matched[1] || matched[2], owner: x.owner}}).filter(Boolean).reverse().forEach(ans=>{var tr = document.createElement("tr");var add = (lang, link)=>{var td = document.createElement("td");var a = document.createElement("a");a.innerHTML = lang;a.href = link;td.appendChild(a);tr.appendChild(td);};add(ans.lang, ans.link);add(ans.owner.display_name, ans.owner.link);document.querySelector("tbody").appendChild(tr);});});
```

```
<html><body><h1>Uncracked Submissions</h1><table><thead><tr><th>Language</th><th>Author</th></tr></thead><tbody></tbody></table></body></html>
```

# Answer
> 12 votes
# Haskell, 173 bytes, 8 unique, 1384 points, safe

```
"[tag:reverse_engineering]"

```

It looks like this answer wants to provide a relevant tag to the question, while using only 8 different bytes.

As usual, your solution should work by being pasted in the code block on TIO: Try it online!

---

### Solution

```
'[':___':_'':_':':':__':__:__'':__:__':____:__:'_':__:___:_':_'_:___:__:__:__':_'_:___:_':']':[]
_:_:_'':_:_:_:__:_:_':_:_'_:_:_:_:_:___:_:_:_:__':____:___':_:__'':_=['_'..]

```

Yes, this is valid Haskell code: Try it online!

### How it works

The underscore `_` is used as a wild card in Haskell's pattern matching. `'` is used for characters, e.g. `'a'`. However, both `_` and `'` are also part of the allowed characters for identifier names (Within some restrictions, e.g. `'` cannot occur at the beginning of the name.). Therefore `__`, `_'`, `_'_`, `_''` and so on are all valid identifier names. Using some more descriptive names, the above code becomes

```
'[':t:a:g:':':r:e:v:e:r:s:e:'_':e:n:g:i:n:e:e:r:i:n:g:']':[]
_:_:a:_:_:_:e:_:g:_:i:_:_:_:_:n:_:_:_:r:s:t:_:v:_=['_'..]

```

The first line yields the string `"[tag:reverse_engineering]"` if each variable is assigned to the correct character. This assignment is achieved in the second line: `['_'..]` yields the string `"_`abcdefghijklmnopqrstuvwxyz{|}~ ... "`, witch is matched on the pattern `_:_:a:_:_:_:e:_:g:_:i:_:_:_:_:n:_:_:_:r:s:t:_:v:_` to get the desired assignment `a='a'`, `e='e'` and so on.

# Answer
> 10 votes
# Brain-Flak, 62 total bytes, 6 unique, 372 points, Cracked

Here is your output:

```
10993592

```

There is something special about this number but its not on the OEIS ;)

In case you are thinking of using a computer tool to solve this, you're out of luck, the integer golfer gets 110 bytes for this number:

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

```

Try it online!

You're going to have to do this one by hand.

---

## Tips

Here are some tips, I will reveal more an more helpful tips over time. Good luck!

> 10993592 is the 97th term of a sequence on OEIS, but does not appear because only a few terms are included.

---

> My solution uses 3 loops, but they are *not* nested 3 levels deep.

---

## My solution

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

```

Try it online!

This uses one of my favorite tricks, the code

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

```

computes the nth term of A090809. The full submission just pads the code with a 97 to make a large number.

# Answer
> 7 votes
# JavaScript (ES8), 103 bytes, 42 unique (4,326 points) \[SAFE\]

Output hexdump:

```
3E 6E 6D 08 33 7A 22 7D 6C 37 7B 36 61 7B 65 71 3A 37 26 7E 7B 7B 38 7B 7D 69 6A 2B 3D 70 74 07 6F 6C 66 7E 1A 2A 3C 37 2D 36 31 38 6A 78 33 62 30 1E 34 3D 66 7B 37 10 26 6A 6A 32 27 6F 2E 33 1B 30 1E 76 27 27 7E 18 6F 68 26 2D 76 6A 6D 6D 2F 2E 0A 3F 17 7D 2B 73 7A 17 38 62 3A 29 20 0C 61 24 21 27 10 2B 20 63 71 72 17 5D 5F 12 5B 02 14 59 17 5A 11 1E 1D 10 16 07 5F 5F 58 58 4B 18 48 4B 04 5F 06 12 16 14 4D 45 5D 5D 16 3A 1C 1D 11 16 1F 51 59 4E 4B 4C 3D 16 1C 0F 2E 46 0E 08 4B 4B 13 45 21 10 06 0E 11 3F 51 57 3E 00 54 5F 49 05 0E 07 5A 51 3E 08 01 25 10 0B 51 36 43 0B 34 1A 43 47 04 46 0E 55 05 00 06 01 40 33 0F 00 53 36 42 42 45 5F 3D 3A 38 74 39 74 71 71 2C 7C 60 38 38 76 63 44 7F 64 28 66 3E 24 7A 66 57 79 24 3C 3C 21 6A 36 27 30 77 7E 36 7E 2A 3E 29

```

The score is abnormally big, I know, but anyway I think this one may be interesting to crack. The program is a function which returns a string (just to avoid confusion, this is not REPL).

It shouldn't be too hard, I suppose, everything is about finding the pattern.

### Solution

It seems that it was harded than I had thought, according to the fact that nobody had cracked it. I believed there may be multiple solutions which are easy to craft. Anyways, here is the intended solution:

> ```
> f=m=>[...m=f+f+f].map((a,p)=>p+1&256?'':String.fromCharCode((p&4?m[p^17]:a).charCodeAt^83^p*.3)).join
> ```

For some reason it is not displayed properly as code snippet. Here is the TIO link.

# Answer
> 7 votes
# MATL, 6 bytes × 3 unique = 18 points. Cracked

```
1+0i 0+1i -1+0i 0-1i

```

# Answer
> 7 votes
# Malbolge, 15 bytes, 13 unique, score 195. Safe!

Outputs:

```
PPCG

```

**Safe!** Intended code:

```
(&a`#""7[}4XE70

```

Try it online!

# Answer
> 6 votes
# Octave, 13 bytes, 5 unique characters, score: 65. Safe!

```
20085918935040000

```

This one shouldn't be too hard. If you don't want to jump in to the most difficult ones straight away it might be a nice first challenge :)

Note: When I read the question, I though it said: Output a number, not output a string. The output looks like this on TIO:

```
ans =    2.0086e+16

```

And will look like this if you have `format long`

```
ans =  20085918935040000

```

or you may print it like this:

```
printf('%i',ans)
20085918935040000

```

### What I had, and explanation:

```
prod prodprod

```

Simple as that. =)

**Explained:**

Normally you'd write this as: `prod('prodprod')`, but Octave treats whatever comes after the function name as a string (array of characters). These are implicitly converted to their ASCII-values, and multiplied together.

# Answer
> 6 votes
# Jelly, 7 bytes × 6 unique = 42 points, cracked

```
843606888284160000

```

Try it online!

> ```
> 8!×16!¤
> ```

# Answer
> 5 votes
# MATL, 11 bytes, 10 unique, 110 points. SAFE!

Output:

```
10803850202590

```

Just to "help" you one the way:

This is the product of:

```
[2, 5, 29, 89, 397, 499, 2113]

```

and it's one less than the `372884884433`rd prime.

---

And here are some real tips. If it's not cracked in a few hours then I'll reveal the solution.

1. > \- There's a `q` in there
2. > \- There's a `B` in there
3. > \- There's a `^` in there
4. > \- There's a `h` in there
5. > \- There's a `t` in there

### The real code:

> 9K^ZqsBthXB

**Explanation:**

> Push two numerals, `9` and `K`, and do exponentiation. Create a list of all primes below that number, and sum them. Convert to binary, duplicate the binary vector and concatenate it with itself. Convert back to decimal and output implicitly.

# Answer
> 4 votes
# MATL, 4 bytes, 4 unique, 16 points. Cracked

Output:

```
1388289520800

```

**What I had:**

> `1X%p`
> This pushes the number 1, checks which class it is, then multiplies the ASCII-values of the resulting string 'double'.

# Answer
> 4 votes
# Java 8 (full program), 97 total bytes, 34 unique, 3298 points (Cracked by *@RobertoGraham*)

Output:

```
1.4241570377303032

```

NOTE: This is a full program. If functions in the form of `()->` are allowed instead:

# Java 8 (lambda function), 40 total bytes, 18 unique, 720 points (Cracked by @user202729)

It's probably quite hard, but whatever.. It's not like Java is going to win anything with this amount of points anyway..

---

**Hints:**

> The intended code doesn't contain any single or double quotes. (The function returns a double.)
> The intended code doesn't contain any digits (`0-9`).

---

**Intended solution:**

Pretty funny (and impressive) how both given cracks are completely different than what I had in mind, but chapeau to both of the crackers!

> Function: `()->Math.log(Math.hypot(Math.PI,Math.E))`
> Full program: `interface M{static void main(String[]a){System.out.print(Math.log(Math.hypot(Math.PI,Math.E)));}}`

# Answer
> 3 votes
# Explode, 9 total bytes, 4 unique, 36 points

Output:

```
22k2Dk}D}

```

Note that the documentation does not completely align with the implementation for this language - I wrote this one day and haven't touched it since, so any bugs in implementation that may exist are now definitely features.

Also, I do not think this language is Turing-complete, so you could probably brute force it, but that's boring.

I'll give you a sizable bounty if you can automate reverse-engineering output into optimally short Explode code.

# Answer
> 3 votes
# Mathematica, 8 bytes, 3 unique, 24 points Cracked

```
7448503425106854065710345345644475127957406351360000000

```

# Answer
> 3 votes
# Haskell, 10 bytes, 3 unique, 30 points, cracked

```
2416508937

```

A nice number which contains every digit, though only 3 unique bytes are used.

The intended solution works by replacing the code part in the following TIO link: Try it online!

# Answer
> 3 votes
# Octave, 4 bytes, 3 unique, 12 points: cracked

```
1.6776e-05

```

Lets see how fast this one goes.

# Answer
> 3 votes
# CJam, 15 bytes * 10 unique = 150 points

```
453630781352162854505467929721140132016201833205823402832306035643819420004950

```

Bad score, but hopefully will be hard to crack.

Note: At the moment I have forgotten what the answer is. As such, I will keep it open until either I or somebody else is able to crack it.

# Answer
> 3 votes
# CJam, 15 bytes * 10 unique = 150 points

```
355605126761554652609272416635107412217265861355621217687464016216276447790261274709847680

```

Note: At the moment I have forgotten what the answer is. As such, I will keep it open until either I or somebody else is able to crack it.

# Answer
> 3 votes
# Jelly, 8 bytes, 2 unique, 8×2 = 16 points -- Safe!

```
-4.408500694095235e-05

```

(There are only **8,355,840** possible such programs so it should get cracked I guess.)

**Get going at Try it online!**

### How?

> `⁽⁽°°°°°°`
> `⁽⁽°` is a base 250 literal yielding `-27221`
> `°` converts from radians to degrees. Applying this five times:
> `-475.09607568537643`
> `-8.291990784013993`
> `-0.1447225407260702`
> `-0.0025258848375215096`
> `-4.408500694095235e-05`

# Answer
> 3 votes
### C (two's complement machine, sizeof(int) = 4), 76 bytes and 35 unique bytes for a score of 2660, Safe

Output:

```
10542949672924294967287429496729029742949672954294967287429496728808914294967289429496728742949672946944294967291429496728742949672914964294967294429496728742949672891980429496728842949672874294967295792

```

which is 203 bytes long.

> #include\<math.h\>
> main(){for(int
> i=0;i\<40;i++)printf("%u",(int)(cos(i)\*10));}
> Without the #include it won't work.

# Answer
> 3 votes
# Haskell, 29 bytes, 15 unique bytes, 435 points, cracked

```
"33333333333333333333333333333333333333333333334333333333333333333333333333"

```

This is a string containing `3` 73 times, and a single sneaky `4`.

The intended solution works by replacing the code part in the following TIO link: Try it online!

*Edit:* H.PWiz found a valid crack (which could even be golfed to 28 bytes), but not the intended solution.

**Hints:**

> No arithmetic needed. There exists a single-expression solution.

# Answer
> 2 votes
# Javascript, `11` Bytes, `7` Unique Bytes (77 points) (Cracked)

```
0.022522522522522525

```

---

> lambda function declaration included in byte count, function call is not.

This should be really easy.

# Answer
> 2 votes
# Pyth, 7 bytes, 6 unique, 7\*6=42 total score

```
312069475503262125385169244603150327250717758754411025379995130624544231547913731661607993843298516888546865336571981925596

```

---

Check out the Pyth tips thread for inspiration ;)

# Answer
> 2 votes
# Jelly, 8 bytes * 6 unique = 48 (Cracked)

```
241975308641975308641975308641975308641975308641926913580246913580246913580246913580246913580246916

```

You can try to crack it here.

> **Intended solution:** `7ẋ²Ḍ²ẋ4S`

# Answer
> 2 votes
# Excel, 22 bytes, 16 unique, 352 points, Cracked

```
หนึ่งล้านห้าแสนสามหมื่นสองพันสี่ร้อยเก้าสิบห้าล้านห้าแสนสี่หมื่นแปดร้อยหกสิบห้าล้านแปดแสนเก้าหมื่นล้านล้านล้านล้านล้านล้านบาทถ้วน

```

This might not be very hard to crack but I get to use a function that I otherwise never get to use. Besides, the score won't win anything unless a lot of others get cracked.

# Answer
> 2 votes
# PowerShell, 7 bytes, 5 unique = 35 points Cracked

Output:

```
1125899906842624

```

# Answer
> 2 votes
# Perl 5, 31 Bytes, 18 Unique Bytes (558 points) -- safe

```
1.76295255109024e+180

```

Intended solution (Try it online!):

```
$_=1;for$=(1..111){$_*=$=}print

```

(this calculates the factorial of 111)

# Answer
> 2 votes
# Japt, 5 bytes, 5 unique bytes (25 points) (Cracked by Scrooble)

Output: `3628801`

# Answer
> 2 votes
# Jelly, 3 bytes × 3 unique = 9 points, cracked

```
263409560461970212832400

```

Try it online!

Another attempt at Jelly, this time more challenging I hope.

> ```
> ȷc⁵
> ```

# Answer
> 2 votes
# Jelly, 4 bytes, 4 unique, 4 × 4 = 16 points -- Safe!

```
121713205122350539153771498803599196214022517709999123476340843193655114000078051089267404501704293755399249186132786797198080437408108773592830098754467315464894774875031495160099382422748898046431945143395996374011431649446848855993397955116462522798880

```

Note that the output is 255 bytes long, right at the limit.

Yep, same score as my other (as yet uncracked) Jelly entry.

**Get going at Try it online!**

### How?

> `7ÆĊ⁺`
> `7` is a literal seven
> `ÆĊ` gets the **nth** Catalan number
> the **7th** Catalan number is **429**
> repeats the previous atom
> the **429th** Catalan number is `121713205122350539153771498803599196214022517709999123476340843193655114000078051089267404501704293755399249186132786797198080437408108773592830098754467315464894774875031495160099382422748898046431945143395996374011431649446848855993397955116462522798880`.

# Answer
> 2 votes
# Alice, 9 bytes x 8 unique = 72 points Cracked

```
KMOQSUWY[]_acegikmoqsuwusqomkigecegikmoqsuwy

```

Try it online!

This one should be funny to crack

# Answer
> 2 votes
# Haskell, 30 bytes, 17 unique, 510 points, cracked

```
"6666666444444455666666666566555533333334333333333"

```

The intended solution works by replacing the code part in the following TIO link: Try it online!

This uses the same approach as my previous answer, which was cracked using a different approach.

Some hints:

> No arithmetic needed. I have a single-expression solution.

# Answer
> 2 votes
# Haskell, 37 bytes, 20 unique, 740 points, safe

The answer is an expression whose result equals the string literal:

```
"4F\\DLE\\C\"S\\T \\\\DC$EO!RUr\\K\\SSS1\\%S\\\\AN\\D&CDI#3SSC\\\\\\E\\C\\YC\\USB2SNN\\ED'\""

```

(That is, when `putStr`’d, you’d get:)

```
4F\DLE\C"S\T \\DC$EO!RUr\K\SSS1\%S\\AN\D&CDI#3SSC\\\E\C\YC\USB2SNN\ED'"

```

> **Safe**! Intended expression:
>
> ```
> [show['\r'..]!!rem(w^7)77|w<-[7..77]]
>
> ```

# Answer
> 2 votes
# Vyxal, 4 bytes, 4 unique, score 16, Cracked by Aaron Miller

Output:

```
aaaabbabaabcbabccabcaabcdbabcdcabcddabcdaabcdebabcdecabcdedabcdeeabcdeaabcdefbabcdefcabcdefdabcdefeabcdeffabcdefaabcdefgbabcdefgcabcdefgdabcdefgeabcdefgfabcdefggabcdefgaabcdefghbabcdefghcabcdefghdabcdefgheabcdefghfabcdefghgabcdefghhabcdefghaabcdefghibabcdefghicabcdefghidabcdefghieabcdefghifabcdefghigabcdefghihabcdefghiiabcdefghiaabcdefghijbabcdefghijcabcdefghijdabcdefghijeabcdefghijfabcdefghijgabcdefghijhabcdefghijiabcdefghijjabcdefghijaabcdefghijkbabcdefghijkcabcdefghijkdabcdefghijkeabcdefghijkfabcdefghijkgabcdefghijkhabcdefghijkiabcdefghijkjabcdefghijkkabcdefghijkaabcdefghijklbabcdefghijklcabcdefghijkldabcdefghijkleabcdefghijklfabcdefghijklgabcdefghijklhabcdefghijkliabcdefghijkljabcdefghijklkabcdefghijkllabcdefghijklaabcdefghijklmbabcdefghijklmcabcdefghijklmdabcdefghijklmeabcdefghijklmfabcdefghijklmgabcdefghijklmhabcdefghijklmiabcdefghijklmjabcdefghijklmkabcdefghijklmlabcdefghijklmmabcdefghijklmaabcdefghijklmnbabcdefghijklmncabcdefghijklmndabcdefghijklmneabcdefghijklmnfabcdefghijklmngabcdefghijklmnhabcdefghijklmniabcdefghijklmnjabcdefghijklmnkabcdefghijklmnlabcdefghijklmnmabcdefghijklmnnabcdefghijklmnaabcdefghijklmnobabcdefghijklmnocabcdefghijklmnodabcdefghijklmnoeabcdefghijklmnofabcdefghijklmnogabcdefghijklmnohabcdefghijklmnoiabcdefghijklmnojabcdefghijklmnokabcdefghijklmnolabcdefghijklmnomabcdefghijklmnonabcdefghijklmnooabcdefghijklmnoaabcdefghijklmnopbabcdefghijklmnopcabcdefghijklmnopdabcdefghijklmnopeabcdefghijklmnopfabcdefghijklmnopgabcdefghijklmnophabcdefghijklmnopiabcdefghijklmnopjabcdefghijklmnopkabcdefghijklmnoplabcdefghijklmnopmabcdefghijklmnopnabcdefghijklmnopoabcdefghijklmnoppabcdefghijklmnopaabcdefghijklmnopqbabcdefghijklmnopqcabcdefghijklmnopqdabcdefghijklmnopqeabcdefghijklmnopqfabcdefghijklmnopqgabcdefghijklmnopqhabcdefghijklmnopqiabcdefghijklmnopqjabcdefghijklmnopqkabcdefghijklmnopqlabcdefghijklmnopqmabcdefghijklmnopqnabcdefghijklmnopqoabcdefghijklmnopqpabcdefghijklmnopqqabcdefghijklmnopqaabcdefghijklmnopqrbabcdefghijklmnopqrcabcdefghijklmnopqrdabcdefghijklmnopqreabcdefghijklmnopqrfabcdefghijklmnopqrgabcdefghijklmnopqrhabcdefghijklmnopqriabcdefghijklmnopqrjabcdefghijklmnopqrkabcdefghijklmnopqrlabcdefghijklmnopqrmabcdefghijklmnopqrnabcdefghijklmnopqroabcdefghijklmnopqrpabcdefghijklmnopqrqabcdefghijklmnopqrrabcdefghijklmnopqraabcdefghijklmnopqrsbabcdefghijklmnopqrscabcdefghijklmnopqrsdabcdefghijklmnopqrseabcdefghijklmnopqrsfabcdefghijklmnopqrsgabcdefghijklmnopqrshabcdefghijklmnopqrsiabcdefghijklmnopqrsjabcdefghijklmnopqrskabcdefghijklmnopqrslabcdefghijklmnopqrsmabcdefghijklmnopqrsnabcdefghijklmnopqrsoabcdefghijklmnopqrspabcdefghijklmnopqrsqabcdefghijklmnopqrsrabcdefghijklmnopqrssabcdefghijklmnopqrsaabcdefghijklmnopqrstbabcdefghijklmnopqrstcabcdefghijklmnopqrstdabcdefghijklmnopqrsteabcdefghijklmnopqrstfabcdefghijklmnopqrstgabcdefghijklmnopqrsthabcdefghijklmnopqrstiabcdefghijklmnopqrstjabcdefghijklmnopqrstkabcdefghijklmnopqrstlabcdefghijklmnopqrstmabcdefghijklmnopqrstnabcdefghijklmnopqrstoabcdefghijklmnopqrstpabcdefghijklmnopqrstqabcdefghijklmnopqrstrabcdefghijklmnopqrstsabcdefghijklmnopqrsttabcdefghijklmnopqrstaabcdefghijklmnopqrstubabcdefghijklmnopqrstucabcdefghijklmnopqrstudabcdefghijklmnopqrstueabcdefghijklmnopqrstufabcdefghijklmnopqrstugabcdefghijklmnopqrstuhabcdefghijklmnopqrstuiabcdefghijklmnopqrstujabcdefghijklmnopqrstukabcdefghijklmnopqrstulabcdefghijklmnopqrstumabcdefghijklmnopqrstunabcdefghijklmnopqrstuoabcdefghijklmnopqrstupabcdefghijklmnopqrstuqabcdefghijklmnopqrsturabcdefghijklmnopqrstusabcdefghijklmnopqrstutabcdefghijklmnopqrstuuabcdefghijklmnopqrstuaabcdefghijklmnopqrstuvbabcdefghijklmnopqrstuvcabcdefghijklmnopqrstuvdabcdefghijklmnopqrstuveabcdefghijklmnopqrstuvfabcdefghijklmnopqrstuvgabcdefghijklmnopqrstuvhabcdefghijklmnopqrstuviabcdefghijklmnopqrstuvjabcdefghijklmnopqrstuvkabcdefghijklmnopqrstuvlabcdefghijklmnopqrstuvmabcdefghijklmnopqrstuvnabcdefghijklmnopqrstuvoabcdefghijklmnopqrstuvpabcdefghijklmnopqrstuvqabcdefghijklmnopqrstuvrabcdefghijklmnopqrstuvsabcdefghijklmnopqrstuvtabcdefghijklmnopqrstuvuabcdefghijklmnopqrstuvvabcdefghijklmnopqrstuvaabcdefghijklmnopqrstuvwbabcdefghijklmnopqrstuvwcabcdefghijklmnopqrstuvwdabcdefghijklmnopqrstuvweabcdefghijklmnopqrstuvwfabcdefghijklmnopqrstuvwgabcdefghijklmnopqrstuvwhabcdefghijklmnopqrstuvwiabcdefghijklmnopqrstuvwjabcdefghijklmnopqrstuvwkabcdefghijklmnopqrstuvwlabcdefghijklmnopqrstuvwmabcdefghijklmnopqrstuvwnabcdefghijklmnopqrstuvwoabcdefghijklmnopqrstuvwpabcdefghijklmnopqrstuvwqabcdefghijklmnopqrstuvwrabcdefghijklmnopqrstuvwsabcdefghijklmnopqrstuvwtabcdefghijklmnopqrstuvwuabcdefghijklmnopqrstuvwvabcdefghijklmnopqrstuvwwabcdefghijklmnopqrstuvwaabcdefghijklmnopqrstuvwxbabcdefghijklmnopqrstuvwxcabcdefghijklmnopqrstuvwxdabcdefghijklmnopqrstuvwxeabcdefghijklmnopqrstuvwxfabcdefghijklmnopqrstuvwxgabcdefghijklmnopqrstuvwxhabcdefghijklmnopqrstuvwxiabcdefghijklmnopqrstuvwxjabcdefghijklmnopqrstuvwxkabcdefghijklmnopqrstuvwxlabcdefghijklmnopqrstuvwxmabcdefghijklmnopqrstuvwxnabcdefghijklmnopqrstuvwxoabcdefghijklmnopqrstuvwxpabcdefghijklmnopqrstuvwxqabcdefghijklmnopqrstuvwxrabcdefghijklmnopqrstuvwxsabcdefghijklmnopqrstuvwxtabcdefghijklmnopqrstuvwxuabcdefghijklmnopqrstuvwxvabcdefghijklmnopqrstuvwxwabcdefghijklmnopqrstuvwxxabcdefghijklmnopqrstuvwxaabcdefghijklmnopqrstuvwxybabcdefghijklmnopqrstuvwxycabcdefghijklmnopqrstuvwxydabcdefghijklmnopqrstuvwxyeabcdefghijklmnopqrstuvwxyfabcdefghijklmnopqrstuvwxygabcdefghijklmnopqrstuvwxyhabcdefghijklmnopqrstuvwxyiabcdefghijklmnopqrstuvwxyjabcdefghijklmnopqrstuvwxykabcdefghijklmnopqrstuvwxylabcdefghijklmnopqrstuvwxymabcdefghijklmnopqrstuvwxynabcdefghijklmnopqrstuvwxyoabcdefghijklmnopqrstuvwxypabcdefghijklmnopqrstuvwxyqabcdefghijklmnopqrstuvwxyrabcdefghijklmnopqrstuvwxysabcdefghijklmnopqrstuvwxytabcdefghijklmnopqrstuvwxyuabcdefghijklmnopqrstuvwxyvabcdefghijklmnopqrstuvwxywabcdefghijklmnopqrstuvwxyxabcdefghijklmnopqrstuvwxyyabcdefghijklmnopqrstuvwxyaabcdefghijklmnopqrstuvwxyzbabcdefghijklmnopqrstuvwxyzcabcdefghijklmnopqrstuvwxyzdabcdefghijklmnopqrstuvwxyzeabcdefghijklmnopqrstuvwxyzfabcdefghijklmnopqrstuvwxyzgabcdefghijklmnopqrstuvwxyzhabcdefghijklmnopqrstuvwxyziabcdefghijklmnopqrstuvwxyzjabcdefghijklmnopqrstuvwxyzkabcdefghijklmnopqrstuvwxyzlabcdefghijklmnopqrstuvwxyzmabcdefghijklmnopqrstuvwxyznabcdefghijklmnopqrstuvwxyzoabcdefghijklmnopqrstuvwxyzpabcdefghijklmnopqrstuvwxyzqabcdefghijklmnopqrstuvwxyzrabcdefghijklmnopqrstuvwxyzsabcdefghijklmnopqrstuvwxyztabcdefghijklmnopqrstuvwxyzuabcdefghijklmnopqrstuvwxyzvabcdefghijklmnopqrstuvwxyzwabcdefghijklmnopqrstuvwxyzxabcdefghijklmnopqrstuvwxyzyabcdefghijklmnopqrstuvwxyzzabcdefghijklmnopqrstuvwxyz

```

Only slightly evil :}

# Answer
> 1 votes
# JavaScript (ES6), 35 bytes x 16 unique = 560 points - Safe!

Some kind of compromise between a reasonable size and an uncrackable algorithm (as it originally was meant to be ^^).

**Expected output** (255 bytes):

```
246913680357025702570358136924703692581470370360360370471582604715938260493827161505050505161728495173962851852963075208642087643221000001123457802570360483728396297532100123581594064200024727410136175571756954621413918119481621442132286383494753789149870

```

### Intended solution

```
f=(x=0xff)=>--x&&(1/7/x+'')[7]+f(x)

O.innerText = f()
```

```
pre {
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  word-wrap: break-word;
}
```

```
<pre id=O></pre>
```

Unique characters: `0`, `1`, `7`, `f`, `=`, `(`, `x`, `)`, `>`, `-`, `&`, `/`, `+`, `'`, `[`, `]`

# Answer
> 1 votes
## Alice, 7 bytes, 6 unique, 42 points, safe

```
-10764@

```

Try it online!

### Solution

> `gZ/`
> `@o@`
> Try it online!
> `g` is the easiest way to get a decently big number onto the stack quickly, because it pops two implicit zeros from the stack and then reads the code point at that cell, which is **113** for `g` itself.
> `Z` then packs **0** and **113** into a single integer, which is a good way to get an even bigger number. That number happens to be **-10764**.
> The number gets printed in Ordinal mode, but then we run into `g` again in Ordinal mode. The label Alice is looking for is just an empty string. It finds that immediately in the bottom left corner and extracts the `@` as a string. When we hit `o` again, that `@` is printed as well.
> Afterwards, the IP finds its way to the bottom right corner where the other `@` terminates the program.

# Answer
> 1 votes
# J, 8 Bytes x 6 Unique = 48 Points, Cracked

Output:

```
23 _0.677447j0.296961 _0.677447j_0.296961 0.125003j0.726137 0.125003j_0.726137 _0.379097j0.630438 _0.379097j_0.630438 0.518498j0.521654 0.518498j_0.521654

```

Hint:

> It has to do with primes

# Answer
> 0 votes
# Explode, 24 total bytes, 7 unique, 168 points

Output:

```
\}AtAY)_)MqGq/Y,Y}AwA_)\)JqDq/Y,Y}AtA_)\)MqDq/Y,Y}AtA_)\)MqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb)\)JqDq2Y,YzAtAb3)yqobUPK>1,'zmhcVID?2% {na\WJ=83&ytobUPK>1,'zmhcVID?2% {na\WJ

```

Now that I've read the question correctly, you can truly see the output explode.

# Answer
> 0 votes
# PHP, 16 Bytes, 10 Unique Bytes (160 points) -- Safe!

```
0.42516833158764

```

---

> Intended Solution (Try it online!)
> `<?=M_PI/M_E/M_E;`
> Simply divides π by e twice.

### Edit

As with ThePirateBay's answer, I marked this as safe before I saw the OP's edit about seeing how long you can go without being cracked. Sorry to any who wanted to attempt a crack.

# Answer
> 0 votes
# Brainf\**k, 220 bytes, 7 unique (1540 points), safe

Edit: Sorry that I counted the bytes wrong.

**output (88 bytes)**

```
rh3NY8C]'t/FS:\7pb5D?yc,G>A@OsWU_6x*gaRo)Hz-w.ul+T&IM<P;BvjK%imn1[Xk2Ef(Z|Q{dL^`e4q0V9J=

```

Just do some brainf\**k for fun.

**Intended solution:**

> ```
> >+[>[-]<[>+>+<<-]>>[<<+>>-]---<[>>>+<<<-]>>>[<<[<+>>+<-]>[<+>-]>-]<<<+]<[>>[-]<[-]<[>+>+<<-]>>[<<+>>-]++++++[-<------>]<->>>++++++[-<+++++[-<+++>]>]<<--[>>+<<<[->>>[-]<+<<]>>>[->+<]<[-<<+>>]<-<->]>>>[<<<<<.>>>>>-]<<<<<<]
> ```
> I didn't golf this too much. This is a sequence generated by linear congruential method, but just I output bytes between 37 and 124.

# Answer
> 0 votes
# Python 2, 98 bytes, 30 unique, 2940 points

Output (249 bytes):

```
-K:&qLcVoJk`N8QS@JH5c`1]T92i_bS.bv<zZK3vI&(kH!6=NrQGTL&VE:j|g..UQC)yk>3IoNhpjc'h0.x'L!aajp;Ip}+BQ/I64Q`5ZBRwOfDtt|O,6b>>UvvTt#8"z0CzEHtiVJ{lR-QBbhdqQnKK@.7Q$RLbso]?gR=ZN2;f5vTh|1@dI.cQ|b;F=lKyFZpx(mBPrqhiw1:`LD>AI{.S;POHfTd[5d;T=`162Hc]=.m7?T_1O<Kty

```

Edit: I think this is going to be too hard so I'll give a hint

Edit: Slightly more informative hint

> `seed(9)`

# Answer
> 0 votes
# \>\<\>, 16 Bytes * 11 Unique = 176 Points

Output:

```
; ;;;;;;;;   ;
;;;
;;;;;;;;;;;;;;;;;;; ;!;";#;$;%;&

```

Shouldn't be too hard.

# Answer
> 0 votes
# x86 Assemble, 22 Bytes * 17 types = 374 points, safe for 3 months

```
00000000h: 80 8A 5E FA 59 DF 69 24 F9 73 DA 8C 50 A6 F1 60
00000010h: 93 E3 3E 87 7D 08 F6 14 9E 03 EE 96 4E 48 99 61
00000020h: 2E 7A 62 71 96 39 69 27 CF 8E F7 AE 1A 37 71 8F
00000030h: B0 52 6A 85 F3 04 47 D4 A5 F1 8E 64 D8 4E A6 C1
00000040h: 0E 1E 35 EB C6 E3 99 28 67 79 80 58 52 F5 BF E7
00000050h: 28 87 1C E7 96 5E CA 8E 63 DB 3C 59 73 11 E1 9C
00000060h: E1 1D 6A 77 6B CD 6B 41 64 EA D6 02 0B 3F 89 60
00000070h: B4 DF 90 C4 AD AA 35 D5 14 6F 47 DC 3A 31 48 B5
00000080h: 50 87 5A 4C 5D FC 07 70 4B 6A 2A 6D 87 32 7F CA
00000090h: AB EB 75 4B 7C 17 1E 7D 01 49 C3 99 AF 98 8A 59
000000a0h: 6A B1 A1 2C B4 08 5D 42 9F AA E0 04 10 38 DC 87
000000b0h: E8 CB 15 BE CE 52 5D 02 4C 3C C4 C3 FF

```

Answer:

```
00000000h: DB 06 01 01 B7 CD DD 17 D9 FE B4 02 8A 57 02 CD
00000010h: 21 FE C2 75 F1 C2

```

# Answer
> 0 votes
# Python 2, 114 Bytes, 27 Unique (3078)

```
両寷動娯爅潟嗁琓偵桋斥獻曕檫垉哣抹妗惱畃

```

Function calls not counted, lambda expression counted.

---

Hint 1

> Pseudo-random number generator with Unicode output. Beware of the offsets ;)

Hint 2

> 2 generators of the same kind but with different parameters are used alternatively, in the form of an+1 = f1(f2(an))

# Answer
> 0 votes
## CJam, 5 bytes × 5 unique = 25 points, safe

```
1406563064942.4553

```

> ```
> J_#mq
> ```
> This code computes `sqrt(19<sup>19</sup>)`.
> It could have been `JJ_#mq` for 20 points, but I didn't realize that until after I posted it.

# Answer
> 0 votes
# Jelly, 13 bytes, 5 unique, 65 points

Output is the following 21 bytes.

```
HCG, AhhsNeg3 Aarrghh

```

The optimized string compressor won't help you.

# Answer
> 0 votes
# CJam, 13 bytes * 10 unique = 130 points

```
819457164140982707422640583089002841689

```

# Answer
> 0 votes
# brainfuck, 25 bytes * 7 unique = 175 points

```
 .KoÌEÚ/îXÉAÀFÓg¤Mý´r7Ö°yh^[_j|µÜ
?{¾Y±vãWÒTÝm¢Gó¦`!é¸kO:,%%,:Ok¸é!`¦óG¢mÝTÒWãv±Y¾{?
Üµ|j_[^hy°Ö7r´ýM¤gÓFÀAÉXî/ÚEÌoK.
```

This contains unprintables which will probably be mangled by SE, so here's the hexdump:

```
00000000: 0918 2e4b 6fc2 9ac3 8c05 45c2 8cc3 9a2f  ...Ko.....E..../
00000010: c28b c3ae 58c3 8941 c380 46c3 9367 02c2  ....X..A..F..g..
00000020: a44d c3bd c2b4 7237 03c3 96c2 b0c2 9179  .M....r7.......y
00000030: 685e 5b5f 6a7c c295 c2b5 c39c 0a3f 7bc2  h^[_j|.......?{.
00000040: be08 59c2 b110 76c3 a357 c392 54c3 9d6d  ..Y...v..W..T..m
00000050: 04c2 a247 c3b3 c2a6 6021 c3a9 c2b8 c28e  ...G....`!......
00000060: 6b4f 3a2c 2525 2c3a 4f6b c28e c2b8 c3a9  kO:,%%,:Ok......
00000070: 2160 c2a6 c3b3 47c2 a204 6dc3 9d54 c392  !`....G...m..T..
00000080: 57c3 a376 10c2 b159 08c2 be7b 3f0a c39c  W..v...Y...{?...
00000090: c2b5 c295 7c6a 5f5b 5e68 79c2 91c2 b0c3  ....|j_[^hy.....
000000a0: 9603 3772 c2b4 c3bd 4dc2 a402 67c3 9346  ..7r....M...g..F
000000b0: c380 41c3 8958 c3ae c28b 2fc3 9ac2 8c45  ..A..X..../....E
000000c0: 05c3 8cc2 9a6f 4b2e 1809 01              .....oK....

```

# Answer
> 0 votes
# Jelly, 4 bytes, 4 unique, 16 points.

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

```

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


# Question
Title: Reversed Engineered from Uniqueness (Robber's Thread)
Given the output of the cop's program (`o`), the byte-count (`n`) and the number of unique bytes (`c`) used, come up with a corresponding piece of code that is `n` bytes long with `c` unique bytes which matches the cop's output `o`.

---

# This is the ***robbers thread***. Post solutions that you cracked here.

# The COPS thread is located here.

---

Robbers should post solutions like this:

```
#[Language], `n` Bytes, `c` Unique Bytes (Cracked)[Original Link to Cop Thread]

    [Solution]

(Explanation)

```

---

# Rules

* You may not take any input for your program.
* The program must use at least 1 byte, but cannot exceed 255 bytes.
* The output itself is also limited to 255 bytes.
* The program must have consistent output results when executed multiple times.
* If your submission is not cracked within 7 days, you may mark it as "safe".
    + When marking it safe, post the intended solution and score it as `c*n`.

# Winning

* The uncracked post with the lowest `c*n` score, wins the cop's thread.
* Whomever cracks the most wins the robbers thread, with earliest crack breaking the tie.
* This will be decided after 10 safe answers, or a few weeks.

# Caveats

* If you feel cocky, you may tell the user the algorithm using a ***spoiler*** tag.

---

Note: Also, please remember to upvote cracks, they're usually the impressive part.

# Answer
> 4 votes
# MATL, 4 bytes, 4 unique bytes, Stewie Griffin

```
1X2p

```

**Try it online!**

### Explanation

```
1X2   % Push predefined literal: string 'double'
p     % Product of array. For strings it uses code points. Implicit display

```

# Answer
> 4 votes
# Java 8, 97 Bytes, 34 Unique Bytes, Kevin Cruijssen

```
interface Fillerrrrrrrrrrr{static void main(String...a){System.out.println(1.4241570377303032);}}

```

Try it online!

Super innovative crack, spent hours on it

# Answer
> 4 votes
# MATL, 6 bytes, 3 unique, Luis Mendo

```
FFFTZF

```

Try it online!

I immediately recognized the output

```
1+0i 0+1i -1+0i 0-1i

```

as the 4-th roots of unity, and I knew that the `fft` on `[0 0 0 1]` would result in this.

It took me quite a while to figure out that `FFFT` would push `[0 0 0 1]` ~~and I'm still not sure how it works.~~ EDIT: Luis Mendo explained that `F` and `T` are "sticky", so a sequence of `F` and `T` will automatically `horzcat` them together, hence, `FFFT` pushes `[0 0 0 1]`.

This is expressed succinctly in the documentation (once I looked it up):

> For logical row vectors the square brackets can be omitted; that is, the notation `[T F T]` or `[TFT]` can be simplified to `TFT`. A separator may be needed if a new logical array follows: `TFT TT`. But it’s not necessary in other cases: `TFT3.5`.

# Answer
> 4 votes
# Haskell, 29 bytes, 15 unique, Laikoni

```
f<$>[1..74]
f 47='4'
f f1='3'

```

Try it online!

I previously had the two nearly solutions:

```
do;d<-[2..74];'3':['4'|d==47]    -- 29,16
do;d<-[-41..31];'3':['4'|d==4]   -- 30,15

```

# Answer
> 3 votes
# JavaScript (ES6), Brian H.

*Thanks @Milk for fixing the last trailing '5'*

```
f=f=>1/44.4

console.log(f())
```

Unique characters: `.`, `/`, `1`, `4`, `=`, `>`, `f`

# Answer
> 3 votes
# Haskell, Laikoni

```
0x90090009

```

Try it online!

I feel like I got lucky here...

# Answer
> 3 votes
# Wolfram Language (Mathematica), 8 bytes, 3 unique, Jenny\_mathy

```
7!!!/77!

```

Try it online!

Breakdown: `Factorial[7!!] / Factorial[77]` where `!!` is double factorial.

First I notice the long sequence of `0` at the end so I guess it may be some kind of factorial. `FactorInteger` gives the largest factor `103`, so I try `n/103!`, and get the next largest (negative) prime factor is `73`. Tweaking the factors for some time gives `105!/77!`, then I think "there are already 3 symbols `7`, `!` and `/`, so the way to create 105 must be from those symbols!". So I tried `7!!` (which is one of a few things to try) and get 105 as the correct result.

# Answer
> 3 votes
# Brain-Flak, 62 total bytes, 6 unique, Wheat Wizard

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

```

Try it online!

# Answer
> 2 votes
# Japt, 5 bytes, 5 unique bytes, Shaggy's submission

```
10l Ä

```

Try it online!

Simple enough: 3628801 is 10! (`10l`) plus one (`Ä`).

# Answer
> 2 votes
# Jelly, 7 bytes, 6 unique, Erik the Outgolfer

\- For some reason I started with a trailing zero in the result. Without it I would have given
`8,16!PP`
as a solution.

---

```
8,⁴!PP0

```

**Try it online!**

### How?

```
8,⁴!PP0 - Main link of a program taking no arguments and no input
  ⁴     - literal sixteen
8       - literal eight
 ,      - pair = [8,16]
   !    - factorial (vectorises) = [8!, 16!] = [40320, 20922789888000]
    P   - product = 40320 × 20922789888000 = 843606888284160000
     P  - product (no effect) = 843606888284160000
      0 - literal zero (just gets printed)
        - leaving STDOUT displaying 8436068882841600000, as required

```

...`8,⁴!’P` for 6 bytes, 6 unique would have been much harder to crack since the result of `843585965494231681` (**40319 × 2092278988799**) does not look so factorial-based.

# Answer
> 2 votes
# Jelly, 3 bytes, 3 unique Erik the Outgolfer

```
ȷc⁵

```

**Try it online!**

### How?

```
ȷc⁵ - Main link: no arguments, no input
ȷ   - literal one-thousand
  ⁵ - literal ten
 c  - choose (A.K.A. binomial coefficient) = 263409560461970212832400 as required.

```

# Answer
> 2 votes
# PowerShell, 7 Bytes, 5 Unique Bytes, AdmBorkBork

```
1PB#---

```

Try it online!

The output `1125899906842624` is equal to `2^50` and `2^50 Bytes` is equal to `1 Pebibyte`. The actual code is just 3 bytes, therefore I added a comment at the end.

# Answer
> 2 votes
# Excel, 22 bytes, 16 unique bytes, EngineerToast

A possible solution is:

```
=BAHTTEXT(2^(480-300))

```

The unique characters are `=BAHTEX()^02348-`.

I recognized that BAHTTEXT was used when seeing the output. By translating the output back from Thai to English, I was able to find the value of the number. I guessed it to be a power of 2, which it indeed is (namely 2180). The expression 480-300=180 was then constructed to make sure the solution contains 22 bytes with 16 unique.

# Answer
> 2 votes
# Alice, 9 bytes, 8 unique bytes, Leo

```
/Yr@
\no/

```

Try it online!

Unfolded, this is `nrYo@`.

```
n  negate the implicit empty string: creates the string "Jabberwocky".
r  range expansion: produces a string that starts with J,
   goes up in ASCII order to w, down to c, and then up to y.
Y  separate this string into even and odd positions
o  output the even positions
@  terminate

```

Incidentally, the orientation of the mirrors in the first column is completely irrelevant, so this could easily be reduced to 7 unique bytes.

# Answer
> 2 votes
# Haskell, Laikoni, 30 bytes, 17 unique

```
show.length.show=<<['\0'..'0']

```

# Answer
> 2 votes
# Vyxal `d`, 4 bytes, 4 unique, cracks emanresu A's answer

```
ka¦²

```

Try it Online!

# Answer
> 1 votes
# , 8 bytes, 6 unique bytes, Bolce Bussiere

```
;p.p:i.9

```

Try it online!

Output:

```
23 _0.677447j0.296961 _0.677447j_0.296961 0.125003j0.726137 0.125003j_0.726137 _0.379097j0.630438 _0.379097j_0.630438 0.518498j0.521654 0.518498j_0.521654

```

The obvious hint is that, in the given output, complex numbers always appear as conjugate pairs. It made me suspect the `p.` verb, which converts between plain polynomial and multiplier-and-roots forms.

So I tried:

```
p. 23;(...those complex numbers)
   2 3 5 7.00001 11 13 17 19 23

```

Yes, my thought was correct. The list of primes is easy. Monadic `;` flattens the list of boxed arrays to simple linear one. The resulting expression has two p's and two dots, so the byte count is perfect.

# Answer
> 0 votes
# Octave, 4 bytes, 3 unique bytes, Tom Carpenter

```
j^7j

```

Try it online!

# Answer
> 0 votes
# Jelly, 8 bytes, 6 unique, Mr. Xcoder

```
7x7²¤ḌḤ²

```

**Try it online!**

### How?

```
7x7²¤ḌḤ² - Main link: no arguments & no input
7        - literal 7
    ¤    - nilad followed by link(s) as a nilad:
  7      -   literal 7
   ²     -   square -> 49
 x       - repeat elements -> [7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]
     Ḍ   - convert from a decimal list -> 7777777777777777777777777777777777777777777777777
      Ḥ  - double -> 15555555555555555555555555555555555555555555555554
       ² - square -> 241975308641975308641975308641975308641975308641926913580246913580246913580246913580246913580246916
         - implicit print

```

---
Tags: code-golf, kolmogorov-complexity, cops-and-robbers
---


title: Find the Serialized Integer

text:
# Question
Title: Find the Serialized Integer
## Task

Write a program that will take (as input) a positive integer. It will then count up from `0`, appending each integer to a `String`, only continuing if the length of the `String` is less than the value of the input.

A *serialized* integer is defined as the fully-formed integer with the maximum value belonging to the `String`. By "fully-formed", the integer should have no missing digits (which would occur if the length constraint of the `String` is met).

The output of the program should be the *serialized* integer for its respective, positive input.

---

## Rules

* It's code golf, so the shortest answer (in bytes) wins!
* Input will always be positive.
* The output must be an integer in base-10 (decimal).
* The program must be 0-indexed.

---

## Example Input | Output

```
   5 | 4   (0 1 2 3 4              - Length of 5)
  11 | 9   (0 1 2 3 4 5 6 7 8 9 1  - Length of 11)
  12 | 10  (0 1 2 3 4 5 6 7 8 9 10 - Length of 12)
1024 | 377 (0 1 2 3 4 5 6 7 8 ...  - Length of 1024)

```

---

## Note(s)

# Answer
> 8 votes
## JavaScript (ES6), ~~40~~ 37 bytes

```
f=(n,i=s='0')=>(s+=++i)[n]?i-1:f(n,i)
```

```
<input type=number min=1 value=1 oninput=o.textContent=f(this.value)><pre id=o>0
```

Edit: Saved 3 bytes with some help from @Arnauld.

# Answer
> 6 votes
# 05AB1E, ~~10~~ 7 bytes

Idea to use prefixes from Jonathan's Jelly answer

```
LηJ€g›O

```

Try it online!

**Explanation**

```
L         # range [1 ... input]
 η        # prefixes
  J       # join each to string
   €g     # get length of each string
     ›    # input is greater than string length
      O   # sum

```

# Answer
> 5 votes
# Japt, 13 bytes

```
1n@P±X l >U}a

```

Test it online!

### Explanation

```
1n@ P± X l >U}a
1nX{P+=X l >U}a
                   Implicit: U = input integer, P = empty string
  X{         }a    Return the first integer X in [0, 1, 2, ...] that returns a truthy value:
    P+=X             Append X to P.
         l >U        Return P.length > U.
                   This returns the first integer that can't fit into the U-char string.
1n                 Subtract 1 from the result.
                   Implicit: output result of last expression

```

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

```
ẈÄ<⁸S

```

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

**Try it online!**

### How?

```
ẈÄ<⁸S - Link: positive integer, n
Ẉ     - length of (implicit decimal digits) of each of (implicit [1..n])
 Ä    - cumulative sums
   ⁸  - n
  <   - (cumulative sum) less than (n)?
    S - sum

```

# Answer
> 5 votes
# Python 2, 55 bytes

Recursive lambda port from @officialaimm's answer.

```
f=lambda k,s='',i=1:k>len(s+`i`)and f(k,s+`i`,i+1)or~-i

```

Try it online!

# Answer
> 4 votes
# Python 2, ~~60 59~~ 58 bytes

* Thanks @Felipe for 2 bytes

```
i,j,k='',1,input()
while len(i+`j`)<k:i+=`j`;j+=1
print~-j

```

Try it online!

# Answer
> 4 votes
# Haskell, ~~55~~ ~~53~~ 50 bytes

```
(n#x)a|l<-a++show x=last$x-1:[n#l$x+1|length l<=n]

```

Try it online!

Usage is `(1024#"") 0`

# Answer
> 4 votes
# PHP, 56 bytes

```
for(;$argn>$l=strlen($r);)$r.=+$i++;echo$i-1-($argn<$l);

```

Try it online!

# Answer
> 4 votes
# Pyth, ~~8~~ 7 bytes

```
tf<Q=+d

```

Try it online. Test suite.

# Answer
> 3 votes
# Perl 6, 36 bytes

```
{(0...^{([~] 0..$^a).comb>$_})[*-1]}

```

Try it online!

* `0 ...^ {...}` is the sequence of numbers from zero until one less than the number for which the code block in braces returns true. (`...` without the caret would return the first number for which the block returned true.)
* `[~] 0 .. $^a` is the concatenation of numbers from `0` up to the current number `$^a` (the parameter to the code block).
* `.comb` is a list of all of the characters (digits) in the concatenated string. Interpreted as a number, it evaluates to the length of the string. `.chars` would be more natural to use here, since it evaluates directly to the length of the string, but the name is one character longer.
* `$_` is the argument to the top-level function.
* `[*-1]` selects the last element of the generated list.

# Answer
> 2 votes
# QBIC, 34 bytes

```
{A=!p$~_lB+A|>:|_xp-1|\B=B+A]p=p+1

```

## Explanation

```
{           DO infinitely
A=!p$       Set A$ to p cast to num
            Note that p starts out as 0.
~      >:   IF the input number is exceeded by
 _l   |     the length of
   B+A      A$ and B$ combined
_xp-1|      THEN QUIT, printing the last int successfully added to B$
            The _X operator quits, (possibly) printing something if followed by a-zA-Z
            _x is slightly different, it prints the expression between the operator _x and |
\B=B+A      ELSE add A$ to B$
]           END IF
p=p+1       Raise p, and rerun

```

# Answer
> 2 votes
# Python 2, 44 bytes

```
f=lambda k,i=0:-2*(k<0)or-~f(k-len(`i`),i+1)

```

Try it online!

# Answer
> 2 votes
# J, 26 bytes

```
(>i:1:)([:+/\[:>.10^.1+i.)

((>i:1:)([:+/\[:>.10^.1+i.))"0 ] 5 11 12 1024 2000 20000 100000 1000000
4 9 10 377 702 5276 22221 185184

```

# Answer
> 2 votes
# , 43 bytes

```
n=scan();sum(cumsum(floor(log10(1:n))+1)<n)

```

Try it online!

# Answer
> 2 votes
# Husk, 8 bytes

```
#ȯ<¹ṁLŀḣ

```

Try it online!

About as hard as I could condense it. Pyth is really hard to beat here.

# Answer
> 1 votes
# Husk, 7 bytes

```
#<¹∫mLḣ

```

Try it online!

**How?**

```
      ḣ    # range from 1..input;
    mL     # get the lengths of string representations of each element;
   ∫       # get the cumulative sums;
#          # how many of these
 <¹        # are less than the input?

```

# Answer
> 1 votes
# Vyxal `s`, 5 bytes

```
ʁvL¦>

```

Try it Online!

```
ʁ     # 0...n
 vL   # Get length of each
   ¦  # Cumulative sums
    > # (input) is greater than each?
      # (s flag) sum ToS at end

```

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

```
{(+\#'$!x)'x}

```

Try it online!

Takes input `n` as `x`.

* `(...)'x` run a binary search (returning the index of the largest value equal to or smaller than `x`) on the list generated by...
* `(+\#'$!)`
    + `$!x` stringify each value from `0..x-1`
    + `#'` count the number of characters in each stringified number
    + `+\` take the cumulative sums

# Answer
> 0 votes
# WendyScript, 42 bytes

```
<<f=>(x){<<n=""#i:0->x{n+=i?n.size>=x/>i}}

f(1024) // returns 377

```

Try it online!

## Ungolfed:

```
let f => (x) {
  let n = ""
  for i : 0->x {
    n+=i
    if n.size >= x
    ret i
  }
  ret
}

```

# Answer
> 0 votes
# PHP, 41 bytes

```
while(strlen($s.=+$i++)<=$argn);echo$i-2;

```

Try it online.

# Answer
> 0 votes
# Java 8, 64 bytes

```
n->{int i=0;for(String t="0";;t+=++i)if(t.length()>n)return~-i;}

```

Or slight alternatives with the same byte-count:

```
n->{int i=0;for(String t="";;t+=i++)if(t.length()>n)return i-2;}
n->{int i=-1;for(String t="";;t+=++i)if(t.length()>n)return~-i;}

```

**Explanation:**

Try it here.

```
n->{                  // Method with integer as both parameter and return-type
  int i=0;            //  Integer `i`, starting at 0
  for(String t="0";   //  String, starting at "0"
      ;               //  Loop indefinitely
       t+=++i)        //    After every iteration: append the String with `i+1`
                      //    by first increasing `i` by 1 with `++i`
    if(t.length()>n)  //   If the length of the String is larger than the input:
      return~-i;      //    Return `i-1`
                      //  End of loop (implicit / single-line body)
}                     // End of method

```

# Answer
> 0 votes
# Ruby, 44 bytes

Inspired by Kevin Cruijssen's JAVA answer. -4 bytes thanks to G B.

```
->n{i,t=0,'';t+="#{i+=1}"while t.size<n;i-1}

```

# Answer
> 0 votes
# Ruby, 39 bytes

```
->n{~-(0..n).find{|x|0>n-="#{x}"=~/$/}}

```

Try it online!

# Answer
> 0 votes
# Perl 5, 31 + 1 (`-p`) = 32 bytes

```
$".=++$\while$_>=length$"}{$\--

```

Try it online!

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


title: 2 factors factorization

text:
# Question
Title: 2 factors factorization
Given a natural number `n` write a program or function to get a list of all the possible two factors multiplications that can be used to achieve `n`. To understand better what is pretended you can go to http://factornumber.com/?page=16777216 to see when `n` is `16777216` we get the following list:

```
   2 × 8388608
   4 × 4194304
   8 × 2097152
  16 × 1048576
  32 ×  524288
  64 ×  262144
 128 ×  131072
 256 ×   65536
 512 ×   32768
1024 ×   16384
2048 ×    8192
4096 ×    4096

```

No need to pretty print things like here. The requirement is that each entry (pair of factors) is well distinguished from each other and inside each pair, the first factor is also well distinguished from the other. If you choose to return a list/array, the inside element can be a list/array with two elements, or some structure of your language that supports a pair of things like C++ `std::pair`.

Do not print the multiplication by 1 entry, nor repeat entries with the first factor commuted by the second, as they are pretty useless.

No winner; it will be a per language basis code golf.

# Answer
# Java (OpenJDK 8), ~~81~~ ~~66~~ 65 bytes

* -15 Bytes thanks to Olivier Grégoire.
* -1 Byte: `++j<=i/j` -\> `j++<i/j`.

```
i->{for(int j=1;j++<i/j;)if(i%j<1)System.out.println(j+" "+i/j);}

```

Try it online!

---

Old one (for reference)

# Java (OpenJDK 8), 126 bytes

```
i->{java.util.stream.IntStream.range(2,i).filter(d->d<=i/d&&i%d==0).forEach(e->System.out.println(""+e+"x"+i/e));return null;}

```

Try it online!

First codegolf submit and first lambda usage. Future self, please forgive me for the code.
> 6 votes

# Answer
# Python 2, 51 bytes

```
f=lambda n,k=2:n/k/k*[f]and[(k,n/k)][n%k:]+f(n,k+1)

```

Try it online!

---

**51 bytes** (thanks to Luis Mendo for a byte)

```
lambda n:[(n/k,k)for k in range(1,n)if(k*k<=n)>n%k]

```

Try it online!

---

**51 bytes**

```
lambda n:[(n/k,k)for k in range(1,n)if n/k/k>n%k*n]

```

Try it online!
> 5 votes

# Answer
# C (gcc), ~~58~~ ~~54~~ 53 bytes

```
f(N,j){for(j=1;j++*j<N;)N%j||printf("|%d,%d",j,N/j);}

```

Try it online!
> 5 votes

# Answer
# 05AB1E, 8 bytes

```
ÑÂ‚ø2äн¦

```

Try it online!
> 5 votes

# Answer
## Haskell, 38 bytes

```
f x=[(a,b)|a<-[2..x],b<-[2..a],a*b==x]

```

Try it online!
> 4 votes

# Answer
# APL (Dyalog), 28 bytes

```
{(⊢,⍵÷⊢)¨o/⍨0=⍵|⍨o←1↓⍳⌊⍵*.5}

```

Try it online!
> 3 votes

# Answer
# Perl 6, 38 bytes

```
{map {$^a,$_/$a},grep $_%%*,2.. .sqrt}

```

Try it

## Expanded:

```
{   # bare block lambda with implicit parameter ｢$_｣

  map
    { $^a, $_ / $a },  # map the number with the other factor

    grep
      $_ %% *,         # is the input divisible by *
      2 .. .sqrt       # from 2 to the square root of the input
}

```
> 3 votes

# Answer
# Brachylog, 8 bytes

```
{~×≜Ċo}ᵘ

```

Try it online!

## Explanation

```
{~×≜Ċo}ᵘ
{     }ᵘ  List the unique outputs of this predicate.
 ~×       Pick a list of integers whose product is the input.
   ≜      Force concrete values for its elements.
    Ċ     Force its length to be 2.
     o    Sort it and output the result.

```

The  part does not include 1s in its output, so for input **N** it gives **\[N\]** instead of **\[1,N\]**, which is later culled by `Ċ`. I'm not entirely sure why  is needed...
> 3 votes

# Answer
# Jelly, ~~12~~ 7 bytes

```
ḊŒċP=¥Ƈ

```

Try it online!
> 2 votes

# Answer
# Japt, 9 bytes

```
â¬Å£[XZo]

```

Test it online! Returns an array of arrays, with some nulls at the end; `-R` flag added to show output more clearly.
> 2 votes

# Answer
# JavaScript (ES6), 55 bytes

```
n=>eval('for(k=1,a=[];k*++k<n;n%k||a.push([k,n/k]));a')

```

### Demo

```
let f =

n=>eval('for(k=1,a=[];k*++k<n;n%k||a.push([k,n/k]));a')

console.log(JSON.stringify(f(6)))
console.log(JSON.stringify(f(7)))
console.log(JSON.stringify(f(16777216)))
```

Try It Online!
> 2 votes

# Answer
# Jelly, 8 bytes

```
½ḊpP⁼¥Ðf

```

A monadic link taking a number and returning a list of lists (pairs) of numbers.

**Try it online!** (times out on TIO for the `16777216` example since it would create a list of 68.7 billion pairs and filter down to those with the correct product!)

### How?

```
½ḊpP⁼¥Ðf - Link: number, n     e.g. 144
½        - square root of n          12
 Ḋ       - dequeue*                 [2,3,4,5,6,7,8,9,10,11,12]
  p      - Cartesian product**      [[2,1],[2,2],...[2,144],[3,1],...,[3,144],...,[12,144]
      Ðf - filter keep if:
     ¥   -   last two links as a dyad (n is on the right):
   P     -     product
    ⁼    -     equals
         -                          [[2,72],[3,48],[4,36],[6,24],[8,18],[9,16],[12,12]]

```

* , dequeue, implicitly makes a range of a numeric input prior to acting, and the range function implicitly floors its input, so with, say, `n=24` the result of `½` is `4.898...`; the range becomes `[1,2,3,4]`; and the dequeued result is `[2,3,4]`

\** Similarly to above, `p`, Cartesian product, makes ranges for numeric input - here the right argument is `n` hence the right argument becomes `[1,2,3,...,n]` prior to the actual Cartisian product taking place.
> 2 votes

# Answer
# Husk, 8 bytes

```
tüOSze↔Ḋ

```

Try it online!

## Explanation

```
tüOSze↔Ḋ  Implicit input, say n=30.
       Ḋ  List of divisors: [1,2,3,5,6,10,15,30]
      ↔   Reverse: [30,15,10,6,5,3,2,1]
   Sze    Zip with original: [[1,30],[2,15],[3,10],[5,6],[6,5],[10,3],[15,2],[30,1]]
 üO       Deduplicate by sort: [[1,30],[2,15],[3,10],[5,6]]
t         Drop first pair: [[2,15],[3,10],[5,6]]

```
> 2 votes

# Answer
# Python 2, 59 bytes

```
lambda N:{(n,N/n,n)[n>N/n:][:2]for n in range(2,N)if N%n<1}

```

Try it online!
> 1 votes

# Answer
# Jelly, 9 bytes

```
ÆḌḊµżUṢ€Q

```

Try it online!
> 1 votes

# Answer
# Octave, 42 bytes

```
@(n)[y=find(~mod(n,x=2:n)&x.^2<=n)+1;n./y]

```

**Try it online!**
> 1 votes

# Answer
# PHP, 70 bytes

As string (70 bytes):

```
$i++;while($i++<sqrt($a=$argv[1])){echo !($a%$i)?" {$i}x".($a/$i):'';}

```

As array dump (71 bytes):

```
$i++;while($i++<sqrt($a=$argv[1]))!($a%$i)?$b[$i]=$a/$i:'';print_r($b);

```

(im not sure if i can use return $b; instead of print\_r since it no longer outputs the array, otherwise i can save 2 bytes here. )

The array gives the results like:

```
Array
(
    [2] => 8388608
    [4] => 4194304
    [8] => 2097152
    [16] => 1048576

```
> 1 votes

# Answer
## Wolfram Language (Mathematica), 41 bytes

```
nRest@Union[Sort@{#,n/#}&/@Divisors@n]

```

Try it online!

is the `Function` operator, which introduces an unnamed function with named parameter `n`.
> 1 votes

# Answer
# Factor, 58

Well, there has to be some Factor in this question!

```
[ divisors dup reverse zip dup length 1 + 2 /i head rest ]

```

It's a quotation. `call` it with the number on the stack, leaves an `assoc` (an array of pairs) on the stack.

I'm never sure if all the imports count or not, as they're part of the language. This one uses:

```
USING: math.prime.factors sequences assocs math ;

```

(If they count, I should look for a longer solution with shorter imports, which is kind of silly)

As a word:

```
: 2-factors ( x -- a ) divisors dup reverse zip dup length 1 + 2 /i head rest ;

50 2-factors .
 --> { { 2 25 } { 5 10 } }

```
> 1 votes

# Answer
# Ruby, 43 bytes

```
->n{(2..n**0.5).map{|x|[[x,n/x]][n%x]}-[p]}

```

Try it online!

### How it works:

For every number up to sqrt(n), generate the pair `[[x, n/x]]`, then take the `n%x`th element of this array. If `n%x==0` this is `[x, n/x]`, otherwise it's `nil`. when done, remove all `nil` from the list.
> 1 votes

# Answer
# Pari/GP, ~~49~~ ~~34~~ 38 bytes

```
n->[[d,n/d]|d<-divisors(n),d>1&d<=n/d]

```

Try it online!

Set builder notation for all pairs `[d, n/d]` where `d` runs through all divisors `d` of `n` subject to `d > 1` and `d <= n/d`.

Huge improvement by alephalpha.
> 1 votes

# Answer
## Perl 5, 53 + 2 (`-p` flag) = 55 bytes

```
$_="@{[map{$_,$n/$_.$/}grep!($n%$_),2..sqrt($n=$_)]}"

```

Ungolfed:

```
while (defined $_ = <>) {
    $n = $_;
    $_ = qq(@{[
        map{ ($_, ($n / $_) . "\n") } grep { !($n % $_) } (2 .. sqrt($n))
    ]});
    print($_);
}

```

Try it online.
> 1 votes

# Answer
# Vyxal, 7 bytes

```
K~/Z's⁼

```

Try it Online!

(not anymore) messy.
> 1 votes

# Answer
# Husk, ~~14~~ 12 bytes

```
tumoOSe`/⁰Ḋ⁰

```

Try it online!

### Explanation

```
tum(OSe`/⁰)Ḋ⁰  -- input ⁰, eg. 30
           Ḋ⁰  -- divisors [1..⁰]: [1,2,3,5,6,10,15,30]
  m(      )    -- map the following function (example on 10):
     Se        --   create list with 10 and ..
       `/⁰     --   .. flipped division by ⁰ (30/10): [10,3]
    O          --   sort: [3,10]
               -- [[1,30],[2,15],[3,10],[5,6],[5,6],[3,10],[2,15],[1,30]]
 u             -- remove duplicates: [[1,30],[2,15],[3,10],[5,6]]
t              -- tail: [[2,15],[3,10],[5,6]]

```
> 0 votes

# Answer
# APL+WIN, 32 bytes

```
m,[.1]n÷m←(0=m|n)/m←1↓⍳⌊(n←⎕)*.5

```

Explanation:

```
(n←⎕) Prompts for screen input

m←(0=m|n)/m←1↓⍳⌊(n←⎕)*.5 Calculates the factors dropping the first

m,[.1]n÷ Identifies the pairs and concatenates into a list.

```
> 0 votes

# Answer
# Add++, ~~18~~ 15 bytes

```
L,F@pB]dBRBcE#S

```

Try it online!

## How it works

```
L,   - Create a lambda function
     - Example argument:     30
  F  - Factors;     STACK = [1 2 3 5 6 10 15]
  @  - Reverse;     STACK = [15 10 6 5 3 2 1]
  p  - Pop;         STACK = [15 10 6 5 3 2]
  B] - Wrap;        STACK = [[15 10 6 5 3 2]]
  d  - Duplicate;   STACK = [[15 10 6 5 3 2] [15 10 6 5 3 2]]
  BR - Reverse;     STACK = [[15 10 6 5 3 2] [2 3 5 6 10 15]]
  Bc - Zip;         STACK = [[15 2] [10 3] [6 5] [5 6] [3 10] [2 15]]
  E# - Sort each;   STACK = [[2 15] [3 10] [5 6] [5 6] [3 10] [2 15]]
  S  - Deduplicate; STACK = [[[2 15] [3 10] [5 6]]]

```
> 0 votes

# Answer
# Befunge-93, 56 bytes

```
&1vg00,+55./.:   <
+1< v`\g00/g00:p00
_ ^@_::00g%!00g\#v

```

Try It Online
> 0 votes

# Answer
# Mathematica, 53 bytes

```
Array[s[[{#,-#}]]&,⌈Length[s=Divisors@#]/2⌉-1,2]&

```

Try it online!
> 0 votes

# Answer
# Julia 0.6, 41 bytes

```
~x=[(y,div(x,y))for y=2:x if x%y<1>y^2-x]

```

Try it online!

Redefines the inbuild unary operator `~` and uses an array comprehension to build the output.

* `div(x,y)` is neccessary for integer division. `x/y` saves 5 bytes but the output is `~4=(2,2.0)`.
* Julia allows chaining the comparisons, saving one byte.
* Looping all the way to x avoids `Int(floor(√x))`.
> 0 votes

# Answer
# APL NARS 99 chars

```
r←f w;i;h
r←⍬⋄i←1⋄→0×⍳0≠⍴⍴w⋄→0×⍳''≡0↑w⋄→0×⍳w≠⌊w⋄→0×⍳w≠+w
A:i+←1⋄→A×⍳∼0=i∣w⋄→0×⍳i>h←w÷i⋄r←r,⊂i h⋄→A

```

9+46+41+3=99 Test: (where not print nothing, it return something it return ⍬ the list null one has to consider as "no solution")

```
  f 101

  f 1 2 3

  f '1'

  f '123'

  f 33 1.23

  f 1.23

  ⎕←⊃f 16777216
   2 8388608
   4 4194304
   8 2097152
  16 1048576
  32  524288
  64  262144
 128  131072
 256   65536
 512   32768
1024   16384
2048    8192
4096    4096
  f 123
3 41

```
> 0 votes

# Answer
# Pyt, ~~67~~ 65 bytes

```
←ĐðĐ0↔/⅟ƖŽĐŁ₂20`ŕ3ȘĐ05Ș↔ŕ↔Đ4Ș⇹3Ș⦋ƥ⇹⁺Ɩ3ȘĐ05Ș↔ŕ↔Đ4Ș⇹3Ș⦋ƤĐ3Ș⁺ƖĐ3Ș<łĉ

```

I'm pretty sure this can be golfed.

Basically, the algorithm generates a list of all of the divisors of the input (let's call it *n*), makes the same list, but flipped, interleaves the two (e.g., if *n*=24, then, at this point, it has \[1,24,2,12,3,8,4,6,6,4,8,3,12,2,24,1\]), and prints out the elements from index 2 until half the array length, printing each number on a new line, and with an extra new line in between every pair.

Most of the work is done in actually managing the stack.

Saved 2 bytes by using increment function.
> 0 votes

# Answer
# Perl 5, 50 bytes

```
sub{map[$_,$_[0]/$_],grep!($_[0]%$_),2..sqrt$_[0]}

```

Ungolfed:

```
sub {
    return map  { [$_, $_[0] / $_] }
           grep { !($_[0] % $_) }
           (2 .. sqrt($_[0]));
}

```

Try it online.
> 0 votes

# Answer
# Japt, 9 bytes

Outputs a 2D array.

```
â ¤ò
£ÎîX

```

Try it
> 0 votes

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


title: Hello, Toroidal Earth!

text:
# Question
Title: Hello, Toroidal Earth!
Your task is to create a program that outputs the string:

```
Hello, Toroidal Earth!

```

with an optional trailing newline.

Additionally if I remove the first line1 of your program and add it as a line after the end of your program the new program should be a valid solution to this challenge in the same programming language.

So if my program were:

```
use module System.IO, Types.String
begin IO with (input as stdin, output as stdout)
new "Hello, Toroidal Earth" >> toBytestream >> output
end IO closing streams

```

then, its shift:

```
begin IO with (input as stdin, output as stdout)
new "Hello, Toroidal Earth" >> toBytestream >> output
end IO closing streams
use module System.IO, Types.String

```

would also have to be a valid solution, meaning that the next shift:

```
new "Hello, Toroidal Earth" >> toBytestream >> output
end IO closing streams
use module System.IO, Types.String
begin IO with (input as stdin, output as stdout)

```

would *also* have to be a valid program. And so on ad infinitum.

Likewise if I remove the final column of the program and insert it before the first column the result must be a valid solution to this challenge in the same programming language. When removing a column if a row doesn't have a character in that column (i.e. it is too short) then you should treat that place as a space character. So for example if my program were:

```
use module System.IO, Types.String
begin IO with (input as stdin, output as stdout)
new "Hello, Toroidal Earth" >> toBytestream >> output
end IO closing streams

```

Then the program:

```
 use module System.IO, Types.String
 begin IO with (input as stdin, output as stdout)
tnew "Hello, Toroidal Earth" >> toBytestream >> outpu
 end IO closing streams

```

should also be a valid solution, and of course any further shifting of it either vertical or horizontal should be as well.

All in all these shifts represent rotations on a torus.

Answers will be scored in bytes with fewer bytes being better.

1: You may choose to have your lines delimited by '\n' or by '\r\n'. Probably the former.

# Answer
> 21 votes
# Cascade, 36 bytes

```
@l"
}
"""
ETH
aoe
rrl
tol
hio
!d,
"a

```

Try it online!

While Cascade programs default to starting in the top left, but an explicit starting point can be created using a single `@`. This makes the program pretty much entirely immune to any column or row shifts, since all execution wraps around the edges of the playing field like a torus anyway. Note that if you had multiple `@`s, they would be triggered in order of appearance in the program, no longer preserving the behaviour.

The naive way of printing a string would be to print it all in one column, however that totals up to 49 bytes because of all the newlines. Instead, I split the string into three parts (coincidentally at each word, and execute each one by (ab)using `}`. One last consideration is put into where the string is split, so the spaces are at the end of the line, saving bytes by leaving them to be implicitly filled in by the interpreter.

# Answer
> 20 votes
# Unary,

**Rev 0 ~~3121491355794998332440739552097977007353231296357070843005722815009035246433220686378881420659391378316482528838109777011691037239240361352724200445025302725444438163079585978557249556~~**

**Rev 1** **276014140987112321091243548089349059271143856599044292139902575100947961955482006878466337854296695443646817751973462391672878955178246166009852634302332948 bytes**

Unary is an encoding for brainfuck programs where each of the 8 characters that can be used in a valid program corresponds to an octal digit. The program is converted to an octal number `n`, then the Unary output is composed of `n` identical characters (usually 1's.) Since all characters are the same, it is a valid submission for this challenge. See this question for Brainfuck/Unary converters.

The underlying Brainfuck programs (not valid submissions) are below

# brainfuck, Rev 1, 172 bytes

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

```

Try it online!

# brainfuck, Rev 0, 203 bytes

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

```

Try it online!

# Answer
> 14 votes
# Prolog (SWI), 107 bytes

```
.                                :-write("Hello, Toroidal Earth!")
A.
:-write("Hello, Toroidal Earth!").
A.

```

Try it online!

SWI doesn't exactly mind syntax errors, so we create two lines which each print the text and overlap by one character. That way when the are roatated there is always exactly one of them intact.

We have to add the `A.`s in between lines because without a `.` the SWI parser can get confused. For example if we remove them in the starting program

```
.                                :-write("Hello, Toroidal Earth!")
:-write("Hello, Toroidal Earth!").

```

The parser doesn't recover from the fail state quick enough to properly parse the second line. `.` seems to be more or less a hard override that tells it to give up on the clause.

# Answer
> 12 votes
# Fission, 26 bytes

```
R"Hello, Toroidal Earth!";

```

Try it online!

Unfortunately, Fission is so good at this we don't need to do anything interesting. `R` creates an atom which moves towards the right. As the atom reaches other characters, it executes them. The first character it hits is `"` which activates string mode, in which each further character encountered is output, except `"` which deactivates it. Then, `;` ends the program. Fission's layout is toroidal by default for atoms, so a shifted program like:

```
l Earth!";R"Hello, Toroida

```

Try it online!

behaves exactly the same.

# Answer
> 11 votes
# Lost, ~~63 58~~ 67 bytes

```
%?\>>>>>>>>>>>>>
>>\"Hello,vV"-+v
v-">^ladioroT"<<
\+x"EarthvU"-+@v

```

Try it online!

My first try with Lost. This is a 2D language, where the starting position and direction are random. So you never know where the instruction pointer starts and where it goes, but you can direct it. The instruction pointer moves in a toroidal way, meaning that if it reaches the end of a line, it starts the same line again. Likewise with columns.

Unfortunately, there is a bug in Lost, that will prevent it from running, when it starts with a space character. So I had to edit it to have no spaces in it and to have equally long lines, resulting in nine bytes more than my previous answer.

Explanation: A good portion of the code is just for directing the ip to the start of the code (\>, \<, v, and ^ instruct the ip to go to that specific direction. "" is a mirror, so the ip will reflect in the intentional way). The code starts in the upper left corner.

`%` deactivates the "safe mode". After that, the code will end, when it reaches the `@`.

`?\` will start a loop, that empties the stack. (The `?` means "if the stack is not empty, pop an item and ignore the next command"). When the stack is empty, the `\` will reflect the ip into the second line.

`\` reflects the ip to the right.

`"Hello,vV"` pushes that exact string onto the stack. The `v` is needed to direct the ip to the start, if it starts within the string.

`-+` means "invert the last item on the stack and add the last two items together. Basically, it pushes 'v' - 'V' = ' '.

Then the ip is redirected into the third row, where it pushes "Toroidal^\>" and again calculates '^' - '\>' = ' '.

In the last row it pushes "EarthvU" and calculates 'v' - 'U' = '!'.

Then, the `@` is the end of the code. The contents of the stack are printed implicitly.

# Answer
> 10 votes
# CSS, 280 bytes

```
:after{content:""}"{}:after{content:""}"{}:after{content:""}"{}
body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}

```

Try the default one:

```
:after{content:""}"{}:after{content:""}"{}:after{content:""}"{}
body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}
```

Try all (WARNING: This may hang your browser!):

```
const source = String.raw`
:after{content:""}"{}:after{content:""}"{}:after{content:""}"{}
body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}body:after{content:"Hello, Toroidal Earth!"}"{}/*/}{}
`.trim();

const lines = source.split('\n');
const width = Math.max(...lines.map(x=>x.length));
const height = lines.length;

for (let i = 0; i < width; i++) {
  for (let j = 0; j <= height; j++) {
    const modify = lines.slice(j).concat(lines.slice(0, j))
      .map(line => line.padEnd(' ', width).slice(i) + line.slice(0, i)).join('\n');
    const iframe = document.body.appendChild(document.createElement('iframe'));
    iframe.style = 'width: 100%; height: 60px;';
    iframe.src = 'data:text/html;base64,' + btoa(`<style>${modify}</style>`);
  }
}
```

The story tells us: You should repeat something ~~2~~ ~~3~~ 4 times whenever it is important.

Also, I have no idea how to golf it.

(I'm using Firefox 91, if this matters.)

# Answer
> 5 votes
# -e 'options(error=function(){})', 183 bytes

(or any other  environment in which errors do not halt execution of subsequent commands: entering the program into the  interactive console (or Rstudio) works fine; in batch mode or TIO we can set the global enviroment option `error` to an empty function; or in Rscript we can set this using the command-line option `-e 'options(error=function(){})'`).

```
if(F)  cat("hello toroidal world")#"                                   F=!F;
    F=!F
                                   `if`(F,cat("hello toroidal world"))#"
F=!F

```

Try it online!

Try all vertical rotations
Try all horizontal rotations

**How?**

The program is based offset copies of the code `if(F)cat("hello toroidal world")#"` and `F=!F`. The first instance of `if(F)cat("hello toroidal world")#` shouldn't output anything (since `F` is the built-in variable for `FALSE`). Then, `F` is flipped to `!F` = `TRUE`, so the second instance writes the output.
The final line flips `F` to `!F` again, to ensure that any vertical rotation of the lines leaves the overall program function unchanged.

But what if we rotate the code horizontally?

Most rotations that cut the first line will cause it to fail, but the second line will still flip `F` to `!F` so the third line will output Ok.
The exceptions are rotations of 5, 6, or 7 characters, which will remove the `if(F)` at the start of the first line, so the `cat` function will be called: however, the `F=!F` on the second line is placed so that any of these rotations will break it, with the result that the `cat` function on the third line will now not be called.

Any rotations that cut the third line (and so could cause it to fail) will bring the extra `F=!F` at the end of the first line, which is otherwise commented-out, to the front of the line, so the first line will now output.

---

# -e 'options(error=function(){})', 80 bytes

```
cat("hello toroidal world")
)                         cat("hello toroidal world"

```

Try it online!

...then I read the other answers and realised that a simple port of Wheat wizard's Prolog answer is much cleaner and shorter... Oh, well...

---
Tags: code-golf, source-layout, hello-world
---


title: Can I restack the buckets?

text:
# Question
Title: Can I restack the buckets?
My little kid has a toy like this:

This toy consists of 10 stackable little buckets, that we are going to number from 1 (the smallest one) to 10 (the biggest one). Sometimes he makes small piles and the toy ends up like this:

We can represent schematically the piles like this:

```
      1  6
4  9  2  7
5  10 3  8
----------  <-- Floor
1  2  3  4  <-- Pile #

```

Or, put it another way:

```
[[4,5],[9,10],[1,2,3],[6,7,8]]

```

This set of bucket piles is easily restackable to rebuild the original set (the first image) just by consecutively placing piles of smaller buckets inside piles of bigger buckets:

```
                             1                            1  6
                             2                            2  7
      1  6                   3        6                   3  8
4  9  2  7                   4  9     7                   4  9
5  10 3  8                   5  10    8                   5  10
---------- > [Pile 3 to 1] > ---------- > [Pile 4 to 2] > ---------- > [Pile 1 to 2] > Done!
1  2  3  4                   1  2  3  4                   1  2  3  4

```

Nonetheless, sometimes my kid tries to build towers, or throws buckets away, and the piles end up being inconsistent and the original set cannot be rebuild just by placing one pile inside another. Examples of this:

```
[[1,3,2],[4]] (the kid tried to build a tower by placing a bigger bucket
               over a smaller one, we would need to reorder the buckets
               first)
[[1,3,4],[2]] (the kid left aside an unordered bucket, we would need to remove
               bucket #1 from pile #1 before restacking)
[[1,2,3],[5]] (the kid lost a bucket, we need to find it first)

```

### Challenge

Given a list of lists of integers representing a set of bucket piles, return a truthy value if the lists represent an easily restackable set of piles, or falsey in any other case.

* Input will be given as a list of lists of integers, representing the buckets from top to bottom for each stack.
* There won't be empty starting piles (you won't get `[[1,2,3],[],[4,5]]` as input).
* The total number of buckets can be any within a reasonable integer range.
* My kid only has one set of buckets so there won't be duplicate elements.
* You can select any two consistent (and coherent) values for truthy or falsey.
* The buckets will be labelled from #1 to #N, being `N` the largest integer in the lists of integers. My kid still does not know the concept of zero.
* You may receive the input in any reasonable format as long as it represents a set of piles of buckets. Just specify it in your answer if you change the way you receive the input.
* This is , so may the shortest program/function for each language win!

### Examples

```
Input:  [[4,5],[9,10],[1,2,3],[6,7,8]]
Output: Truthy

Input:  [[6,7,8,9,10],[1],[2],[3,4,5],[11,12,13]]
Output: Truthy

Input:  [[2,3,4],[1],[5,6,7]]
Output: Truthy

Input:  [[1,2],[5,6],[7,8,9]]
Output: Falsey (buckets #3 and #4 are missing)

Input:  [[2,3,4],[5,6,7]]
Output: Falsey (bucket #1 is missing)

Input:  [[1,3,4],[5,7],[2,6]]
Output: Falsey (non-restackable piles)

Input:  [[1,4,3],[2],[5,6]]
Output: Falsey (one of the piles is a tower)

```

# Answer
# Jelly, ~~6~~ 5 bytes

*Thanks to @Lynn for saving 1 byte.*

```
ṢFµJ⁼

```

Try it online! (comes with test-suite footer)

### Explanation

```
ṢFµJ⁼    Main link. Argument: piles
Ṣ          Sort the piles by the size of the top bucket.
 F         Stack the piles, putting the left one to the top.
   J       See what a full pile with this many buckets would look like.
    ⁼      See if that looks like the pile you built.

```
> 12 votes

# Answer
# Python 2, ~~53~~ 52 bytes

*Thanks for the byte xnor*

```
lambda x:sum(sorted(x),[0])==range(len(sum(x,[]))+1)

```

Try it online!
> 8 votes

# Answer
## JavaScript (ES6), ~~59~~ 58 bytes

```
a=>!(a.sort((a,[b])=>a[i=0]-b)+'').split`,`.some(v=>v-++i)

```

### Explanation

```
a=>                                                        // given a 2D-array 'a'
     a.sort((a,[b])=>a[i=0]-b)                             // sort by first item
                              +''                          // flatten
    (                            ).split`,`                // split again
                                           .some(v=>v-++i) // i such that a[i] != i+1?
   !                                                       // true if none was found

```

### Test cases

```
let f =

a=>!(a.sort((a,[b])=>a[i=0]-b)+'').split`,`.some(v=>v-++i)

// truthy
console.log(f([[4,5],[9,10],[1,2,3],[6,7,8]]))
console.log(f([[6,7,8,9,10],[1],[2],[3,4,5],[11,12,13]]))
console.log(f([[2,3,4],[1],[5,6,7]]))

// falsy
console.log(f([[1,2],[5,6],[7,8,9]]))
console.log(f([[2,3,4],[5,6,7]]))
console.log(f([[1,3,4],[5,7],[2,6]]))
console.log(f([[1,4,3],[2],[5,6]]))
```
> 5 votes

# Answer
# 05AB1E, 4 bytes

```
{˜āQ

```

Try it online!
> 5 votes

# Answer
# Haskell, 54 bytes

```
import Data.List
f l=(sort l>>=id)==[1..length$l>>=id]

```

Try it online!
> 5 votes

# Answer
# Haskell, 37 bytes

```
import Data.List
(<[1..]).concat.sort

```

Try it online!

Checks whether the concatenated sorted list is lexicographically smaller than the infinite list `[1,2,3,...]`. Since there are no duplicates, any missing bucket or out-of-order bucket would cause a value greater than `k` in the `k`'th place, making the resulting list be bigger..
> 5 votes

# Answer
# PROLOG (SWI), 54 bytes

```
s(L):-sort(L,M),flatten(M,N),last(N,O),numlist(1,O,N).

```

Now *that's* better. Still quite verbose, alas.

Try it online!

The `s/1` predicate takes a list as argument and is true if the list is a list of easily stackable buckets.

Improvement in algorithm: if I sort the list *before* I flatten it, this forces all the sublists to be sorted for the predicate to be true. Slightly "borrowed" from Pietu1998's Jelly answer. Thanks to that I can dump the `forall` which is more than half of the program (see below for the original answer).

## How does it work?

The predicate is true if all of its clauses are true:

```
s(L) :-
    sort(L,M),                % M is L sorted in ascending order
    flatten(M,N),             % N is the 1-dimention version of M
    last(N,O),                % O is the last elemnt of N
    numlist(1,O,N).           % N is the list of all integers from 1 to O

```

## Previous answer, PROLOG (SWI), 109 bytes

```
s(L):-flatten(L,M),sort(M,N),last(N,O),numlist(1,O,N),forall(member(A,L),(A=[B|_],last(A,C),numlist(B,C,A))).

```

Try it online!
> 4 votes

# Answer
# Pyth, 6 bytes

```
UItMsS

```

Try it here.

Explanation:

```
UItMsSQ
UI      Invariant from U (range(len(A)) for our purpose)
  tM     Map t (A - 1 for our purpose)
    s     s (flatten 1-deep for our purpose)
     S     S (sort for our purpose)
      Q     Q (autoinitialized to input) (implicit)

```
> 4 votes

# Answer
# Pyth, ~~9 16~~ 11 bytes (Fixed)

Uses a completely different method from the other answer. A shorter, 7-byte approach can be found below.

```
!.EtM.++0sS

```

**Test Suite.**

---

# Explanation

```
!.EtM.++0sSQ  -> Full program, with implicit input at the end.

          SQ  -> Sort the input by the highest element in each sublist.
         s    -> Flatten.
       +0     -> Prepend a 0.
     .+       -> Get the deltas of the list (i.e. differences between consecutive elements)
   tM         -> Decrement each element.
 .E           -> Any truthy element (1s are truthy, 0s are falsy)
!             -> Negate (to have coherent truthy / falsy values)

```

# How does this work?

Let's take a couple of examples, which make it easier to understand. Let's assume the input is `[[1,3,4],[5,7],[2,6]]`. The core of this algorithm is that each delta in the unflattened list must be *1* in order for the buckets to be stackable.

* First off, `S` turns it into `[[1, 3, 4], [2, 6], [5, 7]]`.
* Then, `s` flattens it: `[1, 3, 4, 2, 6, 5, 7]`.
* Prepend a `0` in front: `[0, 1, 3, 4, 2, 6, 5, 7]`
* `.+` gets the deltas of the list, `[1, 2, 1, -2, 4, -1, 2]`.
* `tM` decrements each element, `[0, 1, 0, -3, 3, -2, 1]`.
* Any non-`0` integer is truthy in Pyth, so we check if there is any truthy element with `.E` (which means the stack cannot be formed correctly). We get `True`.
* `!` negates the result, which turns `True` into `False`.

If the input was, for example, `[[6,7,8,9,10],[1],[2],[3,4,5],[11,12,13]]`, the algorithm would work this way:

* Sorted by the highest element: `[[1], [2], [3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13]]` and flattened, with a `0` prepended: `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]`.
* Deltas: `[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]`. All get decremented: `[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`.
* There is no truthy element, so we get `False`. By logical negation, the result is `True`.

---

# Pyth, 7 bytes

```
qSlsQsS

```

**Test Suite.**

Port of the Python answer and a variation of @Erik's solution.
> 3 votes

# Answer
# Japt, ~~13~~ ~~12~~ 11 bytes

This could probably be shorter.

```
ñÎc äaT e¥1

```
* 1 byte saved thanks to ETH

Try it or run all test cases

---

## Explanation

```
                :Implicit input of 2D array `U`
ñÎ              :Sort sub-arrays by their first element
  c             :Flatten
      T         :Prepend 0
    äa          :Consecutive absolute differences
        e¥1     :Does every element equal 1?

```
> 3 votes

# Answer
# Brachylog, 5 bytes

```
oc~⟦₁

```

Try it online!

Explained unifications:

```
?o₀c₀~⟦₁.
?         The input (implicit)
 o₀       Sorted (subscript default = 0 => ascending)
   c₀     Concatenated (subscript default = 0 => no length check)
     ~    Inverse (find the input)
      ⟦₁   Range (subscript = 1 => [1..input])
        . The output (implicit)

```

Analytical explanation:

First of all we sort the list of lists, and then we concatenate (i.e. flatten 1-deep) (`oc`) so that the buckets get stacked right-to-left if possible. Then, to check if the buckets have been stacked correctly (i.e. no missing buckets or towers), we check that the resulting list is an inclusive range from 1 to its length. Now, instead of equal-checking the list with the \[1..n\] range of its length (`{l⟦₁?}`), we try to find an input to a function that generates such a range (`~⟦₁`), if there is one. If an input is found, then the program ends with no issues, so it triggers a `true.` status. If no input is found, the program fails, triggering a `false.` status.
> 3 votes

# Answer
# Python 2, 43 bytes

```
lambda l:sum(sorted(l),[0])<range(len(`l`))

```

Try it online!

Checks whether the concatenated sorted list is lexicographically smaller than `[1,2,3,...N]` for large `N`. Since there are no duplicates, any missing bucket or out-of-order bucket would cause a value greater than `k` in the `k`'th place, making the resulting list be bigger. The string-length of the input suffices as an upper bound since each numbers takes more than 1 character.
> 3 votes

# Answer
# MATL, 5 bytes

```
Sgtf=

```

Try it online!

(Implicit input, say `{[4,5],[9,10],[1,2,3],[6,7,8]}`)

`S` \- sort input arrays in lexicographic order (`{[1,2,3],[4,5],[6,7,8],[9,10]}`)

`g` \- convert into a single array (`cell2mat`)

`t` \- duplicate that

`f` \- find indices of non-zero values. Since input here is all non-zeros, returns the list of indices from 1 to length(array) (`[1,2,3,4,5,6,7,8,9,10],[1,2,3,4,5,6,7,8,9,10]`)

`=` \- check that the array is equal to the range 1 to length(array)
> 3 votes

# Answer
## Scala, 49 Bytes

```
p=>{val s=p.sortBy(_(0)).flatten
s==(1 to s.max)}

```

Ungolfed:

```
piles: List[List[Int]] =>
{
  val sorted = piles.sortBy(pile=>pile(0)).flatten //Since piles are sequential, we can sort them by their first element
  sorted == (1 to sorted.max) //If all the buckets are present and in order, after sorting them it should be equivalent to counting up from 1 to the max bucket
}

```
> 2 votes

# Answer
# , 58 bytes

```
function(v,a=unlist(v[order(sapply(v,min))]))any(a-seq(a))

```

Try it online!

N.B. : FALSE is the truthy outcome, TRUE is the falsy one

* -3 bytes thanks to @JayCe

Explanation :

```
a=unlist(v[order(sapply(v,min))])  # order the list of vector by the min value and flatten
all(a==seq(a=a))                   # if the flattened list is equal to 1:length then it's ok

```
> 2 votes

# Answer
# Japt, 9 bytes

```
ñg c
eUÌõ

```

Try it online!
> 2 votes

# Answer
# C# (.NET Core), ~~157~~ ~~145~~ 132 bytes

*-13 bytes thanks to TheLethalCoder*

```
l=>{var k=l.OrderBy(x=>x[0]).SelectMany(x=>x);return!Enumerable.Range(1,k.Count()).Zip(k,(x,y)=>x==y).Any(x=>!x);}

```

Byte count also includes

```
using System.Linq;

```

Try it online!

Ungolfed:

```
l => {
        var k = l.OrderBy(x=>x[0])              // First, sort stacks by first bucket
                 .SelectMany(x => x);           // Concatenate stacks into one
        return !Enumerable.Range(1, k.Count())  // Create a sequence [1...n]
               .Zip(k, (x, y) => x == y)        // Check if our big stack corresponds the sequence
               .Any(x => !x);                   // Return if there were any differences
     };

```
> 1 votes

# Answer
# CJam, 11 bytes

```
{$:+:(_,,=}

```

Try it online!

Oww `:(`...yeah! `{$:+_,,:)=}`
> 1 votes

# Answer
# Charcoal, 19 bytes (non-competing?)

```
Ａ▷m⟦▷s▷vθυ⟧θ⁼θ…·¹Ｌθ

```

Try it online!

-10 bytes thanks to ASCII-only.

-3 bytes thanks to ASCII-only for a subsequent implementation (see revision history for possibly competing version).

`-` for truthy,  for falsy.

Input is a singleton list of a list of lists, because of how Charcoal takes input.
> 1 votes

# Answer
# Vyxal, 5 bytes

```
sf₅ɾ⁼

```

Try it Online!

```
s     # Sort
 f    # Flatten
  ₅ɾ  # 1...a.length
    ⁼ # Is equal?

```
> 1 votes

# Answer
# Java 10, 213 bytes

```
import java.util.*;m->{Arrays.sort(m,(a,b)->Long.compare(a[0],b[0]));var r=Arrays.stream(m).flatMapToInt(Arrays::stream).toArray();return Arrays.equals(r,java.util.stream.IntStream.range(1,r.length+1).toArray());}

```

Try it online.

It seemed like a good idea when I started, but these builtins only make it longer.. Can definitely be golfed by using a more manual approach..

Inspired by *@EriktheOutgolfer*'s 4-byte 05AB1E answer. 4 vs 213 bytes, rofl.. \>.\>

**Explanation:**

```
import java.util.*;      // Required import for Arrays
m->{                     // Method with 2D integer-array parameter and boolean return-type
  Arrays.sort(m,         //  Sort the 2D input-array on:
    (a,b)->Long.compare(a[0],b[0]));
                         //  The first values of the inner arrays
var r=Arrays.stream(m).flatMapToInt(Arrays::stream).toArray();
                         //  Flatten the 2D array to a single integer-array
return Arrays.equals(r,  //  Check if this integer-array is equal to:
  java.util.stream.IntStream.range(1,r.length+1).toArray());}
                         //  An integer-array of the range [1, length+1]

```
> 0 votes

---
Tags: code-golf, number, decision-problem
---


title: Peano arithmetic at compile time

text:
# Question
Title: Peano arithmetic at compile time
Peano numbers represent nonnegative integers as zero or successors of other Peano numbers. For example, 1 would be represented as `Succ(Zero)` and 3 would be `Succ(Succ(Succ(Zero)))`.

# Task

Implement the following operations on Peano numbers, at compile time:

* Addition
* Subtraction - You will never be required to subtract a greater number from a smaller one.
* Multiplication
* Division - You will never be required to divide two numbers if the result will not be an integer.

# Input/Output

The input and output formats do not have to be the same, but they should be one of these:

* A type constructor of kind `* -> *` to represent `S` and a type of kind `*` to represent `Z`, e.g. `S<S<Z>>` to represent 2 in Java or `int[][]` (`int` for 0, `[]` for `S`).
* A string with a `Z` at the middle and 0 or more `S(`s and `)`s around it, e.g. `"S(S(Z))"` to represent 2.
* Any other format resembling Peano numbers, where there is a value representing zero at the bottom, and another wrapper that can contain other values.

# Rules

* You may use type members, implicits, type constructors, whatever you want, as long as a result can be obtained at compile time.
* For the purposes of this challenge, any execution phase before runtime counts as compile time.
* Since answers must work at compile-time, answers must be in compiled languages. This includes languages like Python, provided you can show that the bytecode contains the result of your computation before you even run the code.
* This is , so shortest code in bytes wins!

## Example for just addition in Scala

```
sealed trait Num {
  //This is like having a method `abstract Num plus(Num n);`
  type Plus[N <: Num] <: Num
}
object Zero extends Num {
  //When we add any n to zero, it's just that n again
  type Plus[N <: Num] = N
}
final class Succ[N <: Num](n: N) extends Num {
  //In Java: `Num plus(Num x) { return new Succ(n.plus(x)) }
  type Plus[X <: Num] = Succ[N#Plus[X]]
}

```

Usage (Scastie):

```
//This is just for sugar
type +[A <: Num, B <: Num] = A#Plus[B]

type Zero = Zero.type
type Two = Succ[Succ[Zero]]
type Three = Succ[Two]
type Five = Succ[Succ[Three]]
val five: Five = null
val threePlusTwo: Three + Two = five
val notFivePlusTwo: Five + Two = five //should fail
val zeroPlusFive: Zero + Five = five

```

# Test cases

S is used for successors and Z is used for zero.

```
S(S(S(Z))) + Z = S(S(S(Z)))                 | 3 + 0 = 3
S(S(Z)) + S(S(S(Z))) = S(S(S(S(S(Z)))))     | 2 + 3 = 5
S(S(S(Z))) - S(S(S(Z))) = Z                 | 3 - 3 = 0
S(S(Z)) * S(S(S(Z))) = S(S(S(S(S(S(Z))))))  | 2 * 3 = 6
S(S(S(S(Z)))) / S(S(Z)) = S(S(Z))           | 4 / 2 = 2
Z / S(S(Z)) = Z                             | 0 / 2 = 0

```

## Some links to help you get started

# Answer
# CP-1610 assembly, 37 bytes

This is simply using macro expansion.

```
Z EQU 0
MACRO S(n)
(%n%+1)
ENDM
 DCW [expression]

```

### Example

With the expression `S(S(Z)) * S(S(S(Z)))`, this gets compiled as:

```
00000000 Z
0x0                             Z EQU 0
                                MACRO S(n)
                                (%n%+1)
                                ENDM
                                ;DCW S(S(Z)) * S(S(S(Z)))
                                ;DCW (S(Z)+1) * S(S(S(Z)))
                                ;DCW ((Z+1)+1) * S(S(S(Z)))
                                ;DCW ((Z+1)+1) * (S(S(Z))+1)
                                ;DCW ((Z+1)+1) * ((S(Z)+1)+1)
0000   **0006**                      DCW ((Z+1)+1) * (((Z+1)+1)+1)
 ERROR SUMMARY - ERRORS DETECTED 0
               -  WARNINGS       0

```

(compiled with **as1600** from the SDK included with jzIntv)
> 8 votes

# Answer
# C++, 328 bytes

```
#define T template<class
#define O T N>struct
#define W T A,class B>struct
#define U using t=
U int;O S;W a;W a<S<A>,B>:a<A,S<B>>{};O a<t,N>{U N;};W s{U A;};W s<S<A>,S<B>>:s<A,B>{};W m{U int;};O m<N,S<t>>{U N;};W m<A,S<B>>:a<typename m<A,B>::t,A>{};T A,class B,class V=t>struct d:d<typename s<A,B>::t,B,S<V>>{};W d<t,A,B>{U B;};

```

Try it online!

`0` (`Z`) is represented by the type `int`. `Succ(N)` is represented by the type `S<N>`.

`A+B` is `a<A, B>::t`, `A-B` is `s<A, B>::t`, `A*B` is `m<A, B>::t` and `A/B` is `d<A, B>::t`.

---

# C++, 285 bytes

```
#define U template<
#define Q U class N>struct
#define X(n,o)U class A,class B>struct n:T<i<A>::v o i<B>::v>{};
Q S;Q i{static const int v=0;};Q i<S<N>>{static const int v=1+i<N>::v;};U int i>struct T{using t=S<typename T<i-1>::t>;};U>struct T<0>{using t=int;};X(a,+)X(s,-)X(m,*)X(d,/)

```

This "cheatier" version (if this is allowed) is shorter. It simply converts type to int -\> do operation -\> convert back to type.

Try it online!

---

# C++ or C, 29 bytes

```
#define Z 0
#define S(N)(N+1)

```

Try it online!

This is even more cheaty, and relies on C having integer constant expressions and C++ having constant evaluation that can be run at compile time
> 6 votes

# Answer
## TypeScript, ~~618~~ 585 bytes

```
type R<T,U,V>=T extends U?V:T
type I<T>=R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<T,20,21>,19,20>,18,19>,17,18>,16,17>,15,16>,14,15>,13,14>,12,13>,11,12>,10,11>,9,10>,8,9>,7,8>,6,7>,5,6>,4,5>,3,4>,2,3>,1,2>,0,1>
type D<T>=R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<R<T,0,[]>,1,0>,2,1>,3,2>,4,3>,5,4>,6,5>,7,6>,8,7>,9,8>,10,9>,11,10>,12,11>,13,12>,14,13>,15,14>,16,15>,17,16>,18,17>,19,18>,20,19>,21,20>
type A<T,U>=T extends 0?U:A<D<T>,I<U>>
type S<T,U>=U extends 0?T:S<D<T>,D<U>>
type F<T,U,V=0>=S<T,U>extends[]?V:F<S<T,U>,U,I<V>>
type B<T,U>=U extends 0?0:U extends 1?T:A<B<T,D<U>>,T>

```

Playground link

### Key

| Value | Syntax |
| --- | --- |
| Zero | `0` |
| Successor of `n` | `I<n>` |
| `n + m` | `A<n, m>` |
| `n - m` | `S<n, m>` |
| `n * m` | `B<n, m>` |
| `floor(n / m)` | `F<n, m>` |

### Test Cases

```
type Zero = 0
type Two = I<I<Zero>>
type Three = I<Two>
type Four = I<Three>
type Five = I<Four>
declare const zero: Zero;
declare const two: Two;
declare const three: Three;
declare const five: Five;
declare const six: I<Five>;

let threePlusTwo: A<Three, Two> = five;
let fivePlusTwo: A<Five, Two> = five; // error: '5' is not '7'
let zeroPlusFive: A<Zero, Five> = five;

let threePlusZero: A<Zero, Three> = three;
let twoPlusThree: A<Two, Three> = five;
let threeMinusThree: S<Three, Three> = zero;
let twoTimesThree: B<Two, Three> = six;
let fourOverTwo: F<Four, Two> = two;
let zeroOverTwo: F<Zero, Two> = zero;

```

### Explanation

* `R<T, U, V>` is a replacement function: It takes `T` as its main input and replaces `U` with `V`.
* `I<T>` and `D<T>` are used to change numbers by 1. I know that I hardcoded it to stop at 21, but unfortunately I can't go further due to TypeScript's recursion limit. I originally tried a different method that was easier to understand and to extend, but it hit the recursion limit even faster. Underflow is represented with `[]` (empty tuple).
* `A<T, U>` returns `U` when `T` = 0, and `A<T - 1, U + 1>` otherwise.
* `S<T, U>` returns `T` when `U` = 0, and `S<T - 1, U - 1>` otherwise.
* `F<T, U, V>` technically returns `floor(T / U) + V`, but `V` defaults to 0. It uses `V` to keep track of the answer.
* `B<T, U>` returns immediately when `U` is 0 or 1, and otherwise returns `B<T, U - 1> + T`.

TL;DR: A lot of recursion.

Dividing by zero gives an error (TS2589), which I think is the correct behavior.

### Bonus

Modulo and primality test:

```
type M<T,U>=S<T,U>extends[]?T:M<S<T,U>,U>
type H<T,U>=U extends 1?1:M<T,U>extends 0?0:H<T,D<U>>
type P<T>=T extends 1?0:H<T,D<T>>

```

`M<T, U>` returns `T` mod `U`. `P<T>` returns 1 when `T` is prime and 0 otherwise.
Like with division, these both give an error when attempting to use 0 where it doesn't make sense.

---

### Original

The original answer was very similar, but with a small difference in how `F` was defined:

```
type G<T,U>=S<U,T>extends []?1:0
type F<T,U,V=0>=G<U,T>extends 1?V:F<S<T,U>,U,I<V>>

```
> 5 votes

# Answer
# Rust, 547 bytes

```
struct Z;struct S<Z>(Vec<Z>);trait A<B>{type R;}impl<B>A<B>for Z{type R=B;}impl<B,N:A<B>>A<B>for S<N>{type R=S<<N as A<B>>::R>;}trait M<B>{type R;}impl<N>M<N>for Z{type R=Z;}impl<N>M<Z>for S<N>{type R=S<N>;}impl<P,N:M<P>>M<S<P>>for S<N>{type R=<N as M<P>>::R;}trait T<B>{type R;}impl<B>T<B>for Z{type R=Z;}impl<B,N:T<B>>T<B>for S<N>where<N as T<B>>::R:A<B>{type R=<<N as T<B>>::R as A<B>>::R;}trait D<B>{type R;}impl<P>D<S<P>>for Z{type R=Z;}impl<P,N:M<P>>D<S<P>>for S<N>where<N as M<P>>::R:D<S<P>>{type R=S<<<S<N> as M<S<P>>>::R as D<S<P>>>::R>;}

```

Try it online

This is basically equivalent to the Scala version. It defines two structs, `Z` and `S<Z>`, and four traits that implement the operations (called `A`, `M`, `T` and `D` in the golfed code).

Readable version:

```
struct Z;
struct S<Z>(Vec<Z>);

trait Add<B>{type R;}
impl<B> Add<B>for Z{type R=B;}
impl<B,N: Add<B>> Add<B>for S<N>{type R=S<<N as Add<B>>::R>;}

trait Sub<B>{type R;}
impl<N>Sub<N>for Z{type R=Z;}
impl<N> Sub<Z>for S<N>{type R=S<N>;}
impl<P,N: Sub<P>> Sub<S<P>>for S<N>{type R=<N as Sub<P>>::R;}

trait Times<B>{type R;}
impl<B> Times<B>for Z{type R=Z;}
impl<B,N: Times<B>> Times<B>for S<N> where <N as Times<B>>::R: Add<B>{type R=<<N as Times<B>>::R as Add<B>>::R;}

trait Divide<B>{type R;}
impl<P>Divide<S<P>>for Z{type R=Z;}
impl<P,N:Sub<P>>Divide<S<P>>for S<N>where<N as Sub<P>>::R:Divide<S<P>>{type R=S<<<S<N> as Sub<S<P>>>::R as Divide<S<P>>>::R>;}

```
> 4 votes

# Answer
# C++ (gcc), 307 bytes

```
#define _ struct
#define n typename
#define t template<n T
#define U{using X
_ Z;
t>_ S U=T;};

t,n B>_ s U=S<n s<n T::X,B>::X>;};
t>_ s<Z,T>U=T;};

t,n B>_ b U=n b<n T::X,n B::X>::X;};
t>_ b<T,Z>U=T;};

t,n B>_ m U=n s<T,n m<T,n B::X>::X>::X;};
t>_ m<T,Z>U=Z;};

t,n B>_ d U=S<n d<n b<T,B>::X,B>::X>;};
t>_ d<Z,T>U=Z;};

```

Try it online!

* There's already a good C++ answer but I was missing template meta programming.
* Left newlines on the code for some "readability" , already subtracted 14 bytes.
* Basically S (succ) stores it's template type which is then recursively inspected inside the various operations (s=sum,b=subtract,m=multiply,d=division) to dig the Peano structure.
> 2 votes

---
Tags: code-golf, compile-time
---