class Item(object):
    def __init__(self, next=None):
        self.next=next
    @staticmethod
    def bind(a,b):
        a.next=b
        return b
def recur_detect(first, n=10, s=5):
    # False - no recurence
    # True - recurence found
    a=first
    b=a.next
    if not a : return False
    c=0
    while b:
       c+=1
       if b is a: return True
       if c==n:
           n+=s
           s*=2
           c=0
           a=b
       b=b.next
    return False
def print_test(n,v):
    s="TEST%3i: " % n
    if v :
        s+="PASSED!"
    else:
        s+="FAILED!"
    print s
def test():
    t=[Item() for i in xrange(100000)]
    reduce(Item.bind, t)
    f1=t[0]
    print_test(1, not recur_detect(f1))
    t[-1].next=t[0]
    print_test(2, recur_detect(f1))
    t[-1].next=t[85000]
    print_test(3, recur_detect(f1))
    t[-1].next=t[99997]
    print_test(4, recur_detect(f1))
    t=[Item() for i in xrange(10)]
    reduce(Item.bind, t)
    f1=t[0]
    print_test(5, not recur_detect(f1))
    t[-1].next=t[0]
    print_test(6, recur_detect(f1))
    t[-1].next=t[8]
    print_test(7, recur_detect(f1))    
if __name__ == "__main__":
    test()

    
      Ответ на:
      
          комментарий
        от Burbaka 
  
    
      Ответ на:
      
          комментарий
        от imp 
  
    
      Ответ на:
      
          комментарий
        от Reset 
  
    
      Ответ на:
      
          комментарий
        от Reset 
  
    
      Ответ на:
      
          комментарий
        от Reset 
  
    
      Ответ на:
      
          комментарий
        от imp 
  
    
      Ответ на:
      
          комментарий
        от Burbaka 
  

    
      Ответ на:
      
          комментарий
        от imp 
  
    
      Ответ на:
      
          комментарий
        от eXOR 
  

    
      Ответ на:
      
          комментарий
        от eXOR 
  
    
      Ответ на:
      
          комментарий
        от eXOR 
  
    
      Ответ на:
      
          комментарий
        от imp 
  
    
      Ответ на:
      
          комментарий
        от imp 
  
    
      Ответ на:
      
          комментарий
        от amm 
  
    
        Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
      
Похожие темы
- Форум [gtk][pygtk] Неправильная реакция на обработчики сигналов «test-collapse-row» и «test-expand-row» виджета gtk.TreeView (2011)
- Форум Быдлокод Pygtk (2012)
- Форум маленький вопрос по Python (2014)
- Форум Наследование от Gtk.Bin (2012)
- Форум python argparse unittest (2013)
- Форум Gtk+ Python3 Как отослать (эмулировать) нажатие клавиш (2017)
- Форум pyqt5 + QPyDesignerTaskMenuExtension (2018)
- Форум SQL Builder для Python: нужны советы (2019)
- Форум [Python] Прожорливый multiprocessing. (2011)
- Форум Строковое представление класса (2012)