Skip to content

Comments

[jiyeeeah] 25.01.03#9

Merged
JooKangsan merged 9 commits intomainfrom
jiyeeeah
Jan 9, 2025
Merged

[jiyeeeah] 25.01.03#9
JooKangsan merged 9 commits intomainfrom
jiyeeeah

Conversation

@jiyeeeah
Copy link
Collaborator

@jiyeeeah jiyeeeah commented Jan 3, 2025

[배열]

📌 푼 문제

[기초]

[중급]

[심화]


📝 간단한 풀이 과정

중급까지는 쉽길래 심화까지 다 풀 수 있을 줄 알았는데.. 별 찍기에서 막혔다.. 🥲

문제를 풀며 몰랐거나 까먹었다가 이제 다시 알게 된 부분들 위주로 정리해봤습니다.

2차원 배열 만드는 방법

const arr = new Array(5).fill(0).map(() => new Array(4));
📄 REFERENCE

https://joonfluence.tistory.com/508

행렬의 곱셈

const r1 = arr1.length;
const c1 = arr1[0].length;
const r2 = arr2.length;
const c2 = arr2[0].length;
// 여기서 c1 === r2이다.

// 결과 배열은 r1 * c2이다.
const answer = new Array(r1).fill(0).map(() => new Array(c2).fill(0));

교점에 별 만들기

function solution(line) {
    
    const cross = [];
    for(let i = 0; i < line.length; i++) {
        const equ = line[i];
        for(let j = i + 1; j < line.length;j++) {
            const comp = line[j];
            if(equ === comp) continue;
            const x = (equ[1] * comp[2] - equ[2] * comp[1]) / (equ[0] * comp[1] - equ[1] * comp[0]);
            const y = (equ[2] * comp[0] - equ[0] * comp[2]) / (equ[0] * comp[1] - equ[1] * comp[0]);
            if(Number.isInteger(x) && Number.isInteger(y))  cross.push([x,y]);
        }
    }
    
    // 별 그리기
    const maxX = Math.max(...cross.map(([x,y]) => x));
    const minX = Math.min(...cross.map(([x,y]) => x));
    const maxWidth = maxX - minX + 1;
    
    const maxY = Math.max(...cross.map(([x,y]) => y));
    const minY = Math.min(...cross.map(([x, y]) => y));
    const maxHeight = maxY - minY + 1;
   
    // 여기서 막혔다..
    return answer;
}

교점 구하기 까지는 성공했다! 그러고 별 그릴 캔버스를 만들었는데 거기에 별을 그리다가 막혔다. 나중에 다시 시도해봐야지..


Copy link
Collaborator

@JooKangsan JooKangsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정렬은 안해도 괜찮을것 같아요!!

const minNum = arr.sort((a, b) => a - b)[0];
answer.splice(answer.indexOf(minNum), 1);

이거는
answer.splice(answer.indexOf(Math.min(...arr)), 1)
이걸로 처리할수 있습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오 그렇네요!! 감사합니다 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map을 사용해서 좀 더 간결하게 풀 수 있어요!

function solution(arr1, arr2) {
    return arr1.map((row, i) => row.map((val, j) => val + arr2[i][j]));
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그렇네요 ㅎㅎ 좋은 의견 감사합니다! 👍 😄

@JooKangsan JooKangsan merged commit 0d42bf4 into main Jan 9, 2025
3 checks passed
bona1122 pushed a commit to bona1122/AlgorithmStudy that referenced this pull request Jan 9, 2025
* 배열 자르기 / 기초

* 배열 원소의 길이 / 기초

* 배열 회전시키기 / 기초

* 중복된 숫자 개수 / 기초

* 제일 작은 수 제거하기 / 중급

* 행렬의 덧셈 / 중급

* 나누어 떨어지는 숫자 배열 / 중급

* 행렬의 곱셈 / 심화

* 배열 배운 것 정리 파일
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants