Skip to content

Instantly share code, notes, and snippets.

@orsenthil
Last active March 14, 2017 04:20
Show Gist options
  • Save orsenthil/d7884506de2333e884f470d92b1251ef to your computer and use it in GitHub Desktop.
Save orsenthil/d7884506de2333e884f470d92b1251ef to your computer and use it in GitHub Desktop.
from itertools import permutations
def diff(a, b):
return abs(a - b) - 1
def all_different(indices):
first, second, third, fourth, fifth = indices
size = len({diff(first, second), diff(first, third), diff(first, fourth), diff(first, fifth),
diff(second, third), diff(second, fourth), diff(second, fifth),
diff(third, fourth), diff(third, fifth),
diff(fourth, fifth)})
if size == 10:
return True
return False
def find_if_suitable(l):
first = l.index('u')
second = l.index('a')
third = l.index('b')
fourth = l.index('c')
fifth = l.index('e')
indices = [first, second, third, fourth, fifth]
return all_different(indices)
cols = ['u', 'a', 'b', 'c', 'e', 0, 0, 0, 0, 0, 0, 0]
#print(len(cols))
#find_indices(cols)
import sys
seen = set()
for vec in permutations(cols):
if find_if_suitable(vec):
s = str(vec)
s = s.replace('a','u')
s = s.replace('b','u')
s = s.replace('c','u')
s = s.replace('e','u')
if s not in seen:
seen.add(s)
print(s)
"""
(python_virtualenv) root@jcbose:~# python find_solutions.py
('u', 'u', 0, 0, 'u', 0, 0, 0, 0, 'u', 0, 'u')
('u', 0, 'u', 0, 0, 0, 0, 'u', 'u', 0, 0, 'u')
('u', 0, 'u', 0, 0, 0, 0, 'u', 0, 0, 'u', 'u')
('u', 0, 0, 'u', 'u', 0, 0, 0, 0, 'u', 0, 'u')
(python_virtualenv) root@jcbose:~#
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment