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).




import Data.List (permutations)
 
solution :: [Int]
solution@(a : b : c : d : e : f : g : h : _) =
  head $
    filter isSolution (permutations [1 .. 8])
  where
    isSolution :: [Int] -> Bool
    isSolution (a : b : c : d : e : f : g : h : _) =
      all ((> 1) . abs) $
        zipWith
          (-)
          [a, c, g, e, a, c, g, e, b, d, h, f, b, d, h, f]
          [d, d, d, d, c, g, e, a, e, e, e, e, d, h, f, b]
 
main :: IO ()
main =
  (putStrLn . unlines) $
    unlines
      ( zipWith
          (\x y -> x : (" = " <> show y))
          ['A' .. 'H']
          solution
      ) :
    ( rightShift . unwords . fmap show
        <$> [[], [a, b], [c, d, e, f], [g, h]]
    )
  where
    rightShift s
      | length s > 3 = s
      | otherwise = "  " <> s