Skip to content

Instantly share code, notes, and snippets.

@trendsetter37
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save trendsetter37/a1497f2a36a0e6379468 to your computer and use it in GitHub Desktop.

Select an option

Save trendsetter37/a1497f2a36a0e6379468 to your computer and use it in GitHub Desktop.
HackerRank challenge Cut The Sticks in Common Lisp
(defun space-split (string)
"works for integers only at this point"
(loop for start = 0 then (1+ finish) ;; increments start by the value of finish
for finish = (position #\Space string :start start) ;; gives position of the next space begins at start
collecting (parse-integer (subseq string start finish)) ;; gathers integers from string list
until (null finish))) ;; continue until finish is nil (runs off the end of the string)
(defun cut-sticks (sticks)
(do ((rest (sort sticks #'<)
(remove (car rest) rest)))
((null rest))
(format t "~d~%" (length rest))))
(read) ;; Just here for consumption. Do not need the length with this implementation
(cut-sticks (space-split (read-line)))
#| Credit goes to the Lisp guys over at StackOverflow for helping me with this one |#
#| http://stackoverflow.com/questions/26454550/cut-the-stick-hackerrank-challenge-lisp-implementation |#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment