git.haldean.org aoc-2018 / 7593865
slightly cleaner? Haldean Brown 2 years ago
1 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
119119
120120 guardSleepTimes :: [Shift] -> [(Integer, Int)] -- sleep time, guard id
121121 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
126127
127128 sleepiestGuard :: [Shift] -> Int
128129 sleepiestGuard = snd . L.maximum . guardSleepTimes
137138 guardMinutes :: Int -> [Shift] -> [(Int, Int)]
138139 guardMinutes g allShifts =
139140 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
142142 countSleepMinutes shifts m = (length $ filter (isAsleepAt m) shifts, m)
143143
144144 sleepiestMinute :: Int -> [Shift] -> (Int, Int) -- sleeps, minute