프로그래머스 | N으로 표현

커몽·2021년 2월 1일
0

프로그래머스 level3

목록 보기
1/17
function solution(N, number) {
    const arr = new Array(8).fill().map(() =>new Array());
    for(let i=0; i<8; i++){
        arr[i].push(Number(N.toString().repeat(i+1)));
        console.log(arr[i][0])
        for(let j=0;j<i;j++){
            for(let arg1 of arr[j]){
                for(let arg2 of arr[i-j-1]){
                    arr[i].push(arg1+arg2);//사용 횟수 i+1번째 배열에 넣는다
                    arr[i].push(arg1-arg2);
                    arr[i].push(arg1*arg2);
                    arr[i].push(arg1/arg2); 
                }
            }
        }
        
        if(arr[i].includes(number))return i+1
    }

    return -1;
}

0개의 댓글