Skip to content

Instantly share code, notes, and snippets.

@xrogaan
Created July 20, 2012 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xrogaan/3151824 to your computer and use it in GitHub Desktop.
Save xrogaan/3151824 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# vim:set sw=4 ts=4 expandtab tw=80:
import hashlib
import base64
import pprint
def get_mutators(myHash):
mutator_type = list()
bodypart = None
mutator_strength = None
hashlen = len(myHash)
for i in range(0,hashlen):
if not (len(mutator_type)<2 or bodypart is None or
mutator_strength is None):
break
if myHash[i].isdigit():
if len(mutator_type) < 2:
mutator_type.append(myHash[i])
elif mutator_strength is None:
mutator_strength = myHash[i]
else:
continue
elif myHash[i].isalpha():
if bodypart is not None:
continue
bodypart = myHash[i].lower()
if len(mutator_type) == 0:
mutator_type.append(0)
elif len(mutator_type) == 1:
if mutator_type[0] is 0:
mutator_type.append(1)
else:
mutator_type.append(0)
mutator_type.reverse()
return {'mutator_type': int(''.join(map(str, mutator_type))),
'bodypart': bodypart,
'mutator_strength': mutator_strength}
def stats(mut):
i=1
if stats.sametype.has_key(mut['mutator_type']):
i+=stats.sametype[mut['mutator_type']]
stats.sametype.update({mut['mutator_type']: i})
i=1
if stats.samebodypart.has_key(mut['bodypart']):
i+=stats.samebodypart[mut['bodypart']]
stats.samebodypart.update({mut['bodypart']: i})
if mut['mutator_strength'] > stats.stronger[1]:
stats.stronger = [mut['bodypart'], mut['mutator_strength']]
stats.changes += 1
stats.sametype = {}
stats.samebodypart = {}
stats.stronger = [0, 0]
stats.changes = 0
fbuf = open('xro','r')
i=0
for line in fbuf:
line_hash = hashlib.sha1(line)
b64 = base64.b64encode(line_hash.hexdigest())
# print(line_hash.hexdigest())
# print(line)
mutators = get_mutators(b64)
stats(mutators)
# print("{0:>4}| type: {1[mutator_type]:<5}" \
# "bodypart: {1[bodypart]:<3}" \
# "mutator_strength: {1[mutator_strength]:<3}".format(i, mutators))
i+=1
fbuf.close()
pp = pprint.PrettyPrinter(indent=4)
print(' Stats:')
print('*-' * 5)
pp.pprint(stats.sametype)
pp.pprint(stats.samebodypart)
pp.pprint(stats.stronger)
pp.pprint(stats.changes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment