我有一串字符串,它们是字典中的键,它们包含不等式系统:
例如“t1+t2>;2^t1和lt;1^t2>;=1英寸
这些字符串是根据用户输入创建的,但有时系统是不可能的:
例如“t1+t3>;2^t1<;=1^t3<;=1".
没有可能的t1和t3值来解系统。如果系统不可能,我需要从字典中删除元素
我确信,对于同一个“主题”,不存在多重不平等。例如,不能有:
“…^t2>;0^t2<;=2^…“
但是
“…^0<;t2<;=2^…“是可能的
如果我必须写一些代码,我会这样做,但它是非常混乱,我不能得到一个很好的图片(或至少是一个很好的)如何得到正确或错误的结果,无论是一个不可能或可能的系统。。。我很确定有更好的方法来处理这个问题(可以有3个以上的变量,但我认为如果我知道如何使用3,我可以使用n):
def logical(string):
h = string.split(" ^ ")
count = [0,0,0]
for i in [1,2,3]:
for j in h:
if "t"+str(i) in h:
count[i-1] += 1
...
#consider the elements of h that contain "t"+1 if count of
#that variable is bigger than 1
#and for those who contain the sum of two or more
#variables check the number of "words" (can be 3 or 5). Then
#check if elements in position 1 and/or 3 are "<=" or "<" or
#">=" or ">" ... and compare it to the element of h that
#contains instead ... veeeery long and mechanical
...
有什么帮助吗
目前没有回答
相关问题 更多 >
编程相关推荐