aboutsummaryrefslogtreecommitdiff
path: root/Puzzle16.hs
blob: a15f80251c0caec6348da6c00dc1250047552218 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import Data.List (elemIndex)
import Data.Maybe (fromJust)

spin n xs = let (ys, zs) = splitAt n xs in zs ++ ys

exchange m n xs 
  | n > m = ys ++ [y] ++ zs ++ [x] ++ ws
  | n == m = xs
  | otherwise = exchange n m xs
      where (ys, x:xs') = splitAt m xs
            (zs, y:ws)  = splitAt (n - m - 1) xs'

partner x y xs = exchange m n xs
  where m = fromJust $ elemIndex x xs
        n = fromJust $ elemIndex y xs