[Tutor] 15 puzzle
Remco Gerlich
scarblac@pino.selwerd.nl
Wed, 9 May 2001 11:50:22 +0200
On 0, alan.gauld@bt.com wrote:
> > Of course, first I have to figure out how to scramble
> > the buttons in order to have an actual game going.
>
> Create a list of numbers
> generate a random index into the list using randint()
> move that number into a new list and delete from the original.
>
> Something like:
>
> baselist = newList = []
Oops. Assign by reference, remember?
> for i in range(15): baseList.append(str(i))
So this appends to both. (And later on as well).
Use random.shuffle, i.e.
import random
buttons = range(15)
random.shuffle(buttons)
print buttons
--
Remco Gerlich