Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created July 3, 2012 13:23
Show Gist options
  • Save nashibao/3039677 to your computer and use it in GitHub Desktop.
Save nashibao/3039677 to your computer and use it in GitHub Desktop.
example answer..
codes = {}
def convert(tag):
return codes.setdefault(tag, 1 << codes.length)
def desc(node):
for child in node.childs:
child_code = convert(child.tag)
child.code = child_code | node.code
if bool(child_code & node.code):
print 'gotcha!!'
desc(child)
root.code = convert(root.tag)
desc(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment