Skip to content

Instantly share code, notes, and snippets.

@effective-light
Last active June 19, 2017 20:08
Show Gist options
  • Save effective-light/9c3c0fa5a92f8e25eff4fa2abdb0408a to your computer and use it in GitHub Desktop.
Save effective-light/9c3c0fa5a92f8e25eff4fa2abdb0408a to your computer and use it in GitHub Desktop.
def calc_exp(b: int, n: int) -> int:
"""
>>> calc_exp(10, 1)
21
>>> calc_exp(3, 4)
960
"""
def _calc_exp(p: int) -> int:
if p == 1:
return b
return b ** p + _calc_exp(p - 1)
def _calc_mul(o: int) -> int:
if o == 1:
return b + 1
return (b + o) * _calc_mul(o - 1)
return _calc_exp(n) + _calc_mul(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment