Skip to content

필수 구현 과제 Lv2 #2

Merged
Roy-wonji merged 5 commits intodevelopfrom
Feature/misson-02
Aug 28, 2025
Merged

필수 구현 과제 Lv2 #2
Roy-wonji merged 5 commits intodevelopfrom
Feature/misson-02

Conversation

@Roy-wonji
Copy link
Contributor

✨ 작업 내용

  • 정답을 맞추기 위해 3자리수를 입력하고 힌트를 받습니다
  • 트는 야구용어인 볼과 스트라이크입니다.
  • 같은 자리에 같은 숫자가 있는 경우 스트라이크, 다른 자리에 숫자가 있는 경우 볼입니다
  • 만약 올바르지 않은 입력값에 대해서는 오류 문구를 보여주세요
  • 3자리 숫자가 정답과 같은 경우 게임이 종료됩니다

@auto-assign auto-assign bot requested review from Peter1119 and minneee August 27, 2025 04:40
@Roy-wonji Roy-wonji changed the title Feature/misson 02 필수 구현 과제 Lv2 Aug 27, 2025
Copy link

@minneee minneee 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

@Peter1119 Peter1119 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 !

trimmed.allSatisfy({ $0.isNumber }),
!trimmed.contains("0") else { return nil }
let numbers = trimmed.compactMap { Int(String($0)) }
guard Set(numbers).count == digits else { return nil }

Choose a reason for hiding this comment

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

Set으로 매핑해서 count를 하신 이유가 있으신가요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Peter1119 중복된 값을 안들어오게 할려고 해서여 그렇게 진행을 했습니다

Comment on lines +60 to +65
let strikeCount = zip(answer, guess).filter { $0 == $1 }.count
let ballCount = guess.filter { answer.contains($0) }.count - strikeCount

if strikeCount == digits { return .correct }
if strikeCount == 0 && ballCount == 0 { return .nothing }
return .strikeAndBall(strike: strikeCount, ball: ballCount)

Choose a reason for hiding this comment

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

answer과 guess에 대한 파라미터로 들어오고
둘의 관계가 더 중요해보입니다. 따라서 digits의 의존성을 제거하는 것도 좋을 것 같아요 ~!
digits로 인해서 answer의 count가 결정된다는 것을 한번 더 생각하게 되는 방향이라서요 ~!

@Roy-wonji Roy-wonji merged commit 44fb695 into develop Aug 28, 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.

3 participants