is a [[Perfect code|perfect -error correcting code]], iff the Hamming balls for any two codewords and code
Proof
Given a codeword , the number of strings with Hamming distance is given by
since there are combinations of positions different from , and each differing position may be one of letters.
Hence, for a code to be perfect,
the closed balls of radius must partition , giving the expression above.