The goal is to write a program that encodes an other program (input) with the fewest character possible.
Scoring
- The score is equal to the different number of characters needed for the output.
- Lower score is better.
Rules
- No target languages with a limited set of commands. (No Brainf**k, Whitespace etc)
Edit: I mean at least 26 significant characters,A
doesn't change the way a brainf**k program operates, so you can't count this character. Same applies to whitespace. - The target language must exist at the time where this question is written.
- You have to include a small explanation how you achieve your score.
- The input program is valid.
- The encoded program must be a valid program in the same language as the input.
- The encoded program must do the same job as the original program.
- Your encoder must work for every valid program in that language.
- Include some sample input and output.
Notes
- The encoder might be written in any language, not only in the language it targets.
- This is not code-golf, readable programs are encouraged.
- The great goal is to see how many different characters are needed to write anything in that language. I disallowed BF etc because there would be no challenge.
- This was inspired by Print a string in as few distinct characters as possible, you could take it as metagolf for that question.
Example
In Java, you can use \uXXXX
instead other characters. A valid entry encodes every character from the input this way. This would have a score of 18. (\ 0-9a-f
)
Code in Tcl, encodes a Java program:
set res {}
foreach char [split [read stdin] {}] {
append res [format \\u%04x [scan $char %c]]
}
puts $res
gets
read a single line of input only? And you missed theu
in your encoder (but on the other hand you don't need the space and thus the score remains the same). \$\endgroup\$