nDisplay screens algorithm

Any ideas?