Created
July 3, 2014 22:02
-
-
Save nottombrown/46156744f9af3ea0af25 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", | |
] | |
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
Sadly, I can't make a pull request BUT:
https://gist.github.com/stymy/a534423d40be41edd95d
or clone URL: https://gist.github.com/a534423d40be41edd95d.git
or otherwise please include me >.<