Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

2022年04月18日(월) jaewon1676 7문제의 풀이 추가 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
jaewon1676 merged 8 commits into codeisneverodd:main from jaewon1676:main
Apr 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add 220418 카펫 1개의 풀이 추가
  • Loading branch information
jaewon1676 committed Apr 18, 2022
commit 5b64e15f46a8856e7ebf99a64a7258c0dae6bace
28 changes: 27 additions & 1 deletion level-2/카펫.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,30 @@ function widthHeightPair(size) {
let result = []
for (let i = 1; i <= Math.sqrt(size); i++) if (size % i === 0) result.push([size / i, i])
return result
}
}

//정답 2 - jaewon1676
function solution(brown, yellow) {
var answer = [];
let sum = brown + yellow;

//카펫의 최소높이는 3부터이다.(테두리 갈색, 가운데 노란색)
for(let height=3; height<brown/2; height++){
//전체 크기에서 높이로 나눌때 나머지가 없을경우만 진행
if(sum % height === 0){
//가로길이
let weight = sum / height;
//테두리를 제외한 길이를 구해야하기 때문에 각각 -2해준뒤 곱셈 하여 답을 구한다.
if( (height-2) * (weight-2) === yellow){
return [weight, height];
}
}
}
return answer;
}
// 완전탐색

// 문제 설명에서의 중앙은 노란색, 테두리는 갈색이 포인트입니다.
// 갈색은 항상 노란색의 가로 세로 크기보다 +2 만큼 큽니다.
// 따라서 높이는 전체 테두리/2보다 작으므로
// 3부터 brown/2 를 순회합니다.

AltStyle によって変換されたページ (->オリジナル) /