Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Knight Journey
--ghc 7.10 type Knight = (Int, Int) type Board = [Knight] between :: Int -> Int -> Int -> Bool between a b c = a <= c && c <= b moves :: Knight -> [Knight] moves (x,y) = let inBoard = between 1 8 in filter (\(i,j) -> inBoard i && inBoard j) $ [(x+i,y+j) | i <- [-2,2], j <- [-1,1]] ++ [(x+j,y+i) | i <- [-2,2], j <- [-1,1]] canMove :: Board -> Knight -> Bool canMove board knight = not $ knight `elem` board allowedMoves :: Board -> [Board] allowedMoves board@(x : xs) = map (:board) $ filter (canMove board) (moves x) journey :: Board -> [Board] journey board | length board == 60 = [board] | otherwise = concat $ map journey $ allowedMoves board main = print $ head $ journey [(4,4)] --canMove [(1,1)] (2,1) --moves (1,1)
run
|
edit
|
history
|
help
0
Kleinste
project euler 10, haskell
Anonymous recursion. Why doesnt compile?
Quicksort in Haskell
Haskell Prime Factorizer
State
equiv
Token
project euler 6, haskell
Traversable