Skip to content

Instantly share code, notes, and snippets.

@nottombrown
Created July 3, 2014 22:02
Show Gist options
  • Save nottombrown/46156744f9af3ea0af25 to your computer and use it in GitHub Desktop.
Save nottombrown/46156744f9af3ea0af25 to your computer and use it in GitHub Desktop.
// 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)")
}
@stymy
Copy link

stymy commented Sep 4, 2014

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 >.<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment