Advertisement
yoshi_squashy

Combinatoric random selection brute-forcer script flop

Sep 6th, 2020
2,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. from random import shuffle
  2.  
  3.  
  4. def testIfValid(c):
  5.     trueD = c['A']+c['D']+c['C']
  6.  
  7.     errorVal = 0
  8.  
  9.     thingsToDo = {1:('B','E','C'),2:('C','K','M'),3:('F','G','J'),4:('H','I','J'),
  10.                   5:('J','L','M'),6:('M','N','O')}
  11.  
  12.     for thingI in thingsToDo:
  13.         Dval = c[thingsToDo[thingI][0]]+c[thingsToDo[thingI][1]]
  14.         Dval += c[thingsToDo[thingI][2]]
  15.         if Dval != trueD:
  16.             errorVal += 1
  17.  
  18.     if errorVal == 0:
  19.         return True
  20.     else:
  21.         return False
  22.    
  23.  
  24. nums = []
  25. for n in range(1,16):
  26.     nums.append(n)
  27.  
  28. with open('attemptsTried.txt','r') as aF:
  29.     tried = eval(aF.read() )
  30.  
  31. labels = []
  32.  
  33. first16ofAlph = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']
  34. for i in range(15):
  35.     labels.append(first16ofAlph[i])
  36.  
  37. print('reading previous combinations text file...')
  38.  
  39. with open('triedCombinations.txt','r') as tcF:
  40.     combinations = eval(tcF.read() )
  41.  
  42. print('tried: '+str(tried)+' combinations so far.')
  43.  
  44. while True:
  45.     shuffle(nums)
  46.     newCombination = {}
  47.     i = -1
  48.     for label in labels:
  49.         i += 1
  50.         newCombination[label] = nums[i]
  51.  
  52.     if not (newCombination in combinations):
  53.         tried += 1
  54.         if tried % 500 == 0:
  55.             print('Tried: '+str(tried)+' combinations so far.')
  56.         if tried % 20000 == 0:
  57.             a = input('Continue (y/n) ?')
  58.             if a != 'y':
  59.                 with open('triedCombinations.txt','w') as triedCombosF:
  60.                     triedCombosF.write(str(combinations))
  61.                 break
  62.                
  63.         combinations.append(newCombination)
  64.         valid = testIfValid(newCombination)
  65.         if valid == True:
  66.             with open('triedCombinations.txt','w') as triedCombosF:
  67.                 triedCombosF.write(str(combinations))
  68.             print(newCombination)
  69.             break
  70.  
  71.  
  72. with open('attemptsTried.txt','w') as aF:
  73.     aF.write(str(tried))
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement