70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
table = [1, ]
|
|
TARGET = 60
|
|
target = TARGET - table[-1]
|
|
|
|
#pas plus de 2 fois le même bond
|
|
#D'où la régle de codage:
|
|
#- bond 1 est 'int'
|
|
#- bond 2 est 'float' et vaut 'int' + 0.01
|
|
#Par faciliter les recherches dans la liste de bonds
|
|
solution = list()
|
|
|
|
def hercule(table, target):
|
|
global solution
|
|
|
|
if target == 0:
|
|
solution.append(table)
|
|
return
|
|
|
|
if target < 0:
|
|
return
|
|
|
|
previous = int(table[-1])
|
|
|
|
#Choix 1 = même longueur que le précédent:
|
|
if not previous+0.01 in table: #Pas la peine de chercher en 'int' car il y est forcément
|
|
hercule(table.copy() + [previous+0.01, ], target-previous)
|
|
|
|
#Choix 2 = bond de 2m plus court
|
|
if previous > 1 and previous+0.01-2 not in table: #Pas la peine de chercher en 'int' car il y est forcément
|
|
hercule(table.copy() + [previous+0.01-2, ], target-(previous-2))
|
|
|
|
#Choix 3a = bond de 2m plus long (1er bond de cette longueur)
|
|
if previous+2 not in table:
|
|
hercule(table.copy() + [previous+2, ], target-(previous+2))
|
|
|
|
#Choix 3b = bond de 2m plus long (2er bond de cette longueur)
|
|
elif previous+0.01+2 not in table:
|
|
hercule(table.copy() + [previous+0.01+2, ], target-(previous+2))
|
|
|
|
hercule(table, target)
|
|
|
|
#J'enlèvre les 0.01
|
|
for i in range(len(solution)):
|
|
solution[i] = [int(x) for x in solution[i]]
|
|
|
|
#Je transforme en offset à partir de 0
|
|
solution2 = list()
|
|
for s in solution:
|
|
tmp = [0,]
|
|
for i in s:
|
|
tmp.append(tmp[-1]+i)
|
|
solution2.append(tmp)
|
|
print(solution2)
|
|
|
|
from itertools import combinations
|
|
|
|
table = [i for i in range(20, 41)]
|
|
table3 = list(combinations(table, 4))
|
|
for i in table3:
|
|
a = i[0]
|
|
b = i[1]
|
|
c = i[2]
|
|
d = i[3]
|
|
for s in solution2:
|
|
if a not in s and b not in s and c not in s and d not in s:
|
|
break
|
|
else:
|
|
print(a,b,c,d)
|
|
|