Data update

This commit is contained in:
Ingy döt Net 2024-11-04 20:28:54 -08:00
parent 52a6ef48dd
commit 157b70a810
604 changed files with 14253 additions and 2100 deletions

View file

@ -0,0 +1,5 @@
fac = product . enumFromTo 1
binCoef n k = fac n `div` (fac k * fac (n - k))
pascal = ((fmap . binCoef) <*> enumFromTo 0) . pred

View file

@ -0,0 +1,11 @@
*Main> putStr $ unlines $ map unwords $ map (map show) $ pascal 10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1

View file

@ -1,4 +1 @@
pascal :: [[Integer]]
pascal =
(1 : [ 0 | _ <- head pascal])
: [zipWith (+) (0:row) row | row <- pascal]
nextRow = (zipWith (+) . (0 :)) <*> (<> [0])

View file

@ -1,2 +1 @@
*Pascal> take 5 <$> (take 5 $ triangle)
[[1,0,0,0,0],[1,1,0,0,0],[1,2,1,0,0],[1,3,3,1,0],[1,4,6,4,1]]
nextRow = (zipWith (+) <*> reverse) . (0 :)

View file

@ -1,5 +1,4 @@
fac = product . enumFromTo 1
binCoef n k = fac n `div` (fac k * fac (n - k))
pascal = ((fmap . binCoef) <*> enumFromTo 0) . pred
pascal :: [[Integer]]
pascal =
(1 : [ 0 | _ <- head pascal])
: [zipWith (+) (0:row) row | row <- pascal]

View file

@ -1,11 +1,2 @@
*Main> putStr $ unlines $ map unwords $ map (map show) $ pascal 10
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
*Pascal> take 5 <$> (take 5 $ triangle)
[[1,0,0,0,0],[1,1,0,0,0],[1,2,1,0,0],[1,3,3,1,0],[1,4,6,4,1]]