My knight's tour does not seem to end

Hi, I tried an implementation of knight's tour and it does not seem to terminate. I am looking for some feedback on algorithm and Haskellness of my implementation (knight.hs attached). -- Regards, Kashyap

Isn't mark is always increasing the size of the board? - I haven't run the code but I if this is the behaviour you want 'mark' is probably not a good name (I'd expect mark to be returning something the same size but with marked elements). In _mark_ the before and after are always splits, so the concatenation on the first line of the definition of _mark_ is taking the splits and adding more between them thus expanding the board.

Apologies -- I was running a wrong snippet. Mark is working correctly,
I'll have another look...
On 10 October 2010 09:15, Stephen Tetley
Isn't mark is always increasing the size of the board? - I haven't run the code but I if this is the behaviour you want 'mark' is probably not a good name (I'd expect mark to be returning something the same size but with marked elements).
In _mark_ the before and after are always splits, so the concatenation on the first line of the definition of _mark_ is taking the splits and adding more between them thus expanding the board.

Hello Kashyap Quite probably the algorithm is working correctly just that for boards
5 it takes a pathologically long time (for boards <= 5 I haven't checked the answer is correct just that it is computed).
In the first message I was looking for places where the input data grew or stayed constant size rather than got pruned. If you have runaway recursive a first debugging step is often to look for errors in pruning. Unfortunately I read the code wrongly, apologies again. To get it to work better, an improved search strategy would help, also better data structure that allows efficient indexing would be nice. That said, a clever algorithm can do a lot without indexing - you might want to search for Richard Bird's Sudoku slide presentation which is expanded in his new book. This paper has search strategies in a lazy setting and a version of n-Queens: Thomas Nordin and Andrew Tolmach - Modular Lazy Search for Constraint Satisfaction Problems http://web.cecs.pdx.edu/~apt/jfp01.ps Best wishes Stephen

Thank you Stephen,
Quite probably the algorithm is working correctly just that for boards
5 it takes a pathologically long time (for boards <= 5 I haven't checked the answer is correct just that it is computed).
I checked it out with 5 and looks like the answer is correct also :)
In the first message I was looking for places where the input data grew or stayed constant size rather than got pruned. If you have runaway recursive a first debugging step is often to look for errors in pruning. Unfortunately I read the code wrongly, apologies again.
no problem :)
To get it to work better, an improved search strategy would help, also better data structure that allows efficient indexing would be nice. That said, a clever algorithm can do a lot without indexing - you might want to search for Richard Bird's Sudoku slide presentation which is expanded in his new book.
Did you mean this http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/sudoku.pdf? Also, is this the book - http://www.flipkart.com/pearls-functional-algorithm-design-richard-book-0521... I dont have this book ... but looks like its a must have.
This paper has search strategies in a lazy setting and a version of n-Queens:
Thomas Nordin and Andrew Tolmach - Modular Lazy Search for Constraint Satisfaction Problems http://web.cecs.pdx.edu/~apt/jfp01.ps
This is probably what I like (and dislike - in a nice way) - my quest to master Haskell has been like traversing through a ever expanding tree :) Very different from a bunch of "learn over a weekend" language!!! -- Regards, Kashyap

On 10 October 2010 11:31, C K Kashyap
Did you mean this http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/sudoku.pdf?
I was actually meaning these slides... http://icfp06.cs.uchicago.edu/bird-talk.pdf
Also, is this the book - http://www.flipkart.com/pearls-functional-algorithm-design-richard-book-0521... I dont have this book ... but looks like its a must have.
Its very good - my copy arrived on Friday, so I've only scan read it so far.For "algorithmics" in the functional style its probably indispensable, for the people less algorithmically inclined (which I suppose is me really as I've never derived an algorithm "on paper") its still a very nice collection of crafted functional programs.

Stephen Tetley wrote:
On 10 October 2010 11:31, C K Kashyap
wrote: Did you mean this http://www.cs.tufts.edu/~nr/comp150fp/archive/richard-bird/sudoku.pdf?
I was actually meaning these slides... http://icfp06.cs.uchicago.edu/bird-talk.pdf
But the paper is definitely worth reading, too! Though it requires only elementary Haskell knowledge, it is still some piece of work if you try to follow all the details. C K Kashyap wrote:
This is probably what I like (and dislike - in a nice way) - my quest to master Haskell has been like traversing through a ever expanding tree :) Very different from a bunch of "learn over a weekend" language!!!
Absolutely. And IME it never ends. I have studied Haskell for over 6 years now and I still find lots of stuff out there that makes my brain hurt (like Oleg's iteratee/enumerator code; though I feel like I am on the verge of finally getting the hang of it). Cheers Ben
participants (3)
-
Ben Franksen
-
C K Kashyap
-
Stephen Tetley