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

[프로그래머스] Lv. 1 실력테스트 - 비밀지도_파이썬

by 에이도 2020. 12. 2.

 

 

 

 

import numpy as np

def solution(n, arr1,arr2):
    answer = []
    answer1, answer2 = [],[]
    for i_1,i_2 in zip(arr1,arr2):
        answer_1,answer_2  = '', ''
        for j in range(n-1,-1,-1):
            if i_1 - 2**j >= 0:
                i_1 = i_1 - 2**j
                answer_1+='#'
            else :
                answer_1+= ' '

            if i_2 - 2**j >= 0:
                i_2 = i_2 - 2**j
                answer_2+='#'
            else :
                answer_2+= ' '
                
        answer1.append(answer_1)
        answer2.append(answer_2)

    for shp1,shp2 in zip(answer1,answer2):
        shp = ''
        for nn in range(0,n):
            if shp1[nn] == '#' or shp2[nn] == '#':
                shp += '#'
            else:
                shp+=' '
        answer.append(shp)
        
   
     print(np.matrix(answer).reshape(n,1))
    return answer

print(solution(5, [9, 20, 28, 18, 11], [30, 1, 21, 17, 28]),'\n'*2)
print(solution(6, [46, 33, 33, 22, 31, 50], [27, 56, 19, 14, 14, 10]))


[out]
[['#####']
 ['# # #']
 ['### #']
 ['#  ##']
 ['#####']]
['#####', '# # #', '### #', '#  ##', '#####'] 


[['######']
 ['###  #']
 ['##  ##']
 [' #### ']
 [' #####']
 ['### # ']]
['######', '###  #', '##  ##', ' #### ', ' #####', '### # ']

댓글