language: Haskell (ghc-6.8.2)
date: 112 days 7 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Data.List
import Data.Function
import Control.Monad
import System.IO
 
average xs = sum xs / fromIntegral (length xs)
 
d4 :: (Fractional t, Ord t) => [t] -> [t]
d4 xs | d > difference * 4 = d4 withoutV
      | otherwise = xs
    where
    v = maximumBy (compare `on` (abs . (average xs -))) xs
    withoutV = delete v xs
    aveWithoutV = average withoutV
    difference = average $ map (abs . (aveWithoutV -)) withoutV
    d = v - aveWithoutV
 
 
main = do
    nums <- readNums
    putStrLn ""
    putStrLn "--------------------------------------------------"
    putStrLn ""
    forM_ (d4 nums) $ \i -> do
        print i
 
readNums :: (Fractional t, Read t) => IO [t]
readNums = do
    eof <- isEOF
    if eof
        then return []
        else do
            line <- getLine
            case line of
                "" -> return []
                s -> fmap (read s :) readNums