Fixed sorting and spacing algorithms for magnets