Bonjour à tous !
Rah, j’ai flashé sur ce problème !
Il est vraiment sympa car on peut déduire des propriétés (surtout des contraintes) assez rapidement.
Le 10 est forcément en bas par exemple car il ne peut être la différence de 2 nombres (compris entre 1 et 9).
De fait le 9 est soit en bas ou soit au dessus du 10.
Les doubles ne peuvent être côte-à-côte : 2 et 1 ne peuvent être côte-à-côte, comme 3 et 6, 4 et 8, 5 et 10.
10 , 9, 8, 7, 6 ne peuvent être au sommet principal.
10, 9, 8 ne peuvent être en dessous du sommet principal.
Bon j’ai une solution, mais est-ce la seule ?

Bonjour,
j’ai commis le programme Python ci-dessous pour trouver les solutions à ce problème.
Il en a trouvé 4 (en écartant les cas symétriques).
—-
def popopop(l, n):
try:
l.pop(l.index(n))
return True
except:
return False
def calcule(a, b, c, d):
aa = abs(a – b)
bb = abs(b – c)
cc = abs(c – d)
aaa = abs(aa – bb)
bbb = abs(bb – cc)
aaaa = abs(aaa – bbb)
return aa, bb, cc, aaa, bbb, aaaa
SOLUTIONS = []
for i in range(10):
a = i + 1
la = [n+1 for n in range(10)]
la.pop(la.index(a))
for b in la:
lb = [n for n in la]
popopop(lb, b)
for c in lb:
lc = [n for n in lb]
popopop(lc, c)
for d in lc:
ld = [n for n in lc]
popopop(ld, d)
# pour éviter les solutions symétriques :
if (d, c, b, a) in SOLUTIONS:
continue
aa, bb, cc, aaa, bbb, aaaa = calcule(a, b, c, d)
if not(popopop(ld, aa)):
continue
if not(popopop(ld, bb)):
continue
if not(popopop(ld, cc)):
continue
if not(popopop(ld, aaa)):
continue
if not(popopop(ld, bbb)):
continue
if not(popopop(ld, aaaa)):
continue
#print(a, b, c, d)
SOLUTIONS.append((a, b, c, d))
for (a, b, c, d) in SOLUTIONS:
aa, bb, cc, aaa, bbb, aaaa = calcule(a, b, c, d)
print(‘ ‘*3, aaaa)
print(‘ ‘*2, aaa, bbb)
print(‘ ‘*1, aa, bb, cc)
print(a, b, c, d)
Désolé le commentaire a perdu les indentations du code.
Du coup je l’ai placé là :
https://gitlab.com/-/snippets/2424006