Last active
August 29, 2015 14:26
-
-
Save jonathanread/5eee8a69efc593631498 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
extension String { | |
func Contains(find: String) -> Bool{ | |
return self.rangeOfString(find) != nil | |
} | |
} | |
extension Int{ | |
func IsMultipleOf(divisableBy: Int) -> Bool{ | |
return self % divisableBy == 0 | |
} | |
} | |
func stage1(){ | |
for index in 1...100{ | |
if index.IsMultipleOf(3) && index.IsMultipleOf(5) | |
{ | |
println("FizzBuzz") | |
} | |
else if index.IsMultipleOf(3) | |
{ | |
println("Fizz") | |
} | |
else if index.IsMultipleOf(5) | |
{ | |
println("Buzz") | |
} | |
else | |
{ | |
println("\(index)") | |
} | |
} | |
println("END STAGE 1\n") | |
} | |
func stage2(){ | |
for index in 1...100{ | |
if index.IsMultipleOf(3) && index.IsMultipleOf(5) || String(index).Contains("3") && String(index).Contains("5") | |
{ | |
println("FizzBuzz") | |
} | |
else if index.IsMultipleOf(3) || String(index).Contains("3") | |
{ | |
println("Fizz") | |
} | |
else if index.IsMultipleOf(5) || String(index).Contains("5") | |
{ | |
println("Buzz") | |
} | |
else | |
{ | |
println("\(index)") | |
} | |
} | |
println("END STAGE 2") | |
} | |
stage1() | |
stage2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment