29
3
Write the smallest program that maps strings injectively to outputs and maps itself to 2020.
To be clear, your program \$p\$ must have the following properties:
- every possible input string \$s\$ has a well-defined output \$p(s)\$,
- for every pair of strings \$s\$ and \$t\$ with \$s\neq t\$, it holds that \$p(s)\neq p(t)\$, and
- \$p(p)=2020\$.
Be sure to explain why your submission satisfies properties 1 and 2. For property 3, the output can be a string or any type of number.
Edit 1: Programs need to be proper quine variants. Reading the source code is not allowed.
Edit 2: Note that as a consequence of property 2, it holds that \$p(s)\neq p(p)\$ for every \$s\neq p\$.
every possible input string Can we support only ASCII? – Luis Mendo – 2020-01-04T18:15:30.683
1@LuisMendo - yes, provided ASCII is the alphabet of the language that your program is written in. – Dustin G. Mixon – 2020-01-04T18:16:15.550
7Do programs need to be proper quine variants or is reading the source code allowed? – FlipTack – 2020-01-04T19:06:34.563
Is a function acceptable or must we write a full program? – Robin Ryder – 2020-01-04T19:21:44.680
1@FlipTack - Thanks for the clarifying question. No reading the source code. I edited the post to reflect this. – Dustin G. Mixon – 2020-01-04T19:37:58.487
1@RobinRyder - A function is acceptable. – Dustin G. Mixon – 2020-01-04T19:41:02.427
How do any of these requirements imply being a quine? If you wrote a whole program that (for example) reads from stdin, you'd get
p(p)
by running./my_program < my_source.c
with the user feeding the program a copy of the source (as opposed to any other input), right? Or for a function, justuint32_t map(char *)
. Exceptuint32_t
can't work- by the pigeonhole principle that would only allow 2^32 possible input strings, not arbitrary length. Or did you mean that if you want your source code as a constant to compare against, you'd need a quine technique to embed it? – Peter Cordes – 2020-01-07T17:38:21.953