Last active
June 25, 2018 08:55
-
-
Save kuribas/e509bd294cf93b8b49cc3f6ac55caa60 to your computer and use it in GitHub Desktop.
numbers rank
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
import Data.List | |
import Data.Function | |
rank :: [Int] -> [Int] | |
rank = order . order | |
where | |
order = | |
map fst . | |
sortBy (compare `on` snd) . | |
zip [1..] |
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
(defun with-index (l &key (start 0)) | |
(if (null l) '() | |
(cons (cons start (car l)) | |
(with-index (cdr l) :start (+ start 1))))) | |
(defun rank (l) | |
(flet ((order (l) | |
(mapcar #'car | |
(sort (with-index l :start 1) | |
#'< :key #'cdr)))) | |
(order (order l)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment