import math

# numbers from http://w...content-available-to-author-only...h.net/puzzles/cube2.htm
s = "1 9 54 321 1,847 9,992 50,136 227,536 870,072 1,887,748 623,800 2,644"
nums = map(int, s.replace(',', '').split())

freqs = [0] * 3
d = 0
for s in nums:
    freqs[d % 3] += s
    print(d, s)
    d += 1
print(sum(freqs), freqs)

arithmetic = huffman = 0
for i in range(3):
    prob = freqs[i] / sum(freqs)
    print('probability for mod-3-distance', i, 'is', prob)
    arithmetic += -math.log(prob, 2) * prob
    huffman += (1 + (freqs[i] < max(freqs))) * prob
print('arithmetic:', arithmetic, 'bits per state')
print('huffman:   ', huffman, 'bits per state')
