Skip to content

Instantly share code, notes, and snippets.

@TheSkorm
Created December 10, 2015 03:14
Show Gist options
  • Select an option

  • Save TheSkorm/8c3da0192c2f86be0744 to your computer and use it in GitHub Desktop.

Select an option

Save TheSkorm/8c3da0192c2f86be0744 to your computer and use it in GitHub Desktop.
results = {"b": 956}
queue = a.split("\n")
while queue:
test = queue.pop(0)
(operation, resultant) = test.split(" -> ")
spaces = operation.count(" ")
print test
process=True
if spaces == 0:
op = "SET"
arg1 = operation
try:
arg1 = int(arg1)
except:
try:
arg1 = results[arg1]
except:
process = False
elif spaces == 1:
(op , arg1) = operation.split(" ")
try:
arg1 = int(arg1)
except:
try:
arg1 = results[arg1]
except:
process = False
elif spaces == 2:
(arg1, op, arg2) = operation.split(" ")
try:
arg1 = int(arg1)
except:
try:
arg1 = results[arg1]
except:
print "fail"
process = False
try:
arg2 = int(arg2)
except:
try:
arg2 = results[arg2]
except:
print "fail"
process = False
if not process:
queue.append(test)
continue
if resultant == "b":
continue
if op == "SET":
results[resultant] = arg1
elif op == "AND":
results[resultant] = arg1 & arg2
elif op == "LSHIFT":
results[resultant] = arg1 << arg2
elif op == "RSHIFT":
results[resultant] = arg1 >> arg2
elif op == "NOT":
results[resultant] = ~ arg1
elif op == "OR":
results[resultant] = arg1 | arg2
print results["a"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment