Last active
June 29, 2017 18:32
-
-
Save mxcl/6366447f15bc52412f1e 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
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fair start.