[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: n-queens -> save the solutions
- From: Olivier Galibert <galibert@...>
- Date: Mon, 1 Aug 2011 10:41:58 +0200
On Mon, Aug 01, 2011 at 09:09:00AM +0100, Maxime Chupin wrote:
> I am playing with the n-queen problem to learn Lua. I want to save all the
> solution in a list (solutions) but it does not work and I do not understand
> why. Here my very simple code with which my problem is more understandable.
You're saving a reference to q (and hence to Dq), not a copy of q. So
your solutions array will end up with a bunch of references to Dq,
which itself will be set at the final queen position.
Best,
OG.