Skip to content

Commit c6860fd

Browse files
committed
Add more tasks
1 parent a4656b7 commit c6860fd

File tree

10 files changed

+1659
-0
lines changed

10 files changed

+1659
-0
lines changed
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
level = "easy"
2+
name = "bulls_and_cows"
3+
tags = ["stdlib"]
4+
time_to_solve_sec = 300
5+
6+
description_en = """
7+
You are given two 4-digit integers: `secret` and `guess`.
8+
9+
For each position:
10+
11+
- If the digit in `guess` is the **same** as in `secret` and in the **same position**, it counts as a **bull**.
12+
- If the digit appears in `secret` but in a **different position**, it counts as a **cow**.
13+
14+
Return an array `[bulls, cows]` with the number of bulls and cows for this pair.
15+
16+
Although in the classic game all digits are different, your function must correctly handle **any** 4-digit numbers, including ones with repeated digits.
17+
"""
18+
19+
description_ru = """
20+
Даны два четырёхзначных числа: `secret` и `guess`.
21+
22+
Для каждой позиции:
23+
24+
- Если цифра в `guess` совпадает с цифрой в `secret` и стоит на **том же месте**, это **бык**.
25+
- Если цифра присутствует в `secret`, но стоит на **другом месте**, это **корова**.
26+
27+
Верните массив `[bulls, cows]` с количеством быков и коров для этой пары.
28+
29+
Хотя в классической игре все цифры различны, ваша функция должна корректно обрабатывать **любые** четырёхзначные числа, включая числа с повторяющимися цифрами.
30+
"""
31+
32+
limits = """
33+
- $1000 \\leq secret \\leq 9999$
34+
- $1000 \\leq guess \\leq 9999$
35+
"""
36+
37+
solution = """
38+
from collections import Counter
39+
from typing import List
40+
41+
def solution(secret: int, guess: int) -> List[int]:
42+
s = str(secret)
43+
g = str(guess)
44+
bulls = sum(1 for i in range(4) if s[i] == g[i])
45+
cs, cg = Counter(s), Counter(g)
46+
cows = sum(min(cs[d], cg[d]) for d in cs) - bulls
47+
return [bulls, cows]
48+
"""
49+
50+
examples = """
51+
solution(1234, 5678) == [0, 0]
52+
solution(1234, 4321) == [0, 4]
53+
solution(4182, 4273) == [1, 1]
54+
solution(4271, 1234) == [1, 2]
55+
solution(4271, 4271) == [4, 0]
56+
solution(4271, 5682) == [0, 1]
57+
"""
58+
59+
[[input_signature]]
60+
argument_name = "secret"
61+
[input_signature.type]
62+
name = "integer"
63+
64+
[[input_signature]]
65+
argument_name = "guess"
66+
[input_signature.type]
67+
name = "integer"
68+
69+
[output_signature.type]
70+
name = "array"
71+
nested = { name = "integer" }
72+
73+
[[asserts]]
74+
arguments = [4271, 1234]
75+
comment = "Given example: one bull (2) and two cows (1 and 4)"
76+
expected = [1, 2]
77+
78+
[[asserts]]
79+
arguments = [4271, 5682]
80+
comment = "Given example: one cow (2), no bulls"
81+
expected = [0, 1]
82+
83+
[[asserts]]
84+
arguments = [4271, 4271]
85+
comment = "Given example: all digits correct and in place"
86+
expected = [4, 0]
87+
88+
[[asserts]]
89+
arguments = [4182, 4273]
90+
comment = "Given example: one bull, one cow"
91+
expected = [1, 1]
92+
93+
[[asserts]]
94+
arguments = [1234, 5678]
95+
comment = "No common digits"
96+
expected = [0, 0]
97+
98+
[[asserts]]
99+
arguments = [1234, 4321]
100+
comment = "All digits present but all in wrong positions"
101+
expected = [0, 4]
102+
103+
[[asserts]]
104+
arguments = [1234, 1278]
105+
comment = "Two bulls, no cows"
106+
expected = [2, 0]
107+
108+
[[asserts]]
109+
arguments = [1234, 1782]
110+
comment = "One bull, one cow"
111+
expected = [1, 1]
112+
113+
[[asserts]]
114+
arguments = [9876, 6789]
115+
comment = "All digits present but all displaced"
116+
expected = [0, 4]
117+
118+
[[asserts]]
119+
arguments = [1111, 1111]
120+
comment = "All digits equal with repeats"
121+
expected = [4, 0]
122+
123+
[[asserts]]
124+
arguments = [1122, 2211]
125+
comment = "All digits present but all in wrong positions with repeats"
126+
expected = [0, 4]
127+
128+
[[asserts]]
129+
arguments = [9090, 9009]
130+
comment = "Two bulls, two cows with repeated digits"
131+
expected = [2, 2]
132+
133+
[[asserts]]
134+
arguments = [1023, 1023]
135+
comment = "Exact match with a zero digit"
136+
expected = [4, 0]
137+
138+
[[asserts]]
139+
arguments = [1023, 1302]
140+
comment = "One bull, three cows, all digits shared"
141+
expected = [1, 3]
142+
143+
[[asserts]]
144+
arguments = [9087, 7890]
145+
comment = "All digits present, all displaced"
146+
expected = [0, 4]
147+
148+
[[asserts]]
149+
arguments = [2468, 8642]
150+
comment = "Even digits, reversed order blocks"
151+
expected = [0, 4]
152+
153+
[[asserts]]
154+
arguments = [1357, 1357]
155+
comment = "Odd digits, all correct"
156+
expected = [4, 0]
157+
158+
[[asserts]]
159+
arguments = [1357, 7531]
160+
comment = "Same digits, rotated positions"
161+
expected = [0, 4]
162+
163+
[[asserts]]
164+
arguments = [1234, 1294]
165+
comment = "Three digits correct and in place"
166+
expected = [3, 0]
167+
168+
[[asserts]]
169+
arguments = [1234, 1203]
170+
comment = "Two bulls, one cow"
171+
expected = [2, 1]
172+
173+
[[asserts]]
174+
arguments = [1234, 9834]
175+
comment = "Two bulls, remaining digits different"
176+
expected = [2, 0]
177+
178+
[[asserts]]
179+
arguments = [5678, 7618]
180+
comment = "Two bulls and one additional shared digit"
181+
expected = [2, 1]
182+
183+
[[asserts]]
184+
arguments = [5678, 5768]
185+
comment = "Two bulls and two cows"
186+
expected = [2, 2]
187+
188+
[[asserts]]
189+
arguments = [5678, 5670]
190+
comment = "Three digits correct, last digit different"
191+
expected = [3, 0]
192+
193+
[[asserts]]
194+
arguments = [5678, 8567]
195+
comment = "All digits present but permuted"
196+
expected = [0, 4]
197+
198+
[[asserts]]
199+
arguments = [1023, 9876]
200+
comment = "No common digits between secret and guess"
201+
expected = [0, 0]
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
level = "easy"
2+
name = "capitalized_words_number"
3+
tags = ["string"]
4+
time_to_solve_sec = 200
5+
6+
description_en = """
7+
Given a string `s`, count how many **words** in it start with a capital letter.
8+
9+
A word is any substring separated by spaces. A word **counts** if its **first character** is an uppercase letter (`'A'`–`'Z'`), even if it is followed by punctuation (for example, `"Hello,"` is counted).
10+
"""
11+
12+
description_ru = """
13+
По заданной строке `s` подсчитайте, сколько в ней **слов** начинается с заглавной буквы.
14+
15+
Слово — это любая подстрока, отделённая пробелами. Слово **засчитывается**, если его **первый символ** — заглавная латинская буква (`'A'`–`'Z'`), даже если далее следует пунктуация (например, `"Hello,"` считается).
16+
"""
17+
18+
limits = """
19+
- $0 \\leq \\text{len}(s) \\leq 1000$
20+
"""
21+
22+
solution = """
23+
def solution(s: str) -> int:
24+
count = 0
25+
for w in s.split(" "):
26+
if w and w[0].isupper():
27+
count += 1
28+
return count
29+
"""
30+
31+
examples = """
32+
solution("loRem ipSum") == 0
33+
solution("lorem ipsum.") == 0
34+
solution("Lorem Ipsum Caesar") == 3
35+
solution("Lorem ipsum, Hello") == 2
36+
solution("lorem, ipsum Hello CaeSar") == 2
37+
"""
38+
39+
[[input_signature]]
40+
argument_name = "s"
41+
[input_signature.type]
42+
name = "string"
43+
44+
[output_signature.type]
45+
name = "integer"
46+
47+
[[asserts]]
48+
arguments = ["lorem ipsum."]
49+
comment = "No words starting with a capital letter"
50+
expected = 0
51+
52+
[[asserts]]
53+
arguments = ["Lorem ipsum, Hello"]
54+
comment = "Two capitalized words: Lorem, Hello"
55+
expected = 2
56+
57+
[[asserts]]
58+
arguments = ["lorem, ipsum Hello CaeSar"]
59+
comment = "Hello and CaeSar start with uppercase"
60+
expected = 2
61+
62+
[[asserts]]
63+
arguments = ["loRem ipSum"]
64+
comment = "Uppercase not at the first character"
65+
expected = 0
66+
67+
[[asserts]]
68+
arguments = ["Lorem Ipsum Caesar"]
69+
comment = "All three words start with uppercase"
70+
expected = 3
71+
72+
[[asserts]]
73+
arguments = [""]
74+
comment = "Empty string has no words"
75+
expected = 0
76+
77+
[[asserts]]
78+
arguments = [" "]
79+
comment = "Only spaces, no words with first character"
80+
expected = 0
81+
82+
[[asserts]]
83+
arguments = ["Hello"]
84+
comment = "Single capitalized word"
85+
expected = 1
86+
87+
[[asserts]]
88+
arguments = ["hello"]
89+
comment = "Single lowercase word"
90+
expected = 0
91+
92+
[[asserts]]
93+
arguments = ["Hello, world!"]
94+
comment = "Hello, starts with uppercase, world! does not"
95+
expected = 1
96+
97+
[[asserts]]
98+
arguments = ["Hello, World!"]
99+
comment = "Both Hello, and World! start with uppercase"
100+
expected = 2
101+
102+
[[asserts]]
103+
arguments = ["(Hello) World"]
104+
comment = "Words start with '(' and 'W'; only World counts as it starts with uppercase W"
105+
expected = 1
106+
107+
[[asserts]]
108+
arguments = ["\"Hello\" World"]
109+
comment = "First characters '\"' and 'W'; only World counts as it starts with uppercase W"
110+
expected = 1
111+
112+
[[asserts]]
113+
arguments = ["A b C d"]
114+
comment = "A and C are counted"
115+
expected = 2
116+
117+
[[asserts]]
118+
arguments = ["ABC def GHI"]
119+
comment = "ABC and GHI start with uppercase"
120+
expected = 2
121+
122+
[[asserts]]
123+
arguments = ["abc DEF ghi"]
124+
comment = "Only DEF starts with uppercase"
125+
expected = 1
126+
127+
[[asserts]]
128+
arguments = ["hello World"]
129+
comment = "Extra spaces, only World counts"
130+
expected = 1
131+
132+
[[asserts]]
133+
arguments = ["Hello world Foo"]
134+
comment = "Hello and Foo start with uppercase"
135+
expected = 2
136+
137+
[[asserts]]
138+
arguments = ["HELLO WORLD"]
139+
comment = "Both words start with uppercase H and W"
140+
expected = 2
141+
142+
[[asserts]]
143+
arguments = ["123abc Hello"]
144+
comment = "Word starting with digit is not counted, Hello is"
145+
expected = 1
146+
147+
[[asserts]]
148+
arguments = ["_Hello World"]
149+
comment = "Word starting with '_' is not counted, World is"
150+
expected = 1
151+
152+
[[asserts]]
153+
arguments = ["Hello-world Foo-bar"]
154+
comment = "Split by spaces, both Hello-world and Foo-bar start with uppercase"
155+
expected = 2
156+
157+
[[asserts]]
158+
arguments = ["a B c D e F"]
159+
comment = "B, D and F are counted"
160+
expected = 3
161+
162+
[[asserts]]
163+
arguments = ["Lorem ipsum. Dolor sit Amet."]
164+
comment = "Lorem, Dolor, Amet. start with uppercase"
165+
expected = 3
166+
167+
[[asserts]]
168+
arguments = ["Mixed CASE Words like JavaScript and HTML"]
169+
comment = "Mixed, CASE, Words, JavaScript and HTML are counted"
170+
expected = 5
171+
172+
[[asserts]]
173+
arguments = ["no Capitals here"]
174+
comment = "Only 'Capitals' starts with uppercase"
175+
expected = 1
176+
177+
[[asserts]]
178+
arguments = ["Edge UpperCase lowerCase"]
179+
comment = "Edge and UpperCase start with uppercase"
180+
expected = 2
181+
182+
[[asserts]]
183+
arguments = ["already Capitalized Words."]
184+
comment = "already is lowercase, Capitalized and Words. counted"
185+
expected = 2

0 commit comments

Comments
 (0)