Last active
March 12, 2018 14:28
-
-
Save samidarko/7a74c52eae60dfaf5b98d35544b10618 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data HotelRank = HotelRank { idh :: Integer, rank :: Integer } deriving (Show, Eq) | |
| instance Ord HotelRank where | |
| compare (HotelRank i r) (HotelRank i' r') | |
| | r == r' = compare i i' | |
| | otherwise = if compare r r' == GT then LT else GT | |
| l = [(4000, 8), (3000, 7), (2000, 8), (1000, 5), (2000, 5), (4000, 5), (3000, 2)] | |
| rankings = map (\(i, r) -> (HotelRank i r)) l | |
| rankingsMap = foldl fn M.empty rankings | |
| where fn acc h = case M.lookup (idh h) acc of | |
| Just(h') -> M.insert (idh h) (h' { rank = rank h + rank h' }) acc | |
| _ -> M.insert (idh h) h acc | |
| mergedRankings = M.elems rankingsMap | |
| sortedRangkings = L.sort mergedRanking |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment