Convert seconds to compound duration: Difference between revisions
Content deleted Content added
→{{header|Haskell}}: Or, parameterising the local names for these durations: |
|||
Line 1,244: | Line 1,244: | ||
Or, parameterising the local names for these durations: |
Or, parameterising the local names for these durations: |
||
<lang haskell>import Data.List (intercalate) |
<lang haskell>import Data.List (intercalate, mapAccumR) |
||
timePhrase :: [String] -> Int -> String |
timePhrase :: [String] -> Int -> String |
||
Line 1,258: | Line 1,258: | ||
weekParts :: Int -> [Int] |
weekParts :: Int -> [Int] |
||
weekParts n = xs where |
weekParts n = xs where |
||
( |
(_, xs) = mapAccumR byUnits n [0, 7, 24, 60, 60] |
||
byUnits :: |
byUnits :: Int -> Int -> (Int, Int) |
||
byUnits |
byUnits rest x = |
||
( |
(quot (rest - m) u, m) where |
||
(u, m) | x > 0 = (x, rem rest x) |
(u, m) | x > 0 = (x, rem rest x) |
||
| otherwise = (1, rest ) |
| otherwise = (1, rest ) |
||
Line 1,275: | Line 1,275: | ||
main :: IO () |
main :: IO () |
||
main = |
main = mapM_ putStrLn $ |
||
translation <$> [7259, 86400, 6000000]</lang> |
translation <$> [7259, 86400, 6000000]</lang> |
||