Comment detail

LL Golf Hole 7 - バイト数を読みやすくする (Nested Flatten)
無難に。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import List
import Maybe

units = " KMGTPEZY"
k = 1024

humanReadable x
 | x < k = show x
 | otherwise = show a ++ "." ++ show b ++ [c] where
   (y,xs) = mapAccumL (\x c -> (div x k, (x,c))) (x*10) $ init units
   (z,c) = fromMaybe (y,last units) $ find ((<k*10).fst) xs
   (a,b) = divMod z 10

{-
> humanReadable 123456789012345678901234567890
"102121.0Y"
-}

Index

Feed

Other

Link

Pathtraq

loading...