Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import shuffle
- def testIfValid(c):
- trueD = c['A']+c['D']+c['C']
- errorVal = 0
- thingsToDo = {1:('B','E','C'),2:('C','K','M'),3:('F','G','J'),4:('H','I','J'),
- 5:('J','L','M'),6:('M','N','O')}
- for thingI in thingsToDo:
- Dval = c[thingsToDo[thingI][0]]+c[thingsToDo[thingI][1]]
- Dval += c[thingsToDo[thingI][2]]
- if Dval != trueD:
- errorVal += 1
- if errorVal == 0:
- return True
- else:
- return False
- nums = []
- for n in range(1,16):
- nums.append(n)
- with open('attemptsTried.txt','r') as aF:
- tried = eval(aF.read() )
- labels = []
- first16ofAlph = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P']
- for i in range(15):
- labels.append(first16ofAlph[i])
- print('reading previous combinations text file...')
- with open('triedCombinations.txt','r') as tcF:
- combinations = eval(tcF.read() )
- print('tried: '+str(tried)+' combinations so far.')
- while True:
- shuffle(nums)
- newCombination = {}
- i = -1
- for label in labels:
- i += 1
- newCombination[label] = nums[i]
- if not (newCombination in combinations):
- tried += 1
- if tried % 500 == 0:
- print('Tried: '+str(tried)+' combinations so far.')
- if tried % 20000 == 0:
- a = input('Continue (y/n) ?')
- if a != 'y':
- with open('triedCombinations.txt','w') as triedCombosF:
- triedCombosF.write(str(combinations))
- break
- combinations.append(newCombination)
- valid = testIfValid(newCombination)
- if valid == True:
- with open('triedCombinations.txt','w') as triedCombosF:
- triedCombosF.write(str(combinations))
- print(newCombination)
- break
- with open('attemptsTried.txt','w') as aF:
- aF.write(str(tried))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement