Skip to content

Instantly share code, notes, and snippets.

@stymy
Forked from nottombrown/chefs.swift
Last active August 29, 2015 14:06
Show Gist options
  • Save stymy/a534423d40be41edd95d to your computer and use it in GitHub Desktop.
Save stymy/a534423d40be41edd95d to your computer and use it in GitHub Desktop.
// 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