#Fibonacci Sort unsorted = [3, 1, 4, 1, 5, 9, 2, 6, 0] counts = [0] * 10 fib = [0] * (10 + 1) sortd = [0] * len(unsorted) #First pass: find the counts for n in unsorted: counts[n]+=1 #Second pass: do the Fibonacci magic i = 0 total = 0 for n in counts: fib[i] = total total += n i+=1 #Third pass: output sorted for n in unsorted: sortd[fib[n]] = n fib[n] += 1 #Results print(sortd)
;count each number ldx #$ff count ldy unsort,x inc count,y dex bne count;15/ea ;Fibonacci step clc lda count inx fib adc count,x sta sta count,x inx bne fib;13/ea ;Copy sorted sort ldy unsort ldx count,y sty sort,x inc count,y inc sort+1 bne sort/27/ea