Last active
August 29, 2015 14:20
-
-
Save vermiculus/3463a8cfb2b84f137dfd to your computer and use it in GitHub Desktop.
This file contains 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 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))))) |
This file contains 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 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