Re: [Tutor] Array pointers

2005-01-06 Thread Alan Gauld
> Pixels - just ones and zeroes? Pack them as integers and apply the > right shift operator: > i>>=1 But you have to remember to overflow right hand ones into the next integer if there are more than 32 bits... Although Python long integers migfht work, dunno what the speed of shifting a long i

Re: [Tutor] Array pointers

2005-01-05 Thread Orri Ganel
I don't know about a large calculation time, but this seems to work: >>> def rightshift(a): ia = a[:] for i in range(len(ia)-1,0,-1): if ia[i-1] == 1 and ia[i]!=1: ia[i]=1 ia[i-1]=0 return ia

Re: [Tutor] Array pointers

2005-01-05 Thread "Jörg Wölke"
Hello! > > I want to move all the 1's move to the right, 1 index at a time, > > preserving any spacing. [ snip ] > > I'm starting to think I'm going to have to go Cpp for this kind of > > direct pixel tweaking stuff. > > (640x480 (let alone 1024x768) is a lot of pixels to run through a for... >

Re: [Tutor] Array pointers

2005-01-05 Thread 沈洁元
This code will work. a=[1,0,0,0,0,1,1,1,0,1,1,0,1,0] shorta=a[:] while 0 in shorta: shorta.reverse() shorta.remove(0) shorta.reverse() print [0,]*(len(a)-len(shorta))+shorta result=[0,]*(len(a)-len(shorta))+shorta Juan Shen 在 2005年1月5日 星期三 11:44,Liam Clarke 写道: > Sorry rephrase

Re: [Tutor] Array pointers

2005-01-05 Thread Alan Gauld
> > I want to move all the 1's move to the right, 1 index at a time, > > preserving any spacing. > > So you want to insert a zero at the front and delete the first > zero from the back? That doesn't require iterating over all > the entries just enough to find the first zero... Playing with this

Re: [Tutor] Array pointers

2005-01-04 Thread Alan Gauld
> I want to move all the 1's move to the right, 1 index at a time, > preserving any spacing. So you want to insert a zero at the front and delete the first zero from the back? That doesn't require iterating over all the entries just enough to find the first zero... > [1,0,0,0,0,1,1,1,0,1,1,0,1,

Re: [Tutor] Array pointers

2005-01-04 Thread Liam Clarke
Sorry rephrase - So I have a list - [0,0,0,0,0,1,1,1,0,1,1,0,1,0] I want to move all the 1's move to the right, 1 index at a time, preserving any spacing. i.e. [1,0,0,0,0,1,1,1,0,1,1,0,1,0] [0,1,0,0,0,0,1,1,1,0,1,1,0,1] [0,0,1,0,0,0,0,1,1,1,0,1,1,1] [0,0,0,1,0,0,0,0,1,1,1,1,1,1] [0,0,0,0

[Tutor] Array pointers

2005-01-04 Thread Liam Clarke
Hi all, Just playing with Pygame, attempting to build a version of Scorched Earth if you remember it. I want to represent dirt, and so far I've come up with using a surface array - 0 644120 64412 64412 00 64412 64412 64412 0 644120