Skip to content

Instantly share code, notes, and snippets.

@mickmaccallum
Last active August 29, 2015 14:18
Show Gist options
  • Save mickmaccallum/994447e9cf6d396c68d8 to your computer and use it in GitHub Desktop.
Save mickmaccallum/994447e9cf6d396c68d8 to your computer and use it in GitHub Desktop.
Swift factorial
// Simple factorial generator. Doesn't handle numbers that overflow Int or the 0! = 1 case.
// Swift 2
let num = (1...17).reduce(1, combine: *) // 355687428096000
// Swift 1.x
let num = reduce(1...17, 1, *) // 355687428096000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment