[AS][OSX] Sort numbers in ascending order

I’m working on numbering page items of an InDesign page to follow a sequence of left-to-right top-to-bottom. I’ve figured out how to use the x-y coordinates to relate the object’s location to a single integer.

Now I need to take a list of numbers and sort them in ascending order. But I can’t figure out how to do it.

Here’s what I have so far. The math goes (Y x 1000) + X


set A to (8.375 * 1000) + 4.75 as integer
set B to (3.333333333333 * 1000) + 0.5 as integer
set C to (6.078125 * 1000) + 0.5 as integer
set D to (0.5 * 1000) + 4.75 as integer
set e to (0.5 * 1000) + 0.5 as integer

my_list to {A, B, C, D, e} 

Hi,

use a sorting subroutine, a common one is bubblesort

set A to (8.375 * 1000) + 4.75 as integer
set B to (3.333333333333 * 1000) + 0.5 as integer
set C to (6.078125 * 1000) + 0.5 as integer
set D to (0.5 * 1000) + 4.75 as integer
set e to (0.5 * 1000) + 0.5 as integer
set my_list to {A, B, C, D, e}
bubblesort(my_list)
my_list

on bubblesort(theList)
	script o
		property lst : theList
	end script
	
	repeat with i from (count theList) to 2 by -1
		set A to beginning of o's lst
		repeat with j from 2 to i
			set B to item j of o's lst
			if (A > B) then
				set item (j - 1) of o's lst to B
				set item j of o's lst to A
			else
				set A to B
			end if
		end repeat
	end repeat
end bubblesort