Skip to content

Instantly share code, notes, and snippets.

@jonathanread
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanread/5eee8a69efc593631498 to your computer and use it in GitHub Desktop.
Save jonathanread/5eee8a69efc593631498 to your computer and use it in GitHub Desktop.
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