Commit 51ca2f7e authored by dnt's avatar dnt

[project @ 1996-11-26 14:46:20 by dnt]

Merged in changes from new-build-system branch
parent f0217cbf
#define IHaveSubdirs
SUBDIRS = exp3_8 \
gen_regexps \
primes \
queens \
rfib \
tak
/* nfib: DIE, ANIMAL! */
TOP = ../..
SUBDIRS = exp3_8 gen_regexps paraffins primes queens rfib tak x2n1
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(exp3_8,)
TOP = ../../..
PROG = exp3_8
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(gen_regexps,-i gen_regexps.stdin)
TOP = ../../..
PROG = gen_regexps
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(paraffins,-i paraffins.stdin)
{- Ensnaffled by SLPJ from MIT
via RPaul <rpaul@juicy-juice.lcs.mit.edu> 93/08/26.
-}
{-
- Id Example Program
- Ensnaffled by SLPJ from MIT via
- RPaul <rpaul@juicy-juice.lcs.mit.edu> 93/08/26.
- Original author: Steve Heller
-}
-- Id Example Program
-- Title: Paraffins
-- Original Author: Steve Heller
module Main (main) where
import Array
-- Needs the following library functions
-- typeof div = I -> I -> I;
-- typeof ceiling = F -> I;
-- typeof float = I -> F;
-- typeof length = (list *0) -> I;
-- typeof odd? = I -> B;
-- typeof max = I -> I -> I;
module Main where
-- Generation of radicals.
-- Generation of radicals
data Radical = H | C Radical Radical Radical
three_partitions m =
[ (i,j,k) | i <- [0..(div m 3)],
j <- [i..(div (m-i) 2)],
k <- [(m - (i+j))]]
[ (i,j,k) | i <- [0..(div m 3)], j <- [i..(div (m-i) 2)], k <- [m - (i+j)]]
remainders [] = []
remainders (r:rs) = (r:rs) : (remainders rs)
radical_generator n = radicals where
{ radicals = array (0,n)
((0 := [H]):
[j := (rads_of_size_n radicals j) | j <- [1..n]])}
-- $[1 1 1 2 4 8 17 39 89 211 507 1238 3057 7639 19241 48865 124906 321198]
test_radicals n =
array (0,n) [i := (length (rads!i)) | rads <- [(radical_generator n)],
i <- [0..n]]
radical_generator n =
radicals
where
radicals =
array (0,n) ((0,[H]) : [(j,rads_of_size_n radicals j) | j <- [1..n]])
rads_of_size_n radicals n =
[ (C ri rj rk) | (i,j,k) <- (three_partitions (n-1)),
[ (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)]
......@@ -50,66 +36,44 @@ rads_of_size_n radicals n =
data Paraffin = BCP Radical Radical | CCP Radical Radical Radical Radical
bcp_generator radicals n =
if (odd n) then
[]
if (odd n) then []
else
[ (BCP r1 r2) | (r1:r1s) <- (remainders (radicals!(div n 2))),
r2 <- (r1:r1s) ]
four_partitions m =
[ (i,j,k,l) | i <- [0..(div m 4)],
[ (i,j,k,l)
| i <- [0..(div m 4)],
j <- [i..(div (m-i) 3)],
k <- [(max j (ceiling ((fromInteger m)/(fromInteger 2)) - i - j))..(div (m-i-j) 2)],
l <- [(m - (i+j+k))]]
ccp_generator radicals n =
[ (CCP ri rj rk rl) | (i,j,k,l) <- (four_partitions (n-1)),
[ (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)]
bcp_until n = let
{ radicals = radical_generator (div n 2)}
in
array (1,n) [j := (bcp_generator radicals j) | j <- [1..n]]
ccp_until n = let
{ radicals = radical_generator (div n 2)}
in
array (1,n) [j := (ccp_generator radicals j) | j <- [1..n]]
ccp_at n = let
{ radicals = radical_generator (div n 2)}
in
(ccp_generator radicals n)
paraffins_until n = let
{ radicals = radical_generator (div n 2)}
in
array (1,n) [j := ((bcp_generator radicals j),(ccp_generator radicals j)) | j <- [1..n]]
-- $[0 1 0 1 0 3 0 10 0 36 0 153 0 780 0 4005 0]
test_bcp_until n = let
{ result = bcp_until n}
in
array (1,n) [i := (length (result!i)) | i <- [1..n]]
-- $[1 0 1 1 3 2 9 8 35 39 159 202 802 1078 4347 6354 24894]
test_ccp_until n = let
{ result = ccp_until n}
in
array (1,n) [i := (length (result!i)) | i <- [1..n]]
-- $[1 1 1 2 3 5 9 18 35 75 159 355 802 1858 4347 10359 24894]
test_paraffins_until n = let
{ result = paraffins_until n}
in
array (1,n) [i := (let { (bv,cv) = result!i} in (length bv) + (length cv))
| i <- [1..n]]
bcp_until n =
[length(bcp_generator radicals j) | j <- [1..n]]
where
radicals = radical_generator (div n 2)
ccp_until n =
[length(ccp_generator radicals j) | j <- [1..n]]
where
radicals = radical_generator (div n 2)
paraffins_until n =
[length (bcp_generator radicals j) + length (ccp_generator radicals j)
| j <- [1..n]]
where
radicals = radical_generator (div n 2)
main = do
putStr "Type in N: "
input <- getContents
putStr (show (test_paraffins_until (read (head (lines input)))))
print [length (rads!i) | rads <- [(radical_generator 17)], i <- [0..17]]
print (bcp_until 17)
print (ccp_until 17)
print (paraffins_until 17)
TOP = ../../..
PROG = paraffins
include $(TOP)/nofib/mk/nofib.mk
[1, 1, 1, 2, 4, 8, 17, 39, 89, 211, 507, 1238, 3057, 7639, 19241, 48865, 124906, 321198]
[0, 1, 0, 1, 0, 3, 0, 10, 0, 36, 0, 153, 0, 780, 0, 4005, 0]
[1, 0, 1, 1, 3, 2, 9, 8, 35, 39, 159, 202, 802, 1078, 4347, 6354, 24894]
[1, 1, 1, 2, 3, 5, 9, 18, 35, 75, 159, 355, 802, 1858, 4347, 10359, 24894]
NoFibOneModuleCompileAndRun(primes,)
......@@ -11,4 +11,3 @@ primes :: [Int]
primes = map head (iterate the_filter (iterate suCC 2))
main = print (primes !! 1500)
--OLD: main = print (take 300 primes)
TOP = ../../..
PROG = primes
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(queens,)
TOP = ../../..
PROG = queens
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(rfib,)
TOP = ../../..
PROG = rfib
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(tak,)
TOP = ../../..
PROG = tak
include $(TOP)/nofib/mk/nofib.mk
NoFibOneModuleCompileAndRun(x2n1,)
......@@ -23,7 +23,10 @@ of all the other programs I thought I'd contribute at least one :-)
...
-}
main = prints (round (realPart (sum [f n | n<-[1..10000]]))) "\n"
module Main ( main ) where
import Complex
main = print (round (realPart (sum [f n | n <- [1..10000]])))
f :: Int -> Complex Double
f n = mkPolar 1 (2*pi/fromInt n) ^ n
TOP = ../../..
PROG = x2n1
include $(TOP)/nofib/mk/nofib.mk
6561
\ No newline at end of file
10000
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment