You are given a box with eight holes labelled   A-to-H,   connected by fifteen straight lines in the pattern as shown below:

             A   B
            /│\ /│\
           / │ X │ \
          /  │/ \│  \
         C───D───E───F
          \  │\ /│  /
           \ │ X │ /
            \│/ \│/
             G   H

You are also given eight pegs numbered   1-to-8.



Objective

Place the eight pegs in the holes so that the (absolute) difference between any two numbers connected by any line is greater than one.



Example

In this attempt:

             4   7
            /│\ /│\
           / │ X │ \
          /  │/ \│  \
         8───1───6───2
          \  │\ /│  /
           \ │ X │ /
            \│/ \│/
             3   5

Note that   7   and   6   are connected and have a difference of   1,   so it is   not   a solution.



Task
Produce and show here   one   solution to the puzzle.



Related tasks

   A* search algorithm
   Solve a Holy Knight's tour
   Knight's tour
   N-queens problem
   Solve a Hidato puzzle
   Solve a Holy Knight's tour
   Solve a Hopido puzzle
   Solve a Numbrix puzzle
   4-rings or 4-squares puzzle


See also
No Connection Puzzle (youtube).




 
Module no_connection_puzzle {
      \\ Holes
      Inventory Connections="A":="CDE","B":="DEF","C":="ADG", "D":="ABCEGH"
      Append Connections, "E":="ABDFGH","F":="HEB", "G":="CDE","H":="DEF"
      Inventory ToDelete, Solutions
      \\ eliminate double connnections
      con=each(Connections)
      While con {
            m$=eval$(con, con^)
            c$=eval$(con)
            If c$="*" Then continue
            For i=1 to len(C$) {
                 d$=mid$(c$,i,1)
                 r$=Filter$(Connections$(d$), m$)
                 If r$<>"" Then  {
                         Return connections, d$:=r$
                  }  else   {
                        If m$=connections$(d$) Then {
                              Return connections, d$:="*"  : If not exist(todelete, d$)  Then  Append todelete, d$
                        }
                  }
            }
      }
      con=each(todelete)
      While con {
            Delete Connections, eval$(con)
      }
      Inventory Holes
      For i=0 to 7 : Append Holes, Chr$(65+i):=i : Next i
      CheckValid=lambda Holes, Connections (a$, arr) -> {
            val=Array(arr, Holes(a$))
            con$=Connections$(a$)
            res=True
            For i=1 to Len(con$) {
                 If Abs(Array(Arr, Holes(mid$(con$,i,1)))-val)<2 Then res=False: Exit
            }
            =res
      }
      a=(1,2,3,4,5,6,7,8)
      h=(,)
      solution=(,)
      done=False
      counter=0
      Print "Wait..."
      P(h, a)
      sol=Each(Solutions)
      While sol {
            Print "Solution:";sol^+1
            Disp(Eval(Solutions))
            aa$=Key$
      }
      Sub P(h, a)
      If len(a)<=1 Then process(cons(h, a)) : Exit Sub
      local b=cons(a)
      For i=1 to len(b) {
                  b=cons(cdr(b),car(b))
                  P(cons(h,car(b)), cdr(b))
      }
      End Sub
      Sub Process(a)
            counter++
            Print counter
            If keypress(32) Then {
            local  sol=Each(Solutions)
                        aa$=Key$
                        While sol {
                                    Print "Solution:";sol^+1
                                    Disp(Eval(Solutions))
                                    aa$=Key$
                        }  
            }
            hole=each(Connections)
            done=True
            While hole {
                  If not CheckValid(Eval$(hole, hole^), a) Then done=False : Exit
            }
            If done Then Append Solutions, Len(Solutions):=a : Print a
      End Sub
      Sub Disp(a)
            Print format$("    {0}   {1}", array(a), array(a,1))
            Print "   /|\ /|\"
            Print "  / | X | \"
            Print " /  |/ \|  \"
            Print Format$("{0} - {1} - {2} - {3}", array(a,2),array(a,3), array(a,4), array(a,5))
            Print " \  |\ /|  /"
            Print "  \ | X | /"
            Print "   \|/ \|/"
            Print Format$("    {0}   {1}", array(a,6), array(a,7))
      End Sub
}
no_connection_puzzle
 
 