Created
September 28, 2019 03:15
-
-
Save dmwit/a899b1cda8901bc7afe3a51e20dcee8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
derangements :: Integer -> Integer | |
derangements n = id | |
. sum | |
. zipWith (*) signs | |
. scanl (*) 1 | |
$ [n,n-1..1] | |
where | |
signs = drop (n .&. 1) (cycle [1,-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment