-
-
Save stymy/a534423d40be41edd95d to your computer and use it in GitHub Desktop.
This file contains 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
// CHEFS!!! | |
import Darwin | |
var peeps = [ | |
"Tom", | |
"Chris", | |
"Connie", | |
"Rob", | |
"Yeti", | |
"Aimi" | |
] | |
func peepPermutations() -> (String, String)[]{ | |
var pairs:(String, String)[] = [] | |
for chef in peeps { | |
for souschef in peeps { | |
if chef != souschef { | |
pairs += (chef, souschef) | |
} | |
} | |
} | |
return pairs | |
} | |
func shuffle<T>(array: Array<T>) -> Array<T> | |
{ | |
// Implementation of Fisher-Yates shuffle | |
// http://en.wikipedia.org/wiki/Fisher-Yates_Shuffle | |
for index in 0..array.count | |
{ | |
var randIndex = Int(arc4random_uniform(UInt32(index))) | |
// We use in-out parameters to swap the internals of the array | |
swap(&array[index], &array[randIndex]) | |
} | |
return array | |
} | |
for (chef, sous) in shuffle(peepPermutations()) { | |
println("\(chef) \(sous)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment