summaryrefslogtreecommitdiffstats
path: root/test_20121121/helpers.py
blob: abe991a6cff30fab79856b31cab775be074b50c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

def stats(s):
    high = s.count('#')
    low = s.count('.')
    print "total: %d" % (high + low)
    print "percent: %f" % (100.0 * (high / (high + low * 1.0)))

# total: 3499
# percent: 46.156045

def hex_stats(s):
    d = dict()
    for k in "0123456789ABCDEF":
        d[k] = s.count(k)*1.0
    bitmap = dict()
    for k in d.keys():
        bitmap[k] = bin(int("0x"+k, 16))[2:].count('1')
    chars = sum(d.values())
    bits = chars*4
    zeros = 0
    ones = 0
    print "chars: %d" % chars
    for k in "0123456789ABCDEF":
        v = d[k]
        print "\t%s: %d\t%f\t%f" % (k, v, v/chars, v/chars*16)
        ones += bitmap[k] * v
        zeros += (4 - bitmap[k]) * v
    print "bits: %d" % bits
    print "\tzeros: %d\t%f" % (zeros, zeros/bits)
    print "\tones: %d\t%f" % (ones, ones/bits)