6c78dfe7ab3465047056e3fc8584825669dd8719
[nofib.git] / imaginary / paraffins / Main.hs
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 -}
7
8 module Main (main) where
9 import Data.Array
10 import System.Environment
11
12 -- Generation of radicals
13
14 data Radical = H | C Radical Radical Radical
15
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)]]
19
20 remainders [] = []
21 remainders (r:rs) = (r:rs) : (remainders rs)
22
23 radical_generator :: Int -> Array Int [Radical]
24 radical_generator n =
25 radicals
26 where
27 radicals =
28 array (0,n) ((0,[H]) : [(j,rads_of_size_n radicals j) | j <- [1..n]])
29
30 rads_of_size_n :: Array Int [Radical] -> Int -> [Radical]
31 rads_of_size_n radicals n =
32 [ (C ri rj rk)
33 | (i,j,k) <- (three_partitions (n-1)),
34 (ri:ris) <- (remainders (radicals!i)),
35 (rj:rjs) <- (remainders (if (i==j) then (ri:ris) else radicals!j)),
36 rk <- (if (j==k) then (rj:rjs) else radicals!k)]
37
38 -- Generation of paraffins.
39
40 data Paraffin = BCP Radical Radical | CCP Radical Radical Radical Radical
41
42 bcp_generator :: Array Int [Radical] -> Int -> [Paraffin]
43 bcp_generator radicals n =
44 if (odd n) then []
45 else
46 [ (BCP r1 r2) | (r1:r1s) <- (remainders (radicals!(div n 2))),
47 r2 <- (r1:r1s) ]
48
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))]]
56
57 ccp_generator :: Array Int [Radical] -> Int -> [Paraffin]
58 ccp_generator radicals n =
59 [ (CCP ri rj rk rl)
60 | (i,j,k,l) <- (four_partitions (n-1)),
61 (ri:ris) <- (remainders (radicals!i)),
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)]
65
66 bcp_until :: Int -> [Int]
67 bcp_until n =
68 [length(bcp_generator radicals j) | j <- [1..n]]
69 where
70 radicals = radical_generator (div n 2)
71
72 ccp_until :: Int -> [Int]
73 ccp_until n =
74 [length(ccp_generator radicals j) | j <- [1..n]]
75 where
76 radicals = radical_generator (div n 2)
77
78 paraffins_until :: Int -> [Int]
79 paraffins_until n =
80 [length (bcp_generator radicals j) + length (ccp_generator radicals j)
81 | j <- [1..n]]
82 where
83 radicals = radical_generator (div n 2)
84
85 main = do
86 [arg] <- getArgs
87 let num = read arg
88 print [length (rads!i) | rads <- [(radical_generator num)], i <- [0..num]]
89 print (bcp_until num)
90 print (ccp_until num)
91 print (paraffins_until num)