이것은 Set과 Line Length의 모든 값에서 발견 된 일반적인 해결책이었습니다. 첫 번째는 동일한 공통 요소를 공유하는 두 가지 솔루션을 원하지 않지만 각 솔루션이 다른 모든 솔루션과 공통된 요소를 갖기를 원한다고 가정합니다. 양식을 선택하는 데 무한한 풀이 주어지면 총 솔루션 수는 각 솔루션의 길이에 따라 제한됩니다.
예를 들어
SET_LENGTH = 10
CHOICE_LENGTH = 300
data = set(range(CHOICE_LENGTH))
solutions =[]
solution_sets = []
used = set()
while True:
new_solution = []
#Try to get unique values from each previous set
try:
for sol_set in solution_sets:
while True:
candidate = sol_set.pop()
if not candidate in used:
new_solution.append(candidate)
used.update([candidate])
break
except KeyError, e:
print e
break
#Fill with new data until the line is long enough
try:
while len(new_solution) < SET_LENGTH:
new_solution.append(data.pop())
except KeyError, e:
print e
break
solutions.append(new_solution)
solution_sets.append(set(new_solution))
#Show the results
for solution in solutions:
print solution
print "Orphans %s" % len(data)
N = 300 X = 10 개 수율 :
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 10, 11, 12, 13, 14, 15, 16, 17, 18]
[1, 10, 19, 20, 21, 22, 23, 24, 25, 26]
[2, 11, 19, 27, 28, 29, 30, 31, 32, 33]
[3, 12, 20, 32, 34, 35, 36, 37, 38, 39]
[4, 13, 21, 33, 34, 40, 41, 42, 43, 44]
[5, 14, 22, 27, 36, 40, 45, 46, 47, 48]
[6, 15, 23, 28, 37, 41, 45, 49, 50, 51]
[7, 16, 24, 29, 38, 42, 47, 49, 52, 53]
[8, 17, 25, 30, 39, 43, 48, 50, 52, 54]
[9, 18, 26, 31, 35, 44, 46, 51, 53, 54]
Orphans 245
당신이 얼마나 많은 솔루션 다음 같은 공통 요소를 공유 상관하지 않는 경우 더 쉽게 :
SET_LENGTH = 2
CHOICE_LENGTH = 300
data = set(range(CHOICE_LENGTH))
solutions =[]
alpha = data.pop()
while True:
new_solution = [alpha]
try:
[new_solution.append(data.pop()) for x in range(SET_LENGTH-1)]
except KeyError, e:
break
solutions.append(new_solution)
for solution in solutions:
print solution
print "Solutions: %s" % len(solutions)
print "Orphans: %s" % len(data)
하는 경우 당신은 단지 26 자 (AZ)이고, 각 목록은 10 자 길이입니다. 그러면 3 번째 목록을 생성 할 때까지 적어도 하나의 다른 편지와 공통된 글자를 가질 것을 보장합니다. – voithos