본문 바로가기
Algorithm/프로그래머스

[프로그래머스] - 비밀지도 (파이썬)

by 2HS 2022. 1. 30.
def solution(n, arr1, arr2):
    answer = []
    for i,j in zip(arr1,arr2):
        temp = bin(i|j)[2:]
        while len(temp) < n:
            temp = '0' + temp
        temp = temp.replace('0',' ')
        temp = temp.replace('1','#')
        answer.append(temp)
    return answer

 

2018 카카오 블라인드 1차 - 1번

1. arr1과 arr2를 비트연산자로 합해서 순수 2진수만 빼온다 (bin(i|j)[2:])

2. n의 길이가 될 때 까지 앞의 빈공간에 '0'을 문자열에 더해준다

3. replace (0은 빈공간으로, 1은 #으로)

4. answer에 append