diff options
Diffstat (limited to 'test_20121121/helpers.py')
| -rw-r--r-- | test_20121121/helpers.py | 30 | 
1 files changed, 30 insertions, 0 deletions
diff --git a/test_20121121/helpers.py b/test_20121121/helpers.py new file mode 100644 index 0000000..abe991a --- /dev/null +++ b/test_20121121/helpers.py @@ -0,0 +1,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)  | 
