Skip to content

Instantly share code, notes, and snippets.

@kylejohnsonkj
Last active January 7, 2020 22:01
Show Gist options
  • Save kylejohnsonkj/4b0a3a063714fd0257626a17cea1fc12 to your computer and use it in GitHub Desktop.
Save kylejohnsonkj/4b0a3a063714fd0257626a17cea1fc12 to your computer and use it in GitHub Desktop.
Shortest variation of FizzBuzz I could come up with
for n in 1...100 {
var s = ""
s += n % 3 == 0 ? "Fizz" : ""
s += n % 5 == 0 ? "Buzz" : ""
print(s.isEmpty ? n : s)
}
@kylejohnsonkj
Copy link
Author

(1...100).forEach {
    var s = $0 % 3 == 0 ? "Fizz" : ""
    s += $0 % 5 == 0 ? "Buzz" : ""
    print(s.isEmpty ? $0 : s)
}

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