Mathematica 116114 octets
Avec plusieurs octets enregistrés grâce à Misha Lavrov.
Last@FindPath[Graph[Rule@@@Cases[Tuples[Tuples[{0,1},{l=Length@#}],{2}],x_/;Count[Plus@@x,1]==1]],##,{1,2^l},Alll]&
Entrée (8 dimensions)
[{1,0,0,1,0,0,0,1},{1,1,0,0,0,0,1,1}]//AbsoluteTiming
Sortie (longueur = 254, après 1,82 seconde)
{1.82393, {{1, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 0}, {0, 0,0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1, 1, 1}, {0, 0, 0, 0, 0, 1, 0, 1}, {0, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 1, 1, 0}, {0, 0, 0, 0,1, 1, 1,0}, {0, 0, 0, 0, 1, 0, 1, 0}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 1, 1}, {0, 0, 0, 0,1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0, 1}, {0, 0, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 1, 1, 1, 0, 0}, {0, 0, 0, 1, 0, 1, 0, 0}, {0, 0, 0, 1,0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0, 1, 1}, {0, 0, 0, 1, 0, 1, 1, 1}, {0, 0, 0, 1, 0, 1, 0, 1}, {0, 0, 0, 1, 1, 1, 0, 1}, {0, 0, 0, 1, 1, 0, 0, 1}, {0, 0, 0, 1, 1, 0, 0, 0}, {0, 0, 0, 1, 1, 0, 1, 0}, {0, 0, 0, 1, 1, 0, 1, 1}, {0, 0, 0, 1,1, 1, 1, 1}, {0, 0, 0, 1, 1, 1, 1, 0}, {0, 0, 0, 1, 0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 1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1,0, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 0, 1}, {1, 1, 1, 1, 1, 1, 0, 1}, {1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 1, 1,1, 0, 1, 0}, {1, 1, 1, 1, 1, 0, 0, 0}, {1, 0, 1, 1, 1, 0, 0, 0}, {1, 0, 1, 1, 1, 0, 0, 1}, {1, 0, 1, 1, 1, 0, 1, 1}, {1, 1, 1, 1,1, 0, 1, 1}, {1, 1, 1, 1, 0, 0, 1, 1}, {1, 1, 1, 0, 0, 0, 1, 1}, {1, 1, 0, 0, 0, 0, 1, 1}}}
Tuples[{0,1},{l=Length@#}],{2}]
& génère les nombres 0 ... 8 sous forme de listes binaires.
L'extérieur Tuples...{2}
produit toutes les paires ordonnées de ces nombres binaires.
Plus@@x
additionne chacune des paires, générant des triplets de 0, 1.
Cases....Count[Plus@@x, 1]==1
renvoie toutes les sommes qui contiennent un seul 1. Celles-ci surviennent lorsque les deux nombres binaires d'origine sont connectés par un bord.
Rules
relie les sommets du graphe, chaque sommet étant un nombre binaire.
Graph
crée un graphique correspondant auxdits sommets et arêtes.
FindPath
trouve jusqu'à 2 ^ n chemins reliant le sommet a au sommet b, les nombres donnés.
Last
prend le plus long de ces chemins.
Pour trois dimensions, le graphique peut être représenté dans un plan comme illustré ici:
Pour l'entrée,, {0,0,0}, {1,1,1}
la sortie est la suivante:
{{{0, 0, 0}, {0, 0, 1}, {0, 1, 1}, {0, 1, 0}, {1, 1, 0}, {1, 0,
0}, {1, 0, 1}, {1, 1, 1}}}
Ce chemin peut être trouvé dans le graphique ci-dessus.
Il peut également être conçu comme le chemin suivant dans 3 espaces, où chaque sommet correspond à un point {x,y,z}
. {0,0,0} représente l'origine et {1,1,1} représente le point "opposé" dans un cube unitaire.
Le chemin de solution correspond donc à une traversée d'arêtes le long du cube unitaire. Dans ce cas, le chemin est hamiltonien: il visite chaque sommet une fois (c'est-à-dire sans croisements et sans sommets omis).