Skip to content

Instantly share code, notes, and snippets.

@imjacobclark
Last active February 3, 2019 17:57
Show Gist options
  • Save imjacobclark/2e425414567c23aa8baf25cd294d2faa to your computer and use it in GitHub Desktop.
Save imjacobclark/2e425414567c23aa8baf25cd294d2faa to your computer and use it in GitHub Desktop.
Pad numbers to same length
(defun pad(thing)
(concatenate 'string "0" thing))
(defun pad-if-length-not-same(thing length)
(cond
((not
(= (length thing) length))
(pad thing))
(t thing)))
(defun pad-list(things length)
(mapcar
(lambda (thing)
(pad-if-length-not-same thing length))
things))
(defun pad-to-length(things length accumulator)
(cond
(
(not (= accumulator (1- length)))
(pad-to-length
(pad-list things length) length (1+ accumulator)))
(t things)))
(defun sort-by-length(a b) (< (length a) (length b)))
(defun get-largest-length(things)
(length
(car
(last
(sort things #'sort-by-length)))))
(defun main(things)
(pad-to-length
things
(get-largest-length things)
0))
(print
(main '("1" "19" "2" "3" "55" "4" "12" "100" "1000")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment