Skip to content

Instantly share code, notes, and snippets.

@vermiculus
Last active August 29, 2015 14:20
Show Gist options
  • Save vermiculus/3463a8cfb2b84f137dfd to your computer and use it in GitHub Desktop.
Save vermiculus/3463a8cfb2b84f137dfd to your computer and use it in GitHub Desktop.
(defun tmp:four* (&rest l)
(when (< (apply #'min l) 0)
(error "All elements must be positive"))
(string-to-number
(apply
#'concat
(nreverse
(sort (mapcar #'number-to-string l)
#'string-lessp)))))
(defun tmp:four (&rest l)
"Returns the largest number obtainable with subsequences L.
Write a function that given a list of non negative integers,
arranges them such that they form the largest possible number.
For example, given [50, 2, 1, 9], the largest formed number is
95021.
<https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour>"
(when (< (apply #'min l) 0)
(error "All elements must be positive"))
(string-to-number
(apply
#'concat
(sort (mapcar #'number-to-string l)
(lambda (a b) (not (string< a b)))))))
(tmp:four 50 2 1 9)
; => 95021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment