Data update

This commit is contained in:
Ingy döt Net 2025-02-27 18:35:13 -05:00
parent 8e4e15fa56
commit 72eb4943cb
1853 changed files with 35514 additions and 9441 deletions

View file

@ -0,0 +1,14 @@
import Data.Ratio ((%), numerator)
infixl 7 *.
(*.) :: Num a => a -> [a] -> [a]
x *. (p:ps) = x*p : x*.ps
instance Num a => Num [a] where
negate = map negate
(+) = zipWith (+)
(*) (p:ps) (q:qs) = p*q : ((p*.qs) + ps*(q:qs))
fromInteger n = fromInteger n:repeat 0
expseq :: [Rational] -> [Rational]
expseq ps = zipWith (\p q -> p*fromInteger q) ps (scanl (*) 1 [1..])

View file

@ -0,0 +1,8 @@
derangements :: [Integer]
derangements = map numerator
(expseq (invexp/(1:(-1):repeat 0)))
invexp :: [Rational]
invexp = zipWith (%) (cycle [1,-1]) factorials
where
factorials = scanl (*) 1 [1..]

View file

@ -0,0 +1,4 @@
ghci> take 10 derangements
[1,0,1,2,9,44,265,1854,14833,133496]
ghci> derangements !! 20
895014631192902121