| 1 | import Control.Monad |
|---|
| 2 | import Data.List |
|---|
| 3 | import Control.Concurrent |
|---|
| 4 | import GHC.Conc |
|---|
| 5 | |
|---|
| 6 | splits xs = zip ( inits xs ) ( tails xs ) |
|---|
| 7 | |
|---|
| 8 | perms [] = return [] |
|---|
| 9 | perms (x:xs) = do |
|---|
| 10 | ys <- perms xs |
|---|
| 11 | (pre,post) <- splits ys |
|---|
| 12 | return $ pre ++ x:post |
|---|
| 13 | |
|---|
| 14 | main = void $ forM [ 1 :: Int .. ] $ \ e -> do |
|---|
| 15 | ch <- newChan |
|---|
| 16 | void $ forM [ 1 .. GHC.Conc.numCapabilities ] $ \ t -> |
|---|
| 17 | writeChan ch $ length $ reverse $ perms $ take e [ t .. ] |
|---|
| 18 | out <- forM [ 1 .. GHC.Conc.numCapabilities ] $ \ t -> readChan ch |
|---|
| 19 | print ( e, out ) |
|---|