module Main (main) where
data Radical = H | C Radical Radical Radical
deriving (Eq,Show)
three_partitions :: Int -> [(Int,Int,Int)]
three_partitions m =
[ (i,j,k) | i <- [0..(div m 3)], j <- [i..(div (m-i) 2)], k <- [m - (i+j)]]
remainders :: [a] -> [[a]]
remainders [] = []
remainders (r:rs) = (r:rs) : (remainders rs)
radical_generator :: Int -> [[Radical]]
radical_generator n = radicals
where radicals = [H] : [rads_of_size_n radicals j | j <- [1..n]]
rads_of_size_n :: [[Radical]] -> Int -> [Radical]
rads_of_size_n radicals n =
[ (C ri rj rk)
| (i,j,k) <- (three_partitions (n-1)),
(ri:ris) <- (remainders (radicals!!i)),
(rj:rjs) <- (remainders (if (i==j) then (ri:ris) else radicals!!j)),
rk <- (if (j==k) then (rj:rjs) else radicals!!k)]
data Paraffin = CCP Radical Radical Radical Radical
deriving (Eq, Show)
four_partitions :: Int -> [(Int,Int,Int,Int)]
four_partitions m =
[ (i,j,k,l)
| i <- [0..(div m 4)],
j <- [i..(div (m-i) 3)],
let z = fromIntegral m / 2 :: Double,
k <- [(max j (ceiling z - i - j))..(div (m-i-j) 2)],
l <- [(m - (i+j+k))]]
ccp_generator :: [[Radical]] -> Int -> [Paraffin]
ccp_generator radicals n =
[ (CCP ri rj rk rl)
| (i,j,k,l) <- (four_partitions (n-1)),
(ri:ris) <- (remainders (radicals!!i)),
(rj:rjs) <- (remainders (if (i==j) then (ri:ris) else radicals!!j)),
(rk:rks) <- (remainders (if (j==k) then (rj:rjs) else radicals!!k)),
rl <- (if (k==l) then (rk:rks) else radicals!!l)]
paraffins_until :: Int
paraffins_until = length (ccp_generator radicals 27)
where
radicals = radical_generator 13
main :: IO ()
main = print paraffins_until