Advertisement
Joporezka1

Untitled

May 23rd, 2022
647
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from itertools import permutations
  2. from math import factorial
  3.  
  4. #=======================HAMPTON-COURT==================
  5. pointList = ['0','1','2','3','4','5','6','7','8','9','10','11','x']
  6. linkList = [('1','0'),('1','11'),('2','1'),('2','3'),('2','4'),('5','2'),('6','5'),('6','7'),('7','5'),('8','6'),('8','7'),('9','8'),('9','10'),('x','9')]
  7.  
  8.  
  9. #=======================TESTS==========================
  10. # pointList = ['0','1','2','3']
  11. # linkList = [('1','0'),('2','0'),('0','3')]
  12. #ANSWER 35
  13.  
  14. # pointList = ['0','1']
  15. # linkList = [('1','0')]
  16. #ANSWER 5
  17.  
  18. def calculate_subgraphs():
  19.     filteredPointList = []
  20.    
  21.     subgraphCount = 0
  22.     for i in range(0,pointList.__len__()+1):
  23.        
  24.         for situation in permutations(pointList,i):
  25.             if(sorted(situation) == list(situation)):
  26.                # print('situation: ' + str(situation))
  27.  
  28.                 filteredLinkList = []
  29.                 filteredLinkList = [link for link in linkList if link[0] in situation and link[1] in situation]
  30.                 filteredLinkListLocalLength = filteredLinkList.__len__()
  31.                 # print('filteredLinkListLocalLength: ' + str(filteredLinkListLocalLength) + ' situation: ' + str(situation))
  32.                 subgraphCount+= 2**filteredLinkListLocalLength
  33.         print('i: ' + str(i) + ' subgraphCount: ' + str(subgraphCount))
  34.    
  35.     return subgraphCount
  36.  
  37.  
  38.  
  39. f= open('output.txt','w')
  40.  
  41. f.write('Answer for \n' +str(pointList)+'\n'+ str(linkList)+ '\nis: ' +str(calculate_subgraphs()))
  42. f.close()
  43.  
Advertisement
RAW Paste Data Copied
Advertisement