diff options
Diffstat (limited to 'Puzzle16.hs')
-rw-r--r-- | Puzzle16.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Puzzle16.hs b/Puzzle16.hs new file mode 100644 index 0000000..a15f802 --- /dev/null +++ b/Puzzle16.hs @@ -0,0 +1,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 |