Last active
August 29, 2015 14:10
-
-
Save tikidunpon/31509881e725d6dd773c to your computer and use it in GitHub Desktop.
SwiftでFizzBuzz(Playgroundで無駄にキャプチャ) ref: http://qiita.com/tikidunponpon/items/00032785e1c9d116ec9a
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
enum FizzBuzzResult { | |
case FIZZ | |
case BUZZ | |
case FIZZBUZZ | |
case OTHERS(Int) | |
func toString() -> String { | |
switch self { | |
case .FIZZ: return "Fizz" | |
case .BUZZ: return "Buzz" | |
case .FIZZBUZZ: return "FizzBuzz" | |
case .OTHERS(let i): return String(i) | |
} | |
} | |
} | |
func fizzbuzz(i: Int) -> FizzBuzzResult { | |
switch (i % 3, i % 5) { | |
case (0, 0): | |
return .FIZZBUZZ | |
case (0, _): | |
return .FIZZ | |
case (_, 0): | |
return .BUZZ | |
case _: | |
return .OTHERS(i) | |
} | |
} | |
for i in 1...100 { | |
var retString = fizzbuzz(i).toString() | |
println(retString) | |
XCPCaptureValue("capture_i", i) | |
} | |
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
import UIKit | |
import XCPlayground | |
let fizz = "Fizz" | |
let buzz = "Buzz" | |
let fizzbuzz = fizz + buzz | |
let others = "Others" | |
for i in 1...100 { | |
if i % 3 == 0 && i % 5 == 0 { | |
println(fizzbuzz) | |
XCPCaptureValue(fizzbuzz, i) | |
} | |
else if i % 3 == 0 { | |
println(fizz) | |
XCPCaptureValue(fizz, i) | |
} | |
else if i % 5 == 0 { | |
println(buzz) | |
XCPCaptureValue(buzz, i) | |
} | |
else { | |
println(i) | |
XCPCaptureValue(others, i) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment