Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
44
Task/Paraffins/Haskell/paraffins-1.hs
Normal file
44
Task/Paraffins/Haskell/paraffins-1.hs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
-- polynomial utils
|
||||
a `nmul` n = map (*n) a
|
||||
a `ndiv` n = map (`div` n) a
|
||||
|
||||
instance (Integral a) => Num [a] where
|
||||
(+) = zipWith (+)
|
||||
negate = map negate
|
||||
a * b = foldr f undefined b where
|
||||
f x z = (a `nmul` x) + (0 : z)
|
||||
abs _ = undefined
|
||||
signum _ = undefined
|
||||
fromInteger n = fromInteger n : repeat 0
|
||||
|
||||
-- replace x in polynomial with x^n
|
||||
repl a n = concatMap (: replicate (n-1) 0) a
|
||||
|
||||
-- S2: (a^2 + b)/2
|
||||
cycleIndexS2 a b = (a*a + b)`ndiv` 2
|
||||
|
||||
-- S4: (a^4 + 6 a^2 b + 8 a c + 3 b^2 + 6 d) / 24
|
||||
cycleIndexS4 a b c d = ((a ^ 4) +
|
||||
(a ^ 2 * b) `nmul` 6 +
|
||||
(a * c) `nmul` 8 +
|
||||
(b ^ 2) `nmul` 3 +
|
||||
d `nmul` 6) `ndiv` 24
|
||||
|
||||
|
||||
a598 = x1
|
||||
-- A000598: A(x) = 1 + (1/6)*x*(A(x)^3 + 3*A(x)*A(x^2) + 2*A(x^3))
|
||||
x1 = 1 : ((x1^3) + ((x2*x1)`nmul` 3) + (x3`nmul`2)) `ndiv` 6
|
||||
x2 = x1`repl`2
|
||||
x3 = x1`repl`3
|
||||
x4 = x1`repl`4
|
||||
|
||||
-- A000678 = x CycleIndex(S4, A000598(x))
|
||||
a678 = 0 : cycleIndexS4 x1 x2 x3 x4
|
||||
|
||||
-- A000599 = CycleIndex(S2, A000598(x) - 1)
|
||||
a599 = cycleIndexS2 (0 : tail x1) (0 : tail x2)
|
||||
|
||||
-- A000602 = A000678(x) - A000599(x) + A000599(x^2)
|
||||
a602 = a678 - a599 + x2
|
||||
|
||||
main = mapM_ print $ take 200 $ zip [0 ..] a602
|
||||
32
Task/Paraffins/Haskell/paraffins-2.hs
Normal file
32
Task/Paraffins/Haskell/paraffins-2.hs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import Data.Array
|
||||
|
||||
choose :: Integer -> Int -> Integer
|
||||
choose m k = let kk = toInteger k in (product [m..m+kk-1]) `div` (product [1..kk])
|
||||
|
||||
max_branches = 4
|
||||
max_nodes = 200
|
||||
|
||||
bcache = listArray (0, max_nodes)
|
||||
[sum[rcache!n!b!r | r <- [0..n], b <- [0..max_branches-1]] | n <- [0..max_nodes]]
|
||||
build_block = (bcache !)
|
||||
|
||||
rcache = listArray (0,max_nodes) [arr_b i | i <- [0..max_nodes]] where
|
||||
arr_b n = listArray(0,max_branches) [arr_r b n | b <- [0..max_branches]]
|
||||
arr_r b n = listArray(0,n) [rooted n b r | r <- [0..n]]
|
||||
|
||||
rooted 1 0 0 = 1
|
||||
rooted 1 _ _ = 0
|
||||
rooted _ 0 _ = 0
|
||||
rooted _ _ 0 = 0
|
||||
rooted n b r
|
||||
| (n <= b) || (n <= r) = 0
|
||||
| otherwise = sum [(firsts b1) * (rests b1) | b1 <- [1..b], r * b1 < n] where
|
||||
firsts = choose (build_block r)
|
||||
rests bb = sum [rcache!(n-r*bb)!(b - bb)!r1 | r1 <- [0..r-1], r1 < (n-r*bb)]
|
||||
|
||||
unrooted n = unicenter + bycenter where
|
||||
unicenter = sum [ rcache!n!b!r | b <- [0..max_branches], r <-[0..n], r * 2 < n]
|
||||
bycenter| odd n = 0
|
||||
| otherwise = x * (x + 1) `div` 2 where x = build_block (n `div` 2)
|
||||
|
||||
main = mapM_ print $ map (\x->(x, unrooted x)) [1..max_nodes]
|
||||
Loading…
Add table
Add a link
Reference in a new issue