Skip to content

Instantly share code, notes, and snippets.

@kenwilcox
Created June 23, 2017 05:07
Show Gist options
  • Save kenwilcox/9a11a225af059bcde0cf3629c793b411 to your computer and use it in GitHub Desktop.
Save kenwilcox/9a11a225af059bcde0cf3629c793b411 to your computer and use it in GitHub Desktop.
FizzBuzz Count
var counter = [
"fizz": 0,
"buzz": 0,
"fizzbuzz": 0,
"numbers": 0
]
for i in 1...100 {
switch i {
case let x where (x % 3) == 0 && (x % 5) == 0:
counter["fizzbuzz"]? += 1
print("FizzBuzz")
case let x where (x % 5) == 0:
counter["buzz"]? += 1
print("Buzz")
case let x where (x % 3) == 0:
counter["fizz"]? += 1
print("Fizz")
default:
counter["numbers"]? += 1
print("\(i)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment