Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Last active August 29, 2015 14:04
Show Gist options
  • Save toshi0383/9ab290b63e87c735c436 to your computer and use it in GitHub Desktop.
Save toshi0383/9ab290b63e87c735c436 to your computer and use it in GitHub Desktop.
let fizz = "Fizz"
let buzz = "Buzz"
func getGenerator(num: Int, out:String) -> (Int -> String) {
func getStr(targetNum:Int) -> String {
if targetNum % num == 0 {
return out
} else {
return ""
}
}
return getStr
}
for i in 1..<101 {
var result:String? = "";
for s in [3,5] {
var getStr = getGenerator(s, s == 3 ? fizz : buzz)
result = result! + getStr(i)
}
if result != "" {
println(result!)
} else {
println(i)
}
}
let fizz = "Fizz"
let buzz = "Buzz"
func fizzbuzz(a:Int) {
if (a % 15 == 0) {
println(fizz + buzz)
} else if (a % 5 == 0) {
println(buzz)
} else if (a % 3 == 0) {
println(fizz)
} else {
println(a)
}
}
var array = [Int]()
for i in 1..<100 {
array.append(i);
}
array.map{ fizzbuzz($0) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment