WARNING: I have no idea what I'm doing and errors probably abound.
I recently came across this incredible graphical and musical representation of sorting algorithms.
It got me thinking about the musical possibilities of such algorithms, and I immediately set about experimenting, taking a pseudo-random sample of 8 notes (the 5 notes of the pentatonic scale plus 3 arbitrary ones) to create an 8-tone sequence or tone row (aided by Python's random module.)
The sequence is split over 2 bars in rather the manner that hexadecimal splits bytes into two 4-bit groups (nibbles). No note is ever repeated within the 2 bar sequence.
The random sequence is first copied and pasted into another 2 bars, before sorting starts.
Each 'nibble' is then processed separately. In the case of my particular tone row, it takes 3 repetitions to sort a bar.
We start by sorting just the 2nd bar of the sequence, meaning the 1st bar remains the same for 3 iterations. The final note in the 2nd bar is compared with the previous note; if the previous note is of a higher pitch, the notes are swapped. The sequence is then copied and pasted again, and the following algorithm is used (in this context, 'greater than' means 'at a higher pitch than'). For demonstrative purposes, let's label our 4 notes A, B, C, and D (this has no relation to actual note pitches!)
D > C > B >A
If this statement is false, the first note to break the rule is compared to each of the previously processed notes to determine its place in the sequence.
This is repeated for the final iteration, by which time all the notes in the 2nd bar in the sequence are sorted. The process is then repeated with the first bar in the sequence, while the 2nd bar remains the same for three iterations.
The LH starts off in the same direction as the RH, but after a few repetitions it retrogrades (is flipped horizontally, in visual terms).
3rds, 5ths and octaves are added to the left and/or right hands at various points. Sometimes 5ths are added below the pure tone row, and sometimes they are added above it. These patterns can also be flipped vertically so that 5ths that were added below the 'melody' are now on top of it, meaning their intervalic relationship changes.
There are rules for these 'filler' notes:
The note must be either a major or minor third, or a perfect fifth, apart from the lowest note in the chord. it must not be the same as any other uppermost or lowermost note in the bar. This means that sometimes (although very rarely), where the overall pattern is using thirds, it becomes necessary to subsitute a 5th in to avoid doubling a note that already exists in the 'melody'.
The fact that this occurrence is so rare - only starting near the very end of the sorting process - fascinates me, although I don't know the reason behind it yet.
The result of my experiment - which I never ended up doing anything interesting with - can be heard here. I cannot stress enough that I don't know what I'm doing. This was just for fun.