Anonymous user
File size distribution: Difference between revisions
m
→{{header|Haskell}}
Line 398:
import Data.List (sort, genericLength, genericTake)
import System.Directory (getDirectoryContents, doesFileExist
import System.Environment (getArgs)
import System.FilePath.Posix (pathSeparator, (</>))
Line 408:
deriving (Show)
type FrequencyGroup = ((Integer, Integer), Integer)
frequencyGroups :: (Integral a) => Int -> [a] -> [((a, a), a)]▼
frequencyGroups totalGroups xs = placeGroups xs groupMinMax
where
range = maximum xs - minimum xs
groupSize = succ $ ceiling $ realToFrac range / realToFrac totalGroups
groups = genericTake (succ totalGroups)
groupMinMax = (,0) <$> zip groups (pred <$> tail groups)
Line 451 ⟶ 453:
pure $ a <> join b <> fmap Folder folders
displayFrequency ::
displayFrequency ((min, max), count) =
printf "%5s <-> %5s = %d\n" (displaySize min) (displaySize max) count
|