More formally, let's the secret string is s and the second player are trying to guess it…
- User
More formally, let's the secret string is s and the second player are trying to guess it with a string x. The number of "bulls" is a number of such positions i (1 ≤ i ≤ 4) where s[i] = x[i]. The number of "cows" is a number of such digits c that s contains c in the position i (i.e. s[i] = c), x contains c, but x[i] ≠ c.
Assistant
Understanding the Definitions:
- Bulls: Positions where both strings have the same character (exact match in position)
- Cows: Characters that appear in both strings but at different positions
Algorithm to Calculate:
- Count bulls: Compare each position, count where s[i] = x[i]
- Count cows: For each digit 0-9, count min(occurrences in s, occurrences in x) minus bulls for that digit