I created an algorithm that takes a non-negative Int value representing the total number of minutes, and returns a triple that gives (days, hours, minutes) that this matches.
Here is my code:
calcdays :: Int -> Int calcdays x = x `div` (24*60) calchours :: Int -> Int calchours x = (x - ((calcdays x)*24*60)) `div` 60 calcmins :: Int -> Int calcmins x = (x - ((calcdays x)*24*60) - ((calchours x)*60)) dayshoursmins :: Int -> (Int,Int,Int) dayshoursmins x = (calcdays x, calchours x, calcmins x)
Using only the basic Haskell operations (guards, divs, mods, etc.), is there an easier way to program this function?
EDIT:
I used the sentence below to make this code simpler, although not as simple as the qoutRem solution, I thought I could post it:
calcdays :: Int -> Int calcdays x = x `div` (24*60) calchours :: Int -> Int calchours x = (x `mod` (24*60)) `div` 60 calcmins :: Int -> Int calcmins x = (x `mod` (24*60)) `mod` 60 dayshoursmins :: Int -> (Int,Int,Int) dayshoursmins x = (calcdays x, calchours x, calcmins x)
source share