Copyright | (c) Levent Erkok |
---|---|
License | BSD3 |
Maintainer | erkokl@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Documentation.SBV.Examples.Puzzles.Tower
Description
Solves the tower puzzle, http://www.chiark.greenend.org.uk/%7Esgtatham/puzzles/js/towers.html.
Synopsis
- type Count a = Array Integer a
- type Grid a = Array (Integer, Integer) a
- type Problem a = (Count a, Count a, Count a, Count a, Grid a)
- problem :: Problem (Maybe Integer)
- symProblem :: Problem (Maybe Integer) -> Symbolic (Problem SInteger)
- visible :: [SInteger] -> SInteger
- tower :: Problem SInteger -> Symbolic ()
- example :: IO ()
Modeling Towers
type Grid a = Array (Integer, Integer) a Source #
The grid itself. The indexes are tuples, first coordinate increases as you go from left to right, and the second increases as you go from top to bottom.
type Problem a = (Count a, Count a, Count a, Count a, Grid a) Source #
The problem has 4 counts, from top, left, bottom, and right. And the grid itself.
problem :: Problem (Maybe Integer) Source #
Example problem. Encodes:
- - 3 - - 4 - 2 5 - 2 - 4 - 2 - - 2 3 - - - 3 4 - -
symProblem :: Problem (Maybe Integer) -> Symbolic (Problem SInteger) Source #
Given a concrete partial board, turn it into a symbolic board, by filling in the empty cells with symbolic variables.
Counting visible towers
visible :: [SInteger] -> SInteger Source #
Given a list of tower heights, count the number of visible ones in the given order. We simply keep track of the tallest we have seen so far, and increment the count for each tower we see if it's taller than the tallest seen so far.
Building constraints
tower :: Problem SInteger -> Symbolic () Source #
Build the constraints for a given problem. We scan the elements and add the required visibility counts for each row and column, viewed both in the correct order and in the backwards order.