Programming challenge

Derek Davis derek.davis at
Fri Sep 28 14:32:54 MDT 2007

> Woot!  Good stuff.  BTW, I don't think actually performing the
> calculation was part of the problem description.  As I understood it,
> it was purely string transformation of one time representation to
> another.

Sweet, that lets me simplify things a bit.  This solution assumes
valid input. :)

(defun parse-string (str)
  (apply #'concatenate 'string (mapcar #'process-time (split str #\Space))))

(defun process-time (str)
  (if (digit-char-p (char str 0))
      (write-to-string (let ((place (length (split str #\Colon))))
	(loop for x in (split str #\Colon)
	      summing (progn (setf place (1- place))
			     (* (expt 60 place) (read-from-string x))))))

(defun split (str char)
  (loop for i = 0 then (1+ j)
	as j = (position char str :start i)
	collect (subseq str i j)
	while j))

More information about the PLUG mailing list