Skip to content

Instantly share code, notes, and snippets.

@mxcl
Last active June 29, 2017 18:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxcl/6366447f15bc52412f1e to your computer and use it in GitHub Desktop.
Save mxcl/6366447f15bc52412f1e to your computer and use it in GitHub Desktop.
enum FizzBuzz {
case fizz
case buzz
case fizzBuzz
case number(Int)
init(rawValue: Int) {
switch (rawValue % 3, rawValue % 5) {
case (0, 0): self = .fizzBuzz
case (0, _): self = .fizz
case (_, 0): self = .buzz
case (_, _): self = .number(rawValue)
}
}
}
extension FizzBuzz: CustomStringConvertible {
var description: String {
switch self {
case .fizzBuzz: return "fizzbuzz"
case .buzz: return "buzz"
case .fizz: return "fizz"
case .number(let x): return String(x)
}
}
}
for x in 1...100 {
print(FizzBuzz(rawValue: x))
}
@Abizern
Copy link

Abizern commented Aug 19, 2014

Fair start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment