From: Tel A.
Subject: Lisp Challenge
Date: 
Message-ID: <1142564802.364504.8010@v46g2000cwv.googlegroups.com>
I'm recently dropping into lisp after spending a great deal of time
with Ruby. While the stuff that filters to c.l.l here is great, I
wonder if there is perhaps a lisp analog to Ruby Quiz
(http://www.rubyquiz.com/) somewhere as I've found Ruby Quiz wonderful
for exposing obscure tricks and techniques for solving problems.

Anyone know of something you could by some stretch call Lisp Quiz?

From: Eric Lavigne
Subject: Re: Lisp Challenge
Date: 
Message-ID: <1142566377.162590.322530@i39g2000cwa.googlegroups.com>
> I'm recently dropping into lisp after spending a great deal of time
> with Ruby. While the stuff that filters to c.l.l here is great, I
> wonder if there is perhaps a lisp analog to Ruby Quiz
> (http://www.rubyquiz.com/) somewhere as I've found Ruby Quiz wonderful
> for exposing obscure tricks and techniques for solving problems.
>
> Anyone know of something you could by some stretch call Lisp Quiz?

Even though it is a Ruby site, the problems seem rather language
neutral. Maybe you could solve problems from that site and post the
answers for review/critique on this newsgroup.
From: Tel A.
Subject: Re: Lisp Challenge
Date: 
Message-ID: <1142568147.327381.242800@e56g2000cwe.googlegroups.com>
Alright, sounds good.

Why not get it started then -- For all who are interested, what are
some solutions to Ruby Quiz #43 (http://www.rubyquiz.com/quiz43.html)
written in lisp? I'm interested to see how people tackle the string
manipulation as its something I've been wrestling myself in various
forms.

I'm currently working on a solution myself, but as I'm very new to the
language it will likely be some time before it is complete.
From: Eric Lavigne
Subject: Re: Lisp Challenge
Date: 
Message-ID: <1142571324.265886.44330@z34g2000cwc.googlegroups.com>
>Why not get it started then -- For all who are interested, what are
>some solutions to Ruby Quiz #43 (http://www.rubyquiz.com/quiz43.html)
>written in lisp? I'm interested to see how people tackle the string
>manipulation as its something I've been wrestling myself in various
>forms.

There was a discussion on Sudoku solutions on this mailing list,
starting on Feb 20, under the title "Sudoku Solver" which started with
this code posting: http://www.frank-buss.de/lisp/sudoku.html

It is not exactly what you want, though, since the input is provided in
a very program friendly manner: no +,-,|, or _, just lists of lists of
numbers with blanks represented by zeroes. That makes the parsing step
very simple in Lisp:
(defvar *board* (read))

For the tougher parsing required for the Ruby Quiz, I suspect the Ruby
and Lisp parsing would not be so different. For Lisp regular
expressions (ripped off shamelessly from Perl) see
http://weitz.de/cl-ppcre/
From: Juho Snellman
Subject: Re: Lisp Challenge
Date: 
Message-ID: <slrne1kfc3.tcn.jsnell@sbz-30.cs.Helsinki.FI>
Tel A. <············@gmail.com> wrote:
> Alright, sounds good.
> 
> Why not get it started then -- For all who are interested, what are
> some solutions to Ruby Quiz #43 (http://www.rubyquiz.com/quiz43.html)
> written in lisp? I'm interested to see how people tackle the string
> manipulation as its something I've been wrestling myself in various
> forms.

The solution depends on how you intend to represent the board
internally. For example with a 9x9 array, with the array cells being
integers (0 for empty squares, 1-9 for the others):

(defun make-board (string)
  (let* ((array (make-array '(9 9))))
    (map-into (make-array (* 9 9) :displaced-to array)
              #'digit-char-p
              (remove-if-not #'digit-char-p (substitute #\0 #\_ string)))
    array))

(I'm afraid this isn't going to teach you much about CL string
 manipulation in general, but who could resist an opportunity to
 use both MAP-INTO and displaced arrays in a four-line function?)

-- 
Juho Snellman
From: Peter Seibel
Subject: Re: Lisp Challenge
Date: 
Message-ID: <m2oe051vy9.fsf@gigamonkeys.com>
Juho Snellman <······@iki.fi> writes:

> Tel A. <············@gmail.com> wrote:
>> Alright, sounds good.
>> 
>> Why not get it started then -- For all who are interested, what are
>> some solutions to Ruby Quiz #43
>> (http://www.rubyquiz.com/quiz43.html) written in lisp? I'm
>> interested to see how people tackle the string manipulation as its
>> something I've been wrestling myself in various forms.
>
> The solution depends on how you intend to represent the board
> internally. For example with a 9x9 array, with the array cells being
> integers (0 for empty squares, 1-9 for the others):
>
> (defun make-board (string)
>   (let* ((array (make-array '(9 9))))
>     (map-into (make-array (* 9 9) :displaced-to array)
>               #'digit-char-p
>               (remove-if-not #'digit-char-p (substitute #\0 #\_ string)))
>     array))
>
> (I'm afraid this isn't going to teach you much about CL string
>  manipulation in general, but who could resist an opportunity to
>  use both MAP-INTO and displaced arrays in a four-line function?)

Since I've already used displaced arrays today, here's a version that
uses another fine feature, ROW-MAJOR-AREF. It also reads the text
version from a stream as the quiz problem requests.

  (defun parse-sodoku (in)
    (loop with board = (make-array '(9 9)) and i = 0
       for char = (read-char in nil nil) while char
       when (find char "_123456789") do
         (setf (row-major-aref board i) (digit-char-p char))
         (incf i)
       finally (return board)))

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Stefan Haflidason
Subject: Re: Lisp Challenge
Date: 
Message-ID: <1142594496.952029.104730@p10g2000cwp.googlegroups.com>
In order to follow the rules of the quiz we would need to be presented
with the problem, and then only discuss everyone's solutions after a
deadline to avoid 'spoilers'.

To do that we would need a site much like the Ruby Quiz site, or for
people to avoid discussion on the list until a particular date. Would
that be something this list would be interested in?

I'm eagerly studying Lisp, but I am very short on time as I am in my
final year of a degree course. It would really need someone very
experienced in Lisp to run it, which leads me to believe that if it was
wanted then someone would have already created it. If that's not the
case, speak out!

Stefan.
From: Vladimir Zolotykh
Subject: Re: Lisp Challenge
Date: 
Message-ID: <20060317131530.21eba596.gsmith@eurocom.od.ua>
On Fri, 17 Mar 2006 05:28:31 GMT
Peter Seibel <·····@gigamonkeys.com> wrote:

> Juho Snellman <······@iki.fi> writes:
> 
> > Tel A. <············@gmail.com> wrote:
> >> Alright, sounds good.
> >> 
> >> Why not get it started then -- For all who are interested, what are
> >> some solutions to Ruby Quiz #43
> >> (http://www.rubyquiz.com/quiz43.html) written in lisp? I'm
> >> interested to see how people tackle the string manipulation as its
> >> something I've been wrestling myself in various forms.
> >
> > The solution depends on how you intend to represent the board
> > internally. For example with a 9x9 array, with the array cells being
> > integers (0 for empty squares, 1-9 for the others):
> >
> > (defun make-board (string)
> >   (let* ((array (make-array '(9 9))))
> >     (map-into (make-array (* 9 9) :displaced-to array)
> >               #'digit-char-p
> >               (remove-if-not #'digit-char-p (substitute #\0 #\_ string)))
> >     array))
> >
> > (I'm afraid this isn't going to teach you much about CL string
> >  manipulation in general, but who could resist an opportunity to
> >  use both MAP-INTO and displaced arrays in a four-line function?)
> 
> Since I've already used displaced arrays today, here's a version that
> uses another fine feature, ROW-MAJOR-AREF. It also reads the text
> version from a stream as the quiz problem requests.
> 
>   (defun parse-sodoku (in)
>     (loop with board = (make-array '(9 9)) and i = 0
>        for char = (read-char in nil nil) while char
>        when (find char "_123456789") do
>          (setf (row-major-aref board i) (digit-char-p char))
>          (incf i)
>        finally (return board)))

Kindly forgive my stupidity. I must have missed something. Let me
quote from http://www.rubyquiz.com/quiz43.html :

  "The task is to fill in the remaining digits (1 through 9 only) such
  that each row, column, and 3 x 3 box contains exactly one of each
  digit. Here's the solution for the above puzzle:"

Neither make-board, nor parse-sodoku does exactly that. What have I
missed?

Besides, I have another, I think more interesting task for a smart
Lisp program. It runs thus:

There are fifteen balls, two of which are radioactive. Also there is a
device which can measure if this collection of balls is radioactive or
not. It doesn't say how many balls in the measured set are
radioactive, just "Yes" or "No", e.g. if at least one ball is active
it says "Yes" otherwise "No". The task is to identify exactly the two
radioactive balls taking not more that seven measures. The number of
balls in the set being measured is not limited. It could be one ball
or fifteen of them.

> 
> -Peter
> 
> -- 
> Peter Seibel           * ·····@gigamonkeys.com
> Gigamonkeys Consulting * http://www.gigamonkeys.com/
> Practical Common Lisp  * http://www.gigamonkeys.com/book/


-- 
Vladimir Zolotykh
From: Juho Snellman
Subject: Re: Lisp Challenge
Date: 
Message-ID: <slrne1le2q.cq3.jsnell@sbz-30.cs.Helsinki.FI>
Vladimir Zolotykh <······@eurocom.od.ua> wrote:
> Kindly forgive my stupidity. I must have missed something. Let me
> quote from http://www.rubyquiz.com/quiz43.html :
> 
>   "The task is to fill in the remaining digits (1 through 9 only) such
>   that each row, column, and 3 x 3 box contains exactly one of each
>   digit. Here's the solution for the above puzzle:"
> 
> Neither make-board, nor parse-sodoku does exactly that. What have I
> missed?

The original poster was especially interested in how people do the
parsing.

Sudoku solvers are dime-a-dozen. Anyone interested in that can easily
use a search engine to find many examples written using different
algorithms, in Lisp or other languages. Writing yet another one didn't
strike me as either interesting or a good use of my time. I presume
the same is true for Peter.

-- 
Juho Snellman
From: Peter Seibel
Subject: Re: Lisp Challenge
Date: 
Message-ID: <m2k6at197t.fsf@gigamonkeys.com>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> On Fri, 17 Mar 2006 05:28:31 GMT
> Peter Seibel <·····@gigamonkeys.com> wrote:
>
>> Juho Snellman <······@iki.fi> writes:
>> 
>> > Tel A. <············@gmail.com> wrote:
>> >> Alright, sounds good.
>> >> 
>> >> Why not get it started then -- For all who are interested, what are
>> >> some solutions to Ruby Quiz #43
>> >> (http://www.rubyquiz.com/quiz43.html) written in lisp? I'm
>> >> interested to see how people tackle the string manipulation as its
>> >> something I've been wrestling myself in various forms.
>> >
>> > The solution depends on how you intend to represent the board
>> > internally. For example with a 9x9 array, with the array cells being
>> > integers (0 for empty squares, 1-9 for the others):
>> >
>> > (defun make-board (string)
>> >   (let* ((array (make-array '(9 9))))
>> >     (map-into (make-array (* 9 9) :displaced-to array)
>> >               #'digit-char-p
>> >               (remove-if-not #'digit-char-p (substitute #\0 #\_ string)))
>> >     array))
>> >
>> > (I'm afraid this isn't going to teach you much about CL string
>> >  manipulation in general, but who could resist an opportunity to
>> >  use both MAP-INTO and displaced arrays in a four-line function?)
>> 
>> Since I've already used displaced arrays today, here's a version that
>> uses another fine feature, ROW-MAJOR-AREF. It also reads the text
>> version from a stream as the quiz problem requests.
>> 
>>   (defun parse-sodoku (in)
>>     (loop with board = (make-array '(9 9)) and i = 0
>>        for char = (read-char in nil nil) while char
>>        when (find char "_123456789") do
>>          (setf (row-major-aref board i) (digit-char-p char))
>>          (incf i)
>>        finally (return board)))
>
> Kindly forgive my stupidity. I must have missed something. Let me
> quote from http://www.rubyquiz.com/quiz43.html :
>
>   "The task is to fill in the remaining digits (1 through 9 only) such
>   that each row, column, and 3 x 3 box contains exactly one of each
>   digit. Here's the solution for the above puzzle:"
>
> Neither make-board, nor parse-sodoku does exactly that. What have I
> missed?

As Juho said, simply that we weren't trying to solve the whole
problem. There was a quite long thread about Sodoku solvers a couple
weeks back; anyone who wants a complete solution to the quiz should
grab the best solver out of that bunch and hook it up to one of these
parsers.

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Tel A.
Subject: Re: Lisp Challenge
Date: 
Message-ID: <1142635369.697461.12400@u72g2000cwu.googlegroups.com>
Alright, I admit that my choice of problem was perhaps not the best
considering there was a Sudoku solver thread very recently. Apologies.

Stefan brings up an interesting point though. Are people really
interested in this sort of thing? Ruby Quiz could be justified by the
fact that Ruby is a new language to the mainstream and growing
visibility is certainly A Good Thing; however, that doesn't appear to
be lisp's situation at all.

Would people be interested in that sort of activity? If so, why doesn't
it exist already? Was it attempted before?

I'm considering experimenting a little. Perhaps if there is interest, a
problem could be set up with solutions being sent to a neutral email
adress and posted after a grace period?

Think it'd be worthwhile?
From: Peter Seibel
Subject: Re: Lisp Challenge
Date: 
Message-ID: <m28xr81xkv.fsf@gigamonkeys.com>
"Tel A." <············@gmail.com> writes:

> Alright, I admit that my choice of problem was perhaps not the best
> considering there was a Sudoku solver thread very recently. Apologies.
>
> Stefan brings up an interesting point though. Are people really
> interested in this sort of thing? Ruby Quiz could be justified by the
> fact that Ruby is a new language to the mainstream and growing
> visibility is certainly A Good Thing; however, that doesn't appear to
> be lisp's situation at all.
>
> Would people be interested in that sort of activity? If so, why doesn't
> it exist already? Was it attempted before?
>
> I'm considering experimenting a little. Perhaps if there is interest, a
> problem could be set up with solutions being sent to a neutral email
> adress and posted after a grace period?

You might want to join the cl-gardeners' mailing list[1] and see if
anyone there is interested in helping you out. Or just go for it and
see what you come up with. I'm sure folks here or on the Gardeners'
list will be happy to kibitz once there's something to kibitz about.

-Peter

[1] http://www.lispniks.com/cl-gardeners/>

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/