This is Richard Howarth's contribution. He asked me to post it as he won't be available to do it himself
code:
; begin CD Sorter
;
; Areas for improvement:
; 1) Convert values to integer. This should speed things up hugely.
;
; 2) Presort the list by track length. This will limit the iterations as will be able to discard
; all iterations once the maximum length has been exceeded. This requires the list to be in
; DESCENDING order, and add return values to abort both the recursion and the iteration when
; the track list gets too large.
;!
Function CDSorter($s, $) ; $s=comma separated list of all track lengths, $=media size.
If IsDeclared($c)=0 ; Redclaring a global will cause a run time error.
Global $c,$g,$t ; Globals: $c=Best List, $g=Smallest Gap, $t=track list array.
EndIf
$t=Split($s,",") ; Convert CD list to array.
$g=$ ; Record maximum gap as worst case.
a(0.+$,"",Ubound($t)) ; Start recursive routine from highest track, force starting gap to floating point.
$CDSorter=SubStr($c,2) ; Assign best list found, dropping the redundant comma.
EndFunction

Function a($f,$l,$) ; $f=Parents gap, $l=current track "path", $=track in array to start looking.
Dim $n,$m ; $n=Gap for each iteration, $m=track list for each iteration.
While $ ; Iterate loop for each element to the left of the parent element.
If $g<0.0001 Return EndIf ; "1" for quick, "0.0001" for best fit, remove for shortest code and longest run time.
$n=$f-$t[$] ; Decrease current gap by the length of this track.
If $n>=0 ; Only continue if current gap is not negative (track list too long)
$m=$l+","+($+1) ; Append current track to parents track list
If $n<$g ; Is the new gap smaller than the best found so far?
$g=$n ; Yes it is. Ok, Record this smaller gap, and
$c=$m ; record the better track list.
EndIf
a($n,$m,$-1) ; See if the tracks to the left of this one can reduce the gap further.
EndIf
$=$-1
Loop
EndFunction
;!
;!

; end CD Sorter

_________________________
There are two types of vessels, submarines and targets.