What's the Point of Learning Functional Programming? - Daniel Beskin's Blog

Just saw this in the Haskell Weekly newsletter and thought it deserved it’s own post.

7 Likes

If we don’t care about performance, I had this in mind as a solution:

isKnightMove (x1, y1) (x2, y2) = abs (x2 - x1) == 1 && abs (y2 - y1) == 2 
                              || abs (x2 - x1) == 2 && abs (y2 - y1) == 1
allTours = filter (\xs -> and $ zipWith isKnightMove xs (tail xs)) 
  $ permutations [(x,y) | x <- [1..8], y <- [1..8]]
1 Like