Created
January 30, 2018 00:02
-
-
Save marcoaaguiar/819cf6ed4b17e22bc274011bf68fcc85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Tue Jan 30 00:31:22 2018 | |
@author: marco | |
""" | |
import itertools | |
import time | |
N = 4 | |
N_string = 33 | |
winner_string = 'Not found' | |
number_string = ''.join([str(i) for i in range(1,N+1)]) | |
def permuation_in_cadidate_string(candidate_string, N): | |
global number_string | |
for permutation in itertools.permutations(number_string, N): | |
if not ''.join(permutation) in candidate_string: | |
return False | |
return True | |
# return all([''.join(permutation) in candidate_string for permutation in itertools.permutations(number_string, N)]) | |
counter = 0 | |
start_time = time.time() | |
for number_list in itertools.product(number_string, repeat=N_string): | |
counter +=1 | |
if counter%10000 ==0 : | |
time_delta = time.time() - start_time | |
avg_time_per_1k = counter/(time_delta) | |
print('''=========================== | |
Total tested: {} \n Average time per 1k: {}'''.format(counter, avg_time_per_1k)) | |
candidate_string = ''.join(number_list) | |
# print(candidate_string) | |
if permuation_in_cadidate_string(candidate_string, N): | |
winner_string = candidate_string | |
break | |
print('Result: {}'.format(winner_string)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment