More lispyness July 11, 2006

I saw a blog entry comparing languages in terms of terseness. I agree that the ruby version maximizes both terseness and readability, but I couldn't help but make my own contribution in common lisp:


(loop for flipcount = 0 then (read)
      for numbers = (sort (loop for i from 1 upto 9 collect i)
                          (lambda (a b) (zerop (random 2))))
      then (nconc (reverse (subseq numbers 0 flipcount))
                  (subseq numbers flipcount))
      as steps from 0
      until (apply #'< numbers) do
      (format t "~{~a~^ ~}~%Reverse how many? " numbers)
      (force-output)
      finally (format t "~{~a~^ ~}~%Done!  That took you ~a steps.~%" numbers steps))

Muhahaha.


1 comment posted.

07/15/2006 - Ozone: Very nice solution, I really like the "sort by random".


Posting comment

To prevent comment spam, you must type a passcode into the passcode box. Right now, the passcode is elbow.

Name:
Passcode:
Comment:
(No HTML)