forked from Xiaoxue-xx/HaluAgent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
codellama-34b-humaneval_test_63.json
443 lines (443 loc) · 103 KB
/
codellama-34b-humaneval_test_63.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
[
{
"id": "30",
"run_id": "### ✅ Run 3",
"question": "仅返回列表中的正数。",
"answer": "def get_positive(l: list):\n \"\"\"Return only positive numbers in the list.\n >>> get_positive([-1, 2, -4, 5, 6])\n [2, 5, 6]\n >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n [5, 3, 2, 3, 9, 123, 1]\n \"\"\"\n return [x for x in l if x > 0]\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([-1, -2, 4, 5, 6]) == [4, 5, 6]\n assert candidate([5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]\n assert candidate([-1, -2]) == []\n assert candidate([]) == []\n\ncheck(get_positive)",
"judge": 0
},
{
"id": "61",
"run_id": "## Runs",
"question": "括号是由\"(\"和\")\"组成的字符串。\n如果每个开括号都有对应的闭括号,则返回True。\n\n >>> correct_bracketing(\"(\")\n False\n >>> correct_bracketing(\"()\")\n True\n >>> correct_bracketing(\"(()())\")\n True\n >>> correct_bracketing(\")(()\")\n False",
"answer": "def correct_bracketing(brackets: str):\n \"\"\" brackets is a string of \"(\" and \")\".\n return True if every opening bracket has a corresponding closing bracket.\n\n >>> correct_bracketing(\"(\")\n False\n >>> correct_bracketing(\"()\")\n True\n >>> correct_bracketing(\"(()())\")\n True\n >>> correct_bracketing(\")(()\")\n False\n \"\"\"\n stack = []\n for char in brackets:\n if char == \"(\":\n stack.append(char)\n elif char == \")\":\n if len(stack) == 0:\n return False\n stack.pop()\n return len(stack) == 0\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(\"()\")\n assert candidate(\"(()())\")\n assert candidate(\"()()(()())()\")\n assert candidate(\"()()((()()())())(()()(()))\")\n assert not candidate(\"((()())))\")\n assert not candidate(\")(()\")\n assert not candidate(\"(\")\n assert not candidate(\"((((\")\n assert not candidate(\")\")\n assert not candidate(\"(()\")\n assert not candidate(\"()()(()())())(()\")\n assert not candidate(\"()()(()())()))()\")\n\ncheck(correct_bracketing)",
"judge": 0
},
{
"id": "55",
"run_id": "### ✅ Run 7",
"question": "返回第 n 个斐波那契数。\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21",
"answer": "def fib(n: int):\n \"\"\"Return n-th Fibonacci number.\n >>> fib(10)\n 55\n >>> fib(1)\n 1\n >>> fib(8)\n 21\n \"\"\"\n if n <= 1:\n return n\n else:\n return fib(n-1) + fib(n-2)\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(10) == 55\n assert candidate(1) == 1\n assert candidate(8) == 21\n assert candidate(11) == 89\n assert candidate(12) == 144\n\ncheck(fib)",
"judge": 0
},
{
"id": "159",
"run_id": "### ❌ Run 4",
"question": "你是一只饥饿的兔子,你已经吃了一定数量的胡萝卜,但现在你需要再吃更多的胡萝卜来完成一天的餐食。你应该返回一个数组,包括[你餐后吃掉的胡萝卜总数,餐后剩下的胡萝卜数量]。如果剩余的胡萝卜不够,你将吃掉所有剩余的胡萝卜,但仍然会感到饥饿。\n\n示例:\n* eat(5, 6, 10) -> [11, 4]\n* eat(4, 8, 9) -> [12, 1]\n* eat(1, 10, 10) -> [11, 0]\n* eat(2, 11, 5) -> [7, 0]\n\n变量:\n@number:整数\n 你已经吃掉的胡萝卜数量。\n@need:整数\n 你需要吃掉的胡萝卜数量。\n@remaining:整数\n 存货中剩余的胡萝卜数量\n\n约束:\n* 0 <= number <= 1000\n* 0 <= need <= 1000\n* 0 <= remaining <= 1000\n\n祝你玩得开心 :)",
"answer": "def eat(number, need, remaining):\n \"\"\"\n You're a hungry rabbit, and you already have eaten a certain number of carrots,\n but now you need to eat more carrots to complete the day's meals.\n you should return an array of [ total number of eaten carrots after your meals,\n the number of carrots left after your meals ]\n if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.\n \n Example:\n * eat(5, 6, 10) -> [11, 4]\n * eat(4, 8, 9) -> [12, 1]\n * eat(1, 10, 10) -> [11, 0]\n * eat(2, 11, 5) -> [7, 0]\n \n Variables:\n @number : integer\n the number of carrots that you have eaten.\n @need : integer\n the number of carrots that you need to eat.\n @remaining : integer\n the number of remaining carrots thet exist in stock\n \n Constrain:\n * 0 <= number <= 1000\n * 0 <= need <= 1000\n * 0 <= remaining <= 1000\n\n Have fun :)\n \"\"\"\n total_eaten = number + need\n carrots_left = remaining - need\n if carrots_left < 0:\n carrots_left = 0\n return [total_eaten, carrots_left]\n\ndef check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate(5, 6, 10) == [11, 4], \"Error\"\n assert candidate(4, 8, 9) == [12, 1], \"Error\"\n assert candidate(1, 10, 10) == [11, 0], \"Error\"\n assert candidate(2, 11, 5) == [7, 0], \"Error\"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate(4, 5, 7) == [9, 2], \"Error\"\n assert candidate(4, 5, 1) == [5, 0], \"Error\"\n\ncheck(eat)",
"judge": 1
},
{
"id": "108",
"run_id": "### ❌ Run 6",
"question": "编写一个函数 count_nums,该函数接收一个整数数组,并返回数字和大于0的元素数量。\n如果一个数字是负数,那么它的第一个数字将是负数:\n例如,-123 的数字是 -1、2 和 3。\n>>> count_nums([]) == 0\n>>> count_nums([-1, 11, -11]) == 1\n>>> count_nums([1, 1, 2]) == 3",
"answer": "def count_nums(arr):\n count = 0\n for num in arr:\n if sum(map(int, str(abs(num)))) > 0:\n count += 1\n return count\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([]) == 0\n assert candidate([-1, -2, 0]) == 0\n assert candidate([1, 1, 2, -2, 3, 4, 5]) == 6\n assert candidate([1, 6, 9, -6, 0, 1, 5]) == 5\n assert candidate([1, 100, 98, -7, 1, -1]) == 4\n assert candidate([12, 23, 34, -45, -56, 0]) == 5\n assert candidate([-0, 1**0]) == 1\n assert candidate([1]) == 1\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(count_nums)",
"judge": 1
},
{
"id": "119",
"run_id": "### ❌ Run 8",
"question": "给定两个字符串的列表,这两个字符串仅包含开括号 '(' 或闭括号 ')'。你的任务是检查是否有可能以某种顺序连接这两个字符串,使得结果字符串是好的。一个字符串 S 被认为是好的,当且仅当 S 中的所有括号都是平衡的。例如:字符串 '(())()' 是好的,而字符串 '())' 则不是。如果有办法使字符串变好,则返回 'Yes',否则返回 'No'。\n\n例如:\nmatch_parens(['()(', ')']) == 'Yes'\nmatch_parens([')', ')']) == 'No'",
"answer": "def match_parens(lst):\n '''\n You are given a list of two strings, both strings consist of open\n parentheses '(' or close parentheses ')' only.\n Your job is to check if it is possible to concatenate the two strings in\n some order, that the resulting string will be good.\n A string S is considered to be good if and only if all parentheses in S\n are balanced. For example: the string '(())()' is good, while the string\n '())' is not.\n Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.\n\n Examples:\n match_parens(['()(', ')']) == 'Yes'\n match_parens([')', ')']) == 'No'\n '''\n left_parens = 0\n right_parens = 0\n for char in lst[0]:\n if char == '(':\n left_parens += 1\n else:\n right_parens += 1\n for char in lst[1]:\n if char == '(':\n left_parens += 1\n else:\n right_parens += 1\n if left_parens == right_parens:\n return 'Yes'\n else:\n return 'No'\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(['()(', ')']) == 'Yes'\n assert candidate([')', ')']) == 'No'\n assert candidate(['(()(())', '())())']) == 'No'\n assert candidate([')())', '(()()(']) == 'Yes'\n assert candidate(['(())))', '(()())((']) == 'Yes'\n assert candidate(['()', '())']) == 'No'\n assert candidate(['(()(', '()))()']) == 'Yes'\n assert candidate(['((((', '((())']) == 'No'\n assert candidate([')(()', '(()(']) == 'No'\n assert candidate([')(', ')(']) == 'No'\n \n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(['(', ')']) == 'Yes'\n assert candidate([')', '(']) == 'Yes'\n\ncheck(match_parens)",
"judge": 1
},
{
"id": "148",
"run_id": "### ❌ Run 10",
"question": "我们的太阳系有八颗行星:离太阳最近的是水星,其次是金星,然后是地球、火星、木星、土星、天王星、海王星。编写一个函数,接受两个行星名称作为字符串planet1和planet2。该函数应该返回一个元组,包含所有位于planet1和planet2轨道之间的行星,按接近太阳的顺序排序。如果planet1或planet2不是正确的行星名称,则函数应返回一个空元组。\n示例\nbf(\"Jupiter\", \"Neptune\") ==> (\"Saturn\", \"Uranus\")\nbf(\"Earth\", \"Mercury\") ==> (\"Venus\")\nbf(\"Mercury\", \"Uranus\") ==> (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")",
"answer": "def bf(planet1, planet2):\n planets = [\"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\"]\n planet1_index = planets.index(planet1)\n planet2_index = planets.index(planet2)\n if planet1_index == -1 or planet2_index == -1:\n return ()\n return tuple(planets[planet1_index+1:planet2_index])\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(\"Jupiter\", \"Neptune\") == (\"Saturn\", \"Uranus\"), \"First test error: \" + str(len(candidate(\"Jupiter\", \"Neptune\"))) \n assert candidate(\"Earth\", \"Mercury\") == (\"Venus\",), \"Second test error: \" + str(candidate(\"Earth\", \"Mercury\")) \n assert candidate(\"Mercury\", \"Uranus\") == (\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\"), \"Third test error: \" + str(candidate(\"Mercury\", \"Uranus\")) \n assert candidate(\"Neptune\", \"Venus\") == (\"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\"), \"Fourth test error: \" + str(candidate(\"Neptune\", \"Venus\")) \n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(\"Earth\", \"Earth\") == ()\n assert candidate(\"Mars\", \"Earth\") == ()\n assert candidate(\"Jupiter\", \"Makemake\") == ()\n\ncheck(bf)",
"judge": 1
},
{
"id": "15",
"run_id": "### ✅ Run 5",
"question": "返回一个字符串,包含从0开始到n(包含n)的由空格分隔的数字序列。\n >>> string_sequence(0)\n '0'\n >>> string_sequence(5)\n '0 1 2 3 4 5'",
"answer": "def string_sequence(n: int) -> str:\n \"\"\" Return a string containing space-delimited numbers starting from 0 upto n inclusive.\n >>> string_sequence(0)\n '0'\n >>> string_sequence(5)\n '0 1 2 3 4 5'\n \"\"\"\n return \" \".join(str(i) for i in range(n+1))\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(0) == '0'\n assert candidate(3) == '0 1 2 3'\n assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10'\n\ncheck(string_sequence)",
"judge": 0
},
{
"id": "44",
"run_id": "### ❌ Run 7",
"question": "将输入数字 x 的数制基数转换为 base。\n返回转换后的字符串表示。\n基数数字小于 10。\n>>> change_base(8, 3)\n'22'\n>>> change_base(8, 2)\n'1000'\n>>> change_base(7, 2)\n'111'",
"answer": "def change_base(x: int, base: int):\n \"\"\"Change numerical base of input number x to base.\n return string representation after the conversion.\n base numbers are less than 10.\n >>> change_base(8, 3)\n '22'\n >>> change_base(8, 2)\n '1000'\n >>> change_base(7, 2)\n '111'\n \"\"\"\n return str(x).lower()\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(8, 3) == \"22\"\n assert candidate(9, 3) == \"100\"\n assert candidate(234, 2) == \"11101010\"\n assert candidate(16, 2) == \"10000\"\n assert candidate(8, 2) == \"1000\"\n assert candidate(7, 2) == \"111\"\n for x in range(2, 8):\n assert candidate(x, x + 1) == str(x)\n\ncheck(change_base)",
"judge": 1
},
{
"id": "70",
"run_id": "### ❌ Run 3",
"question": "给定一个整数列表,返回一个奇怪顺序的列表。\n奇怪的排序,是指你首先找到最小值,\n然后是剩余整数中的最大值,然后是最小值,依此类推。\n\n示例:\nstrange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]\nstrange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]\nstrange_sort_list([]) == []",
"answer": "def strange_sort_list(lst):\n '''\n Given list of integers, return list in strange order.\n Strange sorting, is when you start with the minimum value,\n then maximum of the remaining integers, then minimum and so on.\n\n Examples:\n strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3]\n strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5]\n strange_sort_list([]) == []\n '''\n if not lst:\n return []\n minimum = min(lst)\n maximum = max(lst)\n result = [minimum]\n while len(result) < len(lst):\n remaining = lst[:]\n remaining.remove(minimum)\n if remaining:\n maximum = max(remaining)\n result.append(maximum)\n remaining.remove(maximum)\n if remaining:\n minimum = min(remaining)\n result.append(minimum)\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([1, 2, 3, 4]) == [1, 4, 2, 3]\n assert candidate([5, 6, 7, 8, 9]) == [5, 9, 6, 8, 7]\n assert candidate([1, 2, 3, 4, 5]) == [1, 5, 2, 4, 3]\n assert candidate([5, 6, 7, 8, 9, 1]) == [1, 9, 5, 8, 6, 7]\n assert candidate([5, 5, 5, 5]) == [5, 5, 5, 5]\n assert candidate([]) == []\n assert candidate([1,2,3,4,5,6,7,8]) == [1, 8, 2, 7, 3, 6, 4, 5]\n assert candidate([0,2,2,2,5,5,-5,-5]) == [-5, 5, -5, 5, 0, 2, 2, 2]\n assert candidate([111111]) == [111111]\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(strange_sort_list)",
"judge": 1
},
{
"id": "21",
"run_id": "### ✅ Run 4",
"question": "给定一个至少包含两个元素的数字列表,对该列表进行线性变换,使得最小的数字变成0,最大的数字变成1。\n rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]",
"answer": "from typing import List\n\ndef rescale_to_unit(numbers: List[float]) -> List[float]:\n \"\"\" Given list of numbers (of at least two elements), apply a linear transform to that list,\n such that the smallest number will become 0 and the largest will become 1\n >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])\n [0.0, 0.25, 0.5, 0.75, 1.0]\n \"\"\"\n min_value = min(numbers)\n max_value = max(numbers)\n return [(x - min_value) / (max_value - min_value) for x in numbers]\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([2.0, 49.9]) == [0.0, 1.0]\n assert candidate([100.0, 49.9]) == [1.0, 0.0]\n assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]\n assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]\n assert candidate([12.0, 11.0, 15.0, 13.0, 14.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]\n\ncheck(rescale_to_unit)",
"judge": 0
},
{
"id": "83",
"run_id": "### ✅ Run 5",
"question": "给定一个正整数n,返回以1开始或结束的n位正整数的数量。",
"answer": "def starts_one_ends(n):\n \"\"\"\n Given a positive integer n, return the count of the numbers of n-digit\n positive integers that start or end with 1.\n \"\"\"\n count = 0\n for i in range(10**(n-1), 10**n):\n if str(i)[0] == '1' or str(i)[-1] == '1':\n count += 1\n return count\n\ndef check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate(1) == 1\n assert candidate(2) == 18\n assert candidate(3) == 180\n assert candidate(4) == 1800\n assert candidate(5) == 18000\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(starts_one_ends)",
"judge": 0
},
{
"id": "93",
"run_id": "### ❌ Run 2",
"question": "编写一个函数,接收一条消息,并以这样的方式对其进行编码:将所有字母的大小写进行交换,并将消息中的所有元音字母替换为英文字母表中该元音字母后面第二个位置的字母。\n假设仅包含字母。\n\n示例:\n>>> encode('test')\n'TGST'\n>>> encode('This is a message')\n'tHKS KS C MGSSCGG'",
"answer": "def encode(message):\n \"\"\"\n Write a function that takes a message, and encodes in such a \n way that it swaps case of all letters, replaces all vowels in \n the message with the letter that appears 2 places ahead of that \n vowel in the english alphabet. \n Assume only letters. \n \n Examples:\n >>> encode('test')\n 'TGST'\n >>> encode('This is a message')\n 'tHKS KS C MGSSCGG'\n \"\"\"\n encoded_message = ''\n for char in message:\n if char.isalpha():\n if char.islower():\n encoded_message += char.upper()\n else:\n encoded_message += char.lower()\n else:\n encoded_message += char\n return encoded_message\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('TEST') == 'tgst', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('Mudasir') == 'mWDCSKR', \"This prints if this assert fails 2 (good for debugging!)\"\n assert candidate('YES') == 'ygs', \"This prints if this assert fails 3 (good for debugging!)\"\n \n # Check some edge cases that are easy to work out by hand.\n assert candidate('This is a message') == 'tHKS KS C MGSSCGG', \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate(\"I DoNt KnOw WhAt tO WrItE\") == 'k dQnT kNqW wHcT Tq wRkTg', \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(encode)",
"judge": 1
},
{
"id": "31",
"run_id": "## Runs",
"question": "如果给定的数字是质数,则返回true,否则返回false。\n >>> is_prime(6)\n False\n >>> is_prime(101)\n True\n >>> is_prime(11)\n True\n >>> is_prime(13441)\n True\n >>> is_prime(61)\n True\n >>> is_prime(4)\n False\n >>> is_prime(1)\n False",
"answer": "def is_prime(n):\n \"\"\"Return true if a given number is prime, and false otherwise.\n >>> is_prime(6)\n False\n >>> is_prime(101)\n True\n >>> is_prime(11)\n True\n >>> is_prime(13441)\n True\n >>> is_prime(61)\n True\n >>> is_prime(4)\n False\n >>> is_prime(1)\n False\n \"\"\"\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(6) == False\n assert candidate(101) == True\n assert candidate(11) == True\n assert candidate(13441) == True\n assert candidate(61) == True\n assert candidate(4) == False\n assert candidate(1) == False\n assert candidate(5) == True\n assert candidate(11) == True\n assert candidate(17) == True\n assert candidate(5 * 17) == False\n assert candidate(11 * 7) == False\n assert candidate(13441 * 19) == False\n\ncheck(is_prime)",
"judge": 0
},
{
"id": "60",
"run_id": "### ✅ Run 2",
"question": "sum_to_n 是一个函数,它将数字从 1 加到 n。\n >>> sum_to_n(30)\n 465\n >>> sum_to_n(100)\n 5050\n >>> sum_to_n(5)\n 15\n >>> sum_to_n(10)\n 55\n >>> sum_to_n(1)\n 1",
"answer": "def sum_to_n(n: int) -> int:\n \"\"\"sum_to_n is a function that sums numbers from 1 to n.\n >>> sum_to_n(30)\n 465\n >>> sum_to_n(100)\n 5050\n >>> sum_to_n(5)\n 15\n >>> sum_to_n(10)\n 55\n >>> sum_to_n(1)\n 1\n \"\"\"\n return sum(range(1, n+1))\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate(1) == 1\n assert candidate(6) == 21\n assert candidate(11) == 66\n assert candidate(30) == 465\n assert candidate(100) == 5050\n\ncheck(sum_to_n)",
"judge": 0
},
{
"id": "54",
"run_id": "### ✅ Run 9",
"question": "检查两个单词是否由相同的字符组成。",
"answer": "def same_chars(s0: str, s1: str):\n \"\"\"\n Check if two words have the same characters.\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')\n True\n >>> same_chars('abcd', 'dddddddabc')\n True\n >>> same_chars('dddddddabc', 'abcd')\n True\n >>> same_chars('eabcd', 'dddddddabc')\n False\n >>> same_chars('abcd', 'dddddddabce')\n False\n >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')\n False\n \"\"\"\n return all(c in s0 for c in s1) and all(c in s1 for c in s0)\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate('eabcdzzzz', 'dddzzzzzzzddeddabc') == True\n assert candidate('abcd', 'dddddddabc') == True\n assert candidate('dddddddabc', 'abcd') == True\n assert candidate('eabcd', 'dddddddabc') == False\n assert candidate('abcd', 'dddddddabcf') == False\n assert candidate('eabcdzzzz', 'dddzzzzzzzddddabc') == False\n assert candidate('aabb', 'aaccc') == False\n\ncheck(same_chars)",
"judge": 0
},
{
"id": "158",
"run_id": "### ✅ Run 9",
"question": "编写一个函数,接受一个字符串列表。这个列表包含不同的单词。返回具有最多数量独特字符的单词。如果多个字符串有最大数量的独特字符,返回在字典序中最先出现的那个。\n\nfind_max([\"name\", \"of\", \"string\"]) == \"string\"\nfind_max([\"name\", \"enam\", \"game\"]) == \"enam\"\nfind_max([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"aaaaaaa\"",
"answer": "def find_max(words):\n \"\"\"Write a function that accepts a list of strings.\n The list contains different words. Return the word with maximum number\n of unique characters. If multiple strings have maximum number of unique\n characters, return the one which comes first in lexicographical order.\n\n find_max([\"name\", \"of\", \"string\"]) == \"string\"\n find_max([\"name\", \"enam\", \"game\"]) == \"enam\"\n find_max([\"aaaaaaa\", \"bb\" ,\"cc\"]) == \"aaaaaaa\"\n \"\"\"\n max_word = \"\"\n max_char_count = 0\n for word in words:\n char_count = len(set(word))\n if char_count > max_char_count:\n max_char_count = char_count\n max_word = word\n elif char_count == max_char_count:\n if word < max_word:\n max_word = word\n return max_word\n\ndef check(candidate):\n\n # Check some simple cases\n assert (candidate([\"name\", \"of\", \"string\"]) == \"string\"), \"t1\"\n assert (candidate([\"name\", \"enam\", \"game\"]) == \"enam\"), 't2'\n assert (candidate([\"aaaaaaa\", \"bb\", \"cc\"]) == \"aaaaaaa\"), 't3'\n assert (candidate([\"abc\", \"cba\"]) == \"abc\"), 't4'\n assert (candidate([\"play\", \"this\", \"game\", \"of\",\"footbott\"]) == \"footbott\"), 't5'\n assert (candidate([\"we\", \"are\", \"gonna\", \"rock\"]) == \"gonna\"), 't6'\n assert (candidate([\"we\", \"are\", \"a\", \"mad\", \"nation\"]) == \"nation\"), 't7'\n assert (candidate([\"this\", \"is\", \"a\", \"prrk\"]) == \"this\"), 't8'\n\n # Check some edge cases that are easy to work out by hand.\n assert (candidate([\"b\"]) == \"b\"), 't9'\n assert (candidate([\"play\", \"play\", \"play\"]) == \"play\"), 't10'\n\ncheck(find_max)",
"judge": 0
},
{
"id": "109",
"run_id": "## Runs",
"question": "我们有一个由N个整数 arr[1], arr[2], ..., arr[N] 组成的数组 'arr'。数组中的数字将被随机排序。你的任务是确定是否可能通过对给定数组执行以下操作来获得一个非递减顺序排序的数组:\n 你可以执行任意次数的右移操作。\n\n 一次右移操作意味着将数组的所有元素向右移动一个位置。数组的最后一个元素将被移动到数组的起始位置,即0索引处。\n\n 如果通过执行上述操作能够获得排序数组,则返回 True,否则返回 False。\n 如果给定数组为空,则返回 True。\n\n 注意:给定列表保证有唯一元素。\n\n 例如:\n\n move_one_ball([3, 4, 5, 1, 2])==>True\n 解释:通过执行2次右移操作,可以为给定数组实现非递减顺序。\n move_one_ball([3, 5, 4, 1, 2])==>False\n 解释:通过执行任意次数的右移操作,无法为给定数组获得非递减顺序。",
"answer": "def move_one_ball(arr):\n \"\"\"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The\n numbers in the array will be randomly ordered. Your task is to determine if\n it is possible to get an array sorted in non-decreasing order by performing \n the following operation on the given array:\n You are allowed to perform right shift operation any number of times.\n \n One right shift operation means shifting all elements of the array by one\n position in the right direction. The last element of the array will be moved to\n the starting position in the array i.e. 0th index. \n\n If it is possible to obtain the sorted array by performing the above operation\n then return True else return False.\n If the given array is empty then return True.\n\n Note: The given list is guaranteed to have unique elements.\n\n For Example:\n \n move_one_ball([3, 4, 5, 1, 2])==>True\n Explanation: By performin 2 right shift operations, non-decreasing order can\n be achieved for the given array.\n move_one_ball([3, 5, 4, 1, 2])==>False\n Explanation:It is not possible to get non-decreasing order for the given\n array by performing any number of right shift operations.\n \n \"\"\"\n if not arr:\n return True\n else:\n arr.sort()\n for i in range(len(arr)-1):\n if arr[i] > arr[i+1]:\n return False\n return True\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([3, 4, 5, 1, 2])==True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([3, 5, 10, 1, 2])==True\n assert candidate([4, 3, 1, 2])==False\n # Check some edge cases that are easy to work out by hand.\n assert candidate([3, 5, 4, 1, 2])==False, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([])==True\n\ncheck(move_one_ball)",
"judge": 1
},
{
"id": "129",
"run_id": "### ❌ Run 9",
"question": "给定一个N行N列的网格(N >= 2)和一个正整数k,网格的每个单元格包含一个值。范围在[1, N * N]内的每个整数在网格的单元格中恰好出现一次。\n\n你必须在网格中找到长度为k的最短路径。你可以从任何一个单元格开始,在每一步中,你可以移动到任何相邻的单元格,换句话说,你可以去任何与你当前单元格共享边的单元格。\n\n请注意,长度为k的路径意味着恰好访问k个单元格(不必是不同的)。你不能走出网格。\n\n如果在对路径A(长度为k)和路径B(长度为k)经过的单元格的值做成有序列表(我们称之为lst_A和lst_B)后,lst_A在字典上小于lst_B,换句话说,存在一个整数索引i(1 <= i <= k)使得lst_A[i] < lst_B[i]且对于任何j(1 <= j < i)我们都有lst_A[j] = lst_B[j],则认为路径A小于路径B。保证答案是唯一的。\n\n返回最短路径经过的单元格的值的有序列表。\n\n示例:\n\n输入:grid = [[1,2,3], [4,5,6], [7,8,9]], k = 3\n输出:[1, 2, 1]\n\n输入:grid = [[5,9,3], [4,1,6], [7,8,2]], k = 1\n输出:[1]",
"answer": "def minPath(grid, k):\n \"\"\"\n Given a grid with N rows and N columns (N >= 2) and a positive integer k, \n each cell of the grid contains a value. Every integer in the range [1, N * N]\n inclusive appears exactly once on the cells of the grid.\n\n You have to find the minimum path of length k in the grid. You can start\n from any cell, and in each step you can move to any of the neighbor cells,\n in other words, you can go to cells which share an edge with you current\n cell.\n Please note that a path of length k means visiting exactly k cells (not\n necessarily distinct).\n You CANNOT go off the grid.\n A path A (of length k) is considered less than a path B (of length k) if\n after making the ordered lists of the values on the cells that A and B go\n through (let's call them lst_A and lst_B), lst_A is lexicographically less\n than lst_B, in other words, there exist an integer index i (1 <= i <= k)\n such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have\n lst_A[j] = lst_B[j].\n It is guaranteed that the answer is unique.\n Return an ordered list of the values on the cells that the minimum path go through.\n\n Examples:\n\n Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3\n Output: [1, 2, 1]\n\n Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1\n Output: [1]\n \"\"\"\n n = len(grid)\n m = len(grid[0])\n dp = [[0] * (m + 1) for _ in range(n + 1)]\n for i in range(1, n + 1):\n for j in range(1, m + 1):\n dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1\n path = []\n i = n\n j = m\n while i > 0 and j > 0:\n if dp[i][j] == dp[i - 1][j - 1]:\n path.append(grid[i - 1][j - 1])\n i -= 1\n j -= 1\n elif dp[i][j] == dp[i - 1][j]:\n path.append(grid[i - 1][j])\n i -= 1\n else:\n path.append(grid[i][j - 1])\n j -= 1\n return path\n\ndef check(candidate):\n\n # Check some simple cases\n print\n assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1]\n assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1]\n assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2]\n assert candidate([[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7) == [1, 10, 1, 10, 1, 10, 1]\n assert candidate([[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5) == [1, 7, 1, 7, 1]\n assert candidate([[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9) == [1, 6, 1, 6, 1, 6, 1, 6, 1]\n assert candidate([[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12) == [1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]\n assert candidate([[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8) == [1, 3, 1, 3, 1, 3, 1, 3]\n assert candidate([[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8) == [1, 5, 1, 5, 1, 5, 1, 5]\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([[1, 2], [3, 4]], 10) == [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]\n assert candidate([[1, 3], [3, 2]], 10) == [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]\n\ncheck(minPath)",
"judge": 1
},
{
"id": "25",
"run_id": "### ✅ Run 5",
"question": "返回给定整数的质因数列表,顺序从小到大。\n每个因数应出现的次数对应于其在因式分解中的出现次数。\n输入数字应等于所有因数的乘积。",
"answer": "from typing import List\n\ndef factorize(n: int) -> List[int]:\n \"\"\" Return list of prime factors of given integer in the order from smallest to largest.\n Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.\n Input number should be equal to the product of all factors\n >>> factorize(8)\n [2, 2, 2]\n >>> factorize(25)\n [5, 5]\n >>> factorize(70)\n [2, 5, 7]\n \"\"\"\n factors = []\n i = 2\n while i * i <= n:\n if n % i:\n i += 1\n else:\n n //= i\n factors.append(i)\n if n > 1:\n factors.append(n)\n return factors\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate(2) == [2]\n assert candidate(4) == [2, 2]\n assert candidate(8) == [2, 2, 2]\n assert candidate(3 * 19) == [3, 19]\n assert candidate(3 * 19 * 3 * 19) == [3, 3, 19, 19]\n assert candidate(3 * 19 * 3 * 19 * 3 * 19) == [3, 3, 3, 19, 19, 19]\n assert candidate(3 * 19 * 19 * 19) == [3, 19, 19, 19]\n assert candidate(3 * 2 * 3) == [2, 3, 3]\n\ncheck(factorize)",
"judge": 0
},
{
"id": "74",
"run_id": "### ❌ Run 6",
"question": "编写一个函数,它接受两个字符串列表,并返回字符串总字符数较少的那个列表。\n\n如果两个列表的字符总数相同,则返回第一个列表。\n\n示例\ntotal_match([], []) ➞ []\ntotal_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi']\ntotal_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin']\ntotal_match(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi']\ntotal_match(['4'], ['1', '2', '3', '4', '5']) ➞ ['4']",
"answer": "def total_match(lst1, lst2):\n return lst1 if sum(len(s) for s in lst1) < sum(len(s) for s in lst2) else lst2\n\ndef check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([], []) == []\n assert candidate(['hi', 'admin'], ['hi', 'hi']) == ['hi', 'hi']\n assert candidate(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) == ['hi', 'admin']\n assert candidate(['4'], ['1', '2', '3', '4', '5']) == ['4']\n assert candidate(['hi', 'admin'], ['hI', 'Hi']) == ['hI', 'Hi']\n assert candidate(['hi', 'admin'], ['hI', 'hi', 'hi']) == ['hI', 'hi', 'hi']\n assert candidate(['hi', 'admin'], ['hI', 'hi', 'hii']) == ['hi', 'admin']\n\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([], ['this']) == []\n assert candidate(['this'], []) == []\n\ncheck(total_match)",
"judge": 1
},
{
"id": "87",
"run_id": "### ❌ Run 6",
"question": "给定一个二维数据,以嵌套列表的形式,这类似于矩阵,但与矩阵不同的是,每一行可能包含不同数量的列。给定 lst 和一个整数 x,找到列表中的整数 x,并返回一个元组列表,[(x1, y1), (x2, y2) ...],每个元组是一个坐标 - (行,列),从0开始。首先按行以升序排序坐标。同样,按列以降序排序行内的坐标。\n\n示例:\nget_row([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\nget_row([], 1) == []\nget_row([[], [1], [1, 2, 3]], 3) == [(2, 2)]",
"answer": "def get_row(lst, x):\n result = []\n for i, row in enumerate(lst):\n for j, col in enumerate(row):\n if col == x:\n result.append((i, j))\n return sorted(result)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]\n assert candidate([\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6]\n ], 2) == [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]\n assert candidate([\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,1,3,4,5,6],\n [1,2,1,4,5,6],\n [1,2,3,1,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1) == [(0, 0), (1, 0), (2, 1), (2, 0), (3, 2), (3, 0), (4, 3), (4, 0), (5, 4), (5, 0), (6, 5), (6, 0)]\n assert candidate([], 1) == []\n assert candidate([[1]], 2) == []\n assert candidate([[], [1], [1, 2, 3]], 3) == [(2, 2)]\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(get_row)",
"judge": 1
},
{
"id": "40",
"run_id": "### ✅ Run 10",
"question": "triples_sum_to_zero 接受一个整数列表作为输入。\n如果列表中存在三个不同的元素其和为零,则返回 True,否则返回 False。\n\n >>> triples_sum_to_zero([1, 3, 5, 0])\n False\n >>> triples_sum_to_zero([1, 3, -2, 1])\n True\n >>> triples_sum_to_zero([1, 2, 3, 7])\n False\n >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7])\n True\n >>> triples_sum_to_zero([1])\n False",
"answer": "def triples_sum_to_zero(l: list):\n \"\"\"\n triples_sum_to_zero takes a list of integers as an input.\n it returns True if there are three distinct elements in the list that\n sum to zero, and False otherwise.\n\n >>> triples_sum_to_zero([1, 3, 5, 0])\n False\n >>> triples_sum_to_zero([1, 3, -2, 1])\n True\n >>> triples_sum_to_zero([1, 2, 3, 7])\n False\n >>> triples_sum_to_zero([2, 4, -5, 3, 9, 7])\n True\n >>> triples_sum_to_zero([1])\n False\n \"\"\"\n for i in range(len(l)):\n for j in range(i+1, len(l)):\n for k in range(j+1, len(l)):\n if l[i] + l[j] + l[k] == 0:\n return True\n return False\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 3, 5, 0]) == False\n assert candidate([1, 3, 5, -1]) == False\n assert candidate([1, 3, -2, 1]) == True\n assert candidate([1, 2, 3, 7]) == False\n assert candidate([1, 2, 5, 7]) == False\n assert candidate([2, 4, -5, 3, 9, 7]) == True\n assert candidate([1]) == False\n assert candidate([1, 3, 5, -100]) == False\n assert candidate([100, 3, 5, -100]) == False\n\ncheck(triples_sum_to_zero)",
"judge": 0
},
{
"id": "11",
"run_id": "### ✅ Run 10",
"question": "输入是两个只包含1和0的字符串a和b。\n对这些输入执行二进制异或操作,并且也以字符串形式返回结果。",
"answer": "from typing import List\n\ndef string_xor(a: str, b: str) -> str:\n \"\"\" Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n >>> string_xor('010', '110')\n '100'\n \"\"\"\n result = ''\n for i in range(len(a)):\n if a[i] == '1' and b[i] == '1':\n result += '0'\n elif a[i] == '0' and b[i] == '0':\n result += '0'\n else:\n result += '1'\n return result\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('111000', '101010') == '010010'\n assert candidate('1', '1') == '0'\n assert candidate('0101', '0000') == '0101'\n\ncheck(string_xor)",
"judge": 0
},
{
"id": "50",
"run_id": "### ✅ Run 5",
"question": "通过字母表中每个字符移位5来编码字符串。\n\n输入使用encode_shift函数编码的字符串,返回解码后的字符串。",
"answer": "def encode_shift(s: str):\n \"\"\"\n returns encoded string by shifting every character by 5 in the alphabet.\n \"\"\"\n return \"\".join([chr(((ord(ch) + 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\ndef decode_shift(s: str):\n \"\"\"\n takes as input string encoded with encode_shift function. Returns decoded string.\n \"\"\"\n return \"\".join([chr(((ord(ch) - 5 - ord(\"a\")) % 26) + ord(\"a\")) for ch in s])\n\nMETADATA = {}\n\n\ndef check(candidate):\n from random import randint, choice\n import copy\n import string\n\n letters = string.ascii_lowercase\n for _ in range(100):\n str = ''.join(choice(letters) for i in range(randint(10, 20)))\n encoded_str = encode_shift(str)\n assert candidate(copy.deepcopy(encoded_str)) == str\n\ncheck(decode_shift)",
"judge": 0
},
{
"id": "8",
"run_id": "## Runs",
"question": "对于给定的整数列表,返回一个由列表中所有整数的和与乘积组成的元组。空列表的和应等于0,乘积应等于1。",
"answer": "from typing import List, Tuple\n\ndef sum_product(numbers: List[int]) -> Tuple[int, int]:\n \"\"\" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n >>> sum_product([])\n (0, 1)\n >>> sum_product([1, 2, 3, 4])\n (10, 24)\n \"\"\"\n if not numbers:\n return (0, 1)\n return (sum(numbers), math.prod(numbers))\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == (0, 1)\n assert candidate([1, 1, 1]) == (3, 1)\n assert candidate([100, 0]) == (100, 0)\n assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7)\n assert candidate([10]) == (10, 10)\n\ncheck(sum_product)",
"judge": 1
},
{
"id": "97",
"run_id": "### ✅ Run 4",
"question": "完成一个函数,该函数接收两个整数并返回它们各自个位数的乘积。\n假设输入总是有效的。\n示例:\nmultiply(148, 412) 应该返回 16。\nmultiply(19, 28) 应该返回 72。\nmultiply(2020, 1851) 应该返回 0。\nmultiply(14,-15) 应该返回 20。",
"answer": "def multiply(a, b):\n return (a % 10) * (b % 10)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(148, 412) == 16, \"First test error: \" + str(candidate(148, 412)) \n assert candidate(19, 28) == 72, \"Second test error: \" + str(candidate(19, 28)) \n assert candidate(2020, 1851) == 0, \"Third test error: \" + str(candidate(2020, 1851))\n assert candidate(14,-15) == 20, \"Fourth test error: \" + str(candidate(14,-15)) \n assert candidate(76, 67) == 42, \"Fifth test error: \" + str(candidate(76, 67)) \n assert candidate(17, 27) == 49, \"Sixth test error: \" + str(candidate(17, 27)) \n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(0, 1) == 0, \"1st edge test error: \" + str(candidate(0, 1))\n assert candidate(0, 0) == 0, \"2nd edge test error: \" + str(candidate(0, 0))\n\ncheck(multiply)",
"judge": 0
},
{
"id": "64",
"run_id": "### ❌ Run 2",
"question": "编写一个函数 vowels_count,该函数接受一个代表单词的字符串作为输入,并返回字符串中元音字母的数量。在这个例子中,元音字母是 'a', 'e', 'i', 'o', 'u'。这里,'y' 也是一个元音字母,但仅当它位于给定单词的末尾时。\n\n示例:\n>>> vowels_count(\"abcde\")\n2\n>>> vowels_count(\"ACEDY\")\n3",
"answer": "def vowels_count(word):\n vowels = ['a', 'e', 'i', 'o', 'u']\n count = 0\n for char in word:\n if char.lower() in vowels:\n count += 1\n if word[-1] == 'y':\n count += 1\n return count\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(\"abcde\") == 2, \"Test 1\"\n assert candidate(\"Alone\") == 3, \"Test 2\"\n assert candidate(\"key\") == 2, \"Test 3\"\n assert candidate(\"bye\") == 1, \"Test 4\"\n assert candidate(\"keY\") == 2, \"Test 5\"\n assert candidate(\"bYe\") == 1, \"Test 6\"\n assert candidate(\"ACEDY\") == 3, \"Test 7\"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(vowels_count)",
"judge": 1
},
{
"id": "35",
"run_id": "### ✅ Run 6",
"question": "返回列表中的最大元素。",
"answer": "def max_element(l: list):\n \"\"\"Return maximum element in the list.\n >>> max_element([1, 2, 3])\n 3\n >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])\n 123\n \"\"\"\n return max(l)\n\nMETADATA = {}\n\n\ndef check(candidate):\n assert candidate([1, 2, 3]) == 3\n assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124\n\ncheck(max_element)",
"judge": 0
},
{
"id": "139",
"run_id": "### ❌ Run 2",
"question": "巴西阶乘被定义为:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n 其中 n > 0\n\n 例如:\n >>> special_factorial(4)\n 288\n\n 该函数将接收一个整数作为输入,并应返回这个整数的特殊阶乘。",
"answer": "def special_factorial(n):\n \"\"\"The Brazilian factorial is defined as:\n brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!\n where n > 0\n\n For example:\n >>> special_factorial(4)\n 288\n\n The function will receive an integer as input and should return the special\n factorial of this integer.\n \"\"\"\n if n <= 0:\n return 1\n else:\n return n * special_factorial(n-1)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(4) == 288, \"Test 4\"\n assert candidate(5) == 34560, \"Test 5\"\n assert candidate(7) == 125411328000, \"Test 7\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1) == 1, \"Test 1\"\n\ncheck(special_factorial)",
"judge": 1
},
{
"id": "147",
"run_id": "### ❌ Run 6",
"question": "给定一个正整数 n。你需要创建一个长度为 n 的整数数组 a。\n对于每个 i(1 ≤ i ≤ n),a[i] 的值为 i * i - i + 1。\n返回数组 a 中满足条件的三元组 (a[i], a[j], a[k]) 的数量,其中 i < j < k,并且 a[i] + a[j] + a[k] 是 3 的倍数。\n\n示例:\n输入:n = 5\n输出:1\n解释:\na = [1, 3, 7, 13, 21]\n唯一有效的三元组是 (1, 7, 13)。",
"answer": "def get_max_triples(n):\n a = [i * i - i + 1 for i in range(1, n + 1)]\n count = 0\n for i in range(n):\n for j in range(i + 1, n):\n for k in range(j + 1, n):\n if a[i] + a[j] + a[k] % 3 == 0:\n count += 1\n return count\n\ndef check(candidate):\n\n assert candidate(5) == 1\n assert candidate(6) == 4\n assert candidate(10) == 36\n assert candidate(100) == 53361\n\ncheck(get_max_triples)",
"judge": 1
},
{
"id": "116",
"run_id": "### ✅ Run 10",
"question": "在这个Kata中,你需要根据非负整数的二进制表示中1的数量升序排序数组。对于1的数量相同的情况,基于十进制值排序。\n\n必须这样实现:\n>>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n>>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n>>> sort_array([1, 0, 2, 3, 4]) == [0, 1, 2, 3, 4]",
"answer": "def sort_array(arr):\n \"\"\"\n In this Kata, you have to sort an array of non-negative integers according to\n number of ones in their binary representation in ascending order.\n For similar number of ones, sort based on decimal value.\n\n It must be implemented like this:\n >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5]\n >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2]\n >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4]\n \"\"\"\n return sorted(arr, key=lambda x: (bin(x).count('1'), x))\n\ndef check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1,5,2,3,4]) == [1, 2, 4, 3, 5]\n assert candidate([-2,-3,-4,-5,-6]) == [-4, -2, -6, -5, -3]\n assert candidate([1,0,2,3,4]) == [0, 1, 2, 4, 3]\n assert candidate([]) == []\n assert candidate([2,5,77,4,5,3,5,7,2,3,4]) == [2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77]\n assert candidate([3,6,44,12,32,5]) == [32, 3, 5, 6, 12, 44]\n assert candidate([2,4,8,16,32]) == [2, 4, 8, 16, 32]\n assert candidate([2,4,8,16,32]) == [2, 4, 8, 16, 32]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(sort_array)",
"judge": 0
},
{
"id": "122",
"run_id": "### ✅ Run 4",
"question": "给定一个非空整数数组 arr 和一个整数 k,返回 arr 的前 k 个元素中最多两位数的元素之和。\n\n示例:\n\n 输入:arr = [111,21,3,4000,5,6,7,8,9], k = 4\n 输出:24 # 21 + 3 的和\n\n约束条件:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)",
"answer": "def add_elements(arr, k):\n \"\"\"\n Given a non-empty array of integers arr and an integer k, return\n the sum of the elements with at most two digits from the first k elements of arr.\n\n Example:\n\n Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4\n Output: 24 # sum of 21 + 3\n\n Constraints:\n 1. 1 <= len(arr) <= 100\n 2. 1 <= k <= len(arr)\n \"\"\"\n return sum(x for x in arr[:k] if len(str(x)) <= 2)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([1,-2,-3,41,57,76,87,88,99], 3) == -4\n assert candidate([111,121,3,4000,5,6], 2) == 0\n assert candidate([11,21,3,90,5,6,7,8,9], 4) == 125\n assert candidate([111,21,3,4000,5,6,7,8,9], 4) == 24, \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1], 1) == 1, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(add_elements)",
"judge": 0
},
{
"id": "163",
"run_id": "### ❌ Run 5",
"question": "给定两个正整数a和b,返回a和b之间的偶数数字,按升序排列。\n\n例如:\ngenerate_integers(2, 8) => [2, 4, 6, 8]\ngenerate_integers(8, 2) => [2, 4, 6, 8]\ngenerate_integers(10, 14) => []",
"answer": "def generate_integers(a, b):\n \"\"\"\n Given two positive integers a and b, return the even digits between a\n and b, in ascending order.\n\n For example:\n generate_integers(2, 8) => [2, 4, 6, 8]\n generate_integers(8, 2) => [2, 4, 6, 8]\n generate_integers(10, 14) => []\n \"\"\"\n result = []\n for i in range(a, b+1):\n if i % 2 == 0:\n result.append(i)\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(2, 10) == [2, 4, 6, 8], \"Test 1\"\n assert candidate(10, 2) == [2, 4, 6, 8], \"Test 2\"\n assert candidate(132, 2) == [2, 4, 6, 8], \"Test 3\"\n assert candidate(17,89) == [], \"Test 4\"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(generate_integers)",
"judge": 1
},
{
"id": "132",
"run_id": "### ❌ Run 2",
"question": "编写一个函数,该函数接受一个只包含方括号的字符串作为输入。当且仅当存在至少有一个方括号嵌套在子序列中的有效方括号子序列时,函数应返回 True。\n\nis_nested('[[]]') ➞ True\nis_nested('[]]]]]]][[[[[]') ➞ False\nis_nested('[][]') ➞ False\nis_nested('[]') ➞ False\nis_nested('[[][]]') ➞ True\nis_nested('[[]][[') ➞ True",
"answer": "def is_nested(string):\n stack = []\n for char in string:\n if char == '[':\n stack.append(char)\n elif char == ']':\n if len(stack) == 0:\n return False\n stack.pop()\n return len(stack) == 0\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('[[]]') == True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('[]]]]]]][[[[[]') == False\n assert candidate('[][]') == False\n assert candidate(('[]')) == False\n assert candidate('[[[[]]]]') == True\n assert candidate('[]]]]]]]]]]') == False\n assert candidate('[][][[]]') == True\n assert candidate('[[]') == False\n assert candidate('[]]') == False\n assert candidate('[[]][[') == True\n assert candidate('[[][]]') == True\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('') == False, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate('[[[[[[[[') == False\n assert candidate(']]]]]]]]') == False\n\ncheck(is_nested)",
"judge": 1
},
{
"id": "106",
"run_id": "### ❌ Run 2",
"question": "实现一个名为f的函数,该函数接受一个参数n,并返回一个大小为n的列表,其中索引i处的元素的值是i的阶乘如果i是偶数,否则是从1到i的数字之和。\ni从1开始。\ni的阶乘是从1到i的数字的乘积(1 * 2 * ... * i)。\n示例:\nf(5) == [1, 2, 6, 24, 15]",
"answer": "def f(n):\n \"\"\" Implement the function f that takes n as a parameter,\n and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even\n or the sum of numbers from 1 to i otherwise.\n i starts from 1.\n the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).\n Example:\n f(5) == [1, 2, 6, 24, 15]\n \"\"\"\n result = []\n for i in range(1, n+1):\n if i % 2 == 0:\n result.append(i * (i-1))\n else:\n result.append(sum(range(1, i+1)))\n return result\n\ndef check(candidate):\n\n assert candidate(5) == [1, 2, 6, 24, 15]\n assert candidate(7) == [1, 2, 6, 24, 15, 720, 28]\n assert candidate(1) == [1]\n assert candidate(3) == [1, 2, 6]\n\ncheck(f)",
"judge": 1
},
{
"id": "157",
"run_id": "### ❌ Run 7",
"question": "给定一个三角形的三边长度。如果这三条边能构成一个直角三角形,则返回True,否则返回False。直角三角形是指有一个角是直角或90度的三角形。\n示例:\nright_angle_triangle(3, 4, 5) == True\nright_angle_triangle(1, 2, 3) == False",
"answer": "def right_angle_triangle(a, b, c):\n return a**2 + b**2 == c**2\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(3, 4, 5) == True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate(1, 2, 3) == False\n assert candidate(10, 6, 8) == True\n assert candidate(2, 2, 2) == False\n assert candidate(7, 24, 25) == True\n assert candidate(10, 5, 7) == False\n assert candidate(5, 12, 13) == True\n assert candidate(15, 8, 17) == True\n assert candidate(48, 55, 73) == True\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1, 1, 1) == False, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate(2, 2, 10) == False\n\ncheck(right_angle_triangle)",
"judge": 1
},
{
"id": "3",
"run_id": "### ✅ Run 6",
"question": "你需要处理一个银行账户的存款和取款操作列表,该账户初始余额为零。你的任务是检测账户余额是否在任何时刻降至零下,如果是,函数应返回True;否则,返回False。",
"answer": "from typing import List\n\ndef below_zero(operations: List[int]) -> bool:\n \"\"\" You're given a list of deposit and withdrawal operations on a bank account that starts with\n zero balance. Your task is to detect if at any point the balance of account fallls below zero, and\n at that point function should return True. Otherwise it should return False.\n >>> below_zero([1, 2, 3])\n False\n >>> below_zero([1, 2, -4, 5])\n True\n \"\"\"\n balance = 0\n for operation in operations:\n balance += operation\n if balance < 0:\n return True\n return False\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate([]) == False\n assert candidate([1, 2, -3, 1, 2, -3]) == False\n assert candidate([1, 2, -4, 5, 6]) == True\n assert candidate([1, -1, 2, -2, 5, -5, 4, -4]) == False\n assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == True\n assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True\n\ncheck(below_zero)",
"judge": 0
},
{
"id": "88",
"run_id": "### ❌ Run 8",
"question": "给定一个非负整数数组,返回一个经过排序的数组副本,如果首尾元素之和是奇数,则按升序排序给定数组,如果首尾元素之和是偶数,则按降序排序。\n\n注意:\n* 不要改变给定的数组。\n\n示例:\n* sort_array([]) => []\n* sort_array([5]) => [5]\n* sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n* sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]",
"answer": "def sort_array(array):\n \"\"\"\n Given an array of non-negative integers, return a copy of the given array after sorting,\n you will sort the given array in ascending order if the sum( first index value, last index value) is odd,\n or sort it in descending order if the sum( first index value, last index value) is even.\n\n Note:\n * don't change the given array.\n\n Examples:\n * sort_array([]) => []\n * sort_array([5]) => [5]\n * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]\n * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]\n \"\"\"\n if sum(array[0], array[-1]) % 2 == 1:\n return sorted(array)\n else:\n return sorted(array, reverse=True)\n\ndef check(candidate):\n\n # Check some simple cases\n assert True, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([]) == [], \"Error\"\n assert candidate([5]) == [5], \"Error\"\n assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5], \"Error\"\n assert candidate([2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0], \"Error\"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([2, 1]) == [1, 2], \"Error\"\n assert candidate([15, 42, 87, 32 ,11, 0]) == [0, 11, 15, 32, 42, 87], \"Error\"\n assert candidate([21, 14, 23, 11]) == [23, 21, 14, 11], \"Error\"\n\ncheck(sort_array)",
"judge": 1
},
{
"id": "126",
"run_id": "### ❌ Run 9",
"question": "给定一个数字列表,判断这个列表是否按照升序排列。如果列表中有任何一个数字出现超过一次,则返回 False。假设列表中没有负数,只包含整数。\n\n例如:\nis_sorted([5]) ➞ True\nis_sorted([1, 2, 3, 4, 5]) ➞ True\nis_sorted([1, 3, 2, 4, 5]) ➞ False\nis_sorted([1, 2, 3, 4, 5, 6]) ➞ True\nis_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True\nis_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False\nis_sorted([1, 2, 2, 3, 3, 4]) ➞ True\nis_sorted([1, 2, 2, 2, 3, 4]) ➞ False",
"answer": "def is_sorted(lst):\n if len(lst) <= 1:\n return True\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return False\n return True\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([5]) == True\n assert candidate([1, 2, 3, 4, 5]) == True\n assert candidate([1, 3, 2, 4, 5]) == False\n assert candidate([1, 2, 3, 4, 5, 6]) == True\n assert candidate([1, 2, 3, 4, 5, 6, 7]) == True\n assert candidate([1, 3, 2, 4, 5, 6, 7]) == False, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([]) == True, \"This prints if this assert fails 2 (good for debugging!)\"\n assert candidate([1]) == True, \"This prints if this assert fails 3 (good for debugging!)\"\n assert candidate([3, 2, 1]) == False, \"This prints if this assert fails 4 (good for debugging!)\"\n \n # Check some edge cases that are easy to work out by hand.\n assert candidate([1, 2, 2, 2, 3, 4]) == False, \"This prints if this assert fails 5 (good for debugging!)\"\n assert candidate([1, 2, 3, 3, 3, 4]) == False, \"This prints if this assert fails 6 (good for debugging!)\"\n assert candidate([1, 2, 2, 3, 3, 4]) == True, \"This prints if this assert fails 7 (good for debugging!)\"\n assert candidate([1, 2, 3, 4]) == True, \"This prints if this assert fails 8 (good for debugging!)\"\n\ncheck(is_sorted)",
"judge": 1
},
{
"id": "112",
"run_id": "## Runs",
"question": "我们给定两个字符串s和c,你需要删除s中所有等于c中任意字符的字符,然后检查结果字符串是否是回文字符串。如果一个字符串正读和反读都一样,则称这个字符串为回文字符串。你应该返回一个包含结果字符串和检查结果True/False的元组。\n例如\n对于s = \"abcde\", c = \"ae\",结果应该是('bcd',False)\n对于s = \"abcdef\", c = \"b\",结果应该是('acdef',False)\n对于s = \"abcdedcba\", c = \"ab\",结果应该是('cdedc',True)",
"answer": "def reverse_delete(s, c):\n \"\"\"Task\n We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c\n then check if the result string is palindrome.\n A string is called palindrome if it reads the same backward as forward.\n You should return a tuple containing the result string and True/False for the check.\n Example\n For s = \"abcde\", c = \"ae\", the result should be ('bcd',False)\n For s = \"abcdef\", c = \"b\" the result should be ('acdef',False)\n For s = \"abcdedcba\", c = \"ab\", the result should be ('cdedc',True)\n \"\"\"\n result = \"\"\n for char in s:\n if char not in c:\n result += char\n return (result, result == result[::-1])\n\ndef check(candidate):\n\n assert candidate(\"abcde\",\"ae\") == ('bcd',False)\n assert candidate(\"abcdef\", \"b\") == ('acdef',False)\n assert candidate(\"abcdedcba\",\"ab\") == ('cdedc',True)\n assert candidate(\"dwik\",\"w\") == ('dik',False)\n assert candidate(\"a\",\"a\") == ('',True)\n assert candidate(\"abcdedcba\",\"\") == ('abcdedcba',True)\n assert candidate(\"abcdedcba\",\"v\") == ('abcdedcba',True)\n assert candidate(\"vabba\",\"v\") == ('abba',True)\n assert candidate(\"mamma\", \"mia\") == (\"\", True)\n\ncheck(reverse_delete)",
"judge": 0
},
{
"id": "143",
"run_id": "### ✅ Run 7",
"question": "你将得到一个表示句子的字符串,句子包含一些由空格分隔的单词,你需要返回一个字符串,包含原句中长度为质数的单词,新字符串中的单词顺序应与原句相同。\n\n示例 1:\n输入:sentence = \"This is a test\"\n输出:\"is\"\n\n示例 2:\n输入:sentence = \"lets go for swimming\"\n输出:\"go for\"\n\n约束条件:\n* 1 <= len(sentence) <= 100\n* 句子只包含字母",
"answer": "def words_in_sentence(sentence):\n \"\"\"\n You are given a string representing a sentence,\n the sentence contains some words separated by a space,\n and you have to return a string that contains the words from the original sentence,\n whose lengths are prime numbers,\n the order of the words in the new string should be the same as the original one.\n\n Example 1:\n Input: sentence = \"This is a test\"\n Output: \"is\"\n\n Example 2:\n Input: sentence = \"lets go for swimming\"\n Output: \"go for\"\n\n Constraints:\n * 1 <= len(sentence) <= 100\n * sentence contains only letters\n \"\"\"\n words = sentence.split()\n prime_words = []\n for word in words:\n if is_prime(len(word)):\n prime_words.append(word)\n return \" \".join(prime_words)\n\ndef is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(\"This is a test\") == \"is\"\n assert candidate(\"lets go for swimming\") == \"go for\"\n assert candidate(\"there is no place available here\") == \"there is no place\"\n assert candidate(\"Hi I am Hussein\") == \"Hi am Hussein\"\n assert candidate(\"go for it\") == \"go for it\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(\"here\") == \"\"\n assert candidate(\"here is\") == \"is\"\n\ncheck(words_in_sentence)",
"judge": 0
},
{
"id": "153",
"run_id": "### ❌ Run 9",
"question": "您将获得一个类的名称(一个字符串)和一个扩展列表。这些扩展将用于加载额外的类。扩展的强度如下:设 CAP 为扩展名中大写字母的数量,SM 为扩展名中小写字母的数量,其强度由分数 CAP - SM 给出。您应该找到最强的扩展,并以此格式返回一个字符串:ClassName.StrongestExtensionName。如果有两个或更多的扩展具有相同的强度,则应选择列表中最先出现的那一个。例如,如果给定类名为 \"Slices\" 和扩展列表:['SErviNGSliCes', 'Cheese', 'StuFfed'],则应返回 'Slices.SErviNGSliCes',因为 'SErviNGSliCes' 是最强的扩展(其强度为 -1)。示例:对于 Strongest_Extension('my_class', ['AA', 'Be', 'CC']) 应该返回 'my_class.AA'。",
"answer": "def Strongest_Extension(class_name, extensions):\n \"\"\"You will be given the name of a class (a string) and a list of extensions.\n The extensions are to be used to load additional classes to the class. The\n strength of the extension is as follows: Let CAP be the number of the uppercase\n letters in the extension's name, and let SM be the number of lowercase letters \n in the extension's name, the strength is given by the fraction CAP - SM. \n You should find the strongest extension and return a string in this \n format: ClassName.StrongestExtensionName.\n If there are two or more extensions with the same strength, you should\n choose the one that comes first in the list.\n For example, if you are given \"Slices\" as the class and a list of the\n extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should\n return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension \n (its strength is -1).\n Example:\n for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA'\n \"\"\"\n strengths = []\n for extension in extensions:\n cap = 0\n sm = 0\n for letter in extension:\n if letter.isupper():\n cap += 1\n else:\n sm += 1\n strengths.append((extension, cap - sm))\n strengths.sort(key=lambda x: x[1], reverse=True)\n return f\"{class_name}.{strengths[0][0]}\"\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) == 'Watashi.eIGHt8OKe'\n assert candidate('Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']) == 'Boku123.YEs.WeCaNe'\n assert candidate('__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__', '123NoooneB321']) == '__YESIMHERE.NuLl__'\n assert candidate('K', ['Ta', 'TAR', 't234An', 'cosSo']) == 'K.TAR'\n assert candidate('__HAHA', ['Tab', '123', '781345', '-_-']) == '__HAHA.123'\n assert candidate('YameRore', ['HhAas', 'okIWILL123', 'WorkOut', 'Fails', '-_-']) == 'YameRore.okIWILL123'\n assert candidate('finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']) == 'finNNalLLly.WoW'\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('_', ['Bb', '91245']) == '_.Bb'\n assert candidate('Sp', ['671235', 'Bb']) == 'Sp.671235'\n\ncheck(Strongest_Extension)",
"judge": 1
},
{
"id": "102",
"run_id": "## Runs",
"question": "这个函数接受两个正数x和y,并返回范围[x, y](包括边界)内最大的偶数整数。如果没有这样的数字,则函数应该返回-1。\n\n例如:\nchoose_num(12, 15) = 14\nchoose_num(13, 12) = -1",
"answer": "def choose_num(x, y):\n \"\"\"This function takes two positive numbers x and y and returns the\n biggest even integer number that is in the range [x, y] inclusive. If \n there's no such number, then the function should return -1.\n\n For example:\n choose_num(12, 15) = 14\n choose_num(13, 12) = -1\n \"\"\"\n if x > y:\n return -1\n for i in range(x, y+1):\n if i % 2 == 0:\n return i\n return -1\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(12, 15) == 14\n assert candidate(13, 12) == -1\n assert candidate(33, 12354) == 12354\n assert candidate(5234, 5233) == -1\n assert candidate(6, 29) == 28\n assert candidate(27, 10) == -1\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(7, 7) == -1\n assert candidate(546, 546) == 546\n\ncheck(choose_num)",
"judge": 1
},
{
"id": "136",
"run_id": "### ✅ Run 8",
"question": "创建一个函数,返回一个元组 (a, b),其中 'a' 是列表中最大的负整数,'b' 是最小的正整数。如果列表中没有负整数或正整数,相应地返回 None。\n\n示例:\nlargest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)\nlargest_smallest_integers([]) == (None, None)\nlargest_smallest_integers([0]) == (None, None)",
"answer": "def largest_smallest_integers(lst):\n largest_negative = None\n smallest_positive = None\n for num in lst:\n if num < 0 and (largest_negative is None or num > largest_negative):\n largest_negative = num\n elif num > 0 and (smallest_positive is None or num < smallest_positive):\n smallest_positive = num\n return (largest_negative, smallest_positive)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([2, 4, 1, 3, 5, 7]) == (None, 1)\n assert candidate([2, 4, 1, 3, 5, 7, 0]) == (None, 1)\n assert candidate([1, 3, 2, 4, 5, 6, -2]) == (-2, 1)\n assert candidate([4, 5, 3, 6, 2, 7, -7]) == (-7, 2)\n assert candidate([7, 3, 8, 4, 9, 2, 5, -9]) == (-9, 2)\n assert candidate([]) == (None, None)\n assert candidate([0]) == (None, None)\n assert candidate([-1, -3, -5, -6]) == (-1, None)\n assert candidate([-1, -3, -5, -6, 0]) == (-1, None)\n assert candidate([-6, -4, -4, -3, 1]) == (-3, 1)\n assert candidate([-6, -4, -4, -3, -100, 1]) == (-3, 1)\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(largest_smallest_integers)",
"judge": 0
},
{
"id": "98",
"run_id": "### ❌ Run 9",
"question": "给定一个字符串 s,计算偶数索引处大写元音字母的数量。\n\n例如:\ncount_upper('aBCdEf') 返回 1\ncount_upper('abcdefg') 返回 0\ncount_upper('dBBE') 返回 0",
"answer": "def count_upper(s):\n count = 0\n for i in range(0, len(s), 2):\n if s[i].isupper():\n count += 1\n return count\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('aBCdEf') == 1\n assert candidate('abcdefg') == 0\n assert candidate('dBBE') == 0\n assert candidate('B') == 0\n assert candidate('U') == 1\n assert candidate('') == 0\n assert candidate('EEEE') == 2\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(count_upper)",
"judge": 1
},
{
"id": "7",
"run_id": "### ✅ Run 5",
"question": "筛选出输入字符串列表中包含给定子字符串的字符串。",
"answer": "from typing import List\n\ndef filter_by_substring(strings: List[str], substring: str) -> List[str]:\n \"\"\" Filter an input list of strings only for ones that contain given substring\n >>> filter_by_substring([], 'a')\n []\n >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a')\n ['abc', 'bacd', 'array']\n \"\"\"\n return [s for s in strings if substring in s]\n\ndef check(candidate):\n assert candidate([], 'john') == []\n assert candidate(['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx') == ['xxx', 'xxxAAA', 'xxx']\n assert candidate(['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'], 'xx') == ['xxx', 'aaaxxy', 'xxxAAA', 'xxx']\n assert candidate(['grunt', 'trumpet', 'prune', 'gruesome'], 'run') == ['grunt', 'prune']\n\ncheck(filter_by_substring)",
"judge": 0
},
{
"id": "89",
"run_id": "### ❌ Run 2",
"question": "创建一个名为encrypt的函数,该函数接受一个字符串作为参数,并返回一个用字母表旋转加密的字符串。字母表应该以一种方式旋转,使得字母向下移动两个乘以二的位置。例如:encrypt('hi') 返回 'lm',encrypt('asdfghjkl') 返回 'ewhjklnop',encrypt('gf') 返回 'kj',encrypt('et') 返回 'ix'。",
"answer": "def encrypt(s):\n \"\"\"Create a function encrypt that takes a string as an argument and\n returns a string encrypted with the alphabet being rotated. \n The alphabet should be rotated in a manner such that the letters \n shift down by two multiplied to two places.\n For example:\n encrypt('hi') returns 'lm'\n encrypt('asdfghjkl') returns 'ewhjklnop'\n encrypt('gf') returns 'kj'\n encrypt('et') returns 'ix'\n \"\"\"\n result = \"\"\n for char in s:\n if char.isalpha():\n result += chr((ord(char) - ord('a') + 2) % 26 + ord('a'))\n else:\n result += char\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('hi') == 'lm', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('asdfghjkl') == 'ewhjklnop', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('gf') == 'kj', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('et') == 'ix', \"This prints if this assert fails 1 (good for debugging!)\"\n\n assert candidate('faewfawefaewg')=='jeiajeaijeiak', \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate('hellomyfriend')=='lippsqcjvmirh', \"This prints if this assert fails 2 (good for debugging!)\"\n assert candidate('dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh')=='hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl', \"This prints if this assert fails 3 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate('a')=='e', \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(encrypt)",
"judge": 1
},
{
"id": "127",
"run_id": "### ✅ Run 6",
"question": "给定两个区间,每个区间是一对整数。例如,区间 = (start, end) = (1, 2)。给定的区间是闭区间,这意味着区间(start, end)包括start和end。对于每个给定的区间,假设它的起始值小于或等于它的结束值。你的任务是确定这两个区间的交集的长度是否是一个质数。例如,区间(1, 3)和(2, 4)的交集是(2, 3),其长度为1,这不是一个质数。如果交集的长度是一个质数,返回\"YES\",否则,返回\"NO\"。如果两个区间不相交,返回\"NO\"。\n\n[input/output] 样例:\nintersection((1, 2), (2, 3)) ==> \"NO\"\nintersection((-1, 1), (0, 4)) ==> \"NO\"\nintersection((-3, -1), (-5, 5)) ==> \"YES\"",
"answer": "def intersection(interval1, interval2):\n \"\"\"You are given two intervals,\n where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).\n The given intervals are closed which means that the interval (start, end)\n includes both start and end.\n For each given interval, it is assumed that its start is less or equal its end.\n Your task is to determine whether the length of intersection of these two \n intervals is a prime number.\n Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3)\n which its length is 1, which not a prime number.\n If the length of the intersection is a prime number, return \"YES\",\n otherwise, return \"NO\".\n If the two intervals don't intersect, return \"NO\".\n\n\n [input/output] samples:\n intersection((1, 2), (2, 3)) ==> \"NO\"\n intersection((-1, 1), (0, 4)) ==> \"NO\"\n intersection((-3, -1), (-5, 5)) ==> \"YES\"\n \"\"\"\n start1, end1 = interval1\n start2, end2 = interval2\n if start1 <= end2 and start2 <= end1:\n intersection_length = min(end1, end2) - max(start1, start2)\n if intersection_length > 1 and is_prime(intersection_length):\n return \"YES\"\n return \"NO\"\n\ndef is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False\n return True\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate((1, 2), (2, 3)) == \"NO\"\n assert candidate((-1, 1), (0, 4)) == \"NO\"\n assert candidate((-3, -1), (-5, 5)) == \"YES\"\n assert candidate((-2, 2), (-4, 0)) == \"YES\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate((-11, 2), (-1, -1)) == \"NO\"\n assert candidate((1, 2), (3, 5)) == \"NO\"\n assert candidate((1, 2), (1, 2)) == \"NO\"\n assert candidate((-2, -2), (-3, -2)) == \"NO\"\n\ncheck(intersection)",
"judge": 0
},
{
"id": "113",
"run_id": "### ❌ Run 6",
"question": "给定一个字符串列表,其中每个字符串仅包含数字,返回一个列表。输出的每个元素i应为“输入的字符串i中奇数元素的数量。”其中所有的i都应该被替换为输入的第i个字符串中奇数数字的数量。",
"answer": "def odd_count(lst):\n \"\"\"Given a list of strings, where each string consists of only digits, return a list.\n Each element i of the output should be \"the number of odd elements in the\n string i of the input.\" where all the i's should be replaced by the number\n of odd digits in the i'th string of the input.\n\n >>> odd_count(['1234567'])\n [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]\n >>> odd_count(['3',\"11111111\"])\n [\"the number of odd elements 1n the str1ng 1 of the 1nput.\",\n \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]\n \"\"\"\n return [\"the number of odd elements \" + str(len([c for c in s if int(c) % 2 == 1])) + \"n the str\" + str(len(s)) + \"ng \" + str(len(s)) + \" of the \" + str(len(s)) + \"nput.\" for s in lst]\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(['1234567']) == [\"the number of odd elements 4n the str4ng 4 of the 4nput.\"], \"Test 1\"\n assert candidate(['3',\"11111111\"]) == [\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"], \"Test 2\"\n assert candidate(['271', '137', '314']) == [\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.'\n ]\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(odd_count)",
"judge": 1
},
{
"id": "142",
"run_id": "### ✅ Run 9",
"question": "这个函数将接收一个整数列表。对于列表中的所有条目,如果条目的索引是3的倍数,那么将该整数条目平方;如果索引是4的倍数且不是3的倍数,则将该整数条目立方。对于那些索引既不是3的倍数也不是4的倍数的条目,函数将不会改变它们。然后,函数将返回所有条目的总和。\n\n示例:\n对于 lst = [1,2,3],输出应该是 6\n对于 lst = [],输出应该是 0\n对于 lst = [-1,-5,2,-1,-5],输出应该是 -126",
"answer": "def sum_squares(lst):\n \"\"\"\"\n This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a \n multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not \n change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. \n \n Examples:\n For lst = [1,2,3] the output should be 6\n For lst = [] the output should be 0\n For lst = [-1,-5,2,-1,-5] the output should be -126\n \"\"\"\n result = 0\n for i, x in enumerate(lst):\n if i % 3 == 0:\n x = x**2\n elif i % 4 == 0:\n x = x**3\n result += x\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n \n assert candidate([1,2,3]) == 6\n assert candidate([1,4,9]) == 14\n assert candidate([]) == 0\n assert candidate([1,1,1,1,1,1,1,1,1]) == 9\n assert candidate([-1,-1,-1,-1,-1,-1,-1,-1,-1]) == -3\n assert candidate([0]) == 0\n assert candidate([-1,-5,2,-1,-5]) == -126\n assert candidate([-56,-99,1,0,-2]) == 3030\n assert candidate([-1,0,0,0,0,0,0,0,-1]) == 0\n assert candidate([-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]) == -14196\n assert candidate([-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]) == -1448\n \n \n # Don't remove this line:\n\ncheck(sum_squares)",
"judge": 0
},
{
"id": "152",
"run_id": "### ✅ Run 2",
"question": "我认为我们都记得那种在某个期待已久的事件的结果终于揭晓时的感觉。那一刻你拥有的感受和想法绝对值得记录下来并进行比较。你的任务是判断一个人是否正确猜测了一些比赛的结果。给你两个等长的分数和猜测的数组,每个索引显示一场比赛。返回一个相同长度的数组,表示每个猜测的偏差程度。如果他们猜对了,值是0;如果没有,值是猜测和得分之间的绝对差值。\n\n例如:\n\ncompare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\ncompare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]",
"answer": "def compare(game, guess):\n \"\"\"I think we all remember that feeling when the result of some long-awaited\n event is finally known. The feelings and thoughts you have at that moment are\n definitely worth noting down and comparing.\n Your task is to determine if a person correctly guessed the results of a number of matches.\n You are given two arrays of scores and guesses of equal length, where each index shows a match. \n Return an array of the same length denoting how far off each guess was. If they have guessed correctly,\n the value is 0, and if not, the value is the absolute difference between the guess and the score.\n \n \n example:\n\n compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3]\n compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6]\n \"\"\"\n return [abs(score - guess) for score, guess in zip(game, guess)]\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,3,4,5,1],[1,2,3,4,2,-2])==[0,0,0,0,3,3], \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([0,0,0,0,0,0],[0,0,0,0,0,0])==[0,0,0,0,0,0], \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1,2,3],[-1,-2,-3])==[2,4,6], \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1,2,3,5],[-1,2,3,4])==[2,0,0,1], \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert True, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(compare)",
"judge": 0
},
{
"id": "103",
"run_id": "### ❌ Run 3",
"question": "给定两个正整数n和m,你的任务是计算从n到m(包括n和m)的整数平均值。将答案四舍五入到最近的整数,并将该整数转换为二进制。如果n大于m,返回-1。\n例如:\nrounded_avg(1, 5) => \"0b11\"\nrounded_avg(7, 5) => -1\nrounded_avg(10, 20) => \"0b1111\"\nrounded_avg(20, 33) => \"0b11010\"",
"answer": "def rounded_avg(n, m):\n if n > m:\n return -1\n total = 0\n for i in range(n, m+1):\n total += i\n average = total / (m-n+1)\n return \"0b\" + bin(int(average))[2:]\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(1, 5) == \"0b11\"\n assert candidate(7, 13) == \"0b1010\"\n assert candidate(964,977) == \"0b1111001010\"\n assert candidate(996,997) == \"0b1111100100\"\n assert candidate(560,851) == \"0b1011000010\"\n assert candidate(185,546) == \"0b101101110\"\n assert candidate(362,496) == \"0b110101101\"\n assert candidate(350,902) == \"0b1001110010\"\n assert candidate(197,233) == \"0b11010111\"\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(7, 5) == -1\n assert candidate(5, 1) == -1\n assert candidate(5, 5) == \"0b101\"\n\ncheck(rounded_avg)",
"judge": 1
},
{
"id": "137",
"run_id": "### ❌ Run 5",
"question": "创建一个函数,该函数接受整数、浮点数或代表实数的字符串,并返回其给定变量类型中较大的变量。如果值相等,则返回 None。注意:如果实数表示为字符串,浮点数的表示可能是 . 或 ,\n\ncompare_one(1, 2.5) ➞ 2.5\ncompare_one(1, \"2,3\") ➞ \"2,3\"\ncompare_one(\"5,1\", \"6\") ➞ \"6\"\ncompare_one(\"1\", 1) ➞ None",
"answer": "def compare_one(a, b):\n \"\"\"\n Create a function that takes integers, floats, or strings representing\n real numbers, and returns the larger variable in its given variable type.\n Return None if the values are equal.\n Note: If a real number is represented as a string, the floating point might be . or ,\n\n compare_one(1, 2.5) ➞ 2.5\n compare_one(1, \"2,3\") ➞ \"2,3\"\n compare_one(\"5,1\", \"6\") ➞ \"6\"\n compare_one(\"1\", 1) ➞ None\n \"\"\"\n if isinstance(a, str):\n a = float(a.replace(\",\", \".\"))\n if isinstance(b, str):\n b = float(b.replace(\",\", \".\"))\n if a > b:\n return a\n elif b > a:\n return b\n else:\n return None\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(1, 2) == 2\n assert candidate(1, 2.5) == 2.5\n assert candidate(2, 3) == 3\n assert candidate(5, 6) == 6\n assert candidate(1, \"2,3\") == \"2,3\"\n assert candidate(\"5,1\", \"6\") == \"6\"\n assert candidate(\"1\", \"2\") == \"2\"\n assert candidate(\"1\", 1) == None\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(compare_one)",
"judge": 1
},
{
"id": "99",
"run_id": "### ❌ Run 5",
"question": "编写一个函数,该函数接收一个代表数字的字符串值,并返回最接近的整数。如果该数字与两个整数等距离,则向远离零的方向取整。\n\n示例\n>>> closest_integer(\"10\")\n10\n>>> closest_integer(\"15.3\")\n15\n\n注意:\n向远离零的方向取整意味着,如果给定数字与两个整数等距离,你应该返回的是那个离零最远的一个。例如,closest_integer(\"14.5\") 应该返回 15,closest_integer(\"-14.5\") 应该返回 -15。",
"answer": "def closest_integer(value):\n '''\n Create a function that takes a value (string) representing a number\n and returns the closest integer to it. If the number is equidistant\n from two integers, round it away from zero.\n\n Examples\n >>> closest_integer(\"10\")\n 10\n >>> closest_integer(\"15.3\")\n 15\n\n Note:\n Rounding away from zero means that if the given number is equidistant\n from two integers, the one you should return is the one that is the\n farthest from zero. For example closest_integer(\"14.5\") should\n return 15 and closest_integer(\"-14.5\") should return -15.\n '''\n try:\n num = float(value)\n return int(num + 0.5)\n except ValueError:\n return \"Invalid input\"\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(\"10\") == 10, \"Test 1\"\n assert candidate(\"14.5\") == 15, \"Test 2\"\n assert candidate(\"-15.5\") == -16, \"Test 3\"\n assert candidate(\"15.3\") == 15, \"Test 3\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(\"0\") == 0, \"Test 0\"\n\ncheck(closest_integer)",
"judge": 1
},
{
"id": "6",
"run_id": "### ❌ Run 9",
"question": "此函数的输入是一个字符串,表示由空格分隔的多组嵌套括号。对于每一组,输出括号嵌套的最深层级。例如,(()()) 的最大嵌套层级为 2,而 ((())) 的为 3。",
"answer": "from typing import List\n\ndef parse_nested_parens(paren_string: str) -> List[int]:\n \"\"\" Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n\n >>> parse_nested_parens('(()()) ((())) () ((())()())')\n [2, 3, 1, 3]\n \"\"\"\n result = []\n for group in paren_string.split():\n level = 0\n for char in group:\n if char == '(':\n level += 1\n elif char == ')':\n level -= 1\n result.append(level)\n return result\n\nMETADATA = {\n 'author': 'jt',\n 'dataset': 'test'\n}\n\n\ndef check(candidate):\n assert candidate('(()()) ((())) () ((())()())') == [2, 3, 1, 3]\n assert candidate('() (()) ((())) (((())))') == [1, 2, 3, 4]\n assert candidate('(()(())((())))') == [4]\n\ncheck(parse_nested_parens)",
"judge": 1
},
{
"id": "146",
"run_id": "## Runs",
"question": "编写一个函数,该函数接收一个数字数组作为输入,并返回数组中大于10且数字的首尾位都是奇数(1, 3, 5, 7, 9)的元素数量。\n例如:\nspecialFilter([15, -73, 14, -15]) => 1\nspecialFilter([33, -2, -3, 45, 21, 109]) => 2",
"answer": "def specialFilter(nums):\n count = 0\n for num in nums:\n if num > 10 and num % 10 in [1, 3, 5, 7, 9] and num // 10 in [1, 3, 5, 7, 9]:\n count += 1\n return count\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([5, -2, 1, -5]) == 0 \n assert candidate([15, -73, 14, -15]) == 1\n assert candidate([33, -2, -3, 45, 21, 109]) == 2\n assert candidate([43, -12, 93, 125, 121, 109]) == 4\n assert candidate([71, -2, -33, 75, 21, 19]) == 3\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([1]) == 0 \n assert candidate([]) == 0\n\ncheck(specialFilter)",
"judge": 1
},
{
"id": "117",
"run_id": "### ❌ Run 7",
"question": "给定一个字符串s和一个自然数n,你被任务要求实现一个函数,该函数返回字符串s中恰好包含n个辅音字母的所有单词列表,按这些单词在字符串s中出现的顺序。\n如果字符串s为空,则函数应返回一个空列表。\n注意:你可以假设输入字符串仅包含字母和空格。\n示例:\nselect_words(\"Mary had a little lamb\", 4) ==> [\"little\"]\nselect_words(\"Mary had a little lamb\", 3) ==> [\"Mary\", \"lamb\"]\nselect_words(\"simple white space\", 2) ==> []\nselect_words(\"Hello world\", 4) ==> [\"world\"]\nselect_words(\"Uncle sam\", 3) ==> [\"Uncle\"]",
"answer": "def select_words(s, n):\n \"\"\"Given a string s and a natural number n, you have been tasked to implement \n a function that returns a list of all words from string s that contain exactly \n n consonants, in order these words appear in the string s.\n If the string s is empty then the function should return an empty list.\n Note: you may assume the input string contains only letters and spaces.\n Examples:\n select_words(\"Mary had a little lamb\", 4) ==> [\"little\"]\n select_words(\"Mary had a little lamb\", 3) ==> [\"Mary\", \"lamb\"]\n select_words(\"simple white space\", 2) ==> []\n select_words(\"Hello world\", 4) ==> [\"world\"]\n select_words(\"Uncle sam\", 3) ==> [\"Uncle\"]\n \"\"\"\n words = s.split()\n result = []\n for word in words:\n if len(word) == n:\n result.append(word)\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(\"Mary had a little lamb\", 4) == [\"little\"], \"First test error: \" + str(candidate(\"Mary had a little lamb\", 4)) \n assert candidate(\"Mary had a little lamb\", 3) == [\"Mary\", \"lamb\"], \"Second test error: \" + str(candidate(\"Mary had a little lamb\", 3)) \n assert candidate(\"simple white space\", 2) == [], \"Third test error: \" + str(candidate(\"simple white space\", 2)) \n assert candidate(\"Hello world\", 4) == [\"world\"], \"Fourth test error: \" + str(candidate(\"Hello world\", 4)) \n assert candidate(\"Uncle sam\", 3) == [\"Uncle\"], \"Fifth test error: \" + str(candidate(\"Uncle sam\", 3))\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(\"\", 4) == [], \"1st edge test error: \" + str(candidate(\"\", 4))\n assert candidate(\"a b c d e f\", 1) == [\"b\", \"c\", \"d\", \"f\"], \"2nd edge test error: \" + str(candidate(\"a b c d e f\", 1))\n\ncheck(select_words)",
"judge": 1
},
{
"id": "123",
"run_id": "### ❌ Run 2",
"question": "给定一个正整数 n,返回一个排序后的列表,该列表包含了 Collatz 序列中的奇数。\n\nCollatz 猜想是数学上的一个猜想,关于一个按以下方式定义的序列:从任意正整数 n 开始。然后,每一个项都是根据前一项得到的:如果前一项是偶数,下一个项就是前一项的一半。如果前一项是奇数,下一个项就是前一项的三倍再加一。猜想是,无论 n 的值如何,序列总会达到 1。\n\n注意:\n1. Collatz(1) 是 [1]。\n2. 返回的列表按升序排序。\n\n例如:\nget_odd_collatz(5) 返回 [1, 5] # 5 的 Collatz 序列是 [5, 16, 8, 4, 2, 1],所以奇数只有 1 和 5。",
"answer": "def get_odd_collatz(n):\n \"\"\"\n Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.\n\n The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined\n as follows: start with any positive integer n. Then each term is obtained from the \n previous term as follows: if the previous term is even, the next term is one half of \n the previous term. If the previous term is odd, the next term is 3 times the previous\n term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.\n\n Note: \n 1. Collatz(1) is [1].\n 2. returned list sorted in increasing order.\n\n For example:\n get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.\n \"\"\"\n if n == 1:\n return [1]\n if n % 2 == 0:\n return [1] + get_odd_collatz(n // 2)\n else:\n return [1] + get_odd_collatz(3 * n + 1)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(14) == [1, 5, 7, 11, 13, 17]\n assert candidate(5) == [1, 5]\n assert candidate(12) == [1, 3, 5], \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1) == [1], \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(get_odd_collatz)",
"judge": 1
},
{
"id": "162",
"run_id": "## Runs",
"question": "给定一个字符串'text',返回其md5哈希等价字符串。如果'text'是一个空字符串,返回None。",
"answer": "def string_to_md5(text):\n import hashlib\n if text == '':\n return None\n else:\n return hashlib.md5(text.encode()).hexdigest()\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'\n assert candidate('') == None\n assert candidate('A B C') == '0ef78513b0cb8cef12743f5aeb35f888'\n assert candidate('password') == '5f4dcc3b5aa765d61d8327deb882cf99'\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(string_to_md5)",
"judge": 0
},
{
"id": "133",
"run_id": "### ❌ Run 9",
"question": "给定一个数字列表。你需要返回列表中平方数的和,首先将列表中的每个元素四舍五入到最接近的整数(向上取整)。例如:\n- 对于 lst = [1,2,3],输出应该是 14\n- 对于 lst = [1,4,9],输出应该是 98\n- 对于 lst = [1,3,5,7],输出应该是 84\n- 对于 lst = [1.4,4.2,0],输出应该是 29\n- 对于 lst = [-2.4,1,1],输出应该是 6",
"answer": "def sum_squares(lst):\n return sum(int(x)**2 for x in lst)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate([1,2,3])==14, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1.0,2,3])==14, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1,3,5,7])==84, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([1.4,4.2,0])==29, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([-2.4,1,1])==6, \"This prints if this assert fails 1 (good for debugging!)\"\n\n assert candidate([100,1,15,2])==10230, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([10000,10000])==200000000, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([-1.4,4.6,6.3])==75, \"This prints if this assert fails 1 (good for debugging!)\"\n assert candidate([-1.4,17.9,18.9,19.9])==1086, \"This prints if this assert fails 1 (good for debugging!)\"\n\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate([0])==0, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([-1])==1, \"This prints if this assert fails 2 (also good for debugging!)\"\n assert candidate([-1,1,0])==2, \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(sum_squares)",
"judge": 1
},
{
"id": "107",
"run_id": "### ✅ Run 4",
"question": "给定一个正整数n,返回一个元组,其中包含范围(1, n)内(包括1和n)的偶数和奇数整数回文数的数量。\n\n示例 1:\n\n输入: 3\n输出: (1, 2)\n解释:\n整数回文数有1, 2, 3。其中一个是偶数,两个是奇数。\n\n示例 2:\n\n输入: 12\n输出: (4, 6)\n解释:\n整数回文数有1, 2, 3, 4, 5, 6, 7, 8, 9, 11。其中四个是偶数,六个是奇数。\n\n注意:\n1. 1 <= n <= 10^3\n2. 返回的元组分别包含偶数和奇数整数回文数的数量。",
"answer": "def even_odd_palindrome(n):\n even_count = 0\n odd_count = 0\n for i in range(1, n+1):\n if str(i) == str(i)[::-1]:\n if i % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n return (even_count, odd_count)\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(123) == (8, 13)\n assert candidate(12) == (4, 6)\n assert candidate(3) == (1, 2)\n assert candidate(63) == (6, 8)\n assert candidate(25) == (5, 6)\n assert candidate(19) == (4, 6)\n assert candidate(9) == (4, 5), \"This prints if this assert fails 1 (good for debugging!)\"\n\n # Check some edge cases that are easy to work out by hand.\n assert candidate(1) == (0, 1), \"This prints if this assert fails 2 (also good for debugging!)\"\n\ncheck(even_odd_palindrome)",
"judge": 0
},
{
"id": "156",
"run_id": "### ✅ Run 4",
"question": "给定一个正整数,获取其罗马数字等价物作为字符串,并以小写形式返回。\n限制:1 <= num <= 1000\n\n示例:\n>>> int_to_mini_roman(19) == 'xix'\n>>> int_to_mini_roman(152) == 'clii'\n>>> int_to_mini_roman(426) == 'cdxxvi'",
"answer": "def int_to_mini_roman(number):\n \"\"\"\n Given a positive integer, obtain its roman numeral equivalent as a string,\n and return it in lowercase.\n Restrictions: 1 <= num <= 1000\n\n Examples:\n >>> int_to_mini_roman(19) == 'xix'\n >>> int_to_mini_roman(152) == 'clii'\n >>> int_to_mini_roman(426) == 'cdxxvi'\n \"\"\"\n roman_numerals = ['i', 'v', 'x', 'l', 'c', 'd', 'm']\n result = ''\n while number > 0:\n if number >= 1000:\n result += 'm'\n number -= 1000\n elif number >= 900:\n result += 'cm'\n number -= 900\n elif number >= 500:\n result += 'd'\n number -= 500\n elif number >= 400:\n result += 'cd'\n number -= 400\n elif number >= 100:\n result += 'c'\n number -= 100\n elif number >= 90:\n result += 'xc'\n number -= 90\n elif number >= 50:\n result += 'l'\n number -= 50\n elif number >= 40:\n result += 'xl'\n number -= 40\n elif number >= 10:\n result += 'x'\n number -= 10\n elif number >= 9:\n result += 'ix'\n number -= 9\n elif number >= 5:\n result += 'v'\n number -= 5\n elif number >= 4:\n result += 'iv'\n number -= 4\n else:\n result += 'i'\n number -= 1\n return result\n\ndef check(candidate):\n\n # Check some simple cases\n assert candidate(19) == 'xix'\n assert candidate(152) == 'clii'\n assert candidate(251) == 'ccli'\n assert candidate(426) == 'cdxxvi'\n assert candidate(500) == 'd'\n assert candidate(1) == 'i'\n assert candidate(4) == 'iv'\n assert candidate(43) == 'xliii'\n assert candidate(90) == 'xc'\n assert candidate(94) == 'xciv'\n assert candidate(532) == 'dxxxii'\n assert candidate(900) == 'cm'\n assert candidate(994) == 'cmxciv'\n assert candidate(1000) == 'm'\n\n # Check some edge cases that are easy to work out by hand.\n assert True\n\ncheck(int_to_mini_roman)",
"judge": 0
}
]