Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/06/2018, 16:15
Tachikomaia
Invitado
 
Mensajes: n/a
Puntos:
¿Me traducen este código?

Código:
resolve = lambda a, b: [(a[0], b[1])] if a[1] == b[0] else []
 
def isconsistent(inequations):
  pending = inequations[:]
  done = []
  hashes = set()
  while pending:
    c = pending.pop()
    if c[0] == c[1]:
      return False
    for i in done:
      n = resolve(c, i) + resolve(i, c)
      for e in n:
        h = "%s<%s"%e
        if h in hashes:
          continue
        hashes.add(h)
        pending.append(e)
    done.append(c)
  return True
 
print(isconsistent([("A", "B"), ("B", "C"), ("C", "D")]))
print(isconsistent([("A", "B"), ("B", "C"), ("C", "A")]))
Gracias.