Skip to content

Instantly share code, notes, and snippets.

@iyer-arvind
Created September 6, 2016 21:59
Show Gist options
  • Save iyer-arvind/86240a6a7ffe311954ac432d5551389a to your computer and use it in GitHub Desktop.
Save iyer-arvind/86240a6a7ffe311954ac432d5551389a to your computer and use it in GitHub Desktop.
#!/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