6c78dfe7ab3465047056e3fc8584825669dd8719
1 {-
2 - Id Example Program
3 - Ensnaffled by SLPJ from MIT via
4 - RPaul <rpaul@juicy-juice.lcs.mit.edu> 93/08/26.
5 - Original author: Steve Heller
6 -}
8 module Main (main) where
9 import Data.Array
10 import System.Environment
16 three_partitions :: Int -> [(Int,Int,Int)]
17 three_partitions m =
18 [ (i,j,k) | i <- [0..(div m 3)], j <- [i..(div (m-i) 2)], k <- [m - (i+j)]]
20 remainders [] = []
21 remainders (r:rs) = (r:rs) : (remainders rs)
26 where
28 array (0,n) ((0,[H]) : [(j,rads_of_size_n radicals j) | j <- [1..n]])
32 [ (C ri rj rk)
33 | (i,j,k) <- (three_partitions (n-1)),
35 (rj:rjs) <- (remainders (if (i==j) then (ri:ris) else radicals!j)),
36 rk <- (if (j==k) then (rj:rjs) else radicals!k)]
38 -- Generation of paraffins.
42 bcp_generator :: Array Int [Radical] -> Int -> [Paraffin]
44 if (odd n) then []
45 else
46 [ (BCP r1 r2) | (r1:r1s) <- (remainders (radicals!(div n 2))),
47 r2 <- (r1:r1s) ]
49 four_partitions :: Int -> [(Int,Int,Int,Int)]
50 four_partitions m =
51 [ (i,j,k,l)
52 | i <- [0..(div m 4)],
53 j <- [i..(div (m-i) 3)],
54 k <- [(max j (ceiling ((fromIntegral m)/(fromInteger 2)) - i - j))..(div (m-i-j) 2)],
55 l <- [(m - (i+j+k))]]
57 ccp_generator :: Array Int [Radical] -> Int -> [Paraffin]
59 [ (CCP ri rj rk rl)
60 | (i,j,k,l) <- (four_partitions (n-1)),
62 (rj:rjs) <- (remainders (if (i==j) then (ri:ris) else radicals!j)),
63 (rk:rks) <- (remainders (if (j==k) then (rj:rjs) else radicals!k)),
64 rl <- (if (k==l) then (rk:rks) else radicals!l)]
66 bcp_until :: Int -> [Int]
67 bcp_until n =
68 [length(bcp_generator radicals j) | j <- [1..n]]
69 where
72 ccp_until :: Int -> [Int]
73 ccp_until n =
74 [length(ccp_generator radicals j) | j <- [1..n]]
75 where