slightly cleaner?
Haldean Brown
3 years ago
119 | 119 | |
120 | 120 | guardSleepTimes :: [Shift] -> [(Integer, Int)] -- sleep time, guard id |
121 | 121 | guardSleepTimes shifts = |
122 | L.sort | |
123 | $ map (\gid -> (sum $ map getSleepTime $ filter (\s -> shiftGuard s == gid) shifts, gid)) | |
124 | $ S.toList | |
125 | $ allGuards shifts | |
122 | shifts | |
123 | & allGuards | |
124 | & S.toList | |
125 | & map (\gid -> (sum $ map getSleepTime $ filter (\s -> shiftGuard s == gid) shifts, gid)) | |
126 | & L.sort | |
126 | 127 | |
127 | 128 | sleepiestGuard :: [Shift] -> Int |
128 | 129 | sleepiestGuard = snd . L.maximum . guardSleepTimes |
137 | 138 | guardMinutes :: Int -> [Shift] -> [(Int, Int)] |
138 | 139 | guardMinutes g allShifts = |
139 | 140 | let shifts = filter ((==) g . shiftGuard) allShifts |
140 | minutes = [0..59] | |
141 | in map (countSleepMinutes shifts) minutes where | |
141 | in map (countSleepMinutes shifts) [0..59] where | |
142 | 142 | countSleepMinutes shifts m = (length $ filter (isAsleepAt m) shifts, m) |
143 | 143 | |
144 | 144 | sleepiestMinute :: Int -> [Shift] -> (Int, Int) -- sleeps, minute |