Skip to content

Instantly share code, notes, and snippets.

@selevit
Created June 28, 2014 21:52
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 selevit/bf0478f129d866b7ee3a to your computer and use it in GitHub Desktop.
Save selevit/bf0478f129d866b7ee3a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
LOGIC_OPERATIONS = ["and", "or", "not"]
class ImaginaryVar(object):
"""Мнимая математическая переменная"""
name = None
is_negative = None
def __init__(self, name, is_negative=False):
self.name = name
self.negative = negative
def __not__(self):
return self.is_negative
class SimpleEquation(object):
"""Примитивное логическое выражение"""
is_negative = None
operator = None
operand = None
operation = None
def __init__(self, operator, operand, operation, is_negative=False):
assert isinstance(operator, ImaginaryVar)
assert isinstance(operand, ImaginaryVar)
assert operation in LOGIC_OPERATIONS
self.operator = operator
self.operand = operand
self.operation = operation
self.is_negative = is_negative
def __not__(self):
return self.is_negative
class Equation(object):
raw = None
def __init__(self, raw):
self.raw = raw
def simplify(self):
"""Упростить выражение"""
return self.raw
if __name__ == "__main__":
if len(sys.argv) != 2:
print("usage: {0}: <logic equation>".format(sys.argv[0]))
sys.exit(1)
eq = Equation(sys.argv[1])
print(eq.simplify())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment