프로그래머스[Level 1] 비밀지도 (KAKAO)

bkboy·2022년 6월 24일
0

문제



입력 형식

출력 형식

입출력 예

풀이

// 이진수
const makeMap = (arr,n) => {
    const map = [];
    
    for(let x of arr){
        let binary = x.toString(2);
        while(binary.length < n){
            binary = "0" + binary;
        }
        let tmp = "";
        for(let n of binary){
            if(n == 0){
                tmp += " ";
            } else {
                tmp  += "#";
            }
        }
        map.push(tmp);
    }
    return map;
}

function solution(n, arr1, arr2) {
    const answer = [];
    const map1 = makeMap(arr1,n);
    const map2 = makeMap(arr2,n);
    
    for(let i=0;i<n;i++){
        answer[i] = ""
        for(let j=0;j<n;j++){
            if(map1[i][j] === "#" || map2[i][j] === "#"){
                answer[i] += "#";
            }
            
            if(map1[i][j] === " " && map2[i][j] === " "){
                answer[i] += " "
            }
        }
    }
    return answer;
}
profile
음악하는 개발자

0개의 댓글