Advertisement
Joporezka1

Untitled

May 22nd, 2022
1,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  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'),('3','2'),('4','2'),('5','2'),('6','5'),('6','7'),('7','5'),('7','6'),('8','6'),('8','7'),('9','8'),('9','10'),('10','9'),('11','1'),('x','9')]
  7.  
  8.  
  9. #=======================TESTS==========================
  10. # pointList = ['0','1','2','3']
  11. # linkList = [('0','1'),('0','2'),('0','3')]
  12.  
  13. # pointList = ['0','1']
  14. # linkList = [('0','1')]
  15.  
  16. def calculate_subgraphs():
  17.     filteredPointList = []
  18.    
  19.     subgraphCount = 0
  20.     for i in range(0,pointList.__len__()+1):
  21.        
  22.         for situation in permutations(pointList,i):
  23.             if(sorted(situation) == list(situation)):
  24.                # print('situation: ' + str(situation))
  25.  
  26.                 filteredLinkList = []
  27.                 filteredLinkList = [link for link in linkList if link[0] in situation and link[1] in situation]
  28.                 filteredLinkListLocalLength = filteredLinkList.__len__()
  29.                 # print('filteredLinkListLocalLength: ' + str(filteredLinkListLocalLength) + ' situation: ' + str(situation))
  30.                 subgraphCount+= 2**filteredLinkListLocalLength
  31.         print('i: ' + str(i) + ' subgraphCount: ' + str(subgraphCount))
  32.    
  33.     return subgraphCount
  34.  
  35.  
  36.  
  37. f= open('output.txt','w')
  38.  
  39. f.write('Answer for \n' +str(pointList)+'\n'+ str(linkList)+ '\nis: ' +str(calculate_subgraphs()))
  40. f.close()
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement