Re: [long] nested lists as arrays

2005-02-20 Thread [EMAIL PROTECTED]
great thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: [long] nested lists as arrays

2005-02-14 Thread bruno modulix
[EMAIL PROTECTED] a écrit : Thanks for the code. What I want to do is this: I want to solve the block puzzle problem. The problem is as follows: You have a nxn Array of Numbers and one empty space. Now you there are up to four possible moves: up, right, down and left, so that each neighbour of the

Re: nested lists as arrays

2005-02-14 Thread Michael Spencer
Terry Reedy wrote: <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] def setRandomState(self): # container for the elements to pick from container = [1,2,3,4,5,6,7,8,-1] # create elements of puzzle randomly i = 0 j = 0 while i <= self.dim-1: whil

Re: nested lists as arrays

2005-02-14 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >def setRandomState(self): > # container for the elements to pick from > container = [1,2,3,4,5,6,7,8,-1] > > # create elements of puzzle randomly > i = 0 > j = 0 > while i <= self.dim-1: >

Re: nested lists as arrays

2005-02-14 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Allright. What difference in runtime and space would it make using > dictionaries instead? is this for an interactive game? if so, the answer is "none at all". (on my machine, you can make about 600 dict[x,y] accesses per second, compared to 750 list[x][y] acc

Re: nested lists as arrays

2005-02-14 Thread [EMAIL PROTECTED]
Allright. What difference in runtime and space would it make using dictionaries instead? Do you have a pointer for me concerning runtime of standard manipulations in Pythons? Thanks for the tip. -- http://mail.python.org/mailman/listinfo/python-list

Re: nested lists as arrays

2005-02-14 Thread [EMAIL PROTECTED]
Allright. What difference in runtime and space would it make using dictionaries instead? Do you have a pointer for me concerning runtime of standard manipulations in Pythons? Thanks for tip. -- http://mail.python.org/mailman/listinfo/python-list

Re: nested lists as arrays

2005-02-14 Thread Terry Reedy
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message > >And use xrange instead of range. For small dimensions like 3,4,5, xrange is way overkill and perhaps takes both more space and time. Since dim is a constant for a given puzzle, I would set self._range = range(dim) in __init__() and us

Re: Problem with nested lists as arrays

2005-02-14 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] 'Having trouble' is too vague to figure out. However, I would delete this: >def getEmptySlot(self): >i = 0 >j = 0 >while i <= self.dim-1: >while j <= self.dim-1: >if self.eleme

Re: nested lists as arrays

2005-02-14 Thread [EMAIL PROTECTED]
Thanks for the code. What I want to do is this: I want to solve the block puzzle problem. The problem is as follows: You have a nxn Array of Numbers and one empty space. Now you there are up to four possible moves: up, right, down and left, so that each neighbour of the empty slot can be moved the

Re: nested lists as arrays

2005-02-14 Thread Michael Spencer
naturalborncyborg wrote: Hi, I'm using nested lists as arrays and having some problems with that approach. In my puzzle class there is a swapelement method which doesn't work out. What "doesn't work out"? On casual inspection that method seems to "work": >

Re: nested lists as arrays

2005-02-14 Thread Fredrik Lundh
"naturalborncyborg" <[EMAIL PROTECTED]> wrote: > Hi, I'm using nested lists as arrays and having some problems with > that approach. In my puzzle class there is a swapelement method which > doesn't work out. what happens, and what do you expect? > Any

Re: nested lists as arrays

2005-02-14 Thread [EMAIL PROTECTED]
Diez B. Roggisch wrote: > [EMAIL PROTECTED] wrote: > > > Hi, > > > > why can't I do this: > > > > dummy = self.elements[toy][tox] > > > > self.elements[toy][tox] = self.elements[fromy][fromx] > > self.elements[fromy][fromx] = dummy > > > > after initialising my nested list

nested lists as arrays

2005-02-14 Thread naturalborncyborg
Hi, I'm using nested lists as arrays and having some problems with that approach. In my puzzle class there is a swapelement method which doesn't work out. Any help and comments on the code will be appreciated. Thanks. # Puzzle.py # class for a sliding block puzzle # an starting st

Re: nested lists as arrays

2005-02-14 Thread bruno modulix
[EMAIL PROTECTED] wrote: Hi, why can't I do this: dummy = self.elements[toy][tox] self.elements[toy][tox] = self.elements[fromy][fromx] self.elements[fromy][fromx] = dummy after initialising my nested list like this: self.elements = [[0 for column in range(dim)] for r

Re: nested lists as arrays

2005-02-14 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > Hi, > > why can't I do this: > > dummy = self.elements[toy][tox] > > self.elements[toy][tox] = self.elements[fromy][fromx] > self.elements[fromy][fromx] = dummy > > after initialising my nested list like this: > >self.elements = [[0 f

nested lists as arrays

2005-02-14 Thread [EMAIL PROTECTED]
Hi, why can't I do this: dummy = self.elements[toy][tox] self.elements[toy][tox] = self.elements[fromy][fromx] self.elements[fromy][fromx] = dummy after initialising my nested list like this: self.elements = [[0 for column in range(dim)] for row in range(dim) ]

Re: Problem with nested lists as arrays

2005-02-14 Thread Diez B. Roggisch
Some general remarks: > def getEmptySlot(self): > i = 0 > j = 0 > while i <= self.dim-1: > while j <= self.dim-1: > if self.elements[j][i] == -1: > return [j, i] > j = j+1 > j = 0 >

Problem with nested lists as arrays

2005-02-14 Thread benjamin . cordes
Hello, For a class modeling the block puzzle I use nested lists as arrays. Within this class there is a method for swaping elements. I have lots of trouble with that method but can't figure it out. It has probably to do with my unuseful approach to nested lists, but I don't want to writ