ghc-dup: be23c78c54ba72f1a9e1b3edaa80159879a8abee

     1: import Data.Word
     2: import Data.List
     3: import Data.Bits
     4: import Data.Function
     5: import System.Environment
     6: import System.Mem
     7: import System.IO
     8: 
     9: import GHC.Dup
    10: 
    11: data Tree = Node Word32 [Tree]
    12: firstChild (Node _ (t:_)) = t
    13: 
    14: t1 = tree 1
    15: tree n = Node n (map tree [n * 3, n * 5, n * 7, n * 9])
    16: 
    17: 
    18: depth = 4
    19: 
    20: solveDup t = case dup t of Box t -> solve t
    21: 
    22: solveDeepDup t = case deepDup t of Box t -> solve t
    23: 
    24: solve' (Node n ts) = n :
    25:     solve' (fst (maximumBy (compare `on` snd) [ (t, rate' depth t) | t <- ts ]))
    26: 
    27: solve (Node n ts) = n :
    28:     solve (fst (maximumBy (compare `on` snd) [ (t, rate depth t) | t <- ts ]))
    29: 
    30: --rate d t = rate' d t
    31: rate' d t = case dup t of Box t2 -> rate d t2
    32: 
    33: rate 0 (Node n _) = popCount n
    34: rate d (Node _ ts) = maximum (map (rate (d-1)) ts)
    35: 
    36: ht :: [Word32] -> Word32
    37: ht xs = last xs + head xs
    38: 
    39: ht' :: [Word32] -> Word32
    40: ht' xs = case dup xs of Box xs' -> last xs' + head xs
    41: 
    42: ht'' :: [Word32] -> Word32
    43: ht'' xs = case deepDup xs of Box xs' -> last xs' + head xs
    44: 
    45: main = do
    46:     [n] <- getArgs 
    47:     let k = read n
    48:     print k
    49:     performGC
    50:     let t = tree k
    51:     -- let l = [1..(100000000)]
    52:     --print (take 5 l)
    53:     -- hFlush stdout
    54:     -- performGC
    55:     --print $ ht'' l
    56:     --print (head l)
    57: 
    58:     --hFlush stdout
    59: 
    60:     --t `seq` return ()
    61:     --print $ rate 1 t
    62: 
    63:     print $ solve t !! 10000
    64:     print $ solve t !! 10000
    65:     hFlush stdout
    66:     print $ solve t !! 1
    67:     
    68: 
    69: 

Generated by git2html.