Knight's tour: Difference between revisions
m
→{{header|Haskell}}
Line 4,090:
import Data.List (intercalate, minimumBy, sort, (\\))
import Data.Ord (comparing)
import Control.Monad (join)
---------------------- KNIGHT'S TOUR ---------------------
Line 4,111 ⟶ 4,112:
knightMoves >>= go . bimap (+ x) (+ y)
where
go
|
| otherwise = []
knightMoves :: [(Int, Int)]
knightMoves =
((>>=) <*> (\deltas n -> deltas >>= go n)) [1, 2, -1, -2]
where
go i x
Line 4,126:
onBoard :: Int -> Bool
onBoard = (&&) . (0 <) <*> (9 >)
both :: (a -> b) -> (a, a) -> (b, b)
both = join bimap
--------------------------- TEST -------------------------
|