SPOILER : Re: [quiz] call for quizzes, and [QUIZ 4] centering

Sean rosssd at gmail.com
Thu Jul 12 09:09:12 UTC 2007


A solution using the minpad argument to ~A



(defun center (&rest list)
  (let ((max (reduce #'max vals :key #'length)))
    (mapcar #'(lambda (x)
                (format nil "~,,v at A" (floor (- max (length x)) 2) x))
            list)))


Sean.

On Wed, 2007-07-11 at 18:36 -0400, Larry Clapp wrote:
> I think there's interest in this list, I just think the guy that
> started it (Marco Baringer) ran out of or overestimated his free time.
> 
> If you have a puzzle or quiz, feel free to post it to the list.  Heck,
> if you have some (short) Lisp code that's just not working and you
> don't know why, post it to the list.
> 
> [ /me Googles ... ]
> 
> This list started as an imitation of the Perl quiz of the week, so
> I'll shamelessly copy their first quiz (see below).
> 
> I'd also like to ask everyone to take a moment and re-read the rules
> of the game as posted here[1].  In particular: no solutions for 48
> hours; if you post one after that, include "[SPOILER]" in the subject.
> I'll add to that: If you reply to a SPOILER thread and cut out the
> solution, you can remove SPOILER from the subject (or maybe change it
> to UNSPOILED just for fun :).  Also, the Perl quiz site has the
> following Q&A (paraphrased): Q: Where to I send my answer?  A: Don't
> feel obligated to send it anywhere.  The point of solving the puzzle
> is to have solved it.
> 
> I'm not Marco, of course, so feel free to ignore me.  :)
> 
> Anyway, the quiz:
> 
> Write a function, 'center', whose argument is a list of strings, which
> will be lines of text.  'center' should insert spaces at the beginning
> of the lines of text so that if they were printed, the text would be
> centered, and return the modified lines.
> 
> For example,
> 
>   (center "This" "is" "a test of the" "center function")
> 
> should return the list:
> 
>   ("     This" "      is" " a test of the" "center function")
> 
> because if these lines were printed, they would look like:
> 
>        This
>         is
>    a test of the
>   center function
> 
> -- Larry
> 
> 
> [1] http://common-lisp.net/project/quiz/
> 
> _______________________________________________
> quiz mailing list
> quiz at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/quiz
-- 
...Please don't assume Lisp is only useful for Animation and Graphics,
AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor
applications, Expert Systems, Finance, Intelligent Agents, Knowledge
Management, Mechanical CAD, Modeling and Simulation, Natural Language,
Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web
Authoring just because these are the only things they happened to list.

Kent Pitman.





More information about the Quiz mailing list