Skip to main content

Encode a program with the fewest distinct characters possible,

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)
  • The target language must exist at the time where this question is written.
  • You have to include a small explanation how you archive 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 , 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 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
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44