Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Text-processing-2/Haskell/text-processing-2.hs
Normal file
18
Task/Text-processing-2/Haskell/text-processing-2.hs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import Data.List (nub, (\\))
|
||||
|
||||
data Record = Record {date :: String, recs :: [(Double, Int)]}
|
||||
|
||||
duplicatedDates rs = rs \\ nub rs
|
||||
|
||||
goodRecords = filter ((== 24) . length . filter ((>= 1) . snd) . recs)
|
||||
|
||||
parseLine l = let ws = words l in Record (head ws) (mapRecords (tail ws))
|
||||
|
||||
mapRecords [] = []
|
||||
mapRecords [_] = error "invalid data"
|
||||
mapRecords (value:flag:tail) = (read value, read flag) : mapRecords tail
|
||||
|
||||
main = do
|
||||
inputs <- (map parseLine . lines) `fmap` readFile "readings.txt"
|
||||
putStr (unlines ("duplicated dates:": duplicatedDates (map date inputs)))
|
||||
putStrLn ("number of good records: " ++ show (length $ goodRecords inputs))
|
||||
Loading…
Add table
Add a link
Reference in a new issue