At the bottom of that script you have a section of comments which
begins "Raul M.'s brute force sudoku instance. (doesn't work for me)."

So I tried to run it, and the first failure I encountered was:

|domain error: script
|   C    =:,|:9#,:i.9

That's an error because I was running your code as a script, and your
script had already declared C as a local variable.  (Assigning to a
global name in a context where that name is local is almost always an
error, and if you really need to accomplish that you can always use a
fresh context as the mechanism.)

So I copied and pasted the lines into a J session, and it didn't
produce any error messages. But it also didn't solve any sudoku
puzzles.

If I recall correctly, when I originally wrote that code I was not
trying to solve a sudoku puzzle - Roger Hui already has a sudoku
solver up, and you were working on a system loosely related to sudoku
puzzle solvers but also introducing some abstractions which would not
be necessary. Anyways, I remember thinking that I was trying to
re-express to you the concepts that I understood you expressing to me.
(This might have been a module in a program to solve sudoku puzzles
(and more generalized puzzles) but I don't think it was anything like
a complete solutions.)

Anyways, I hope to take some time to understand your code, but I
thought I'd comment on that block at the bottom since it initially
confused me.

Thanks,

-- 
Raul


On Fri, Jun 28, 2013 at 12:14 AM, Michal D. <[email protected]> wrote:
> The attached file didn't come through:
>
> http://pastebin.com/Qf5j35dg
>
>
> On Wed, Jun 26, 2013 at 10:47 PM, Michal D. <[email protected]>wrote:
>
>> Hi Mike,
>>
>> I don't fully follow your example because it never returns a value that
>> you are searching for.  Something like this would seem to make more sense
>> to me:
>>
>> def bk(w)
>>   if illegal(w) return null
>>   if goal(w) return w
>>   a = bk(w+'a'); if a != null then return a
>>   b = bk(w+'b'); if b != null then return b
>>   c = bk(w+'c'); if c != null then return c
>> end
>> bk('')
>>
>> The above also doesn't jive all that well with "searching for the longest
>> string" which seems like a potentially infinite endeavour.
>>
>> I have attached some code I quickly hacked up for doing arc consistency
>> search.  There's a lot more context there but you are interested in the
>> 'search' function.  Maybe someone else can shed light on how to pass around
>> and apply verbs as arguments.  Combining the two would give you what you're
>> looking for I think.
>>
>> Like Raul said, this isn't the use case where J shines unless the
>> computations denoted by illegal(), goal() or +'a' are significant.
>>
>> Cheers,
>>
>> Mike
>>
>>
>>
>>
>> On Wed, Jun 26, 2013 at 1:37 AM, Mike Müller <[email protected]> wrote:
>>
>>> Hello!
>>>
>>> I hope this is not too simple a question for this list, but I'm still
>>> learning J and wonder how to do a simple backtracking in J.
>>> For instance, I might want to see what is the longest string consisting
>>> of a,b, and c, that fulfills some property P.
>>> In any imperative language (here: ruby) I would do something like this…
>>>
>>> def bk(w)
>>>    if (!P(w)) return
>>>    bk(w+"a")
>>>    bk(w+"b")
>>>    bk(w+"c")
>>> end
>>> bk("")
>>>
>>> …and combine it with some bookkeeping of which was the longest that I've
>>> seen so far and maybe some output every 100 steps,
>>> if there is actually no longest one (that is, there is an infinite one
>>> fulfilling P).
>>>
>>> I'm very interested how to do these kind of things elegantly in J.
>>>
>>> Best regards,
>>> Mike
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to