For fair comparison of codegolf solutions in languages with different source alphabets, there should be a common unit of information.

Most sizes here are expressed in "characters" or "bytes", but not all characters are created equal. A brainfuck character can only have 8 values.

The standard measure of information in information theory is a bit. A brainfuck character is better counted as 3 bits.

Syntactic constraints may further reduce the entropy of program source.

In brainfuck not all 3^n length n programs are valid, because brackets must balance. A fancier measure of information content per character would be the limit for n->infinity of

log (# valid programs of n charcters) / n

but that is generally hard to compute.

For your favorite language, what is the number of possible values of a character? And what is the best known upper bound on the source entropy?

  • 1
    \$\begingroup\$ "what is the best known upper bound on the source entropy?" -- There is no upper bound, and the lower bound of 1 bit per symbol is attained in languages such as Jot (which has only the two symbols 0 and 1, every {0,1}-string being a valid program). \$\endgroup\$
    – r.e.s.
    Sep 11, 2012 at 1:05
  • 10
    \$\begingroup\$ This is a slippery slope. After a while, this gets into insane territory like people compressing their programs before counting the size, etc. Just say no. Instead, it's probably better to just go with the flow and accept that some languages are naturally more succinct than others, and that yes, they will have a golfing advantage. \$\endgroup\$ Sep 11, 2012 at 12:21
  • 1
    \$\begingroup\$ Also, for a real-life example of golfing advantage being used for military advantage, see en.wikipedia.org/wiki/Code_talker. Yes, this stuff matters. :-) \$\endgroup\$ Sep 11, 2012 at 12:31
  • 1
    \$\begingroup\$ @ChrisJester-Young "people compressing their programs before counting the size" is exactly what we're seeing with some languages that allow 8-bit strings. as much data as possible, and sometimes some code to be eval()'d, gets put in a string and then zipped up to save the empty bits in a 6-7 bit language. \$\endgroup\$
    – Sparr
    Jun 26, 2015 at 20:17
  • \$\begingroup\$ @r.e.s. - For a fixed-size alphabet, it's log2(size of alphabet) bits per symbol as the upper bound. \$\endgroup\$ Jun 30, 2015 at 11:36
  • 2
    \$\begingroup\$ There is a spectrum of measuring techniques. At one end, we measure pure information (think atomic-code-golf), which is language independent. At the other end we measure the information representation (measuring by characters/bytes), which is what we using for code-golf. Anything in the middle of that spectrum is optional and up to the OP \$\endgroup\$ Jun 30, 2015 at 16:48
  • \$\begingroup\$ FYI Most languages use ASCII only, so byte count is same as character count. Many languages which use non-ASCII characters have some 8-bit default codepage (character set): flax, 05AB1E, Nekomata, Jelly, Vyxal. Other non-ASCII languages use at most 256 characters (but don't specify a single code page): APL, Charcoal, Japt, Brachylog. For the remaining languages we could simply use UTF-8 byte count as a fallback. \$\endgroup\$
    – pts
    Feb 28, 2023 at 12:34

6 Answers 6


Most questions clearly include the winning criteria, and one of those is usually “the shortest code in bytes wins”. I don’t believe there are any restrictions on your asking a question with a slightly different winning criterion: “The shortest code as measured by method X wins.”

Go ahead and do that. If people like it, they might imitate it in their own questions. If they don’t, they won’t.

Be certain that method X is clearly defined.


For fair comparison of codegolf solutions in languages with different source alphabets, there should be a common unit of information.

Define 'fair'. How do you want to count that in languages allowing the full range of utf-8 for example?


I think this would be permissible for languages that are literally written as binary, hex, or similar, but NOT as unary. Unary programs should be treated as if they were written in binary.

This is all unless the poster of the question says otherwise in their question description.


Keep the existing approach

Encourage new challenge types / scoring methods for variety and balance

I don't think a general approach to making language differences fair will work - different languages have different advantages that vary from question to question. However, having a variety of scoring methods for question posters to choose from means that in addition to standard golf questions, other questions can have a scoring method that seems to fit best.

Inspired by Sparr's unpopular suggestion for making a fair size comparison between languages with different sized alphabets, I wondered if something vaguely similar might be better received as a new challenge type / scoring method, rather than trying to apply it to every code golf question.

For this challenge type, you submit two pieces of source code, your primary code and your secondary code.

  • Primary code solves the problem posed in the question.
  • Secondary code outputs the primary source code.

Your score is the length in bytes of your secondary code, which need not be in the same language as your primary code.

This doesn't make any changes for standard code golf questions, just adds an alternative that some questions can use if the poster sees fit. If there are no strong objections here, I'll post an example question using this scoring method in the sandbox.

  • 1
    \$\begingroup\$ Scoring should either be pure entropy or pure code-golf. Although high-entropy languages will (when someone makes one) theoretically always win code golf, and scoring by entropy has its own problems, there's no need for anything in between--especially an answer that requires more work. (On the other hand, this will tend towards entropy as people make increasingly better compression scripts...) \$\endgroup\$
    – lirtosiast
    Jul 7, 2015 at 21:35
  • \$\begingroup\$ If I've understood this correctly, this doesn't really solve the problem because I foresee a lot of PHP/CJam combos \$\endgroup\$
    – Sp3000
    Jul 8, 2015 at 1:08
  • \$\begingroup\$ @Sp3000 I don't see why that would be a problem (or at least I see it causing less of a problem than language differences cause with golf already). \$\endgroup\$ Jul 8, 2015 at 5:33

Well, I for one, agree in principle.

I also agree with all the obstacles to accomplishing something like this. "How are you gonna handle ...?" [shrug!]

But everyone says a thing can't be done until someone does it.


As of the time of posting this answer, for the purpose of the site rules about only using languages published before a question is asked, I am defining the meta-language "Simple Bit Encoding", which might be abbreviated "SBE-". This meta-language can be applied to any other language, so you might write a program in "SBE-Python" or "SBE-Brainfuck".

The meta-language is loosely defined as follows:

Given a language with a character set representable in N bits, reversibly encode an M-character program in that language as a series of M*N bits. This bitstream is the SBE-[language] program. Executing a SBE-[language] involves decoding the bitstream back to M separate characters, then the resulting string is provided to the original language's compiler or interpreter.

By convention, SBE-[language] programs are presented in their decoded format, which conveniently and coincidentally happens to be indistinguishable from the original program in the original language.


SBE-Brainfuck is equivalent to Binaryfuck without the leading 1. Brainfuck has only 8 non-comment characters, which can be encoded as 3 bits each. A 240-byte Brainfuck program is thus equivalent to a 90-byte SBE-Brainfuck / Binaryfuck program.

Python uses 7-bit ASCII for program text (ref). A 240-byte Python program is equivalent to a 210-byte SBE-Python program.

The practical result of this meta-language definition is that any code-golf solution written in a language using a N-bit character set can claim to be a decoded representation of a SBE-[language] program that will be smaller by a factor of (8-N)/8.

EDIT: SBE-Python converter, written in CJam, thanks to @Dennis: q256b128b:c

  • 1
    \$\begingroup\$ Defining languages is one thing, but we usually expect an actual interpreter to exist before the challenge was posted. Otherwise you can define an infinite number of languages whose source code is always empty and where the actual behaviour is encoded in a number in the language name. \$\endgroup\$ Jun 26, 2015 at 20:02
  • \$\begingroup\$ @MartinBüttner The encoder/decoder is, as Dennis has illustrated, just a few bytes of code. You just pipe the output of that into the normal language's interpreter. It seems almost superfluous to actually implement all of the possible different encoders/decoders. \$\endgroup\$
    – Sparr
    Jun 26, 2015 at 20:05
  • \$\begingroup\$ It's worth noting that this actual language definition is rather tongue-in-cheek. What I'm actually saying with all of this is "Yes, it would be fair to count code sized based on alphabet size". \$\endgroup\$
    – Sparr
    Jun 26, 2015 at 20:08
  • \$\begingroup\$ I think this might be better received as a challenge type than an override for golf scores. For example, someone might choose to post a question where the winning condition takes into account the number of characters in the language, as you describe. Trying to apply the new approach to all golf questions is likely to meet with resistance. \$\endgroup\$ Jul 7, 2015 at 17:30
  • \$\begingroup\$ It's a step towards scoring based on the Kolmorogov complexity of the source code: Write code to answer the question, then write shorter code that outputs the source code that answers the question. The score is the length of the shorter code that outputs the longer code. \$\endgroup\$ Jul 7, 2015 at 17:31
  • \$\begingroup\$ @trichoplax that meta-answer idea is nifty and I might steal it for my next challenge, if I ever write one. \$\endgroup\$
    – Sparr
    Jul 7, 2015 at 17:42
  • \$\begingroup\$ I've added it as an answer to see how the community feels about it. If it doesn't get heavily downvoted I'll try posting something in the sandbox to see if it survives on main. \$\endgroup\$ Jul 7, 2015 at 19:06
  • \$\begingroup\$ The result of my new answer seems to be both of our answers getting downvotes, and the question. Oh well... \$\endgroup\$ Jul 7, 2015 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .