[Tutor] fake defrag revisited

Dave Angel d at davea.name
Wed Oct 5 15:18:23 CEST 2011


On 10/05/2011 07:58 AM, R. Alan Monroe wrote:
>> Since all the moves are swaps, it'll be guaranteed to be in a sequence
>> that converges on the correct final order.  Will it be the minimum
>> number of moves? Definitely not.  But that wasn't a requirement, and if
>> it were, you wouldn't start by building that list of tuples.
> I did get a semi-working version, but it was crazy inefficient because
> it regenerated the swap list after every move, and it bombed out with
> a IndexError about half the time. I found that moving a single block
> at a time lacked the aesthetic appeal I was hoping for, so I bagged it
> for now.
>
> I changed gears and wrote a similar program to randomize all the
> pixels in a photo and then restore them one by one, by using two
> shuffled arrays as large as the pixel count to swap/unswap
> known-but-seemingly-random pixel pairs, but that also lacked the
> aesthetic appeal I wanted.
>
> I think to capture visual interest, the pieces would have to visibly
> assemble themselves by travelling across the screen, rather that just
> being painted in their final poistion. I may be biting off more than I
> can chew here.
>
> Alan
>
> __
I still recommend using sort, but perhaps the bulit-in sort is too 
fast.  Why not try a bubble sort first, where only adjacent pixels are 
swapped, and only if they're in the wrong order.

Then once you have the mechanism (a compare function, and a swap 
function) in place, you can try other algorithms, some faster and some 
slower.

I knew somebody who put together a demo sorting a random string of 2000 
characters, simply doing the sort algorithm directly on the video 
hardware screen buffer.   Processors were so slow (4mhz) that the 
display worked great, showing bubble sort traversing  back and forth, 
and showring various other algorithms being faster.  And the quicksort 
algorithm pretty much shimmered for a moment, then stopped with the 
characters in their final places.

Anyway, you can slow it down drastically by alternating bubble passes 
with random passes, where in each case a random pair is swapped if 
they're out of order.

DaveA


-- 

DaveA



More information about the Tutor mailing list