Skip to content

Instantly share code, notes, and snippets.

@Pre1
Last active April 14, 2016 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pre1/282a22d2f831da65788e953d75f1a8e5 to your computer and use it in GitHub Desktop.
Save Pre1/282a22d2f831da65788e953d75f1a8e5 to your computer and use it in GitHub Desktop.
99 bottles of beer in swift 2.2...3.0
/*
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
.
.
.
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
*/
let (beers, wall, take, end) = ("bottles of beer", " on the wall",
"Take one down and pass it around,",
"Go to the store and buy some more,")
for i in (0...99).reverse() {
print(
"\(i == 0 ? "No more" : "\(i)") \(beers + wall),",
"\(i == 0 ? "no more" : "\(i)") \(beers).\n",
"\(i == 0 ? end : take)",
"\(i-1 == 0 ? "no more" : "\(i == 0 ? "\(i+99)" : "\(i-1)") ") \(beers + wall).\n"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment