Created
September 6, 2016 21:59
-
-
Save iyer-arvind/86240a6a7ffe311954ac432d5551389a 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
#!/usr/bin/env python | |
import numpy as np | |
s = 0 | |
c = 9 | |
solved = False | |
trials = 0 | |
while not solved: | |
trials+=1 | |
if trials > 100: | |
break | |
N = tuple(np.random.randint(c-s) for i in range(s, c+1)) | |
bag = [] | |
while True: | |
counts = tuple(N.count(i)+1 for i in range(s, c+1)) | |
if counts == N: | |
solved = True | |
break | |
N = counts | |
if N in bag: | |
break | |
bag.append(N) | |
#print(N) | |
#print('------------------------') | |
if solved: | |
print(s,c, ', '.join('{} is {}'.format(i+s, n) for i, n in enumerate(N))) | |
else: | |
print(s,c, '-No solution-') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment