Skip to content

Latest commit

 

History

History
17 lines (15 loc) · 422 Bytes

File metadata and controls

17 lines (15 loc) · 422 Bytes

step3 3回続けて10分以内に書いてエラーを出さなければOKとする

# @param {Float} base
# @param {Integer} exponent
# @return {Float}
def my_pow(base, exponent)
    return 1 if exponent.zero?
    return 1.0 / my_pow(base, -exponent) if exponent < 0

    if exponent.even?
        return my_pow(base, exponent / 2) ** 2
    else
        return base * my_pow(base, exponent - 1)
    end
end