Skip to content

Conversation

@dongglehada
Copy link
Member

🔗 문제 링크

✔️ 소요된 시간

70분

📚 새롭게 알게된 내용

  • 집합식을 몰랐음

@dongglehada dongglehada self-assigned this Feb 5, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @dongglehada, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 '뉴스 클러스터링' 문제에 대한 Swift 솔루션을 도입합니다. 이 솔루션은 두 개의 입력 문자열을 처리하여 두 글자 단어 쌍(빅그램)을 추출하고, 이들의 다중집합 교집합과 합집합을 계산한 다음, 이 계산된 수를 기반으로 유사도 지수를 산출합니다.

Highlights

  • 문제 해결: 프로그래머스 '뉴스 클러스터링' 문제에 대한 Swift 솔루션을 구현했습니다.
  • 핵심 로직: 두 글자 쌍(빅그램)을 생성하고 그 빈도를 계산하는 makeWordList 헬퍼 함수를 사용합니다.
  • 유사도 계산: 빅그램의 교집합과 합집합을 계산하여 자카드 유사도 지수를 결정합니다.
  • 예외 처리: 두 입력 문자열 모두에서 유효한 빅그램이 생성되지 않는 경우(두 집합이 모두 공집합인 경우) 65536을 반환하도록 처리합니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • WEEK03/프로그래머스_[1차] 뉴스 클러스터링/Raven.swift
    • solution 함수와 헬퍼 함수 makeWordList를 포함하는 새로운 Swift 파일이 추가되었습니다.
Activity
  • 작성자는 이 문제를 해결하는 데 70분을 소요했습니다.
  • 작성자는 집합식에 대해 새롭게 알게 되었다고 언급했습니다.
  • 이 솔루션은 문제 해결의 첫 번째 시도입니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

제출하신 [1차] 뉴스 클러스터링 문제 풀이 코드를 검토했습니다. makeWordList 함수를 통해 두 글자씩 끊어 단어 리스트와 개수를 효율적으로 생성하고, 이를 바탕으로 자카드 유사도를 계산하는 방식이 명확하고 잘 구현되었습니다. 특히, 두 집합이 모두 공집합일 경우 65536을 반환하는 예외 처리도 문제의 요구사항에 맞게 잘 처리되었습니다. 전반적으로 깔끔하고 이해하기 쉬운 코드입니다. 몇 가지 가독성 및 유지보수성 측면에서 개선할 수 있는 부분을 제안합니다.

Comment on lines +13 to +15
return 65536
}
return 65536 * intersection / union

Choose a reason for hiding this comment

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

medium

65536이라는 상수가 두 번 사용되고 있습니다. 이러한 '매직 넘버'는 코드의 가독성을 저해하고 향후 변경 시 오류를 유발할 수 있으므로, 상수로 정의하여 사용하는 것이 좋습니다. 예를 들어, let JACCARD_MULTIPLIER = 65536과 같이 정의한 후 사용하는 것을 고려해 보세요.

return 65536 * intersection / union
}

func makeWordList(_ str: String) -> ([String: Int], Int) {

Choose a reason for hiding this comment

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

medium

makeWordList 함수가 반환하는 튜플에 이름을 지정하여, 호출하는 쪽에서 .0, .1과 같은 인덱스 대신 의미 있는 이름으로 접근할 수 있도록 개선할 수 있습니다. 이는 코드의 가독성과 유지보수성을 높이는 좋은 방법입니다.

Suggested change
func makeWordList(_ str: String) -> ([String: Int], Int) {
func makeWordList(_ str: String) -> (wordMap: [String: Int], totalCount: Int) {

Comment on lines +3 to +13
var str1 = makeWordList(str1)
var str2 = makeWordList(str2)
var intersection: Int = 0
for key in str1.0.keys {
let num = min(str1.0[key] ?? 0, str2.0[key] ?? 0)
intersection += num
}
let union = str1.1 + str2.1 - intersection

if str1.1 == 0 && str2.1 == 0 {
return 65536

Choose a reason for hiding this comment

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

medium

makeWordList 함수에서 반환하는 튜플의 요소에 이름을 부여하면 코드의 가독성을 크게 향상시킬 수 있습니다. 또한, str1str2 매개변수를 섀도잉하는 대신, 튜플을 직접 구조 분해하여 명확한 변수 이름을 사용하는 것이 좋습니다.

Suggested change
var str1 = makeWordList(str1)
var str2 = makeWordList(str2)
var intersection: Int = 0
for key in str1.0.keys {
let num = min(str1.0[key] ?? 0, str2.0[key] ?? 0)
intersection += num
}
let union = str1.1 + str2.1 - intersection
if str1.1 == 0 && str2.1 == 0 {
return 65536
let (str1Map, str1Count) = makeWordList(str1)
let (str2Map, str2Count) = makeWordList(str2)
var intersection: Int = 0
for key in str1Map.keys {
let num = min(str1Map[key] ?? 0, str2Map[key] ?? 0)
intersection += num
}
let union = str1Count + str2Count - intersection
if str1Count == 0 && str2Count == 0 {
return 65536

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant