Reputation: 73
I'm trying to write an algorithm in Java to calculate the optimum order of batsmen in a cricket game, based on the experience they have playing in each order.
I have a list of 11 lists. Each of the 11 lists contains all 11 batsmen in the team, ranked by the number of games they've played in this position.
So the first list would start with the player who's played most games in the first position, and ends with the player who's played least games in first position. The second list starts with the player who's played most games in 2nd position, and ends with the player who's played least games in 2nd position. etc..
What I want to do is find the combination of batsmen, one from each list, which minimises the sum of the players' locations in the lists. If all players have only played one game then this would be easy, the top player of each list. However some players top more than one list, while others may not top any.
I realise this may need quite a few loops, what is the most efficient way to calculate this? If you need any more info please ask..sorry it's a bit confusing...
Is this going to be 11! combinations? Oh gaaaaad
Upvotes: 0
Views: 1194
Reputation: 17784
The Guava method Collections2.permutations calculates for you all the possible permutations (11!), does all the looping, you only need to evaluate the results.
EDIT: in order to check the memory consumption, run the following test (it takes some time, but you shouldn't get an OutOfMemoryError):
public class Perm {
public static void main(String[] args) {
List<String> list = Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
Collection<List<String>> permutations = Collections2.permutations(list);
for (List<String> strings : permutations) {
String s = strings.toString();
System.out.println(s);
}
}
}
Upvotes: 1