Skip to content

Instantly share code, notes, and snippets.

@darkf
Created July 30, 2012 06:22
Show Gist options
  • Select an option

  • Save darkf/3205301 to your computer and use it in GitHub Desktop.

Select an option

Save darkf/3205301 to your computer and use it in GitHub Desktop.
Logic, how does it work?
def parse(expr):
lst = []
for line in expr.split('\n'):
s = line.split(' -> ')
if len(s) == 1:
lst.append(('def', line))
else:
lst.append(('imply', s[0], s[1]))
return lst
def leval(expr):
sym = {}
for p in expr:
if p[0] == 'def':
sym[p[1]] = True
elif p[0] == 'imply':
if sym.setdefault(p[1], False) is True:
sym[p[2]] = True
elif not p[2] in sym:
sym[p[2]] = False
return sym
def main():
p = parse("""F
F -> G
H -> F
Y -> L
H""")
assert p == [('def', 'F'),
('imply', 'F', 'G'),
('imply', 'H', 'F'),
('imply', 'Y', 'L'),
('def', 'H')]
print leval(p)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment