lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.