blob: 516fc85d107e60203c52d988ce7d1122bf636590 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
-- This is a parallel varient of factorial
module Main where
fac :: Int -> Int
fac 0 = 1
fac n = pfac 1 n
pfac :: Int -> Int -> Int
pfac low high | low == high = low
| low + 1 == high = (low * high)
| otherwise = pfac low mid * pfac (mid + 1) high
where
mid = (high + low) `div` 2
main = appendChan stdout "Type in N: " abort $
readChan stdin abort $ \ input ->
appendChan stdout (show (fac (read (head (lines input))))) abort done
|