sbv-8.0: SMT Based Verification: Symbolic Haskell theorem prover using SMT solving.

Documentation.SBV.Examples.Puzzles.HexPuzzle

Description

Author : Levent Erkok License : BSD3 Maintainer: erkokl@gmail.com Stability : experimental

A solution to the hexagon solver puzzle: http://www5.cadence.com/2018ClubVQuiz_LP.html In case the above URL goes dead, here's an ASCII rendering of the problem.

We're given a board, with 19 hexagon cells. The cells are arranged as follows:

                    01  02  03
04  05  06  07
08  09  10  11  12
13  14  15  16
17  18  19

• Each cell has a color, one of BLACK, BLUE, GREEN, or RED.
• At each step, you get to press one of the center buttons. That is, one of 5, 6, 9, 10, 11, 14, or 15.
• Pressing a button that is currently colored BLACK has no effect.
• Otherwise (i.e., if the pressed button is not BLACK), then colors rotate clockwise around that button. For instance if you press 15 when it is not colored BLACK, then 11 moves to 16, 16 moves to 19, 19 moves to 18, 18 moves to 14, 14 moves to 10, and 10 moves to 11.
• Note that by "move," we mean the colors move: We still refer to the buttons with the same number after a move.

You are given an initial board coloring, and a final one. Your goal is to find a minimal sequence of button presses that will turn the original board to the final one.

Synopsis

# Documentation

data Color Source #

Colors we're allowed

Constructors

 Black Blue Green Red
Instances
 Source # Instance details Methods(==) :: Color -> Color -> Bool #(/=) :: Color -> Color -> Bool # Source # Instance details Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Color -> c Color #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Color #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Color) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Color) #gmapT :: (forall b. Data b => b -> b) -> Color -> Color #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Color -> r #gmapQ :: (forall d. Data d => d -> u) -> Color -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Color -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Color -> m Color #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Color -> m Color # Source # Instance details Methods(<) :: Color -> Color -> Bool #(<=) :: Color -> Color -> Bool #(>) :: Color -> Color -> Bool #(>=) :: Color -> Color -> Bool #max :: Color -> Color -> Color #min :: Color -> Color -> Color # Source # Instance details Methods Source # Instance details MethodsshowsPrec :: Int -> Color -> ShowS #show :: Color -> String #showList :: [Color] -> ShowS # Source # Instance details Methods Source # Instance details MethodsisConcretely :: SBV Color -> (Color -> Bool) -> Bool Source #forall :: MonadSymbolic m => String -> m (SBV Color) Source #forall_ :: MonadSymbolic m => m (SBV Color) Source #mkForallVars :: MonadSymbolic m => Int -> m [SBV Color] Source #exists :: MonadSymbolic m => String -> m (SBV Color) Source #exists_ :: MonadSymbolic m => m (SBV Color) Source #mkExistVars :: MonadSymbolic m => Int -> m [SBV Color] Source #free :: MonadSymbolic m => String -> m (SBV Color) Source #free_ :: MonadSymbolic m => m (SBV Color) Source #mkFreeVars :: MonadSymbolic m => Int -> m [SBV Color] Source #symbolic :: MonadSymbolic m => String -> m (SBV Color) Source #symbolics :: MonadSymbolic m => [String] -> m [SBV Color] Source # Source # Make Color a symbolic value. Instance details MethodsparseCVs :: [CV] -> Maybe (Color, [CV]) Source #cvtModel :: (Color -> Maybe b) -> Maybe (Color, [CV]) -> Maybe (b, [CV]) Source # Source # Instance details MethodssexprToVal :: SExpr -> Maybe Color Source #

Give symbolic colors a name for convenience.

type Button = Word8 Source #

Use 8-bit words for button numbers, even though we only have 1 to 19.

Symbolic version of button.

The grid is an array mapping each button to its color.

Given a button press, and the current grid, compute the next grid. If the button is "unpressable", i.e., if it is not one of the center buttons or it is currently colored black, we return the grid unchanged.

search :: [Color] -> [Color] -> IO () Source #

Iteratively search at increasing depths of button-presses to see if we can transform from the initial board position to a final board position.

example :: IO () Source #

A particular example run. We have:

>>> example
Searching at depth: 0
Searching at depth: 1
Searching at depth: 2
Searching at depth: 3
Searching at depth: 4
Searching at depth: 5
Searching at depth: 6
Found: [10,10,11,9,14,6]
Found: [10,10,9,11,14,6]
There are no more solutions.