We often get restricted-source questions here on PPCG that favour submitting solutions using only a subset of characters (sufficiently so that there's a tag printable-ascii that identifies a particular subset of those challenges). Wouldn't it be nice if we could automatically cut languages down to a subset of their normal character set?
As an example, JavaScript is sometimes translated into a subset known as JSFuck which contains only the characters []()!+
. In this challenge, you're aiming to write the equivalent of a JavaScript to JSFuck translator, but without the language restriction: you're compiling a language of your choice down to a subset of its characters (well, bytes, in order to avoid dubious corner cases).
Clarifications and detailed specification
- Call the program you submit program A. The input to program A will be a string representing a program (program B). Its output must also be a string representing a program (program C). Program B will be in the same language as program A (there are no restrictions on how your program reacts to invalid input). Program C must also be a program in that language, and have the same behaviour in all cases as program B (i.e. if program C is given input X, it will produce the same probability distribution of outputs as program A does).
- You may assume that in the case where programs A and B are distinct, program B does not access any files from disk. (In particular, you may assume it does not attempt to read its own source code from disk.).
- Although part of the scoring is based on a single test case (program A itself), your program must work for any input (in the sense of complying with the specification above; that is, any valid program B must lead to a corresponding output for program C). Optimizing specifically for the test case given is allowed (and might or might not be helpful).
- A
cat
implementation is technically speaking a valid answer to this question (as the subsetting of characters is part of the scoring criterion, not the validity criterion), but the scoring is designed so that such a program is unlikely to win. Just as solutions to code-golf competitions should make at least an attempt to minimize the number of bytes, solutions to this competition should make at least an attempt to minimize score. (Note that in some languages,cat
may genuinely work best because the character sets are already small or impossible to shave down further. These solutions are valid, but ideally wouldn't be upvoted.) - You can accept the strings used for your input and output via any reasonable method.
- Because languages with no computational ability might potentially lead to trivial solutions due to there being few possible programs to consider, this competition is open only to entries written in programming languages.
Victory condition
Let S be the set of bytes that can appear in the outputs C of your program (that is: for any valid input B, if the corresponding output C can potentially contain a byte, then that byte must be an element of S). Let c be the number of elements in S.
Now, let Q be the result of running your program on itself (i.e. the output C produced when A and B are the same program). Let b be the number of bytes in Q. (In order to minimize b and thus your score, you'll want to keep your program short, as in code-golf, but also the size of your program's output short, as in metagolf.)
Your score for this code-challenge is:
(b+1000)×loge(c+1)
The winner is the entry with the lowest score. (If there's a tie for first place, the lowest c among the tied entries will win; if there's still a tie for first place, the earliest entry among the entries tied for first will win.) Even if you can't win, though, you're encouraged to show off interesting answers (perhaps answers with a particularly low c, or in a language other people haven't attempted yet).