Output with the same length always



With challenges like Output with the same length as the code and Create output twice the length of the code, I thought of a separate, but similar challenge.

The task is to produce an output. It can either be a string, a list of characters, or whatever is the default output format of your program. However, your output must always be the same length, regardless of the input. And more importantly, the output should be different for different inputs.


A single integer \$n\$, the ranges of which is determined by the choice of language. If your language has variable length integers, the range is \$-2^{31} \leq n < 2^{31}\$.


A string or a list of characters, or a print to STDOUT or STDERR. You may only use one of these methods. The output should be of the same length regardless of the input, but it is up to you to define which length that is. The output may not contain the digit characters 0-9, or the minus sign -. The output should be deterministic.

You should be able to prove that for every output there is only one possible input, either by a formal proof, an argument, or a brute-force search.

This is a code golf question, so shave off any extraneous bytes. All languages are welcome, the more the better!


Posted 2019-08-16T13:13:08.103

Reputation: 5 754

4Should the program in theory work for any input? Or does it suffice to use a method that only works for the specified range (bounded by $\pm 2^{31}$), not necessarily due to language limitations but method limitations? – Mr. Xcoder – 2019-08-16T13:28:30.157

4@Mr.Xcoder how could you pick a length if you had to work for arbitrary length integers? – Stephen – 2019-08-16T13:34:19.703

@Stephen I guess it would be impossible given that the unicode set is limited in length. But I just wanted to clarify that aspect, maybe I'm missing something. – Mr. Xcoder – 2019-08-16T13:36:47.807

2@Mr.Xcoder You must only prove that it works for that range. This rule is to help languages such as Python, where numbers can be thousands of digits. Without that rule, it'd be much harder for both Python, and Python derivatives (which includes a lot of golfing languages). – maxb – 2019-08-16T13:37:01.223

@Arnauld As Mr. Xcoder says, you must avoid all digits in your output. The approach that you take is up to you. If could be transliteration, substitution, dictionary fetching, or something that I haven't thought of. I wanted to leave it quite open, to leave room for creativity. – maxb – 2019-08-16T13:48:03.060

11If a language doesn't have variable length integers but can support values larger than $2^{31}$, are we allowed to use the restricted range $-2^{31}\le n<2^{31}$? – Arnauld – 2019-08-16T15:20:55.347

Can we take input as a string? – Shaggy – 2019-08-16T17:49:32.873

2@Arnauld the maximum range is 32 bit signed integers, regardless of the limitations of the language. The language can only decrease that range. – maxb – 2019-08-16T22:30:13.757

@Shaggy if your language doesn't separate strings and ints, i guess you could. But input should be an integer. Otherwise it'd be too trivial in some languages (I can think of a 3-byter in mathgolf). – maxb – 2019-08-16T22:32:27.737



JavaScript (ES8), 33 bytes

Expects the input in the range of safe JS integers: \$-2^{53}\le n < 2^{53}\$.

Returns a string of 76 characters.


Try it online!


Step 1

The input is first converted to binary. This preserves the leading minus sign for negative numbers.


  • 123"1111011"
  • -77"-1001101"

Step 2

The resulting string is encoded in base-64.

It means that each block of 1 to 3 characters will be turned into a new block of 4 characters. This conversion is safe because none of the resulting blocks contain the forbidden symbols (digits or minus sign).

3-character blocks

"-10" -> "LTEw" | "011" -> "MDEx"
"-11" -> "LTEx" | "100" -> "MTAw"
"000" -> "MDAw" | "101" -> "MTAx"
"001" -> "MDAx" | "110" -> "MTEw"
"010" -> "MDEw" | "111" -> "MTEx"

A single final block of 1 or 2 characters has to be encoded if the length of the binary string is not a multiple of 3:

1-character blocks

"0"   -> "MA==" | "1"   -> "MQ=="

2-character blocks

"-1"  -> "LTE=" | "10"  -> "MTA="
"00"  -> "MDA=" | "11"  -> "MTE="
"01"  -> "MDE=" | 

Step 3

The final output is padded with trailing spaces.


Posted 2019-08-16T13:13:08.103

Reputation: 111 334

1Did you already know that these particular combinations of character contain no numbers when converted to base64, or did you find out experimentally? – Tomáš Zato - Reinstate Monica – 2019-08-19T10:33:43.300

@TomášZato That was a confident guess, based on the fact that it is a very small charset in the lower part of the ASCII table. – Arnauld – 2019-08-19T12:35:22.890


Python 3, 49 39 bytes

lambda i:[chr(ord(x)*2)for x in"%9x"%i]

Try it online!

-10 bytes thanks to negative seven

Converts the integer to hexadecimal, and prepends spaces up to 9 characters total. Then, doubles the ASCII code of each character in the string (some extend outside of ASCII into Unicode, but Python handles it fine), outputting a list of characters.

This works because every digit, including -, is mapped to a different ASCII character. No integers between -2147483648 and 2147483648 are equal, so converting them to hexadecimal and prepending spaces would not make them equal. Then, mapping them to different codepoints does not lead to collisions, so there are still no two values in the range which lead to equal outputs.

Python 3, 59 56 47 bytes

lambda i:[*map(lambda x:chr(ord(x)*2),"%9x"%i)]

Try it online!

-3 bytes thanks to Jitse

-9 bytes thanks to negative seven

Same algorithm, but using map instead of a for loop.


Posted 2019-08-16T13:13:08.103

Reputation: 12 293

2You can shave off 3 bytes in the map approach by replacing list( ... ) with [* ... ] – Jitse – 2019-08-16T13:47:38.937

3You could create the padded string with "%9x"%i – negative seven – 2019-08-16T14:03:11.390

@negativeseven thank you, that is really genius – Stephen – 2019-08-16T14:22:19.830

1Could stay within ASCII and at 39 bytes in Python 2 using \4e9+n`` – Jonathan Allan – 2019-08-17T00:09:54.603


05AB1E, 11 5 bytes


-6 bytes porting @Stephen's approach, so make sure to upvote him!

Outputs a list of up to 100 characters, with \$100-(\text{input length})\$ amount of @ (double the space codepoint), and all -0123456789 mapped to Z`bdfhjlnpr (double the ASCII codepoints).

Try it online.


 j     # Prepend spaces in front of the (implicit) input-integer to make it of length:
т      # 100
  Ç    # Convert each character to its unicode value
   ·   # Double each
    ç  # And convert it back to a character
       # (after which the resulting list is output implicitly)

Original 11 bytes answer:


Try it online (limited to 1000 instead of 2147483648).


The output length is always 2,147,483,648 characters long. It will output \$2147483648-|n|-1\$ amount of spaces, appended with \$|n|\$ amount of newlines, appended with either an 'a' if \$n\lt0\$ or 'b' if \$n\geq0\$.

Ä            # Get the absolute value of the (implicit) input-integer
 ¶×          # And have a string with that many newline characters
   A         # Push the lowercase alphabet
    Id       # Check if the input is non-negative (>=0) (1 if truthy; 0 if falsey)
      è      # Use that to index into the alphabet (so "a" for <0 and "b" for >=0)
       «     # Append that to the newline-string we created earlier
          j  # And prepend spaces to make the string of a length:
        žI   # 2147483648 (this has been replaced with `₄`/1000 in the TIO)
             # (after which the result is output implicitly)

Kevin Cruijssen

Posted 2019-08-16T13:13:08.103

Reputation: 67 575


brainfuck, 48 29 28 16 13 bytes

This program requires cells, where \$ c_n \in \mathbb{N} \$, but if you want consistent results, make sure that \$ c_n < 256 \$

Output will obviously be unique no matter what number will you enter (\$ -\infty \lt n \lt \infty \$). If the integer is shorter, the program will pad out the output to match exactly \$ \infty \$ bytes, so the length is always the same.

This answer is a bit loopholing the challenge, as it didn't state that output has to be finite.


Try it online!

Original, 28 byte answer:


This one will pad the output to be exactly \$ 2^8 - 1 \$ bytes. The number conversion mechanism works the same here. This program assumes the same as the program above.

Krzysztof Szewczyk

Posted 2019-08-16T13:13:08.103

Reputation: 3 819

Infinite output is not allowed

– Jo King – 2019-08-18T05:09:10.803

@JoKing this was stated after I made this answer. But if you really feel hurt by this, I can simply opt out of challenge and declare first answer as non-competing – Krzysztof Szewczyk – 2019-08-18T08:12:53.723


Python 3, 39 bytes

lambda n:f"{n:33b}".translate("abc"*99)

Try it online!

Turns the given number into a binary string representation (padded with spaces), then maps the characters (space)-01 to caab with the str.translate function.

negative seven

Posted 2019-08-16T13:13:08.103

Reputation: 1 931


Ruby, 27 bytes


Try it online!

('%34b'%n) Converts an integer into its binary representation, using ..1 to indicate a negative number (this is meant to represent an infinitely-long prefix of 1s), and left-pads this out to 34 characters using spaces. Then we replace the 0s with 'a' and the 1s with 'h' to create the Maniacal Base 2 Representation: strings like "haaahahahaaha" prepended with spaces and sometimes ... Since every step here is invertible this is 1:1.

Edit: Let the record show that @manatwork posted this identical solution first. Oops. I should've refreshed.


Posted 2019-08-16T13:13:08.103

Reputation: 20 600

3Lol. Your output is much funnier than mine. – manatwork – 2019-08-16T15:58:19.963


Jelly, 4 bytes


A monadic Link accepting an integer which yields a list of 52 characters.

The input range may be up to somewhat more than \$-2^{223} \leq n \lt 2^{223}\$ since \$52!>2^{224}\$.

Try it online!


œ?ØẠ - Link: integer, n
  ØẠ - alphabet (Jelly's longest built-in character list containing no digits
     -           or hyphen) = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
œ?   - permutation at index (n) if all 52! permutations were written out
     - in lexicographical order.
     - This indexing is modular so when n = -x we fetch the (52!-x)th entry.


-2147483648 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONIGCDAMLJKFEHB
-2147483647 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONIGCDAMLJKFHBE
-2147483646 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONIGCDAMLJKFHEB
-2147483645 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONIGCDAMLJKHBEF
         -4 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDACB
         -3 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDBAC
         -2 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDBCA
         -1 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCAB
          0 zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA
          1 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
          2 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxzy
          3 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyxz
          4 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwyzx
 2147483644 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmrtxwznoqpsvyu
 2147483645 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmrtxwznoqpsyuv
 2147483646 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmrtxwznoqpsyvu
 2147483647 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmrtxwznoqpusvy

Jonathan Allan

Posted 2019-08-16T13:13:08.103

Reputation: 67 804


Jelly, 6 bytes


Try it online!

Since Jelly has arbitrary length integers, this monadic link takes an integer in the range \$±2^{31}\$ and returns a length 7 alphabetic string. It works by adding \$2^{32}\$ and then base decompressing into the capital letters.

Nick Kennedy

Posted 2019-08-16T13:13:08.103

Reputation: 11 829


C# (Visual C# Interactive Compiler), 35 bytes


Try it online!

Embodiment of Ignorance

Posted 2019-08-16T13:13:08.103

Reputation: 7 014

Crashes for x = int.MinValue as it can't be negated. – Hand-E-Food – 2019-08-19T03:55:02.500

1@Hand-E-Food Fixed by changing to an entirely different version – Embodiment of Ignorance – 2019-08-19T04:42:18.573


C (gcc), 38 bytes


Try it online!

This expands each bit of the input integer into a byte that is either 0 or 1 (which are both unprintable characters, but there is no rule against that). So the output is always 32 bytes, and guaranteed to be unique.

G. Sliepen

Posted 2019-08-16T13:13:08.103

Reputation: 580

Clever approach, similar to the Brainfuck response padding with NUL bytes. – maxb – 2019-08-17T12:41:27.830

I'm not sure a program that doesn't terminate is really within specs... but if it is, 28 bytes? f(a){putchar(a&1);f(a/2);} – G. Sliepen – 2019-08-17T12:49:40.763

I made an exception for Malbolge, but in general the program should terminate. Having "infinity" as the length is a bit of a cheat. – maxb – 2019-08-17T17:01:25.020


Haskell, 31 bytes


Try it online!

Adds 2^60 to the input so that the resulting number has the same amount of digits for the whole input range. Turn into a string and shift each character 10 places to the right in the ASCII order (0 -> : ... 9 -> C).


Posted 2019-08-16T13:13:08.103

Reputation: 34 639

1Does it handle negative numbers? – maxb – 2019-08-16T14:39:11.387

@maxb: no, but now it's fixed. – nimi – 2019-08-16T15:32:51.520


Perl 5 -MDigest::MD5=md5_hex -p, 23 bytes


Try it online!


Perl 5 -p, 29 bytes


Try it online!

Converts the number to its 64 bit binary representation, then transliterates 0 and 1 to a and b, respectively.


Posted 2019-08-16T13:13:08.103

Reputation: 7 671

5And you have confirmed there are no collisions for all valid inputs? – Sparr – 2019-08-16T22:45:06.050

... and that no md5 hash produces a digit character by chance? – AlexR – 2019-08-18T22:05:50.303

Forgot about the requirement to exclude digits. I've updated to accommodate that. – Xcali – 2019-08-19T03:44:19.587

9 bytes, 0 risk of MD5 collision. – Grimmy – 2019-08-19T12:51:48.133


C# (Visual C# Interactive Compiler), 52 bytes

x=>(new char[32]).Select(y=>(char)(x%2+65+(x/=2)*0))

Try it online!

Different approach to a c# solution, takes advantage of the fact that c# modulus is negative for negative numbers. I suppose you could shave off a byte or two if you allow non-display characters ('\0', and so on) by updating the +65... to not offset the character value to something human readable.

Andrew Baumher

Posted 2019-08-16T13:13:08.103

Reputation: 351

44? - I am outputting non-printable characters (which seems ok) but you could convert to printable by adding 65 like your current answer. – dana – 2019-08-17T17:18:54.047

142 - This time with printable characters :) – dana – 2019-08-17T17:26:20.100


T-SQL, 73 70 61 bytes


I'm just directly replacing the digits (and -) with letters, after STR pads the integer to 11 characters. No conversion to hex or binary is necessary.

TRANSLATE was introduced in SQL 2017.

Input is via a pre-existing table \$t\$ with INT column \$n\$, per our IO rules. Range of the INT datatype in SQL is \$-2^{31} \leq n < 2^{31}\$.

EDIT: Saved 3 bytes by replacing manual padding with a conversion to CHAR(11), which is a fixed-width character format that automatically pads with spaces.

EDIT 2: Saved 9 bytes by using STR() function instead of CAST. STR converts a number to a text string padded to the specified length.


Posted 2019-08-16T13:13:08.103

Reputation: 6 099


APL (Dyalog Unicode), 28 bytes

{11↑' Z'[⍵≤0],⎕A[⍎¨'¯'~⍨⍕⍵]}

Try it online!

Simple Dfn, taking an integer argument. Uses ⎕IO←0.

TIO links to a test case from -2^10 to 2^10. The 0~⍨ part removes the duplicate 0 from the arguments.


{11↑' Z'[⍵≤0],⎕A[⍎¨'¯'~⍨⍕⍵]} ⍝ Dfn
              ⎕A[         ]  ⍝ Index the Uppercase Alphabet with
                        ⍕⍵   ⍝ String representation of the argument
                   '¯'~⍨     ⍝ Without the character ¯
                 ⍎¨          ⍝ Executing each digit back into integers
             ,               ⍝ Prepend
    ' Z'[   ]                ⍝ A character from the string ' Z' indexed by
         ⍵≤0                 ⍝ Argument ≤ 0. Returns 1 if true, else 0.
                             ⍝ This will prepend a whitespace to positive numbers, and a Z otherwise.
 11↑                         ⍝ Take the first 11 characters, padding with whitespace.

J. Sallé

Posted 2019-08-16T13:13:08.103

Reputation: 3 233


Japt, 6 bytes

I think this is right. Inspired by Stephen's Python solution so please +1 him.

¤ùI cÑ

Try it

¤ùI cÑ     :Implicit input of integer
¤          :Convert to binary string
 ù         :Left pad with spaces
  I        :  To length 64
    c      :Map codepoints
     Ñ     :  Multiply by 2


Posted 2019-08-16T13:13:08.103

Reputation: 24 623


Wolfram Language (Mathematica), 44 33 bytes


Try it with a smaller domain

-2 thanks to Greg Martin

Prints >> , followed by the 523069747202-character string representation of a list of \$13!+n\$ Nulls padded by Trues to a length of \$14!\$, and a newline. Works on the domain \$[-13!,14!-13!)\$, which is a superset of \$[-2^{31},2^{31})\$.

Given the size of the output, I've included a test case with a smaller domain of \$[-2^4,2^4)\$ instead


Posted 2019-08-16T13:13:08.103

Reputation: 3 495

Nice :) I think you can save two bytes by changing 2^31 and 2^32 to 13! and 14! respectively. At the loss of some "brevity" in the output.... – Greg Martin – 2019-08-17T06:20:12.377


Malbolge, 2708 bytes

This answer is super cheaty, because it always produces the same amount of input, which is equal to \$ \infty \$.


Try it online!

Krzysztof Szewczyk

Posted 2019-08-16T13:13:08.103

Reputation: 3 819

1With it being Malbolge, I might let that slide... Fantastic job! – maxb – 2019-08-17T12:39:55.257


Perl 6, 12 bytes

*~|('@'x 11)

Try it online!

Anonymous Whatever lambda that takes a number and string ORs it with 11 @s. This maps the digits to pqrstuvwxy and the dash to m, then pads the string out to 11 characters with @s

Jo King

Posted 2019-08-16T13:13:08.103

Reputation: 38 234


Perl 5 (-p), 9 bytes

$_^=A x$=

Try it online!



Posted 2019-08-16T13:13:08.103

Reputation: 12 521


PHP, 64 54 bytes

-10 bytes by using strtr function instead of manual character replacement.


Try it online!

Largest int value possible in PHP as of now is 9223372036854775807 which is 19 digits long, considering the minus sign in negative numbers, it will be 20. The code above replaces minus sign (-) with the A character and every digit from 0 to 9 with a character from D to M and then pads the string in the right with space character to always make it 20 characters long. For example, the output for input of -9876543210 is "AMLKJIHGFED ".

The output is unique for each integer input and you can get back to the input by removing all spaces, replacing A with - and replacing D to M with 0 to 9.

PHP, 44 bytes


Try it online!

This is same idea as Arnauld's answer. Converts the input to binary, and then converts it to base-64. Also pads it to 88 characters (largest length is for -9223372036854775807 which is 88 characters) with space character at right to always get same length in the output.


Posted 2019-08-16T13:13:08.103

Reputation: 5 484


Stax, 6 bytes


Run and debug it


  1. Left pad input to 11 characters.
  2. Double each non-space ascii character.


Posted 2019-08-16T13:13:08.103

Reputation: 8 616


Zsh, 43 bytes

for c (${(s::)${(l:30::0:)1}})echo \\x$[#c]

               ${(l:30:0:)1}                 # left-pad with zeroes to 30 characters
        ${(s::)             }                # split characterwise
 for c (                     )               # for each character
                                      $[#c]  # get character code (in decimal)
                              echo \\x$[#c]  # interpret as hex code, print (with newline)

Try it online!

This solution gets around the long long limits of Zsh's integers by working with only characters. I only padded it to 30 characters for readability, but replacing 30 with 99 will allow this method to work on all numbers from -1E99+1 to 1E100-1.

The effect of interpreting the decimal codes as hexadecimal are as follows:

0 => 48 => H    1 => 49 => I    2 => 50 => P    3 => 51 => Q
4 => 52 => R    5 => 53 => S    6 => 54 => T    7 => 55 => U
8 => 56 => V    9 => 57 => W    - => 45 => E

Zsh, 46 bytes

integer -i2 -Z66 x=$1

Try it online!

Declares x as a binary number, zero-padded to a width of 66. Then maps 0a and 1b. We also map 2 and - to a, since those characters are printed in [[-]][base]#[num] notation. To see what $x looks like before replacement, and Zsh's limits in parsing integer types, check the Debug output in the TIO link.


Posted 2019-08-16T13:13:08.103

Reputation: 2 838


Retina 0.8.2, 21 bytes


Try it online! Always outputs 11 characters from the range n..z. Explanation:


Translate the printable ASCII characters to the lowercase letters. This maps - to n and 0..9 to q..z. (It's really fortunate that the digits are the 16th to the 25th printable ASCII characters!)


Append 10 os. Since the input will have between 1 and 11 characters, there are now between 11 and 21 characters.


Extract the first 11 characters. Since there are fewer than 22 characters, this will only match once.


Posted 2019-08-16T13:13:08.103

Reputation: 95 035


Charcoal, 9 bytes


Try it online! Link is to verbose version of code. Always outputs 10 spaces and uppercase letters. Explanation:

   N        Input as a number
  ﹪         Modulo
     χ      10
    X       To power
      χ     10
 ⍘     α    Convert to base 26 using uppercase letters
◧       χ   Left pad to length 10


Posted 2019-08-16T13:13:08.103

Reputation: 95 035


brainfuck, 20 19 bytes

-1 byte thanks to Krzysztof Szewczyk


Try it online!

Outputs the number with each digit and dash mapped to 255 minus their ordinal value, padded out to 255 characters with NUL bytes.

Jo King

Posted 2019-08-16T13:13:08.103

Reputation: 38 234

1You can save one byte: -[>,[->-<]>.[-]<<-] – Krzysztof Szewczyk – 2019-08-17T11:46:48.810


R, 37 bytes


Try it online!

Looks like the output is random, but it isn't! The input is used as the seed of the Pseudo-Random Number Generator, and we then get one of the \$26!=4\cdot 10^{26}\$ permutations of the alphabet. The output is always of length 51 (26 letters + 25 spaces).

There is still the issue of insuring that all the outputs are different. We end up with \$2^{32}\approx 4\cdot 10^9\$ permutations (out of \$4\cdot 10^{26}\$). If we pretend that the permutations are distributed uniformly at random, then the probability that all the permutations are different can be computed following the same calculations as for the Birthday problem. The probability that 2 specific outputs are identical is \$10^{-17}\$, so a first order approximation of the probability that all \$2^{32}\$ outputs are distinct is


which is close enough to 1 for me.

Robin Ryder

Posted 2019-08-16T13:13:08.103

Reputation: 6 625

While yes, it's statistically unlikely that there's a collision, that doesn't mean it's impossible as the question asks for – Jo King – 2019-08-17T09:59:50.440

2I like the probability calculation. I guess you could run through all 4 billion inputs if you really wanted to check for collisions, but if you don't feel like doing that I might let it slide. As it is now, you've presented a compelling argument, and if anyone finds a counterexample, you'd have to modify your submission. – maxb – 2019-08-17T10:11:31.777


R, 40 37 bytes


Try it online!

An alternative to Robin Ryder's answer; this is certainly deterministic.

This converts the input to a raw vector of 32 bytes, each byte being a hex number 00 or 01 representing the bits of the integer. We then coerce to a logical by comparing to 0, so 00 is mapped to FALSE and 01 to TRUE. Then we need to remove a single letter from each FALSE to guarantee equal-length output, arbitrarily selected to be S. Result is printed (with space) for a length of 169.


Posted 2019-08-16T13:13:08.103

Reputation: 21 077


Java (JDK), 42 bytes


Try it online!

First, this creates the hexadecimal representation of the input, left-padded with spaces which provides the same length constraint (8 characters-long), removes the minus sign, and keeps each intermediate output unique.

This gives a string with 17 different possible characters: 0123456789abcdef and space.

Then each character is streamed and mapped by adding 64 to its codepoint if it's a digit or a space. Effectively, this results in the following mapping: 0123456789abcdef<space> to pqrstuvwxyabcdef` which has 17 different characters, so no two numbers will result in the same output.

Olivier Grégoire

Posted 2019-08-16T13:13:08.103

Reputation: 10 647


Bash, 30 bytes

echo $1|md5sum|tr '0-9-' 'A-K'

Try it online!

To prove that output is unique, I just googled for MD5 collisions, and found no results within the integers between \$-2^{31}\$ and \$2^{31}\$. To avoid having forbidden characters in the output, just translate the characters in question to be upper case letters. Output is always the same length by definition, and guaranteed to not contain any forbidden characters.


Posted 2019-08-16T13:13:08.103

Reputation: 5 754