Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
533 B
2
Indexable
Never
def min_moves(n):
    """
    Calculate the minimum number of moves required to reduce the enemy army to 1 soldier.

    Args:
        n (int): The number of enemy soldiers.

    Returns:
        int: The minimum number of moves required.
    """
    moves = 0
    while n > 1:
        if n % 3 == 0:
            # Reduce by two-thirds
            n = n // 3
        elif n % 2 == 0:
            # Reduce by half
            n = n // 2
        else:
            # Reduce by 1
            n = n - 1
        moves += 1
    return moves
Leave a Comment