From 87230cee867d6d4695be460103b47ac0090e59ec Mon Sep 17 00:00:00 2001 From: Dmitrii Ushakov Date: Fri, 8 May 2026 18:35:23 +0300 Subject: [PATCH 1/3] Desctiptions clarified --- tasks/easy/stdlib/bulls_and_cows.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/easy/stdlib/bulls_and_cows.toml b/tasks/easy/stdlib/bulls_and_cows.toml index 4ddebb4..f11c528 100644 --- a/tasks/easy/stdlib/bulls_and_cows.toml +++ b/tasks/easy/stdlib/bulls_and_cows.toml @@ -8,12 +8,12 @@ You are given two 4-digit integers: `secret` and `guess`. For each position: -- If the digit in `guess` is the **same** as in `secret` and in the **same position**, it counts as a **bull**. -- If the digit appears in `secret` but in a **different position**, it counts as a **cow**. +- If a digit from `guess` matches the digit in `secret` at the **same position**, then it counts as a **bull**. +- If a digit from `guess` appears in `secret`, but at the **another position**, then it counts as a **cow**. Note that no more than one digit from `guess` can be considered a **cow** in relation to the same digit in `secret`. Return an array `[bulls, cows]` with the number of bulls and cows for this pair. -Although in the classic game all digits are different, your function must correctly handle **any** 4-digit numbers, including ones with repeated digits. +Although all the digits in `secret` should be different in the classic game, your function must correctly handle **any** 4-digit numbers, including numbers with repeating digits (this is why the description of **cows** was specified). """ description_ru = """ @@ -21,12 +21,12 @@ description_ru = """ Для каждой позиции: -- Если цифра в `guess` совпадает с цифрой в `secret` и стоит на **том же месте**, это **бык**. -- Если цифра присутствует в `secret`, но стоит на **другом месте**, это **корова**. +- Если цифра из `guess` совпадает с цифрой в `secret` на **том же месте**, то это **бык**. +- Если цифра из `guess` присутствует в `secret`, но стоит на **другом месте**, то это **корова**. При этом по отношению к одной и той же цифре в `secret` **коровой** может считаться не более одной цифры из `guess`. Верните массив `[bulls, cows]` с количеством быков и коров для этой пары. -Хотя в классической игре все цифры различны, ваша функция должна корректно обрабатывать **любые** четырёхзначные числа, включая числа с повторяющимися цифрами. +Хотя в классической игре все цифры в `secret` должны быть различны, ваша функция должна корректно обрабатывать **любые** четырёхзначные числа, включая числа с повторяющимися цифрами (именно для этого было дано уточнение в описании **коров**). """ limits = """ From 13d588363971c9a0ead8fb5ef0e48e51cae8b6a1 Mon Sep 17 00:00:00 2001 From: Dmitrii Ushakov Date: Fri, 8 May 2026 20:00:15 +0300 Subject: [PATCH 2/3] Slightly changed solution --- tasks/easy/stdlib/bulls_and_cows.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tasks/easy/stdlib/bulls_and_cows.toml b/tasks/easy/stdlib/bulls_and_cows.toml index f11c528..bdfea3b 100644 --- a/tasks/easy/stdlib/bulls_and_cows.toml +++ b/tasks/easy/stdlib/bulls_and_cows.toml @@ -39,9 +39,8 @@ from collections import Counter from typing import List def solution(secret: int, guess: int) -> List[int]: - s = str(secret) - g = str(guess) - bulls = sum(1 for i in range(4) if s[i] == g[i]) + s, g = str(secret), str(guess) + bulls = sum(s[i] == g[i] for i in range(4)) cs, cg = Counter(s), Counter(g) cows = sum(min(cs[d], cg[d]) for d in cs) - bulls return [bulls, cows] From 5b348f14bdf813fd4fad68b487718c41c4c68d8e Mon Sep 17 00:00:00 2001 From: Dmitrii Ushakov Date: Fri, 8 May 2026 20:16:18 +0300 Subject: [PATCH 3/3] Add extra asserts to ruin simple solutions --- tasks/easy/stdlib/bulls_and_cows.toml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tasks/easy/stdlib/bulls_and_cows.toml b/tasks/easy/stdlib/bulls_and_cows.toml index bdfea3b..bb07118 100644 --- a/tasks/easy/stdlib/bulls_and_cows.toml +++ b/tasks/easy/stdlib/bulls_and_cows.toml @@ -198,3 +198,23 @@ expected = [0, 4] arguments = [1023, 9876] comment = "No common digits between secret and guess" expected = [0, 0] + +[[asserts]] +arguments = [7792, 8997] +comment = "One bull, one cow" +expected = [1, 1] + +[[asserts]] +arguments = [4020, 5447] +comment = "One 4 in secret, two 4's in guess" +expected = [0, 1] + +[[asserts]] +arguments = [2026, 7217] +comment = "Two 2's in secret, one 2 in guess" +expected = [0, 1] + +[[asserts]] +arguments = [9429, 1999] +comment = "One 9 is bull, one 9 is cow, one 9 is nothing" +expected = [1, 1]