Skip to content

Instantly share code, notes, and snippets.

@lenstr
Created December 3, 2009 23:26
Show Gist options
  • Save lenstr/248665 to your computer and use it in GitHub Desktop.
Save lenstr/248665 to your computer and use it in GitHub Desktop.
{- successively select elements from xs and remove one in each result list -}
import List
removeEach :: [a] -> [[a]]
removeEach xs =
zipWith (++) (List.inits xs) (tail (List.tails xs))
alternate :: (Num a) => [a] -> [a]
alternate = zipWith id (cycle [id, negate])
det :: (Num a) => [[a]] -> a
det [] = 1
det m = sum (alternate
(zipWith (*) (map head m)
(map det (removeEach (map tail m)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment