Skip to content

Instantly share code, notes, and snippets.

@stefc
Created January 4, 2018 08:35
Show Gist options
  • Save stefc/6d5a5e17eacc3bfa0b02ac1d3bf512ba to your computer and use it in GitHub Desktop.
Save stefc/6d5a5e17eacc3bfa0b02ac1d3bf512ba to your computer and use it in GitHub Desktop.
import Foundation
public func IntPow(_ base: Int, exp: Int) -> Int {
guard exp >= 0 else {
return 0
}
guard exp > 0 else {
return 1
}
return (1..<exp).reduce(base) { (accu, _) in accu * abs(base) }
}
public func IntPow10(exp: Int) -> Int {
return IntPow(10, exp: exp)
}
public func IntPow2(exp: Int) -> Int {
return 1 << exp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment