# [Tutor] pytunes (Was __slots__, struct, etc.)

Liam Clarke ml.cyresse at gmail.com
Fri Oct 21 09:44:25 CEST 2005

```Hmmm, that's interesting.

Obviously, for a playlist with x songs, and n songs by a particular
artist, the optimum separation between songs would be x/n.

Which would be easy for one artist, but for all of them?

Hmm...

Let's see. First off, let's discount all the artists with only one
song, they can be the space filler.

Next, you'd have to work out optimal spacing for each artist's songs,
and try to insert them into a list. If that slot was already taken,
you'd want to look down and up the list for the next free space,
choosing whichever maximised the distance. And you'd have to treat
x[5] - 10 as x[96] for a list x where len(x) == 100.

Err, there's got to be an algorithm for this sorta stuff, but I can't

On 10/21/05, John Fouhy <john at fouhy.net> wrote:
> Hmm, neat. I don't have any feedback for you on your code, but since
> you're working with this sort of thing, I have a puzzle for you:
>
> Suppose you have a collection of MP3 files.  You want to build a
> random playlist, subject to the condition that tracks by the same
> artist are as far apart as possible.  You can assume you have the
> track / artist data in any structure you like.  How would you do this?
>
> (I have a solution, but I don't think it is optimal.  In fact, I'm not
> sure how to actually define "optimal" here... And so I am interested
> in how other people would solve this problem :-) )
>
> --
> John.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
```