본문 바로가기
코딩테스트/Python

프로그래머스 스쿨 - 이진 변환 반복하기(Python)(복습)

by 보안매크로 2023. 10. 10.
728x90
# x = "01110"

# def binary_conversion(x):
#         count_zeros = x.count('0')
#         print("count_zero :", count_zeros)
#         c = len(x) - count_zeros
#         print("c :", c)
#         print("bin(c) :", bin(c))
#         print("bin(c)[2:] : ", bin(c)[2:])
#         return bin(c)[2:], count_zeros

# binary_conversion(x)

def binary_conversion(x):
        count_zeros = x.count('0')
        c = len(x) - count_zeros
        return bin(c)[2:], count_zeros

def solution(s):
    answer = []
    count_transform = 0
    total_zeros_removed = 0

    while s != "1":
        s, zeros_removed = binary_conversion(s)
        count_transform += 1
        total_zeros_removed += zeros_removed

    answer = [count_transform, total_zeros_removed]
    return answer
728x90