DEV Community

Discussion on: Daily Challenge #24 - Shortest Step

Collapse
 
peter279k profile image
peter279k

Here is the simple solution with Python:

def shortest_steps_to_num(num):
    steps = 0
    if num == 1:
        return steps

    while num != 1:
        if num % 2 == 0:
            num /= 2
            num = int(num)
        else:
            num -= 1

        steps += 1

    return steps