Created
January 4, 2018 08:35
-
-
Save stefc/6d5a5e17eacc3bfa0b02ac1d3bf512ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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