Greedy algorithm for assigning sides in axes checker