Skip to content

Conversation

@snughnu
Copy link
Collaborator

@snughnu snughnu commented Feb 3, 2026

🔗 문제 링크

링크: https://school.programmers.co.kr/learn/courses/30/lessons/17683
난이도: Lv2

✔️ 소요된 시간

1h

📚 새롭게 알게된 내용

계속 34번 틀려서 고민했는데, 레이븐 덕분에 알게됐음
(근데 B#을 C라고 할 수 있는건가)

@gemini-code-assist
Copy link

Summary of Changes

Hello @snughnu, 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

  • 음악 정보 처리: 주어진 음악 정보에서 시작 및 종료 시간을 분 단위로 변환하고, 멜로디의 반음 처리를 위한 halfStep 함수를 구현합니다.
  • 멜로디 매칭 로직: 각 음악 정보에 대해 재생 시간을 계산하고, 멜로디를 재생 시간에 맞춰 반복하여 전체 재생된 멜로디를 구성합니다. 목표 멜로디가 재생된 멜로디에 포함되는지 확인합니다.
  • 최장 재생 시간 음악 선택: 목표 멜로디를 포함하는 음악 중 재생 시간이 가장 긴 음악의 제목을 반환하며, 일치하는 음악이 없으면 "(None)"을 반환합니다.

🧠 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/프로그래머스_[3차] 방금그곡/Oliver.swift
    • 새로운 Swift 파일이 추가되어 "방금그곡" 프로그래머스 문제에 대한 솔루션을 구현합니다.
    • 시간 문자열을 분 단위 정수로 변환하는 toMinute 헬퍼 함수를 포함합니다.
    • 반음(예: C#, D#)을 단일 소문자(예: c, d)로 변환하여 멜로디 매칭을 단순화하는 halfStep 헬퍼 함수를 포함합니다.
    • 주어진 멜로디 m과 음악 정보 musicinfos를 처리하여 조건에 맞는 음악 제목을 찾는 메인 로직을 구현합니다.
Activity
  • PR이 생성되었으며, 현재 검토를 기다리고 있습니다.
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

전반적으로 문제의 요구사항을 잘 이해하고 올바르게 구현하셨습니다. 특히 halfStep 함수에서 B#과 E#을 처리한 점이 인상 깊습니다. 코드의 안정성과 효율성을 높이기 위해 몇 가지 개선점을 제안합니다. toMinute 함수에서 강제 언래핑 대신 안전한 변환을 사용하고, halfStep 함수를 더 간결하게 만들고, played 문자열을 생성하는 로직을 더 효율적으로 개선하는 것을 고려해볼 수 있습니다.

Comment on lines +4 to +7
func toMinute(_ time: String) -> Int {
let t = time.split(separator: ":").map { Int($0)! }
return t[0] * 60 + t[1]
}

Choose a reason for hiding this comment

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

medium

toMinute 함수에서 Int($0)!를 사용하여 강제 언래핑을 하고 있습니다. 이는 입력값이 항상 "HH:MM" 형식의 유효한 정수임을 가정하지만, 만약 그렇지 않은 경우 런타임 오류를 발생시켜 앱을 중단시킬 수 있습니다. compactMap을 사용하여 옵셔널을 안전하게 해제하고, guard 문으로 배열의 크기를 확인하여 코드를 더 견고하게 만드는 것이 좋습니다.

Suggested change
func toMinute(_ time: String) -> Int {
let t = time.split(separator: ":").map { Int($0)! }
return t[0] * 60 + t[1]
}
func toMinute(_ time: String) -> Int {
let components = time.split(separator: ":").compactMap { Int($0) }
guard components.count == 2 else { return 0 }
return components[0] * 60 + components[1]
}

Comment on lines +10 to +19
func halfStep(_ s: String) -> String {
return s
.replacingOccurrences(of: "C#", with: "c")
.replacingOccurrences(of: "D#", with: "d")
.replacingOccurrences(of: "F#", with: "f")
.replacingOccurrences(of: "G#", with: "g")
.replacingOccurrences(of: "A#", with: "a")
.replacingOccurrences(of: "B#", with: "C")
.replacingOccurrences(of: "E#", with: "F")
}

Choose a reason for hiding this comment

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

medium

replacingOccurrences(of:with:)를 연달아 호출하는 방식은 잘 동작하지만, 코드가 길어지고 새로운 치환 규칙을 추가하거나 수정하기 번거로울 수 있습니다. 치환 규칙을 딕셔너리로 정의하고 reduce를 사용하면 코드를 더 간결하고 유지보수하기 쉽게 만들 수 있습니다.

    func halfStep(_ s: String) -> String {
        let replacements = [
            "C#": "c", "D#": "d", "F#": "f", "G#": "g", "A#": "a", "B#": "C", "E#": "F"
        ]
        return replacements.reduce(s) { $0.replacingOccurrences(of: $1.key, with: $1.value) }
    }

Comment on lines +35 to +38
var played = ""
for i in 0..<playTime {
played.append(melody[i % melody.count])
}

Choose a reason for hiding this comment

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

medium

playTime 만큼 반복하면서 한 글자씩 played 문자열을 만드는 방식은 playTime이 클 경우 비효율적일 수 있습니다. Swift의 String은 값 타입이므로 append 할 때마다 새로운 문자열이 생성되고 복사될 수 있기 때문입니다. 멜로디를 필요한 만큼 반복하고 남는 부분을 붙이는 방식으로 더 효율적으로 played 문자열을 생성할 수 있습니다.

        let melodyString = String(melody)
        let repeatedCount = playTime / melody.count
        let remainingCount = playTime % melody.count
        let played = String(repeating: melodyString, count: repeatedCount) + melodyString.prefix(remainingCount)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants