From f0fdd4b91cd4dded9e029a7a3a8b6a158d721a30 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 22 Nov 2012 00:21:11 +0100 Subject: add Nov 22nd notes and scripts --- test_20121121/helpers.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test_20121121/helpers.py (limited to 'test_20121121/helpers.py') 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) -- cgit v1.2.3