Skip to content

Instantly share code, notes, and snippets.

@kuribas
Last active June 25, 2018 08:55
Show Gist options
  • Save kuribas/e509bd294cf93b8b49cc3f6ac55caa60 to your computer and use it in GitHub Desktop.
Save kuribas/e509bd294cf93b8b49cc3f6ac55caa60 to your computer and use it in GitHub Desktop.
numbers rank
import Data.List
import Data.Function
rank :: [Int] -> [Int]
rank = order . order
where
order =
map fst .
sortBy (compare `on` snd) .
zip [1..]
(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