Thursday, February 28, 2008

2008 Scripting Games - Advanced Event 7

 

$teams = "A","B","C","D","E","F"
$rounds=@()

for($i=0; $i -lt $teams.length; $i++){
   0..2 | foreach { $rounds += ("{0} vs. {1}" -f $teams[$_],$teams[-($_+1)]) }
   1..($teams.length-1) | foreach { $teams[1],$teams[$_] = $teams[$_],$teams[1] }
} 

# remove duplicates
$rounds = $rounds | select -unique

# random positions
$rnd = new-object random (get-date).millisecond 
$list = new-object System.Collections.ArrayList
$list.AddRange(0..($rounds.count-1))

1..$rounds.count | foreach {
   $n=$rnd.next($list.count)	
   $rounds[$list[$n]]
   [void]$list.removeAt($n)
}



#result

B vs. E
A vs. C
C vs. D
A vs. E
F vs. D
C vs. F
D vs. B
F vs. B
B vs. C
A vs. D
A vs. B
A vs. F
E vs. F
E vs. C
D vs. E

No comments: