Created
December 23, 2012 04:52
-
-
Save chinhodado/4362028 to your computer and use it in GitHub Desktop.
Champions League 2012/2013 1/16 draw simulation. Total 5463 possibilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.Collections2; | |
import java.util.*; | |
public class ChampionsLeague { | |
public static class Team{ | |
String name, country; | |
int place; | |
char group; | |
public Team(){} | |
public Team(String name, String country, int place, char group){ | |
this.name=name; | |
this.country=country; | |
this.place=place;//first or second | |
this.group=group; | |
} | |
public String toString(){ | |
return name; | |
} | |
} | |
public static boolean isValid(Team team1, Team team2){ | |
boolean valid = true; | |
if (team1.country.equals(team2.country)) valid = false; | |
if (team1.place==team2.place) valid = false; | |
if (team1.group==team2.group) valid = false; | |
return valid; | |
} | |
public static void main(String args[]){ | |
Team[] round16 = new Team[16]; | |
round16[0] = new Team("MU", "England", 1, 'A'); | |
round16[1] = new Team("Galatasaray", "Turkey", 2, 'A'); | |
round16[2] = new Team("PSG", "France", 1, 'B'); | |
round16[3] = new Team("Porto", "Portugal", 2, 'B'); | |
round16[4] = new Team("Schalke", "German", 1, 'C'); | |
round16[5] = new Team("Arsenal", "England", 2, 'C'); | |
round16[6] = new Team("Malaga", "Spain", 1, 'D'); | |
round16[7] = new Team("AC", "Italy", 2, 'D'); | |
round16[8] = new Team("Dortmund", "German", 1, 'E'); | |
round16[9] = new Team("Real", "Spain", 2, 'E'); | |
round16[10] = new Team("Juve", "Italy", 1, 'F'); | |
round16[11] = new Team("Shakta", "Ukraine", 2, 'F'); | |
round16[12] = new Team("Bayern", "German", 1, 'G'); | |
round16[13] = new Team("Valencia", "Spain", 2, 'G'); | |
round16[14] = new Team("Barca", "Spain", 1, 'H'); | |
round16[15] = new Team("Celtic", "scotland", 2, 'H'); | |
Team[] first = new Team[8]; | |
Team[] second = new Team[8]; | |
for (int i=0; i<16; i++){ | |
if (i%2==0) first[i/2]=round16[i]; | |
else second[i/2]=round16[i]; | |
} | |
ArrayList<Team> teamSecond = new ArrayList<Team>(Arrays.asList(second)); | |
Collection<List<Team>> permuted = Collections2.permutations(teamSecond); | |
@SuppressWarnings("unchecked") | |
List<Team>[] permutedList = permuted.toArray(new List[40320]); | |
Team[][] permutedArray = new Team[40320][8]; | |
for (int i = 0; i < 40320; i++) { | |
permutedArray[i] = permutedList[i].toArray(new Team[8]); | |
} | |
int count = 0; | |
for (int i=0; i<permutedArray.length; i++){ | |
boolean valid = true; | |
for (int j=0; j<8; j++){ | |
if(!isValid(first[j], permutedArray[i][j])){ | |
valid = false; | |
break; | |
} | |
} | |
if (valid) count++; | |
} | |
System.out.println("Total " + count+ " possibilities"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment