23

3

# Challenge

Your task is to encode an integer as a string of ASCII characters, then successfully decode it after said string has been randomly shuffled.

You will write two programs/functions, which will be referred to as *Encoder* and *Decoder*.

*Encoder*

**Input:**an integer \$n\$ in the range \$[0,2^{31}-1]\$.**Output:**a string \$s\$ of ASCII characters (not necessarily printable).

*Decoder*

**Input:**a random permutation \$s'\$ of the string \$s\$.**Output:**the integer \$n\$.

# Scoring

Let \$A\$ be the **maximum length** of \$s\$ across all possible values of \$n\$. If the *Encoder* acts non-deterministically (which is allowed, see below), then the \$A\$ will be the maximum length of \$s\$ that may occur (possibly \$\infty\$).

Let \$L_E\$ be the **length of the Encoder** in bytes and \$L_D\$ the

**length of the**in bytes.

*Decoder*Then your score is \$A\cdot(L_E+L_D)\$.

Victory is awarded to the submission the **lowest score**.

# Time limit

There is a somewhat arbitrary **time limit of 1 minute** on the execution time of both the *Encoder* and the *Decoder* for a single testcase (i.e. a single value of \$n\$).

The goal is to avoid solution that find that brute-force the encoding by enumerating all sequences with certain properties. If your solution does something more clever than that, it will most likely fit the time constraint and will be considered valid. Likewise, if it works on TIO for some randomly selected values of \$n\$ it will be considered valid. Otherwise I will test it on my machine, but note that if your solution is pure brute-force it will almost certainly fail.

# Rules

- The
*Encoder*and the*Decoder*must be written in the**same language**. - The
*Decoder*must output the**correct**integer \$n\$ for every possible permutation \$s'\$ of the string \$s\$ returned by the*Encoder*. - The
*Encoder*and the*Decoder*are**not**allowed to**share information**in any way (e.g. by means of global variables or files). - The output of the
*Encoder*need**not**be**deterministic**(that is, the same input \$n\$ may produce different output strings if the*Encoder*is run multiple times), but the*Decoder*must always guess the correct integer \$n\$. - The
*Encoder*and the*Decoder*may take and return the integer \$n\$ in**any convenient way**(e.g. if \$n=14\$ it is fine for the input to be`14`

,`"14"`

or`[1,4]`

). - The
*Encoder*may output the string \$s\$ either by**printing**it on`stdout`

**or**by**returning**a string, a list/array of characters or a list/array of integers in the range \$[0,127]\$; note that the*Decoder*will receive as input a permutation of \$s\$ as returned by the*Encoder*, so it should accept the string \$s'\$ in the**same format**as \$s\$. **Standard loopholes**are forbidden.- If possible,
**explain**how your code works and why the score you claim is correct.

# Example

Assume \$n=14\$.

- The
Encoderreceives`14`

as input. It may output`"qwerty"`

.- The
Decoderreceives a permutation of`"qwerty"`

as input, for instance`"tweyqr"`

. It must output`14`

(in any convenient format).

The *Encoder* could have returned `[113,119,101,114,116,121]`

as well, in which case the *Decoder* would have received (for instance) `[116,119,101,121,113,114]`

.

Note that the string returned by the *Encoder* may also include non-printable ASCII characters (but always in the range `[0x00, ..., 0x7F]`

).

Surely the output length can't be infinity, you can't shuffle an infinite string – H.PWiz – 2018-09-23T16:21:12.997

@H.PWiz No it can't, but the lenght may be unbounded if the

Encoderis non-deterministic – Delfad0r – 2018-09-23T16:43:26.297"The Encoder and the Decoder are not allowed to share information in any way" Does this include helper functions? i.e. A custom function that calculates N factorial plus three (random example) – pizzapants184 – 2018-09-24T03:04:03.950

Can our Encoder return an empty string/list? – pizzapants184 – 2018-09-24T05:30:23.810

@pizzapants184 The empty string/list is certainly a valid return value. As for shared helper functions, I would say they are not allowed, but I am unsure about standard rules, so please let me know if there is a consensus approving them. – Delfad0r – 2018-09-24T06:09:56.943

What if the decoder and encoder are the same? Do you have to count the bytes twice or just once? – Kroppeb – 2018-09-24T09:06:37.190

2@Kroppeb Yes, as of now the rules say you should count the bytes twice. I'm very interested in seeing a submission with two identical programs, though. – Delfad0r – 2018-09-24T09:27:10.283

Can we print leading zeroes for the decoder? – Jo King – 2018-09-26T04:48:06.873

@Jo King Yes you can. – Delfad0r – 2018-09-26T07:07:49.773