Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

So my task is to score all the possible rankings of the 14 SEC football teams and find the best one, using who won in head-to-head games as the sole criterion (so not factoring in strength of schedule or homefield advantage yet).

RandomSample[Range[14]] gives me one random ranking of the 14 teams, then I score that ranking by seeing how many wins and losses it actually predicted. For example, if "1" represents Missouri (miss) and "3" represents Georgia (ga), then if the generated ranking has 1 listed before 3, that ranking gets +1 to its ranking score, since Missouri beat Georgia this season. If 3 is listed before 1, the ranking score receives a -1 to its score, for incorrectly ranking those teams with respect to each other. And so on for every head-to-head SEC match up from last year.

Once I can correctly score one ranking, I would use Permutations[RandomSample[Range[14]]] and apply the scoring algorithm to all the permutations of a list of 14, and select the list (ranking) with the max ranking score (k).

My main issue right now is comparing the positions of teams in the rankings. In the code, k is the ranking score and one test for Missouri being listed before Georgia is listed at the bottom, with the output below it. However {{7}} cannot be compared to {{5}} as in 7 > 5, and that's my problem.

Here's the code:

list1 = RandomSample[Range[14]]

(* Out: {11, 6, 8, 13, 3, 9, 1, 4, 5, 12, 7, 14, 10, 2} *)

miss = Position[list1, 1]];
  sc = Position[list1, 2];
  ga = Position[list1, 3]];
vandy = Position[list1, 4];
fl = Position[list1, 5];
tenn = Position[list1, 6];
kent = Position[list1, 7];
aub = Position[list1, 8];
bama = Position[list1, 9];
lsu = Position[list1, 10];
tam = Position[list1, 11];
missst = Position[list1, 12];
olemiss = Position[list1, 13];
ark = Position[list1, 14];

k = 0;
If[miss > ga, k++, k--]
(* Output:  If[{{7}} > {{5}}, k++, k--] *)
share|improve this question
    
First@First@{{7}} == 7 or {{7}}[[1, 1]] == 7. But perhaps you should create a function to tell you what team won: whoWon[team1_,team2_,{{rank1_}},{{rank2_}}]:= .. this will take care of the issue with {{...}} as well. –  Pickett Feb 23 at 13:24

1 Answer 1

up vote 1 down vote accepted

Id suggest it will be far more efficient if you do

  rank=Ordering@list1;

then you can access the rank directly, ie

  rank[[1]] -> same as Position[list1,1][[1,1]]

If you really intend to process all 90 billion permutations this i think will make a big difference vs calling Position 14 times.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.