loading...

re: Daily Challenge #152 - Strongest Number in an Interval VIEW POST

FULL DISCUSSION
 

Inefficient Python w/ tail recursion:

def strongness_tail(n, a):
    return a if n % 2 == 1 else strongness_tail(n/2, 1 + a)

def strongness(n):
    return strongness_tail(n, 0)

def strongest_even(n, m):
    strongest = [-1, -1]
    for i in range(n, m+1):
        strength = strongness(i)
        if strength > strongest[0]:
            strongest = [strength, i]

    return strongest[1]
Code of Conduct Report abuse