Skip to content
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

[장희직] 킹, 바닥 장식, 빙고, 랜선 자르기, 가로수 #25

Merged
merged 5 commits into from
Oct 16, 2022

Conversation

jhg3410
Copy link
Member

@jhg3410 jhg3410 commented Oct 16, 2022

📌 from issue #21 📌

📋문제 목록📋

킹: ✅
바닥 장식: ✅
빙고: ✅
랜선 자르기: ✅
가로수: ✅

📝메모

  • 오랜만에 이분탐색이랑, 최대공약수 구하는 알고리즘을 부딪혀서 애먹었네요..
  • 킹 문제와 같이 기본적인 2*2 배열의 index 순서와 반대인 친구는 힘드네요..

gcd = getGcd(gcd,diff[i])
}

println(((tree.last() - tree.first()) / gcd) + 1 - tree.size)
Copy link
Member

Choose a reason for hiding this comment

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

저도 처음에 이렇게 접근했었는데..!! 틀렸길래 제 생각이 틀린 줄 알았습니다ㅜㅜ 그런데 다른 곳에서 틀렸었나보네요..!!

}

var start = 0L
var end = s / n
Copy link
Member

Choose a reason for hiding this comment

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

가능성이 없는 범위는 미리 없애버려서 효율성이 증가할 것 같아요!!

var end = s / n
if (end == 1L) {
println(1)
exitProcess(0)
Copy link
Member

Choose a reason for hiding this comment

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

exitProcess(0) 대신에 그냥 return해도 종료가 됩니다..!!

println(answer)
}

fun isCorrect(length: Long): Long {
Copy link
Member

Choose a reason for hiding this comment

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

isCorrect는 뭔가 Boolean을 반환할 것 같은 함수명이네요...!!! 개수를 반환한다는 것을 알 수 있는 함수명은 어떨까요??

}

repeat(n) { i ->
answer += floor[i].split('|').filter { it.isNotEmpty() }.size
Copy link
Member

Choose a reason for hiding this comment

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

고차함수 너무 너무 잘 다루시는 것 같아요...!! 배우고 갑니다!


chairMan.forEachIndexed { _, ints ->
ints.forEachIndexed { _, num ->
bingo.forEachIndexed { _, row ->
Copy link
Member

Choose a reason for hiding this comment

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

_처리 깔끔하고 보기 좋은 것 같아요~

}
}

fun isBingo(): Int {
Copy link
Member

Choose a reason for hiding this comment

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

요것두 빙고의 개수를 반환한다는 것을 알 수 있는 함수명이 더 잘 어울릴 것 같아요

var cnt = 0
var tmp = 0
repeat(5) { i ->
if (bingo[i].filter { it == -1 }.size == 5) cnt += 1
Copy link
Member

Choose a reason for hiding this comment

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

all을 써도 괜찮지 않았을까요??

Comment on lines +12 to +14
if (tree.isNotEmpty()) {
diff.add(location - tree.last())
}
Copy link
Member

Choose a reason for hiding this comment

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

입력 받을 때 한번에 거리 계산도 해주신게 인상깊었습니다!

}

var start = 0L
var end = s / n
Copy link
Member

Choose a reason for hiding this comment

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

end값을 이렇게 계산해 넣어주신 게 진짜 좋은 것 같아요!

Comment on lines +14 to +16
repeat(n) { i ->
answer += floor[i].split('|').filter { it.isNotEmpty() }.size
}
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 간단히 풀 수 있다니.. 반성하고 갑니다 👍

gcd = getGcd(gcd,diff[i])
}

println(((tree.last() - tree.first()) / gcd) + 1 - tree.size)
Copy link
Contributor

Choose a reason for hiding this comment

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

처음이랑 마지막 사이를 나눠주는 거 대박입니다!!

Comment on lines +30 to +34
while (b > 0) {
val tmp = a
a = b
b = tmp % b
}
Copy link
Contributor

Choose a reason for hiding this comment

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

재귀로 하는 법 밖에 몰랐는데 반복문으로 하는 법 배워갑니다👍

}

repeat(n) { i ->
answer += floor[i].split('|').filter { it.isNotEmpty() }.size
Copy link
Contributor

Choose a reason for hiding this comment

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

split 진짜 대박입니다....고차함수 응용왕

Comment on lines +19 to +21
chairMan.forEachIndexed { _, ints ->
ints.forEachIndexed { _, num ->
bingo.forEachIndexed { _, row ->
Copy link
Contributor

@bngsh bngsh Oct 16, 2022

Choose a reason for hiding this comment

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

이거 앞 인자를 다 _로 바꿔주셨으니 forEach로 바꿀 수도 있을 것 같아요...!!

package heejik.`5week`


val y = listOf('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')
Copy link
Contributor

Choose a reason for hiding this comment

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

리스트로 처리한 게 깔끔한 것 같습니다!!

@jhg3410 jhg3410 merged commit 2e3b86e into main Oct 16, 2022
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.

4 participants