Program capable of generating formations for soccer

I would like to create a program capable of generating formations for soccer based on the votes obtained by the players in the previous game.

Then, based on the votes obtained, the program “sorts” the players in order to create balanced teams

Example

7 7 4 6 7 4 5 5 7 8

Team1: 6 4 7 7 7

Team2: 5 5 6 8 7

How can i do this?

Hi @Adamo ,
may I ask a question to understand it better.
Where are those numbers coming from? In which order are they coming?
The sorting into Team1 & Team2 was solely based upon the aim to have an equal sum?
6+4+7+7+7 = 5+5+6+8+7 = 31?

Best,
Richard