Created
August 27, 2011 05:06
-
-
Save budu/1175007 to your computer and use it in GitHub Desktop.
Snake my_turn_in puzzle implementation in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Snake my_turn_in puzzle implementation | |
| -- | |
| -- The direction argument accept an Ordering value where GT is | |
| -- :forward, LT is :backward and EQ is :same. | |
| -- | |
| -- Problem definition can be found in: | |
| -- https://github.com/budu/Puzzles | |
| myTurnIn :: (Ord a, Integral a) => a -> a -> Ordering -> a -> a | |
| myTurnIn _ _ _ 1 = 0 | |
| myTurnIn p1 p2 d s | |
| | mc == 0 && d == EQ = 0 | |
| | rd == d || rd == EQ || d == EQ = dist - rdist | |
| | otherwise = rdist | |
| where mp = p1 - 1 | |
| mc = mp - p2 + 1 | |
| rd = 0 `compare` mc | |
| rdist = abs mc | |
| dist = 1 + 2 * | |
| | mc < 0 || rd == EQ && d == GT = s - mp - 1 | |
| | otherwise = mp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment