C Code Compressor (WIP)
Your task is to create a lossless compression scheme that is optimized for ASCII-only C code. Whitespace and indentation should be preserved.
Your score is the total compressed size of various samples from well known open source C projects. A sample of the largest few files will be taken from one specific commit. Both header files and source files will be included from the following projects:
- The CPython Interpreter
- The Linux Kernel
- Git
Comments will be stripped from the source files for the set of scoring, therefore you do not need to optimize for comments, however you still need to handle them. An
Three additional filefiles will existalso be included in the corpus that ensures this is, which must be handled bycorrectly, but do not contribute to your code.score:
- A C source file with comments
- A Python source file
- A non-programming plain text file (probably a short story or poem from the public domain. Jabberwocky?)
Scoring
$$ Score = {C + D + L^2 \over O} $$
Where:
- \$C\$ is the total size, in bytes, of the compressed text
- \$O\$ is the total size, in bytes, of the original text
- \$D\$ is the total length, in bytes, of all strings in any predefined dictionary
- \$L\$ is the length, in bytes, of the longest string in any predefined dictionary
Lowest score wins
Predefined Dictionaries
(Needs refinement)
A predefined dictionary, for the purposes of this challenge, is a collection of predefined output strings of length 2 or greater which are included only in the source code and not in the compressed outputbaked into your encoding format.
- An entry in a predefined dictionary must have at least two different characters to be counted in scoring, so repeating a single character \$n\$ times does not count as a dictionary entry.
- Leading and trailing whitespace on a predefined string does not count as a distinct entry from one without matching leading or trailing whitespace
A predefined dictionary may, for instance, be helpful for keywords and common identifiers, but it is ultimately up to you what approach you take.
For instance, if you map \x80
to int
and \x81
to float
, your dictionary score would be \$8\$ for the total length, plus \$25\$ for the longest string (float
), for a total of \$33\$. However, mapping runs of tabs and spaces to \xC0
-\xFF
would not count toward dictionary size in this case.
Rules
- Standard rules and loopholes apply.
- Although scoring only depends on how well you can compress C, your algorithm needs to work even when the input text is not valid C; it must work for all ASCII input text.
- Your algorithm must be deterministic, meaning it should always produce the same compressed text every time for any given input, regardless of external factors such as time.