File size: 135,082 Bytes
931ee76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{"content": "/// Write a rsthon function to identify non-prime numbers.\nfn is_not_prime(n: isize) -> bool {\n    let mut result = false;\n    for i in 2..n {\n        if n % i == 0 {\n            result = true;\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a rsthon function to identify non-prime numbers.\nfn is_not_prime(n: isize) -> bool {\n", "task": "mbpp_3_is_not_prime"}
{"content": "/// Write a function to find the n largest integers from a given vector of numbers, returned in descending order.\nfn heap_queue_largest(nums: Vec<isize>, n: isize) -> Vec<isize> {\n    let mut largest_nums: Vec<isize> = nums;\n    largest_nums.sort();\n    largest_nums.reverse();\n    largest_nums[0..n as usize].to_vec()\n}", "retrieval_text": "/// Write a function to find the n largest integers from a given vector of numbers, returned in descending order.\nfn heap_queue_largest(nums: Vec<isize>, n: isize) -> Vec<isize> {\n", "task": "mbpp_4_heap_queue_largest"}
{"content": "/// Write a rsthon function to check whether the two numbers differ at one bit position only or not.\nfn differ_At_One_Bit_Pos(a: isize, b: isize) -> bool {\n    if a == b {\n        return false;\n    }\n    return (a ^ b).count_ones() == 1;\n}", "retrieval_text": "/// Write a rsthon function to check whether the two numbers differ at one bit position only or not.\nfn differ_At_One_Bit_Pos(a: isize, b: isize) -> bool {\n", "task": "mbpp_6_differ_At_One_Bit_Pos"}
{"content": "/// Write a function to find squares of individual elements in a vector.\nfn square_nums(nums: Vec<isize>) -> Vec<isize> {\n    nums.iter().map(|x| x * x).collect()\n}", "retrieval_text": "/// Write a function to find squares of individual elements in a vector.\nfn square_nums(nums: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_8_square_nums"}
{"content": "/// Write a rsthon function to remove first and last occurrence of a given character from the string.\nfn remove_Occ(s: String, ch: String) -> String {\n    let mut s = s;\n    s = s.replace(ch.as_str(), \"\");\n    s = s.replace(ch.as_str(), \"\");\n    s\n}", "retrieval_text": "/// Write a rsthon function to remove first and last occurrence of a given character from the string.\nfn remove_Occ(s: String, ch: String) -> String {\n", "task": "mbpp_11_remove_Occ"}
{"content": "/// Write a function to sort a given matrix in ascending order according to the sum of its rows.\nfn sort_matrix(M: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n    let mut m = M.clone();\n    m.sort_by(|a, b| a.iter().sum::<isize>().cmp(&b.iter().sum::<isize>()));\n    m\n}", "retrieval_text": "/// Write a function to sort a given matrix in ascending order according to the sum of its rows.\nfn sort_matrix(M: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n", "task": "mbpp_12_sort_matrix"}
{"content": "/// Write a rsthon function to find the volume of a triangular prism.\nfn find_Volume(l: isize, b: isize, h: isize) -> isize {\n    (l * b * h) / 2\n}", "retrieval_text": "/// Write a rsthon function to find the volume of a triangular prism.\nfn find_Volume(l: isize, b: isize, h: isize) -> isize {\n", "task": "mbpp_14_find_Volume"}
{"content": "/// Write a function that returns the perimeter of a square given its side length as input.\nfn square_perimeter(a: isize) -> isize {\n    4 * a\n}", "retrieval_text": "/// Write a function that returns the perimeter of a square given its side length as input.\nfn square_perimeter(a: isize) -> isize {\n", "task": "mbpp_17_square_perimeter"}
{"content": "/// Write a function to remove characters from the first string which are present in the second string.\nfn remove_dirty_chars(string: String, second_string: String) -> String {\n\tlet mut dirty_chars: Vec<char> = second_string.chars().collect();\n\tlet mut result: String = String::new();\n\tlet mut char_count: [u8; 128] = [0; 128];\n\tfor c in dirty_chars.iter() {\n\t\tchar_count[*c as usize] = 1;\n\t}\n\n\tfor c in string.chars() {\n\t\tif char_count[c as usize] == 0 {\n\t\t\tresult.push(c);\n\t\t}\n\t}\n\n\tresult\n}", "retrieval_text": "/// Write a function to remove characters from the first string which are present in the second string.\nfn remove_dirty_chars(string: String, second_string: String) -> String {\n", "task": "mbpp_18_remove_dirty_chars"}
{"content": "/// Write a function to find whether a given vector of integers contains any duplicate element.\nfn test_duplicate(arraynums: Vec<isize>) -> bool {\n    let nums_set = arraynums.clone().into_iter().collect::<std::collections::HashSet<isize>>();\n    arraynums.len() != nums_set.len()\n}", "retrieval_text": "/// Write a function to find whether a given vector of integers contains any duplicate element.\nfn test_duplicate(arraynums: Vec<isize>) -> bool {\n", "task": "mbpp_19_test_duplicate"}
{"content": "/// Write a function to check if the given number is woodball or not.\nfn is_woodall(x: isize) -> bool {\n    if x % 2 == 0 {\n        return false;\n    }\n    let mut x = x + 1;\n    let mut p = 0;\n    while x % 2 == 0 {\n        x = x / 2;\n        p = p + 1;\n        if p == x {\n            return true;\n        }\n    }\n    false\n}", "retrieval_text": "/// Write a function to check if the given number is woodball or not.\nfn is_woodall(x: isize) -> bool {\n", "task": "mbpp_20_is_woodall"}
{"content": "/// Write a rsthon function to find the largest number that can be formed with the given vector of digits.\nfn find_Max_Num(arr: Vec<isize>) -> isize {\n    let mut arr: Vec<_> = arr.iter().map(|x| *x).collect();\n    arr.sort_by(|a, b| b.cmp(a));\n    let mut num = 0;\n    for i in 0..arr.len() {\n        num = num * 10 + arr[i];\n    }\n    return num;\n}", "retrieval_text": "/// Write a rsthon function to find the largest number that can be formed with the given vector of digits.\nfn find_Max_Num(arr: Vec<isize>) -> isize {\n", "task": "mbpp_57_find_Max_Num"}
{"content": "/// Write a rsthon function to check whether the given two integers have opposite sign or not.\nfn opposite_Signs(x: isize, y: isize) -> bool {\n    (x ^ y) < 0\n}", "retrieval_text": "/// Write a rsthon function to check whether the given two integers have opposite sign or not.\nfn opposite_Signs(x: isize, y: isize) -> bool {\n", "task": "mbpp_58_opposite_Signs"}
{"content": "/// Write a function to find the nth octagonal number.\nfn is_octagonal(n: isize) -> isize {\n\t3 * n * n - 2 * n\n}", "retrieval_text": "/// Write a function to find the nth octagonal number.\nfn is_octagonal(n: isize) -> isize {\n", "task": "mbpp_59_is_octagonal"}
{"content": "/// Write a rsthon function to find smallest number in a vector.\nfn smallest_num(xs: Vec<isize>) -> isize {\n    xs.iter().fold(isize::MAX, |a, &b| a.min(b))\n}", "retrieval_text": "/// Write a rsthon function to find smallest number in a vector.\nfn smallest_num(xs: Vec<isize>) -> isize {\n", "task": "mbpp_62_smallest_num"}
{"content": "/// Write a function to find the maximum difference between available pairs in the given tuple vector.\nfn max_difference(test_list: Vec<(isize, isize)>) -> isize {\n    let mut temp: Vec<isize> = Vec::new();\n\n    for (a, b) in test_list.iter() {\n        temp.push((b - a).abs());\n    }\n\n    *temp.iter().max().unwrap()\n}", "retrieval_text": "/// Write a function to find the maximum difference between available pairs in the given tuple vector.\nfn max_difference(test_list: Vec<(isize, isize)>) -> isize {\n", "task": "mbpp_63_max_difference"}
{"content": "/// Write a function to sort a vector of tuples using the second value of each tuple.\nfn subject_marks(subjectmarks: Vec<(String, isize)>) -> Vec<(String, isize)> {\n    let mut subject_marks = subjectmarks;\n    subject_marks.sort_by_key(|k| k.1);\n    subject_marks\n}", "retrieval_text": "/// Write a function to sort a vector of tuples using the second value of each tuple.\nfn subject_marks(subjectmarks: Vec<(String, isize)>) -> Vec<(String, isize)> {\n", "task": "mbpp_64_subject_marks"}
{"content": "/// Write a rsthon function to count the number of positive numbers in a vector.\nfn pos_count(list: Vec<isize>) -> isize {\n  let mut pos_count = 0;\n  for num in list {\n    if num >= 0 {\n      pos_count += 1;\n    }\n  }\n  pos_count\n}", "retrieval_text": "/// Write a rsthon function to count the number of positive numbers in a vector.\nfn pos_count(list: Vec<isize>) -> isize {\n", "task": "mbpp_66_pos_count"}
{"content": "/// Write a rsthon function to check whether the given vector is monotonic or not.\nfn is_Monotonic(A: Vec<isize>) -> bool {\n    if A.len() == 1 {\n        return true;\n    }\n    let mut incr = true;\n    let mut decr = true;\n    for i in 0..A.len() - 1 {\n        if A[i] > A[i + 1] {\n            incr = false;\n        }\n        if A[i] < A[i + 1] {\n            decr = false;\n        }\n    }\n    (incr || decr)\n}", "retrieval_text": "/// Write a rsthon function to check whether the given vector is monotonic or not.\nfn is_Monotonic(A: Vec<isize>) -> bool {\n", "task": "mbpp_68_is_Monotonic"}
{"content": "/// Write a function to check whether a vector contains the given subvector or not.\nfn is_sublist(l: Vec<isize>, s: Vec<isize>) -> bool {\n    if s.is_empty() { return true; }\n\n    for (i, &x) in l.iter().enumerate() {\n        if s[0] == x {\n            let mut n = 1;\n            while n < s.len() && l[i+n] == s[n] {\n                n += 1;\n            }\n            if n == s.len() {\n                return true;\n            }\n        }\n    }\n    return false;\n}", "retrieval_text": "/// Write a function to check whether a vector contains the given subvector or not.\nfn is_sublist(l: Vec<isize>, s: Vec<isize>) -> bool {\n", "task": "mbpp_69_is_sublist"}
{"content": "/// Write a function to find whether all the given vectors have equal length or not.\nfn get_equal(Input: Vec<Vec<isize>>) -> bool {\n    Input.iter().fold(true, |f, tuple| f & (tuple.len() == Input[0].len()))\n}", "retrieval_text": "/// Write a function to find whether all the given vectors have equal length or not.\nfn get_equal(Input: Vec<Vec<isize>>) -> bool {\n", "task": "mbpp_70_get_equal"}
{"content": "/// Write a rsthon function to check whether the given number can be represented as the difference of two squares or not.\nfn dif_Square(n: isize) -> bool {\n    n % 4 != 2\n}", "retrieval_text": "/// Write a rsthon function to check whether the given number can be represented as the difference of two squares or not.\nfn dif_Square(n: isize) -> bool {\n", "task": "mbpp_72_dif_Square"}
{"content": "/// Write a function to check whether it follows the sequence given in the patterns vector.\nfn is_samepatterns(colors: Vec<String>, patterns: Vec<String>) -> bool {\n    if colors.len() != patterns.len() {\n        return false;\n    }\n\n    let mut sdict = std::collections::HashMap::new();\n    let mut pset: std::collections::HashSet<_> = patterns.iter().collect();\n    let mut sset: std::collections::HashSet<_> = colors.iter().collect();\n\n    if pset.len() != sset.len() {\n        return false;\n    }\n\n    for (i, pattern) in patterns.iter().enumerate() {\n        let values = sdict.entry(pattern).or_insert_with(Vec::new);\n        values.push(colors[i].clone());\n    }\n\n    for values in sdict.values() {\n        if values[0] != values[values.len() - 1] {\n            return false;\n        }\n    }\n\n    true\n}", "retrieval_text": "/// Write a function to check whether it follows the sequence given in the patterns vector.\nfn is_samepatterns(colors: Vec<String>, patterns: Vec<String>) -> bool {\n", "task": "mbpp_74_is_samepatterns"}
{"content": "/// Write a function to find tuples which have all elements divisible by k from the given vector of tuples.\nfn find_tuples(test_list: Vec<(isize, isize, isize)>, K: isize) -> Vec<(isize, isize, isize)> {\n    test_list\n        .into_iter()\n        .filter(|(x, y, z)| x % K == 0 && y % K == 0 && z % K == 0)\n        .collect()\n}", "retrieval_text": "/// Write a function to find tuples which have all elements divisible by k from the given vector of tuples.\nfn find_tuples(test_list: Vec<(isize, isize, isize)>, K: isize) -> Vec<(isize, isize, isize)> {\n", "task": "mbpp_75_find_tuples"}
{"content": "/// Write a rsthon function to find whether a number is divisible by 11.\nfn is_Diff(n: isize) -> bool {\n    n % 11 == 0\n}", "retrieval_text": "/// Write a rsthon function to find whether a number is divisible by 11.\nfn is_Diff(n: isize) -> bool {\n", "task": "mbpp_77_is_Diff"}
{"content": "/// Write a rsthon function to check whether the length of the word is odd or not.\nfn word_len(s: String) -> bool {\n    s.split(' ')\n        .any(|word| word.len() % 2 != 0)\n}", "retrieval_text": "/// Write a rsthon function to check whether the length of the word is odd or not.\nfn word_len(s: String) -> bool {\n", "task": "mbpp_79_word_len"}
{"content": "/// Write a function to find the nth tetrahedral number.\nfn tetrahedral_number(n: isize) -> isize {\n  (n * (n + 1) * (n + 2)) / 6\n}", "retrieval_text": "/// Write a function to find the nth tetrahedral number.\nfn tetrahedral_number(n: isize) -> isize {\n", "task": "mbpp_80_tetrahedral_number"}
{"content": "/// Write a function to find the nth number in the newman conway sequence.\nfn sequence(n: isize) -> isize {\n    if n == 1 || n == 2 {\n        return 1;\n    } else {\n        return sequence(sequence(n - 1)) + sequence(n - sequence(n - 1));\n    }\n}", "retrieval_text": "/// Write a function to find the nth number in the newman conway sequence.\nfn sequence(n: isize) -> isize {\n", "task": "mbpp_84_sequence"}
{"content": "/// Write a function to find nth centered hexagonal number.\nfn centered_hexagonal_number(n: isize) -> isize {\n    3 * n * (n - 1) + 1\n}", "retrieval_text": "/// Write a function to find nth centered hexagonal number.\nfn centered_hexagonal_number(n: isize) -> isize {\n", "task": "mbpp_86_centered_hexagonal_number"}
{"content": "use std::collections::HashMap;\n\n/// Write a function to get the frequency of all the elements in a vector, returned as a HashMap.\nfn freq_count(list1: Vec<isize>) -> HashMap<isize, isize> {\n    let mut freq_count = HashMap::new();\n    for i in &list1 {\n        *freq_count.entry(*i).or_insert(0) += 1;\n    }\n    freq_count\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write a function to get the frequency of all the elements in a vector, returned as a HashMap.\nfn freq_count(list1: Vec<isize>) -> HashMap<isize, isize> {\n", "task": "mbpp_88_freq_count"}
{"content": "/// Write a function to find the closest smaller number than n.\nfn closest_num(N: isize) -> isize {\n    N - 1\n}", "retrieval_text": "/// Write a function to find the closest smaller number than n.\nfn closest_num(N: isize) -> isize {\n", "task": "mbpp_89_closest_num"}
{"content": "/// Write a rsthon function to find the length of the longest word.\nfn len_log(list1: Vec<String>) -> isize {\n    let mut max = 0;\n    for i in list1 {\n        if i.len() > max {\n            max = i.len();\n        }\n    }\n    max as isize\n}", "retrieval_text": "/// Write a rsthon function to find the length of the longest word.\nfn len_log(list1: Vec<String>) -> isize {\n", "task": "mbpp_90_len_log"}
{"content": "/// Write a function to check if a string is present as a substring in a given vector of string values.\nfn find_substring(str1: Vec<String>, sub_str: String) -> bool {\n    str1.iter().any(|s| s.contains(&sub_str))\n}", "retrieval_text": "/// Write a function to check if a string is present as a substring in a given vector of string values.\nfn find_substring(str1: Vec<String>, sub_str: String) -> bool {\n", "task": "mbpp_91_find_substring"}
{"content": "/// Write a function to check whether the given number is undulating or not.\nfn is_undulating(n: isize) -> bool {\n    if n > 0 {\n        let mut i = 2;\n        while i < n.to_string().len() {\n            if n.to_string().chars().nth(i) != n.to_string().chars().nth(i - 2) {\n                return false;\n            }\n            i += 1;\n        }\n        return true;\n    }\n    false\n}", "retrieval_text": "/// Write a function to check whether the given number is undulating or not.\nfn is_undulating(n: isize) -> bool {\n", "task": "mbpp_92_is_undulating"}
{"content": "/// Write a function to calculate the value of 'a' to the power 'b'.\nfn power(a: isize, b: isize) -> isize {\n    if b == 0 {\n        1\n    } else if a == 0 {\n        0\n    } else if b == 1 {\n        a\n    } else {\n        a * power(a, b - 1)\n    }\n}", "retrieval_text": "/// Write a function to calculate the value of 'a' to the power 'b'.\nfn power(a: isize, b: isize) -> isize {\n", "task": "mbpp_93_power"}
{"content": "/// Given a vector of tuples, write a function that returns the first value of the tuple with the smallest second value.\nfn index_minimum(test_list: Vec<(String, isize)>) -> String {\n    test_list\n        .iter()\n        .min_by_key(|&(_, value)| value)\n        .unwrap()\n        .0\n        .to_owned()\n}", "retrieval_text": "/// Given a vector of tuples, write a function that returns the first value of the tuple with the smallest second value.\nfn index_minimum(test_list: Vec<(String, isize)>) -> String {\n", "task": "mbpp_94_index_minimum"}
{"content": "/// Write a rsthon function to find the number of divisors of a given integer.\nfn divisor(n: isize) -> isize {\n  let mut divs:isize = 0;\n  for i in 1..(n+1) {\n    if n % i == 0 {\n      divs += 1;\n    }\n  }\n  return divs;\n}", "retrieval_text": "/// Write a rsthon function to find the number of divisors of a given integer.\nfn divisor(n: isize) -> isize {\n", "task": "mbpp_96_divisor"}
{"content": "use std::collections::HashMap;\n\n/// Write a function to find frequency of each element in a flattened vector of vectors, returned in a HashMap.\nfn frequency_lists(list1: Vec<Vec<isize>>) -> HashMap<isize, isize> {\n    let mut map = HashMap::new();\n    for v in list1 {\n        for item in v {\n            let count = map.entry(item).or_insert(0);\n            *count += 1;\n        }\n    }\n    map\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write a function to find frequency of each element in a flattened vector of vectors, returned in a HashMap.\nfn frequency_lists(list1: Vec<Vec<isize>>) -> HashMap<isize, isize> {\n", "task": "mbpp_97_frequency_lists"}
{"content": "/// Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.\nfn decimal_to_binary(n: isize) -> String {\n    let mut binary_str = String::new();\n    let mut n = n;\n    loop {\n        let rem = n % 2;\n        binary_str.push_str(&rem.to_string());\n        n /= 2;\n        if n == 0 {\n            break;\n        }\n    }\n    binary_str.chars().rev().collect()\n}", "retrieval_text": "/// Write a function to convert the given decimal number to its binary equivalent, represented as a string with no leading zeros.\nfn decimal_to_binary(n: isize) -> String {\n", "task": "mbpp_99_decimal_to_binary"}
{"content": "/// Write a function to convert a snake case string to camel case string.\nfn snake_to_camel(word: String) -> String {\n    let mut res = String::new();\n    let mut first_char = true;\n    for c in word.chars() {\n        if c == '_' {\n            first_char = true;\n        } else {\n            let c = if first_char { c.to_uppercase().next().unwrap() } else { c };\n            res.push(c);\n            first_char = false;\n        }\n    }\n    res\n}", "retrieval_text": "/// Write a function to convert a snake case string to camel case string.\nfn snake_to_camel(word: String) -> String {\n", "task": "mbpp_102_snake_to_camel"}
{"content": "/// Write a function to find the Eulerian number a(n, m).\nfn eulerian_num(n: isize, m: isize) -> isize {\n    if m >= n || n == 0 {\n        return 0;\n    }\n    if m == 0 {\n        return 1;\n    }\n    (n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1, m)\n}", "retrieval_text": "/// Write a function to find the Eulerian number a(n, m).\nfn eulerian_num(n: isize, m: isize) -> isize {\n", "task": "mbpp_103_eulerian_num"}
{"content": "/// Write a function to sort each subvector of strings in a given vector of vectors.\nfn sort_sublists(input_list: Vec<Vec<String>>) -> Vec<Vec<String>> {\n    let mut result = vec![];\n    for sub in input_list {\n        let mut sub_result = vec![];\n        for x in sub {\n            sub_result.push(x.to_string());\n        }\n        sub_result.sort_by(|a, b| a.to_lowercase().cmp(&b.to_lowercase()));\n        result.push(sub_result);\n    }\n    return result;\n}", "retrieval_text": "/// Write a function to sort each subvector of strings in a given vector of vectors.\nfn sort_sublists(input_list: Vec<Vec<String>>) -> Vec<Vec<String>> {\n", "task": "mbpp_104_sort_sublists"}
{"content": "/// Write a rsthon function to count true booleans in the given vector.\nfn count(lst: Vec<bool>) -> isize {\n    lst.iter()\n        .filter(|&&b| b == true)\n        .count() as isize\n}", "retrieval_text": "/// Write a rsthon function to count true booleans in the given vector.\nfn count(lst: Vec<bool>) -> isize {\n", "task": "mbpp_105_count"}
{"content": "/// Write a function to check if a string represents an integer or not.\nfn check_integer(text: String) -> bool {\n    text.trim().is_empty()\n        || text.chars().all(|c| c.is_ascii_digit())\n}", "retrieval_text": "/// Write a function to check if a string represents an integer or not.\nfn check_integer(text: String) -> bool {\n", "task": "mbpp_113_check_integer"}
{"content": "/// Write a function to convert a given tuple of positive integers into a single integer.\nfn tuple_to_int(nums: (isize, isize, isize)) -> isize {\n    return (nums.0 * 100) + (nums.1 * 10) + nums.2;\n}", "retrieval_text": "/// Write a function to convert a given tuple of positive integers into a single integer.\nfn tuple_to_int(nums: (isize, isize, isize)) -> isize {\n", "task": "mbpp_116_tuple_to_int"}
{"content": "/// Write a function to convert a string to a vector of strings split on the space character.\nfn string_to_list(string: String) -> Vec<String> {\n    return string.split(\" \").map(|x| x.to_string()).collect();\n}", "retrieval_text": "/// Write a function to convert a string to a vector of strings split on the space character.\nfn string_to_list(string: String) -> Vec<String> {\n", "task": "mbpp_118_string_to_list"}
{"content": "/// Write a rsthon function to find the element that appears only once in a sorted vector.\nfn search(arr: Vec<isize>) -> isize {\n    let mut XOR: isize = 0;\n    for i in &arr {\n        XOR = XOR ^ i;\n    }\n    return XOR;\n}", "retrieval_text": "/// Write a rsthon function to find the element that appears only once in a sorted vector.\nfn search(arr: Vec<isize>) -> isize {\n", "task": "mbpp_119_search"}
{"content": "/// Write a function to find the maximum absolute product between numbers in pairs of tuples within a given vector.\nfn max_product_tuple(list1: Vec<(isize, isize)>) -> isize {\n    list1.iter().map(|(x, y)| x * y).map(|y| y.abs()).max().unwrap()\n}", "retrieval_text": "/// Write a function to find the maximum absolute product between numbers in pairs of tuples within a given vector.\nfn max_product_tuple(list1: Vec<(isize, isize)>) -> isize {\n", "task": "mbpp_120_max_product_tuple"}
{"content": "/// Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.\nfn find_length(string: String) -> isize {\n\tlet n = string.len();\n\tlet mut current_sum = 0;\n\tlet mut max_sum = 0;\n\n\tfor i in 0..n {\n\t\tcurrent_sum += if string.as_bytes()[i] == b'0' { 1 } else { -1 };\n\n\t\tif current_sum < 0 {\n\t\t\tcurrent_sum = 0;\n\t\t}\n\t\tmax_sum = max_sum.max(current_sum);\n\t}\n\n\tif max_sum == 0 {\n\t\t0\n\t} else {\n\t\tmax_sum as isize\n\t}\n}", "retrieval_text": "/// Write a function to find the maximum difference between the number of 0s and number of 1s in any sub-string of the given binary string.\nfn find_length(string: String) -> isize {\n", "task": "mbpp_125_find_length"}
{"content": "/// Write a rsthon function to find the sum of common divisors of two given numbers.\nfn sum(a: isize, b: isize) -> isize {\n    let mut sum: isize = 0;\n    for i in 1..a.min(b) {\n        if a % i == 0 && b % i == 0 {\n            sum += i\n        }\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the sum of common divisors of two given numbers.\nfn sum(a: isize, b: isize) -> isize {\n", "task": "mbpp_126_sum"}
{"content": "/// Write a function to multiply two integers.\nfn multiply_int(x: isize, y: isize) -> isize {\n    if y < 0 {\n        -multiply_int(x, -y)\n    } else if y == 0 {\n        0\n    } else if y == 1 {\n        x\n    } else {\n        x + multiply_int(x, y - 1)\n    }\n}", "retrieval_text": "/// Write a function to multiply two integers.\nfn multiply_int(x: isize, y: isize) -> isize {\n", "task": "mbpp_127_multiply_int"}
{"content": "/// Write a function to find words that are longer than n characters from a given vector of words.\nfn long_words(n: isize, str: String) -> Vec<String> {\n    let mut result = Vec::new();\n    for word in str.split_whitespace() {\n        if word.len() > n as usize {\n            result.push(word.to_string());\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a function to find words that are longer than n characters from a given vector of words.\nfn long_words(n: isize, str: String) -> Vec<String> {\n", "task": "mbpp_128_long_words"}
{"content": "/// Write a function to calculate whether the matrix is a magic square.\nfn magic_square_test(my_matrix: Vec<Vec<isize>>) -> bool {\n    // First, we get the dimension of the matrix.\n    let i_size = my_matrix[0].len();\n\n    // Then we calculate the sum of each row and add it to a list.\n    let mut sum_list = vec![];\n    for lines in my_matrix.iter() {\n        sum_list.push(lines.iter().sum::<isize>());\n    }\n\n    // We iterate through the columns of the matrix and add the elements of each column to the list.\n    for col in 0..i_size {\n        let mut sum_col = 0;\n        for row in 0..i_size {\n            sum_col += my_matrix[row][col];\n        }\n        sum_list.push(sum_col);\n    }\n\n    // We add the main diagonal to the list.\n    let mut sum_main_diag = 0;\n    for i in 0..i_size {\n        sum_main_diag += my_matrix[i][i];\n    }\n    sum_list.push(sum_main_diag);\n\n    // We add the anti-diagonal to the list.\n    let mut sum_anti_diag = 0;\n    for i in 0..i_size {\n        sum_anti_diag += my_matrix[i][i_size - 1 - i];\n    }\n    sum_list.push(sum_anti_diag);\n\n    // We remove the duplicate sums and check whether the list is empty.\n    let sum_list_without_duplicates = sum_list.iter().cloned().collect::<std::collections::HashSet<_>>();\n    if sum_list_without_duplicates.len() > 1 {\n        return false;\n    }\n\n    return true;\n}", "retrieval_text": "/// Write a function to calculate whether the matrix is a magic square.\nfn magic_square_test(my_matrix: Vec<Vec<isize>>) -> bool {\n", "task": "mbpp_129_magic_square_test"}
{"content": "/// Write a function to find the item with maximum frequency in a given vector.\nfn max_occurrences(nums: Vec<isize>) -> isize {\n    let mut dict = std::collections::HashMap::new();\n    for i in nums {\n        let count = dict.entry(i).or_insert(0);\n        *count += 1;\n    }\n    let mut max_key = None;\n    let mut max_value = 0;\n    for (key, value) in dict.iter() {\n        if *value > max_value {\n            max_key = Some(*key);\n            max_value = *value;\n        }\n    }\n    match max_key {\n        Some(key) => key,\n        None => panic!(\"No elements in array\"),\n    }\n}", "retrieval_text": "/// Write a function to find the item with maximum frequency in a given vector.\nfn max_occurrences(nums: Vec<isize>) -> isize {\n", "task": "mbpp_130_max_occurrences"}
{"content": "/// Write a function to convert a vector to a string.\nfn tup_string(tup1: Vec<String>) -> String {\n    let mut str = \"\".to_string();\n    for s in tup1 {\n        str = str + &s;\n    }\n    str\n}", "retrieval_text": "/// Write a function to convert a vector to a string.\nfn tup_string(tup1: Vec<String>) -> String {\n", "task": "mbpp_132_tup_string"}
{"content": "/// Write a function to calculate the sum of the negative numbers of a given vector of numbers.\nfn sum_negativenum(nums: Vec<isize>) -> isize {\n    nums.iter().filter(|&&x| x < 0).sum()\n}", "retrieval_text": "/// Write a function to calculate the sum of the negative numbers of a given vector of numbers.\nfn sum_negativenum(nums: Vec<isize>) -> isize {\n", "task": "mbpp_133_sum_negativenum"}
{"content": "/// Write a function to find the nth hexagonal number.\nfn hexagonal_num(n: isize) -> isize {\n\tn * (2 * n - 1)\n}", "retrieval_text": "/// Write a function to find the nth hexagonal number.\nfn hexagonal_num(n: isize) -> isize {\n", "task": "mbpp_135_hexagonal_num"}
{"content": "/// Write a rsthon function to check whether the given number can be represented as sum of non-zero powers of 2 or not.\nfn is_Sum_Of_Powers_Of_Two(n: isize) -> bool {\n    if n % 2 == 1 {\n        return false;\n    } else {\n        return true;\n    }\n}", "retrieval_text": "/// Write a rsthon function to check whether the given number can be represented as sum of non-zero powers of 2 or not.\nfn is_Sum_Of_Powers_Of_Two(n: isize) -> bool {\n", "task": "mbpp_138_is_Sum_Of_Powers_Of_Two"}
{"content": "/// Write a function to count number items that are identical in the same position of three given vectors.\nfn count_samepair(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> isize {\n    let mut result = 0;\n    for i in 0..list1.len() {\n        if list1[i] == list2[i] && list1[i] == list3[i] {\n            result += 1;\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a function to count number items that are identical in the same position of three given vectors.\nfn count_samepair(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> isize {\n", "task": "mbpp_142_count_samepair"}
{"content": "/// Write a rsthon function to find the maximum difference between any two elements in a given vector.\nfn max_Abs_Diff(arr: Vec<isize>) -> isize {\n    let mut min = arr[0];\n    let mut max = arr[0];\n\n    for i in 1..arr.len() {\n        min = min.min(arr[i]);\n        max = max.max(arr[i]);\n    }\n    max - min\n}", "retrieval_text": "/// Write a rsthon function to find the maximum difference between any two elements in a given vector.\nfn max_Abs_Diff(arr: Vec<isize>) -> isize {\n", "task": "mbpp_145_max_Abs_Diff"}
{"content": "/// Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.\nfn find_solution(a: isize, b: isize, n: isize) -> Option<(isize, isize)> {\n\tlet mut i = 0;\n\twhile i * a <= n {\n\t\tif (n - (i * a)) % b == 0 {\n\t\t\treturn Some((i, (n - (i * a)) / b));\n\t\t}\n\t\ti += 1;\n\t}\n\tNone\n}", "retrieval_text": "/// Write a function that returns integers x and y that satisfy ax + by = n as a tuple, or return None if no solution exists.\nfn find_solution(a: isize, b: isize, n: isize) -> Option<(isize, isize)> {\n", "task": "mbpp_160_find_solution"}
{"content": "/// Write a function to remove all elements from a given vector present in another vector.\nfn remove_elements(list1: Vec<isize>, list2: Vec<isize>) -> Vec<isize> {\n    list1.into_iter().filter(|x| !list2.contains(x)).collect()\n}", "retrieval_text": "/// Write a function to remove all elements from a given vector present in another vector.\nfn remove_elements(list1: Vec<isize>, list2: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_161_remove_elements"}
{"content": "/// Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).\nfn sum_series(n: isize) -> isize {\n  if n < 1 {\n    return 0;\n  } else {\n    return n + sum_series(n - 2);\n  }\n}", "retrieval_text": "/// Write a function to calculate the sum (n - 2*i) from i=0 to n // 2, for instance n + (n-2) + (n-4)... (until n-x =< 0).\nfn sum_series(n: isize) -> isize {\n", "task": "mbpp_162_sum_series"}
{"content": "/// Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).\nfn count_char_position(str1: String) -> isize {\n    let mut count_chars = 0;\n    let str1 = str1.to_lowercase();\n    for (index, c) in str1.chars().enumerate() {\n        if (c as u32 - 'a' as u32) as isize == index as isize {\n            count_chars += 1\n        }\n    }\n    count_chars\n}", "retrieval_text": "/// Write a function to count the number of characters in a string that occur at the same position in the string as in the English alphabet (case insensitive).\nfn count_char_position(str1: String) -> isize {\n", "task": "mbpp_165_count_char_position"}
{"content": "/// Write a function that counts the number of pairs of integers in a vector that xor to an even number.\nfn find_even_pair(A: Vec<isize>) -> isize {\n    A.iter().enumerate()\n        .flat_map(|(i, &a)| A.iter().enumerate().skip(i + 1).map(move |(j, &b)| (i, j, a, b)))\n        .filter(|&(_, _, a, b)| (a ^ b) % 2 == 0)\n        .count() as isize\n}", "retrieval_text": "/// Write a function that counts the number of pairs of integers in a vector that xor to an even number.\nfn find_even_pair(A: Vec<isize>) -> isize {\n", "task": "mbpp_166_find_even_pair"}
{"content": "/// Write a function to count the number of occurrences of a number in a given vector.\nfn frequency(a: Vec<isize>, x: isize) -> isize {\n    let mut count = 0;\n    for i in a {\n        if i == x {\n            count += 1\n        }\n    }\n    count\n}", "retrieval_text": "/// Write a function to count the number of occurrences of a number in a given vector.\nfn frequency(a: Vec<isize>, x: isize) -> isize {\n", "task": "mbpp_168_frequency"}
{"content": "/// Write a function to find the sum of numbers in a vector within a range specified by two indices.\nfn sum_range_list(list1: Vec<isize>, m: isize, n: isize) -> isize {\n    let mut sum_range = 0;\n    for i in m..=n {\n        sum_range += list1[i as usize];\n    }\n    sum_range\n}", "retrieval_text": "/// Write a function to find the sum of numbers in a vector within a range specified by two indices.\nfn sum_range_list(list1: Vec<isize>, m: isize, n: isize) -> isize {\n", "task": "mbpp_170_sum_range_list"}
{"content": "/// Write a function to find the perimeter of a regular pentagon from the length of its sides.\nfn perimeter_pentagon(a: isize) -> isize {\n    a * 5\n}", "retrieval_text": "/// Write a function to find the perimeter of a regular pentagon from the length of its sides.\nfn perimeter_pentagon(a: isize) -> isize {\n", "task": "mbpp_171_perimeter_pentagon"}
{"content": "/// Write a function to count the number of occurence of the string 'std' in a given string.\nfn count_occurance(s: String) -> isize {\n    let count: isize = s.match_indices(\"std\").count() as isize;\n    return count;\n}", "retrieval_text": "/// Write a function to count the number of occurence of the string 'std' in a given string.\nfn count_occurance(s: String) -> isize {\n", "task": "mbpp_172_count_occurance"}
{"content": "/// Write a rsthon function to remove the characters which have odd index values of a given string.\nfn odd_values_string(str: String) -> String {\n    let mut result = String::new();\n    for i in 0..str.len() {\n        if i % 2 == 0 {\n            result.push_str(&str[i..i + 1]);\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a rsthon function to remove the characters which have odd index values of a given string.\nfn odd_values_string(str: String) -> String {\n", "task": "mbpp_226_odd_values_string"}
{"content": "/// Write a function to find minimum of three numbers.\nfn min_of_three(a: isize, b: isize, c: isize) -> isize {\n    if (a <= b) && (a <= c) {\n        a\n    } else if (b <= a) && (b <= c) {\n        b\n    } else {\n        c\n    }\n}", "retrieval_text": "/// Write a function to find minimum of three numbers.\nfn min_of_three(a: isize, b: isize, c: isize) -> isize {\n", "task": "mbpp_227_min_of_three"}
{"content": "/// Write a rsthon function to check whether all the bits are unset in the given range or not.\nfn all_Bits_Set_In_The_Given_Range(n: isize, l: isize, r: isize) -> bool {\n    let mut num = (((1 << r) - 1) ^ ((1 << (l - 1)) - 1)) & n;\n    if num == 0 {\n        return true;\n    }\n    return false;\n}", "retrieval_text": "/// Write a rsthon function to check whether all the bits are unset in the given range or not.\nfn all_Bits_Set_In_The_Given_Range(n: isize, l: isize, r: isize) -> bool {\n", "task": "mbpp_228_all_Bits_Set_In_The_Given_Range"}
{"content": "/// Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.\nfn replace_blank(str1: String, char: String) -> String {\n    let mut res = String::new();\n    for i in str1.chars() {\n        if i == ' ' {\n            res.push_str(char.as_str());\n        } else {\n            res.push(i);\n        }\n    }\n    return res;\n}", "retrieval_text": "/// Write a function that takes in a string and character, replaces blank spaces in the string with the character, and returns the string.\nfn replace_blank(str1: String, char: String) -> String {\n", "task": "mbpp_230_replace_blank"}
{"content": "/// Write a function to find the volume of a cube given its side length.\nfn volume_cube(l: isize) -> isize {\n    l * l * l\n}", "retrieval_text": "/// Write a function to find the volume of a cube given its side length.\nfn volume_cube(l: isize) -> isize {\n", "task": "mbpp_234_volume_cube"}
{"content": "/// Write a rsthon function to count the number of non-empty substrings of a given string.\nfn number_of_substrings(str: String) -> isize {\n    let mut str_len = 0;\n    let mut res = 0;\n    for s in str.chars() {\n        str_len += 1;\n        res += str_len;\n    }\n    res\n}", "retrieval_text": "/// Write a rsthon function to count the number of non-empty substrings of a given string.\nfn number_of_substrings(str: String) -> isize {\n", "task": "mbpp_238_number_of_substrings"}
{"content": "/// Write a function to count the total number of characters in a string.\nfn count_charac(str1: String) -> isize {\n    let mut count = 0;\n    for _ in str1.chars() {\n        count += 1;\n    }\n    count\n}", "retrieval_text": "/// Write a function to count the total number of characters in a string.\nfn count_charac(str1: String) -> isize {\n", "task": "mbpp_242_count_charac"}
{"content": "/// Write a function to find the length of the longest palindromic subsequence in the given string.\nfn lps(str: String) -> isize {\n    let n = str.len();\n    let mut L = vec![vec![0; n]; n];\n    for i in 0..n {\n        L[i][i] = 1;\n    }\n    for cl in 2..=n {\n        for i in 0..n-cl+1 {\n            let j = i + cl - 1;\n            if str.as_bytes()[i] == str.as_bytes()[j] {\n                L[i][j] = L[i + 1][j - 1] + 2;\n            } else {\n                L[i][j] = L[i][j - 1].max(L[i + 1][j]);\n            }\n        }\n    }\n    L[0][n - 1]\n}", "retrieval_text": "/// Write a function to find the length of the longest palindromic subsequence in the given string.\nfn lps(str: String) -> isize {\n", "task": "mbpp_247_lps"}
{"content": "/// Write a function to find the intersection of two vectors.\nfn intersection_array(array_nums1: Vec<isize>, array_nums2: Vec<isize>) -> Vec<isize> {\n    let mut result = Vec::new();\n\n    for n in array_nums1 {\n        if array_nums2.contains(&n) {\n            result.push(n);\n        }\n    }\n\n    result\n}", "retrieval_text": "/// Write a function to find the intersection of two vectors.\nfn intersection_array(array_nums1: Vec<isize>, array_nums2: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_249_intersection_array"}
{"content": "/// Write a rsthon function that takes in a tuple and an element and counts the occcurences of the element in the vector.\nfn count_X(tup: Vec<isize>, x: isize) -> isize {\n    let mut count = 0;\n    for ele in tup {\n        if ele == x {\n            count += 1;\n        }\n    }\n    count\n}", "retrieval_text": "/// Write a rsthon function that takes in a tuple and an element and counts the occcurences of the element in the vector.\nfn count_X(tup: Vec<isize>, x: isize) -> isize {\n", "task": "mbpp_250_count_X"}
{"content": "/// Write a function that takes in a vector and an element and inserts the element before each element in the vector, and returns the resulting vector.\nfn insert_element(list: Vec<String>, element: String) -> Vec<String> {\n    let mut ret = Vec::new();\n    for i in list {\n        ret.push(element.clone());\n        ret.push(i);\n    }\n    ret\n}", "retrieval_text": "/// Write a function that takes in a vector and an element and inserts the element before each element in the vector, and returns the resulting vector.\nfn insert_element(list: Vec<String>, element: String) -> Vec<String> {\n", "task": "mbpp_251_insert_element"}
{"content": "/// Write a rsthon function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.\nfn count_Primes_nums(n: isize) -> isize {\n    let mut ctr: isize = 0;\n    for num in 2..n {\n        let mut isPrime = true;\n        for i in 2..num {\n            if (num % i) == 0 {\n                isPrime = false;\n                break;\n            }\n        }\n        if isPrime {\n            ctr += 1;\n        }\n    }\n    return ctr\n}", "retrieval_text": "/// Write a rsthon function that takes in a non-negative number and returns the number of prime numbers less than the given non-negative number.\nfn count_Primes_nums(n: isize) -> isize {\n", "task": "mbpp_256_count_Primes_nums"}
{"content": "/// Write a function that takes in two numbers and returns a vector with the second number and then the first number.\nfn swap_numbers(a: isize, b: isize) -> Vec<isize> {\n    vec![b, a]\n}", "retrieval_text": "/// Write a function that takes in two numbers and returns a vector with the second number and then the first number.\nfn swap_numbers(a: isize, b: isize) -> Vec<isize> {\n", "task": "mbpp_257_swap_numbers"}
{"content": "/// Write a function to maximize the given two vectors.\nfn maximize_elements(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n    let mut res = Vec::new();\n    for (a, b) in test_tup1.iter().zip(test_tup2.iter()) {\n        let c = a.iter().zip(b.iter()).map(|(&a, &b)| a.max(b)).collect();\n        res.push(c);\n    }\n    res\n}", "retrieval_text": "/// Write a function to maximize the given two vectors.\nfn maximize_elements(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n", "task": "mbpp_259_maximize_elements"}
{"content": "/// Write a function to find the nth newman\u2013shanks\u2013williams prime number.\nfn newman_prime(n: isize) -> isize {\n    if n == 0 || n == 1 {\n        return 1\n    }\n    2 * newman_prime(n - 1) + newman_prime(n - 2)\n}", "retrieval_text": "/// Write a function to find the nth newman\u2013shanks\u2013williams prime number.\nfn newman_prime(n: isize) -> isize {\n", "task": "mbpp_260_newman_prime"}
{"content": "/// Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples.\nfn division_elements(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n    (test_tup1.0 / test_tup2.0, test_tup1.1 / test_tup2.1, test_tup1.2 / test_tup2.2, test_tup1.3 / test_tup2.3)\n}", "retrieval_text": "/// Write a function that takes in two tuples and performs mathematical division operation element-wise across the given tuples.\nfn division_elements(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n", "task": "mbpp_261_division_elements"}
{"content": "/// Write a function to find the lateral surface area of a cube given its side length.\nfn lateralsurface_cube(l: isize) -> isize {\n  l * l * 4\n}", "retrieval_text": "/// Write a function to find the lateral surface area of a cube given its side length.\nfn lateralsurface_cube(l: isize) -> isize {\n", "task": "mbpp_266_lateralsurface_cube"}
{"content": "/// Write a rsthon function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.\nfn square_Sum(n: isize) -> isize {\n    return n*(4*n*n-1)/3;\n}", "retrieval_text": "/// Write a rsthon function that takes in an integer n and returns the sum of the squares of the first n odd natural numbers.\nfn square_Sum(n: isize) -> isize {\n", "task": "mbpp_267_square_Sum"}
{"content": "/// Write a function to find the n'th star number.\nfn find_star_num(n: isize) -> isize {\n\t6 * n * (n - 1) + 1\n}", "retrieval_text": "/// Write a function to find the n'th star number.\nfn find_star_num(n: isize) -> isize {\n", "task": "mbpp_268_find_star_num"}
{"content": "/// Write a function to find the ascii value of a character.\nfn ascii_value(k: String) -> isize {\n    let ch = k.chars().nth(0).unwrap();\n    ch as isize\n}", "retrieval_text": "/// Write a function to find the ascii value of a character.\nfn ascii_value(k: String) -> isize {\n", "task": "mbpp_269_ascii_value"}
{"content": "/// Write a rsthon function to find the sum of even numbers at even positions of a vector.\nfn sum_even_and_even_index(arr: Vec<isize>) -> isize {\n    let mut sum = 0;\n    for i in (0..arr.len()).step_by(2) {\n        if arr[i] % 2 == 0 {\n            sum += arr[i];\n        }\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the sum of even numbers at even positions of a vector.\nfn sum_even_and_even_index(arr: Vec<isize>) -> isize {\n", "task": "mbpp_270_sum_even_and_even_index"}
{"content": "/// Write a rsthon function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.\nfn even_Power_Sum(n: isize) -> isize {\n    let mut sum = 0;\n    for i in 1..n+1 {\n        let j = 2*i;\n        sum += j.pow(5)\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function that takes in an integer n and finds the sum of the first n even natural numbers that are raised to the fifth power.\nfn even_Power_Sum(n: isize) -> isize {\n", "task": "mbpp_271_even_Power_Sum"}
{"content": "/// Write a function that takes in a vector of tuples and returns a vector containing the rear element of each tuple.\nfn rear_extract(test_list: Vec<(isize, String, isize)>) -> Vec<isize> {\n    let res = test_list.iter().map(|x| x.2).collect();\n    res\n}", "retrieval_text": "/// Write a function that takes in a vector of tuples and returns a vector containing the rear element of each tuple.\nfn rear_extract(test_list: Vec<(isize, String, isize)>) -> Vec<isize> {\n", "task": "mbpp_272_rear_extract"}
{"content": "/// Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index.\nfn substract_elements(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> (isize, isize, isize) {\n    let (a, b, c) = test_tup1;\n    let (d, e, f) = test_tup2;\n    (a - d, b - e, c - f)\n}", "retrieval_text": "/// Write a function that takes in two tuples and subtracts the elements of the first tuple by the elements of the second tuple with the same index.\nfn substract_elements(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> (isize, isize, isize) {\n", "task": "mbpp_273_substract_elements"}
{"content": "/// Write a rsthon function that takes in a positive integer n and finds the sum of even index binomial coefficients.\nfn even_binomial_Coeff_Sum(n: isize) -> isize {\n    1 << (n - 1)\n}", "retrieval_text": "/// Write a rsthon function that takes in a positive integer n and finds the sum of even index binomial coefficients.\nfn even_binomial_Coeff_Sum(n: isize) -> isize {\n", "task": "mbpp_274_even_binomial_Coeff_Sum"}
{"content": "use std::collections::HashMap;\n\n/// Write a function that takes in a HashMap and integer n and filters the HashMap to only include entries with values greater than or equal to n.\nfn dict_filter(dict: HashMap<String, isize>, n: isize) -> HashMap<String, isize> {\n    dict.into_iter().filter(|(k, v)| *v >= n).collect()\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write a function that takes in a HashMap and integer n and filters the HashMap to only include entries with values greater than or equal to n.\nfn dict_filter(dict: HashMap<String, isize>, n: isize) -> HashMap<String, isize> {\n", "task": "mbpp_277_dict_filter"}
{"content": "/// Write a function to find the nth decagonal number.\nfn is_num_decagonal(n: isize) -> isize {\n\t4 * n * n - 3 * n\n}", "retrieval_text": "/// Write a function to find the nth decagonal number.\nfn is_num_decagonal(n: isize) -> isize {\n", "task": "mbpp_279_is_num_decagonal"}
{"content": "/// Write a rsthon function to check if the elements of a given vector are unique or not.\nfn all_unique(test_list: Vec<isize>) -> bool {\n    if test_list.len() > test_list.iter().collect::<std::collections::HashSet<_>>().len() {\n        return false;\n    }\n    return true;\n}", "retrieval_text": "/// Write a rsthon function to check if the elements of a given vector are unique or not.\nfn all_unique(test_list: Vec<isize>) -> bool {\n", "task": "mbpp_281_all_unique"}
{"content": "/// Write a function to subtract two vectors element-wise.\nfn sub_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<isize> {\n    nums1\n        .iter()\n        .zip(nums2.iter())\n        .map(|(x, y)| *x - *y)\n        .collect::<Vec<isize>>()\n}", "retrieval_text": "/// Write a function to subtract two vectors element-wise.\nfn sub_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_282_sub_list"}
{"content": "/// Write a rsthon function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.\nfn validate(n: isize) -> bool {\n    let mut digit_count = [0; 10];\n    let mut temp = n;\n    while temp > 0 {\n        let digit = (temp % 10) as usize;\n        digit_count[digit] += 1;\n        temp /= 10;\n    }\n    digit_count\n        .iter()\n        .enumerate()\n        .all(|(i, &count)| count <= i)\n}", "retrieval_text": "/// Write a rsthon function takes in an integer and check whether the frequency of each digit in the integer is less than or equal to the digit itself.\nfn validate(n: isize) -> bool {\n", "task": "mbpp_283_validate"}
{"content": "/// Write a rsthon function takes in an integer n and returns the sum of squares of first n even natural numbers.\nfn square_Sum(n: isize) -> isize {\n    return 2*n*(n+1)*(2*n+1)/3\n}", "retrieval_text": "/// Write a rsthon function takes in an integer n and returns the sum of squares of first n even natural numbers.\nfn square_Sum(n: isize) -> isize {\n", "task": "mbpp_287_square_Sum"}
{"content": "/// Write a rsthon function to find quotient of two numbers (rounded down to the nearest integer).\nfn find(n: isize, m: isize) -> isize {\n    n / m\n}", "retrieval_text": "/// Write a rsthon function to find quotient of two numbers (rounded down to the nearest integer).\nfn find(n: isize, m: isize) -> isize {\n", "task": "mbpp_292_find"}
{"content": "/// Write a function to find the third side of a right angled triangle.\nfn otherside_rightangle(w: isize, h: isize) -> f64 {\n    let s = (w as f64).powf(2.0) + (h as f64).powf(2.0);\n    s.sqrt() as f64\n}", "retrieval_text": "/// Write a function to find the third side of a right angled triangle.\nfn otherside_rightangle(w: isize, h: isize) -> f64 {\n", "task": "mbpp_293_otherside_rightangle"}
{"content": "/// Write a function to return the sum of all divisors of a number.\nfn sum_div(number: isize) -> isize {\n    let mut sum = 1;\n    for i in 2..number {\n        if number % i == 0 {\n            sum += i;\n        }\n    }\n    return sum;\n}", "retrieval_text": "/// Write a function to return the sum of all divisors of a number.\nfn sum_div(number: isize) -> isize {\n", "task": "mbpp_295_sum_div"}
{"content": "/// Write a rsthon function to count inversions in a vector.\nfn get_Inv_Count(arr: Vec<isize>) -> isize {\n    let n = arr.len();\n    let mut inv_count = 0;\n\n    for i in 0..n {\n        for j in i + 1..n {\n            if arr[i] > arr[j] {\n                inv_count += 1;\n            }\n        }\n    }\n    inv_count\n}", "retrieval_text": "/// Write a rsthon function to count inversions in a vector.\nfn get_Inv_Count(arr: Vec<isize>) -> isize {\n", "task": "mbpp_296_get_Inv_Count"}
{"content": "/// Write a function to calculate the maximum aggregate from the vector of tuples.\nfn max_aggregate(stdata: Vec<(String, isize)>) -> (String, isize) {\n    let mut temp = std::collections::HashMap::new();\n    for (name, marks) in stdata {\n        *temp.entry(name).or_insert(0) += marks;\n    }\n    temp.into_iter().max_by_key(|x| x.1).unwrap()\n}", "retrieval_text": "/// Write a function to calculate the maximum aggregate from the vector of tuples.\nfn max_aggregate(stdata: Vec<(String, isize)>) -> (String, isize) {\n", "task": "mbpp_299_max_aggregate"}
{"content": "/// Write a function to return two words from a vector of words starting with letter 'p'.\nfn start_withp(words: Vec<String>) -> (String, String) {\n    for w in words {\n        if w.starts_with(\"P\") {\n            let mut m = w.split(' ');\n            let w1 = m.next().unwrap();\n            let w2 = m.next().unwrap();\n            return (w1.to_string(), w2.to_string());\n        }\n    }\n    panic!(\"No words start with 'P'\");\n}", "retrieval_text": "/// Write a function to return two words from a vector of words starting with letter 'p'.\nfn start_withp(words: Vec<String>) -> (String, String) {\n", "task": "mbpp_305_start_withp"}
{"content": "/// Write a function to find the specified number of largest products from two given vectors, selecting one factor from each vector.\nfn large_product(nums1: Vec<isize>, nums2: Vec<isize>, N: isize) -> Vec<isize> {\n    // 1. Create an empty vector to store the products.\n    let mut products = Vec::new();\n    // 2. Loop through each element in the first vector.\n    for &num1 in nums1.iter() {\n        // 3. Loop through each element in the second vector.\n        for &num2 in nums2.iter() {\n            // 4. Append the product of the two elements to the products vector.\n            products.push(num1 * num2);\n        }\n    }\n    // 5. Sort the products vector in descending order.\n    products.sort_by(|a, b| b.cmp(a));\n    // 6. Return a new vector containing the first N products.\n    products[..N as usize].to_vec()\n}", "retrieval_text": "/// Write a function to find the specified number of largest products from two given vectors, selecting one factor from each vector.\nfn large_product(nums1: Vec<isize>, nums2: Vec<isize>, N: isize) -> Vec<isize> {\n", "task": "mbpp_308_large_product"}
{"content": "/// Write a rsthon function to find the maximum of two numbers.\nfn maximum(a: isize, b: isize) -> isize {\n    if a > b {\n        a\n    } else {\n        b\n    }\n}", "retrieval_text": "/// Write a rsthon function to find the maximum of two numbers.\nfn maximum(a: isize, b: isize) -> isize {\n", "task": "mbpp_309_maximum"}
{"content": "/// Write a function to convert a given string to a vector of characters.\nfn string_to_tuple(str1: String) -> Vec<String> {\n    let mut result = Vec::new();\n    for c in str1.chars() {\n        if !c.is_whitespace() {\n            result.push(c.to_string());\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a function to convert a given string to a vector of characters.\nfn string_to_tuple(str1: String) -> Vec<String> {\n", "task": "mbpp_310_string_to_tuple"}
{"content": "/// Write a rsthon function to find the highest power of 2 that is less than or equal to n.\nfn highest_Power_of_2(n: isize) -> isize {\n    if n < 1 {\n        return 0;\n    } else if n == 1 {\n        return 1;\n    }\n    let mut res = 1;\n    while res * 2 <= n {\n        res *= 2;\n    }\n    res\n}", "retrieval_text": "/// Write a rsthon function to find the highest power of 2 that is less than or equal to n.\nfn highest_Power_of_2(n: isize) -> isize {\n", "task": "mbpp_388_highest_Power_of_2"}
{"content": "/// Write a function to find the n'th lucas number.\nfn find_lucas(n: isize) -> isize {\n    if n == 0 {\n        return 2;\n    }\n    if n == 1 {\n        return 1;\n    }\n    find_lucas(n - 1) + find_lucas(n - 2)\n}", "retrieval_text": "/// Write a function to find the n'th lucas number.\nfn find_lucas(n: isize) -> isize {\n", "task": "mbpp_389_find_lucas"}
{"content": "/// Write a function to check if given vector contains no duplicates.\nfn check_distinct(test_tup: Vec<isize>) -> bool {\n    let mut temp: Vec<isize> = test_tup.clone();\n    temp.sort();\n    let result: bool = temp.windows(2).all(|x| x[0] != x[1]);\n    result\n}", "retrieval_text": "/// Write a function to check if given vector contains no duplicates.\nfn check_distinct(test_tup: Vec<isize>) -> bool {\n", "task": "mbpp_394_check_distinct"}
{"content": "/// Write a rsthon function to find the first non-repeated character in a given string.\nfn first_non_repeating_character(str1: String) -> Option<String> {\n    let mut ctr = std::collections::HashMap::new();\n\n    for ch in str1.chars() {\n        let count = ctr.entry(ch).or_insert(0);\n        *count += 1;\n    }\n\n    for ch in str1.chars() {\n        if ctr.get(&ch) == Some(&1) {\n            return Some(ch.to_string());\n        }\n    }\n    None\n}", "retrieval_text": "/// Write a rsthon function to find the first non-repeated character in a given string.\nfn first_non_repeating_character(str1: String) -> Option<String> {\n", "task": "mbpp_395_first_non_repeating_character"}
{"content": "/// Write a function to check whether the given string starts and ends with the same character or not.\nfn check_char(string: String) -> String {\n    let string_char: Vec<char> = string.chars().collect();\n    let first_char: char = string_char[0];\n    let last_char: char = string_char[string_char.len() - 1];\n    if first_char == last_char {\n        \"Valid\".to_string()\n    } else {\n        \"Invalid\".to_string()\n    }\n}", "retrieval_text": "/// Write a function to check whether the given string starts and ends with the same character or not.\nfn check_char(string: String) -> String {\n", "task": "mbpp_396_check_char"}
{"content": "/// Write a function to find the median of three numbers.\nfn median_numbers(a: isize, b: isize, c: isize) -> f64 {\n    if a > b {\n        if a < c {\n            return a as f64;\n        } else if b > c {\n            return b as f64;\n        } else {\n            return c as f64;\n        }\n    } else {\n        if a > c {\n            return a as f64;\n        } else if b < c {\n            return b as f64;\n        } else {\n            return c as f64;\n        }\n    }\n}", "retrieval_text": "/// Write a function to find the median of three numbers.\nfn median_numbers(a: isize, b: isize, c: isize) -> f64 {\n", "task": "mbpp_397_median_numbers"}
{"content": "/// Write a function to perform the mathematical bitwise xor operation across the given tuples.\nfn bitwise_xor(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n  (test_tup1.0 ^ test_tup2.0, test_tup1.1 ^ test_tup2.1, test_tup1.2 ^ test_tup2.2, test_tup1.3 ^ test_tup2.3)\n}", "retrieval_text": "/// Write a function to perform the mathematical bitwise xor operation across the given tuples.\nfn bitwise_xor(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n", "task": "mbpp_399_bitwise_xor"}
{"content": "/// Write a function to perform index wise addition of vector elements in the given two nested vectors.\nfn add_nested_tuples(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n    test_tup1.into_iter()\n        .zip(test_tup2.into_iter())\n        .map(|(tup1, tup2)| tup1.into_iter().zip(tup2.into_iter()).map(|(a, b)| a + b).collect())\n        .collect()\n}", "retrieval_text": "/// Write a function to perform index wise addition of vector elements in the given two nested vectors.\nfn add_nested_tuples(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n", "task": "mbpp_401_add_nested_tuples"}
{"content": "/// Write a rsthon function to find the minimum of two numbers.\nfn minimum(a: isize, b: isize) -> isize {\n    if a <= b {\n        a\n    } else {\n        b\n    }\n}", "retrieval_text": "/// Write a rsthon function to find the minimum of two numbers.\nfn minimum(a: isize, b: isize) -> isize {\n", "task": "mbpp_404_minimum"}
{"content": "/// Write a rsthon function to find whether the parity of a given number is odd.\nfn find_Parity(x: isize) -> bool {\n    let mut y: isize = x ^ (x >> 1);\n    y = y ^ (y >> 2);\n    y = y ^ (y >> 4);\n    y = y ^ (y >> 8);\n    y = y ^ (y >> 16);\n    y & 1 == 1\n}", "retrieval_text": "/// Write a rsthon function to find whether the parity of a given number is odd.\nfn find_Parity(x: isize) -> bool {\n", "task": "mbpp_406_find_Parity"}
{"content": "/// Write a function to find the minimum product from the pairs of tuples within a given vector.\nfn min_product_tuple(list1: Vec<(isize, isize)>) -> isize {\n    list1.into_iter().map(|(x, y)| x * y).min().unwrap()\n}", "retrieval_text": "/// Write a function to find the minimum product from the pairs of tuples within a given vector.\nfn min_product_tuple(list1: Vec<(isize, isize)>) -> isize {\n", "task": "mbpp_409_min_product_tuple"}
{"content": "/// Write a function to convert the given snake case string to camel case string.\nfn snake_to_camel(word: String) -> String {\n    let mut result = String::new();\n    let mut is_first_char = true;\n\n    for c in word.chars() {\n        if c == '_' {\n            is_first_char = true;\n        } else if is_first_char {\n            result.push(c.to_uppercase().next().unwrap());\n            is_first_char = false;\n        } else {\n            result.push(c);\n        }\n    }\n\n    result\n}", "retrieval_text": "/// Write a function to convert the given snake case string to camel case string.\nfn snake_to_camel(word: String) -> String {\n", "task": "mbpp_411_snake_to_camel"}
{"content": "/// Write a rsthon function to remove odd numbers from a given vector.\nfn remove_odd(l: Vec<isize>) -> Vec<isize> {\n    let mut v: Vec<isize> = l;\n    v.retain(|&x| x % 2 == 0);\n    v\n}", "retrieval_text": "/// Write a rsthon function to remove odd numbers from a given vector.\nfn remove_odd(l: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_412_remove_odd"}
{"content": "/// Write a rsthon function to check whether any value in a sequence exists in a sequence or not.\nfn overlapping(list1: Vec<isize>, list2: Vec<isize>) -> bool {\n    let c = list1.len();\n    let d = list2.len();\n    for i in 0..c {\n        for j in 0..d {\n            if list1[i] == list2[j] {\n                return true;\n            }\n        }\n    }\n    false\n}", "retrieval_text": "/// Write a rsthon function to check whether any value in a sequence exists in a sequence or not.\nfn overlapping(list1: Vec<isize>, list2: Vec<isize>) -> bool {\n", "task": "mbpp_414_overlapping"}
{"content": "/// Write a rsthon function to find a pair with highest product from a given vector of integers.\nfn max_Product(arr: Vec<isize>) -> (isize, isize) {\n    if arr.len() < 2 {\n        panic!(\"No pairs exists\");\n    }\n\n    let mut x = arr[0];\n    let mut y = arr[1];\n\n    for i in 0..arr.len() {\n        for j in i + 1..arr.len() {\n            if arr[i] * arr[j] > x * y {\n                x = arr[i];\n                y = arr[j];\n            }\n        }\n    }\n\n    (x, y)\n}", "retrieval_text": "/// Write a rsthon function to find a pair with highest product from a given vector of integers.\nfn max_Product(arr: Vec<isize>) -> (isize, isize) {\n", "task": "mbpp_415_max_Product"}
{"content": "/// Write a rsthon function to find the cube sum of first n even natural numbers.\nfn cube_Sum(n: isize) -> isize {\n    let mut sum = 0;\n    for i in 1..n + 1 {\n        sum += (2 * i) * (2 * i) * (2 * i);\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the cube sum of first n even natural numbers.\nfn cube_Sum(n: isize) -> isize {\n", "task": "mbpp_420_cube_Sum"}
{"content": "/// Write a function to filter odd numbers.\nfn filter_oddnumbers(nums: Vec<isize>) -> Vec<isize> {\n    nums.into_iter().filter(|&x| x % 2 != 0).collect()\n}", "retrieval_text": "/// Write a function to filter odd numbers.\nfn filter_oddnumbers(nums: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_426_filter_oddnumbers"}
{"content": "/// Write a function to sort the given vector by using shell sort.\nfn shell_sort(my_list: Vec<isize>) -> Vec<isize> {\n    let mut my_list = my_list;\n    let length = my_list.len();\n\n    let mut gap = length / 2;\n\n    while gap > 0 {\n        for i in (gap..length).step_by(gap) {\n            let current_item = my_list[i];\n            let mut j = i;\n            while j >= gap && my_list[j - gap] > current_item {\n                my_list[j] = my_list[j - gap];\n                j -= gap;\n            }\n            my_list[j] = current_item;\n        }\n        gap = gap / 2;\n    }\n\n    my_list\n}", "retrieval_text": "/// Write a function to sort the given vector by using shell sort.\nfn shell_sort(my_list: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_428_shell_sort"}
{"content": "/// Write a function to extract the elementwise and tuples from the given two tuples.\nfn and_tuples(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n    let res = (test_tup1.0 & test_tup2.0, test_tup1.1 & test_tup2.1, test_tup1.2 & test_tup2.2, test_tup1.3 & test_tup2.3);\n    res\n}", "retrieval_text": "/// Write a function to extract the elementwise and tuples from the given two tuples.\nfn and_tuples(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n", "task": "mbpp_429_and_tuples"}
{"content": "/// Write a function to find the directrix of a parabola.\nfn parabola_directrix(a: isize, b: isize, c: isize) -> isize {\n    (c - (b * b + 1) * 4 * a) as isize\n}", "retrieval_text": "/// Write a function to find the directrix of a parabola.\nfn parabola_directrix(a: isize, b: isize, c: isize) -> isize {\n", "task": "mbpp_430_parabola_directrix"}
{"content": "/// Write a function to find the median length of a trapezium.\nfn median_trapezium(base1: isize, base2: isize, height: isize) -> f64 {\n    let median = 0.5 * (base1 + base2) as f64;\n    median\n}", "retrieval_text": "/// Write a function to find the median length of a trapezium.\nfn median_trapezium(base1: isize, base2: isize, height: isize) -> f64 {\n", "task": "mbpp_432_median_trapezium"}
{"content": "/// Write a function to check whether the entered number is greater than the elements of the given vector.\nfn check_greater(arr: Vec<isize>, number: isize) -> bool {\n    let mut arr = arr;\n    arr.sort();\n    let index = arr.len() - 1;\n    if number > arr[index] {\n        return true;\n    } else {\n        return false;\n    }\n}", "retrieval_text": "/// Write a function to check whether the entered number is greater than the elements of the given vector.\nfn check_greater(arr: Vec<isize>, number: isize) -> bool {\n", "task": "mbpp_433_check_greater"}
{"content": "/// Write a rsthon function to find the last digit of a given number.\nfn last_Digit(n: isize) -> isize {\n    n % 10\n}", "retrieval_text": "/// Write a rsthon function to find the last digit of a given number.\nfn last_Digit(n: isize) -> isize {\n", "task": "mbpp_435_last_Digit"}
{"content": "/// Write a rsthon function to return the negative numbers in a vector.\nfn neg_nos(list1: Vec<isize>) -> Vec<isize> {\n  let mut result: Vec<isize> = Vec::new();\n  for num in list1 {\n    if num < 0 {\n      result.push(num);\n    }\n  }\n  result\n}", "retrieval_text": "/// Write a rsthon function to return the negative numbers in a vector.\nfn neg_nos(list1: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_436_neg_nos"}
{"content": "/// Write a function to count bidirectional tuple pairs.\nfn count_bidirectional(test_list: Vec<(isize, isize)>) -> isize {\n    let mut res = 0;\n    for idx in 0..test_list.len() {\n        for iidx in idx + 1..test_list.len() {\n            if test_list[iidx].0 == test_list[idx].1 && test_list[idx].1 == test_list[iidx].0 {\n                res += 1;\n            }\n        }\n    }\n    res\n}", "retrieval_text": "/// Write a function to count bidirectional tuple pairs.\nfn count_bidirectional(test_list: Vec<(isize, isize)>) -> isize {\n", "task": "mbpp_438_count_bidirectional"}
{"content": "/// Write a function to join a vector of multiple integers into a single integer.\nfn multiple_to_single(L: Vec<isize>) -> isize {\n    let s = L.into_iter().map(|x| x.to_string()).collect::<String>();\n    isize::from_str_radix(&s, 10).unwrap()\n}", "retrieval_text": "/// Write a function to join a vector of multiple integers into a single integer.\nfn multiple_to_single(L: Vec<isize>) -> isize {\n", "task": "mbpp_439_multiple_to_single"}
{"content": "/// Write a function to find the surface area of a cube of a given size.\nfn surfacearea_cube(l: isize) -> isize {\n    6 * l * l\n}", "retrieval_text": "/// Write a function to find the surface area of a cube of a given size.\nfn surfacearea_cube(l: isize) -> isize {\n", "task": "mbpp_441_surfacearea_cube"}
{"content": "/// Write a rsthon function to find the largest negative number from the given vector.\nfn largest_neg(list1: Vec<isize>) -> isize {\n    let mut max = list1[0];\n    for x in list1 {\n        if x < max {\n            max = x\n        }\n    }\n    max\n}", "retrieval_text": "/// Write a rsthon function to find the largest negative number from the given vector.\nfn largest_neg(list1: Vec<isize>) -> isize {\n", "task": "mbpp_443_largest_neg"}
{"content": "/// Write a function to trim each vector by k in the given vectors.\nfn trim_tuple(test_list: Vec<Vec<isize>>, K: isize) -> Vec<Vec<isize>> {\n    let mut res = vec![];\n    for ele in test_list {\n        let N = ele.len();\n        let ele = ele[K as usize..N as usize - K as usize].to_vec();\n        res.push(ele);\n    }\n    res\n}", "retrieval_text": "/// Write a function to trim each vector by k in the given vectors.\nfn trim_tuple(test_list: Vec<Vec<isize>>, K: isize) -> Vec<Vec<isize>> {\n", "task": "mbpp_444_trim_tuple"}
{"content": "/// Write a function to perform index wise multiplication of vector elements in the given two vectors.\nfn index_multiplication(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n    test_tup1\n        .iter()\n        .zip(test_tup2.iter())\n        .map(|(a, b)| {\n            a.iter()\n                .zip(b.iter())\n                .map(|(x, y)| x * y)\n                .collect()\n        })\n        .collect()\n}", "retrieval_text": "/// Write a function to perform index wise multiplication of vector elements in the given two vectors.\nfn index_multiplication(test_tup1: Vec<Vec<isize>>, test_tup2: Vec<Vec<isize>>) -> Vec<Vec<isize>> {\n", "task": "mbpp_445_index_multiplication"}
{"content": "/// Write a function to find cubes of individual elements in a vector.\nfn cube_nums(nums: Vec<isize>) -> Vec<isize> {\n    nums.iter()\n        .map(|&x| x.pow(3))\n        .collect()\n}", "retrieval_text": "/// Write a function to find cubes of individual elements in a vector.\nfn cube_nums(nums: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_447_cube_nums"}
{"content": "/// Write a function to extract specified size of strings from a given vector of string values.\nfn extract_string(str: Vec<String>, l: isize) -> Vec<String> {\n    str.into_iter().filter(|e| e.len() == l as usize).collect()\n}", "retrieval_text": "/// Write a function to extract specified size of strings from a given vector of string values.\nfn extract_string(str: Vec<String>, l: isize) -> Vec<String> {\n", "task": "mbpp_450_extract_string"}
{"content": "/// Write a function to remove all whitespaces from the given string.\nfn remove_whitespaces(text1: String) -> String {\n    text1.replace(\" \", \"\")\n}", "retrieval_text": "/// Write a function to remove all whitespaces from the given string.\nfn remove_whitespaces(text1: String) -> String {\n", "task": "mbpp_451_remove_whitespaces"}
{"content": "/// Write a function that gives loss amount on a sale if the given amount has loss else return 0.\nfn loss_amount(actual_cost: isize, sale_amount: isize) -> isize {\n    if sale_amount > actual_cost {\n        sale_amount - actual_cost\n    } else {\n        0\n    }\n}", "retrieval_text": "/// Write a function that gives loss amount on a sale if the given amount has loss else return 0.\nfn loss_amount(actual_cost: isize, sale_amount: isize) -> isize {\n", "task": "mbpp_452_loss_amount"}
{"content": "/// Write a function to check whether the given month number contains 31 days or not.\nfn check_monthnumb_number(monthnum2: isize) -> bool {\n    match monthnum2 {\n        1 | 3 | 5 | 7 | 8 | 10 | 12 => true,\n        _ => false\n    }\n}", "retrieval_text": "/// Write a function to check whether the given month number contains 31 days or not.\nfn check_monthnumb_number(monthnum2: isize) -> bool {\n", "task": "mbpp_455_check_monthnumb_number"}
{"content": "/// Write a function to reverse each string in a given vector of string values.\nfn reverse_string_list(stringlist: Vec<String>) -> Vec<String> {\n    stringlist.into_iter().map(|string| string.chars().rev().collect()).collect()\n}", "retrieval_text": "/// Write a function to reverse each string in a given vector of string values.\nfn reverse_string_list(stringlist: Vec<String>) -> Vec<String> {\n", "task": "mbpp_456_reverse_string_list"}
{"content": "/// Write a function to find the area of a rectangle.\nfn rectangle_area(l: isize, b: isize) -> isize {\n    l * b\n}", "retrieval_text": "/// Write a function to find the area of a rectangle.\nfn rectangle_area(l: isize, b: isize) -> isize {\n", "task": "mbpp_458_rectangle_area"}
{"content": "/// Write a rsthon function to get the first element of each subvector.\nfn Extract(lst: Vec<Vec<isize>>) -> Vec<isize> {\n    let mut result = Vec::new();\n    for v in lst {\n        result.push(v[0]);\n    }\n    result\n}", "retrieval_text": "/// Write a rsthon function to get the first element of each subvector.\nfn Extract(lst: Vec<Vec<isize>>) -> Vec<isize> {\n", "task": "mbpp_460_Extract"}
{"content": "use std::collections::HashMap;\n\n/// Write a function to check if all values are same in a HashMap.\nfn check_value(dict: HashMap<String, isize>, n: isize) -> bool {\n    dict.values().all(|&x| x == n)\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write a function to check if all values are same in a HashMap.\nfn check_value(dict: HashMap<String, isize>, n: isize) -> bool {\n", "task": "mbpp_464_check_value"}
{"content": "/// Write a function to find the pairwise addition of the neighboring elements of the given tuple.\nfn add_pairwise(test_tup: (isize, isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n    let add = (test_tup.0 + test_tup.1, test_tup.1 + test_tup.2, test_tup.2 + test_tup.3, test_tup.3 + test_tup.4);\n    return add;\n}", "retrieval_text": "/// Write a function to find the pairwise addition of the neighboring elements of the given tuple.\nfn add_pairwise(test_tup: (isize, isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n", "task": "mbpp_470_add_pairwise"}
{"content": "/// Write a rsthon function to find the product of the vector multiplication modulo n.\nfn find_remainder(arr: Vec<isize>, n: isize) -> isize {\n    let mut mul = 1;\n    for &i in &arr {\n        mul = (mul * (i % n)) % n;\n    }\n    return mul % n;\n}", "retrieval_text": "/// Write a rsthon function to find the product of the vector multiplication modulo n.\nfn find_remainder(arr: Vec<isize>, n: isize) -> isize {\n", "task": "mbpp_471_find_remainder"}
{"content": "/// Write a rsthon function to check whether the given vector contains consecutive numbers or not.\nfn check_Consecutive(l: Vec<isize>) -> bool {\n    let mut s = l.to_owned();\n    s.sort();\n    for i in 0..s.len() - 1 {\n        if s[i] + 1 != s[i + 1] {\n            return false;\n        }\n    }\n    true\n}", "retrieval_text": "/// Write a rsthon function to check whether the given vector contains consecutive numbers or not.\nfn check_Consecutive(l: Vec<isize>) -> bool {\n", "task": "mbpp_472_check_Consecutive"}
{"content": "/// Write a function to replace characters in a string.\nfn replace_char(str1: String, ch: String, newch: String) -> String {\n    let mut str2 = str1.replace(&ch, &newch);\n    str2\n}", "retrieval_text": "/// Write a function to replace characters in a string.\nfn replace_char(str1: String, ch: String, newch: String) -> String {\n", "task": "mbpp_474_replace_char"}
{"content": "use std::collections::HashMap;\n\n/// Write a function to sort a HashMap by value.\nfn sort_counter(dict1: HashMap<String, isize>) -> Vec<(String, isize)> {\n    let mut x: Vec<(String, isize)> = vec![];\n    for (key, value) in dict1 {\n        x.push((key, value));\n    }\n    x.sort_by(|a, b| b.1.cmp(&a.1));\n    x\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write a function to sort a HashMap by value.\nfn sort_counter(dict1: HashMap<String, isize>) -> Vec<(String, isize)> {\n", "task": "mbpp_475_sort_counter"}
{"content": "/// Write a rsthon function to find the sum of the largest and smallest value in a given vector.\nfn big_sum(nums: Vec<isize>) -> isize {\n    let sum = nums[0] + nums[nums.len() - 1];\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the sum of the largest and smallest value in a given vector.\nfn big_sum(nums: Vec<isize>) -> isize {\n", "task": "mbpp_476_big_sum"}
{"content": "/// Write a rsthon function to convert the given string to lower case.\nfn is_lower(string: String) -> String {\n    string.to_lowercase()\n}", "retrieval_text": "/// Write a rsthon function to convert the given string to lower case.\nfn is_lower(string: String) -> String {\n", "task": "mbpp_477_is_lower"}
{"content": "/// Write a function to remove lowercase substrings from a given string.\nfn remove_lowercase(str1: String) -> String {\n    let mut new_str = String::new();\n    for c in str1.chars() {\n        if c.is_ascii_uppercase() {\n            new_str.push(c);\n        }\n    }\n    return new_str;\n}", "retrieval_text": "/// Write a function to remove lowercase substrings from a given string.\nfn remove_lowercase(str1: String) -> String {\n", "task": "mbpp_478_remove_lowercase"}
{"content": "/// Write a rsthon function to find the first digit of a given number.\nfn first_Digit(n: isize) -> isize {\n    let mut n = n;\n    while n >= 10 {\n        n = n / 10;\n    }\n    n\n}", "retrieval_text": "/// Write a rsthon function to find the first digit of a given number.\nfn first_Digit(n: isize) -> isize {\n", "task": "mbpp_479_first_Digit"}
{"content": "/// Write a rsthon function which takes a vector of integers and only returns the odd ones.\nfn Split(list: Vec<isize>) -> Vec<isize> {\n    list.into_iter().filter(|&x| x % 2 != 0).collect()\n}", "retrieval_text": "/// Write a rsthon function which takes a vector of integers and only returns the odd ones.\nfn Split(list: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_554_Split"}
{"content": "/// Write a rsthon function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.\nfn difference(n: isize) -> isize {\n    let mut s = (n * (n + 1)) / 2;\n    let res = s * (s - 1);\n    return res;\n}", "retrieval_text": "/// Write a rsthon function to find the difference between the sum of cubes of the first n natural numbers and the sum of the first n natural numbers.\nfn difference(n: isize) -> isize {\n", "task": "mbpp_555_difference"}
{"content": "/// Write a function to toggle the case of all characters in a string.\nfn toggle_string(string: String) -> String {\n    string.chars().map(|c| if c.is_uppercase() { c.to_lowercase().to_string() } else { c.to_uppercase().to_string() }).collect::<String>()\n}", "retrieval_text": "/// Write a function to toggle the case of all characters in a string.\nfn toggle_string(string: String) -> String {\n", "task": "mbpp_557_toggle_string"}
{"content": "/// Write a rsthon function to find the sum of the per-digit difference between two integers.\nfn digit_distance_nums(n1: isize, n2: isize) -> isize {\n    let diff = n1.abs_diff(n2);\n    diff.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum::<u32>() as isize\n}", "retrieval_text": "/// Write a rsthon function to find the sum of the per-digit difference between two integers.\nfn digit_distance_nums(n1: isize, n2: isize) -> isize {\n", "task": "mbpp_558_digit_distance_nums"}
{"content": "/// Write a function to find the sum of the largest contiguous subvector in the given vector.\nfn max_sub_array_sum(a: Vec<isize>, size: isize) -> isize {\n  let mut max_so_far = 0;\n  let mut max_ending_here = 0;\n\n  for i in 0..size {\n    max_ending_here = max_ending_here + a[i as usize];\n\n    if max_ending_here < 0 {\n      max_ending_here = 0;\n    } else if max_so_far < max_ending_here {\n      max_so_far = max_ending_here;\n    }\n  }\n  max_so_far\n}", "retrieval_text": "/// Write a function to find the sum of the largest contiguous subvector in the given vector.\nfn max_sub_array_sum(a: Vec<isize>, size: isize) -> isize {\n", "task": "mbpp_559_max_sub_array_sum"}
{"content": "/// Write a function to find the union of the elements of two given vectors and output them in sorted order.\nfn union_elements(test_tup1: Vec<isize>, test_tup2: Vec<isize>) -> Vec<isize> {\n    let mut vec: Vec<isize> = vec![];\n    for elem in test_tup1.iter() {\n        vec.push(*elem);\n    }\n    for elem in test_tup2.iter() {\n        vec.push(*elem);\n    }\n    vec.sort();\n    vec.dedup();\n    vec\n}", "retrieval_text": "/// Write a function to find the union of the elements of two given vectors and output them in sorted order.\nfn union_elements(test_tup1: Vec<isize>, test_tup2: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_560_union_elements"}
{"content": "/// Write a rsthon function to find the length of the longest subvectors.\nfn Find_Max_Length(lst: Vec<Vec<isize>>) -> isize {\n    lst.iter().fold(0, |max, x| {\n        let length = x.len() as isize;\n        max.max(length)\n    })\n}", "retrieval_text": "/// Write a rsthon function to find the length of the longest subvectors.\nfn Find_Max_Length(lst: Vec<Vec<isize>>) -> isize {\n", "task": "mbpp_562_Find_Max_Length"}
{"content": "/// Write a rsthon function which takes a vector of integers and counts the number of possible unordered pairs where both elements are unequal.\nfn count_Pairs(arr: Vec<isize>, n: isize) -> isize {\n    let mut cnt = 0;\n    for i in 0..n as usize {\n        for j in i + 1..n as usize {\n            if arr[i] != arr[j] {\n                cnt += 1;\n            }\n        }\n    }\n    cnt\n}", "retrieval_text": "/// Write a rsthon function which takes a vector of integers and counts the number of possible unordered pairs where both elements are unequal.\nfn count_Pairs(arr: Vec<isize>, n: isize) -> isize {\n", "task": "mbpp_564_count_Pairs"}
{"content": "/// Write a rsthon function to split a string into characters.\nfn split(word: String) -> Vec<String> {\n    word.chars().map(|x| x.to_string()).collect()\n}", "retrieval_text": "/// Write a rsthon function to split a string into characters.\nfn split(word: String) -> Vec<String> {\n", "task": "mbpp_565_split"}
{"content": "/// Write a function to get the sum of the digits of a non-negative integer.\nfn sum_digits(n: isize) -> isize {\n    match n {\n        0 => 0,\n        _ => n % 10 + sum_digits(n / 10),\n    }\n}", "retrieval_text": "/// Write a function to get the sum of the digits of a non-negative integer.\nfn sum_digits(n: isize) -> isize {\n", "task": "mbpp_566_sum_digits"}
{"content": "/// Write a function to check whether a specified vector is sorted or not.\nfn issort_list(list1: Vec<isize>) -> bool {\n    let result = list1\n        .iter()\n        .zip(list1.iter().skip(1))\n        .all(|(a, b)| *a <= *b);\n    result\n}", "retrieval_text": "/// Write a function to check whether a specified vector is sorted or not.\nfn issort_list(list1: Vec<isize>) -> bool {\n", "task": "mbpp_567_issort_list"}
{"content": "/// Write a rsthon function to calculate the product of the unique numbers in a given vector.\nfn unique_product(list_data: Vec<isize>) -> isize {\n    let mut temp: Vec<isize> = vec![];\n    let mut p: isize = 1;\n    for i in list_data {\n        if !temp.contains(&i) {\n            temp.push(i);\n        }\n    }\n    for i in temp {\n        p *= i;\n    }\n    p\n}", "retrieval_text": "/// Write a rsthon function to calculate the product of the unique numbers in a given vector.\nfn unique_product(list_data: Vec<isize>) -> isize {\n", "task": "mbpp_573_unique_product"}
{"content": "/// Write a function to find the surface area of a cylinder.\nfn surfacearea_cylinder(r: isize, h: isize) -> f64 {\n    let surfacearea: f64 = (2.0 * 3.1415 * r as f64 * r as f64) + (2.0 * 3.1415 * r as f64 * h as f64);\n    return surfacearea;\n}", "retrieval_text": "/// Write a function to find the surface area of a cylinder.\nfn surfacearea_cylinder(r: isize, h: isize) -> f64 {\n", "task": "mbpp_574_surfacearea_cylinder"}
{"content": "/// Write a rsthon function to check whether a vector is subvector of another or not.\nfn is_Sub_Array(A: Vec<isize>, B: Vec<isize>) -> bool {\n    let mut i = 0;\n    let mut j = 0;\n\n    while i < A.len() && j < B.len() {\n        if A[i] == B[j] {\n            i += 1;\n            j += 1;\n        } else {\n            i = i - j + 1;\n            j = 0;\n        }\n    }\n\n    j == B.len()\n}", "retrieval_text": "/// Write a rsthon function to check whether a vector is subvector of another or not.\nfn is_Sub_Array(A: Vec<isize>, B: Vec<isize>) -> bool {\n", "task": "mbpp_576_is_Sub_Array"}
{"content": "/// Write a rsthon function to find the last digit in factorial of a given number.\nfn last_Digit_Factorial(n: isize) -> isize {\n    if (n == 0) { return 1; }\n    else if (n <= 2) { return n; }\n    else if (n == 3) { return 6; }\n    else if (n == 4) { return 4; }\n    else { return 0; }\n}", "retrieval_text": "/// Write a rsthon function to find the last digit in factorial of a given number.\nfn last_Digit_Factorial(n: isize) -> isize {\n", "task": "mbpp_577_last_Digit_Factorial"}
{"content": "/// Write a function to interleave 3 vectors of the same length into a single flat vector.\nfn interleave_lists(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> Vec<isize> {\n    // return [el for pair in zip(list1, list2, list3) for el in pair]\n    let mut result: Vec<isize> = Vec::new();\n    for i in 0..list1.len() {\n        result.push(list1[i]);\n        result.push(list2[i]);\n        result.push(list3[i]);\n    }\n    result\n}", "retrieval_text": "/// Write a function to interleave 3 vectors of the same length into a single flat vector.\nfn interleave_lists(list1: Vec<isize>, list2: Vec<isize>, list3: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_578_interleave_lists"}
{"content": "/// Write a rsthon function to find the surface area of a square rsramid with a given base edge and height.\nfn surface_Area(b: isize, s: isize) -> isize {\n    2 * b * s + b.pow(2)\n}", "retrieval_text": "/// Write a rsthon function to find the surface area of a square rsramid with a given base edge and height.\nfn surface_Area(b: isize, s: isize) -> isize {\n", "task": "mbpp_581_surface_Area"}
{"content": "/// Write a function which returns nth catalan number.\nfn catalan_number(num: isize) -> isize {\n    if num <= 1 {\n        return 1;\n    }\n    let mut res_num = 0;\n    for i in 0..num {\n        res_num += catalan_number(i) * catalan_number(num - i - 1);\n    }\n    res_num\n}", "retrieval_text": "/// Write a function which returns nth catalan number.\nfn catalan_number(num: isize) -> isize {\n", "task": "mbpp_583_catalan_number"}
{"content": "/// Write a rsthon function to split a vector at the nth eelment and add the first part to the end.\nfn split_Arr(l: Vec<isize>, n: isize) -> Vec<isize> {\n    let v1 = &l[0..n as usize];\n    let v2 = &l[n as usize..];\n    let mut result: Vec<isize> = v2.iter().chain(v1.iter()).cloned().collect();\n    return result;\n}", "retrieval_text": "/// Write a rsthon function to split a vector at the nth eelment and add the first part to the end.\nfn split_Arr(l: Vec<isize>, n: isize) -> Vec<isize> {\n", "task": "mbpp_586_split_Arr"}
{"content": "/// Write a rsthon function to find the difference between largest and smallest value in a given vector.\nfn big_diff(nums: Vec<isize>) -> isize {\n    let mut max = 0;\n    let mut min = 1000; // set to max possible value\n\n    for n in nums.iter() {\n        if *n > max {\n            max = *n;\n        }\n        if *n < min {\n            min = *n;\n        }\n    }\n\n    max - min\n}", "retrieval_text": "/// Write a rsthon function to find the difference between largest and smallest value in a given vector.\nfn big_diff(nums: Vec<isize>) -> isize {\n", "task": "mbpp_588_big_diff"}
{"content": "/// Write a function to find perfect squares between two given numbers.\nfn perfect_squares(a: isize, b: isize) -> Vec<isize> {\n    let mut res = Vec::new();\n    let mut i = a;\n    while i <= b {\n        let mut j = 1;\n        while j * j <= i {\n            if j * j == i {\n                res.push(i);\n            }\n            j += 1;\n        }\n        i += 1;\n    }\n    res\n}", "retrieval_text": "/// Write a function to find perfect squares between two given numbers.\nfn perfect_squares(a: isize, b: isize) -> Vec<isize> {\n", "task": "mbpp_589_perfect_squares"}
{"content": "/// Write a function to remove leading zeroes from an ip address.\nfn removezero_ip(ip: String) -> String {\n    let string = ip.replace(\".0\", \".\");\n    string\n}", "retrieval_text": "/// Write a function to remove leading zeroes from an ip address.\nfn removezero_ip(ip: String) -> String {\n", "task": "mbpp_593_removezero_ip"}
{"content": "/// Write a function to find the difference of the first even and first odd number of a given vector.\nfn diff_even_odd(list1: Vec<isize>) -> isize {\n    let first_even = list1.iter().find(|&&x| x % 2 == 0).cloned().unwrap_or(-1);\n    let first_odd = list1.iter().find(|&&x| x % 2 != 0).cloned().unwrap_or(-1);\n\n    first_even - first_odd\n}", "retrieval_text": "/// Write a function to find the difference of the first even and first odd number of a given vector.\nfn diff_even_odd(list1: Vec<isize>) -> isize {\n", "task": "mbpp_594_diff_even_odd"}
{"content": "/// Write a function to find kth element from the given two sorted vectors.\nfn find_kth(arr1: Vec<isize>, arr2: Vec<isize>, k: isize) -> isize {\n    let mut i = 0;\n    let mut j = 0;\n    let mut d = 0;\n\n    while i < arr1.len() && j < arr2.len() {\n        if arr1[i] < arr2[j] {\n            d += 1;\n            if d == k {\n                return arr1[i];\n            }\n            i += 1;\n        } else {\n            d += 1;\n            if d == k {\n                return arr2[j];\n            }\n            j += 1;\n        }\n    }\n\n    while i < arr1.len() {\n        d += 1;\n        if d == k {\n            return arr1[i];\n        }\n        i += 1;\n    }\n\n    while j < arr2.len() {\n        d += 1;\n        if d == k {\n            return arr2[j];\n        }\n        j += 1;\n    }\n\n    0\n}", "retrieval_text": "/// Write a function to find kth element from the given two sorted vectors.\nfn find_kth(arr1: Vec<isize>, arr2: Vec<isize>, k: isize) -> isize {\n", "task": "mbpp_597_find_kth"}
{"content": "/// Write a function to check whether the given number is armstrong or not.\nfn armstrong_number(number: isize) -> bool {\n    let mut sum = 0;\n    let mut times = 0;\n    let mut temp = number;\n    while temp > 0 {\n        times = times + 1;\n        temp = temp / 10;\n    }\n    temp = number;\n    while temp > 0 {\n        let mut reminder = temp % 10;\n        sum = sum + (reminder as isize).pow(times);\n        temp = temp / 10;\n    }\n    number == sum\n}", "retrieval_text": "/// Write a function to check whether the given number is armstrong or not.\nfn armstrong_number(number: isize) -> bool {\n", "task": "mbpp_598_armstrong_number"}
{"content": "/// Write a function to find sum and average of first n natural numbers.\nfn sum_average(number: isize) -> (isize, f64) {\n    let mut total = 0;\n    for value in 1..number+1 {\n        total += value;\n    }\n    let average = total as f64 / number as f64;\n    (total, average)\n}", "retrieval_text": "/// Write a function to find sum and average of first n natural numbers.\nfn sum_average(number: isize) -> (isize, f64) {\n", "task": "mbpp_599_sum_average"}
{"content": "/// Write a rsthon function to check whether the given number is even or not.\nfn is_Even(n: isize) -> bool {\n    if n ^ 1 == n + 1 {\n        true\n    } else {\n        false\n    }\n}", "retrieval_text": "/// Write a rsthon function to check whether the given number is even or not.\nfn is_Even(n: isize) -> bool {\n", "task": "mbpp_600_is_Even"}
{"content": "/// Write a rsthon function to find the first repeated character in a given string.\nfn first_repeated_char(str1: String) -> Option<String> {\n    let mut chars = Vec::new();\n    for c in str1.chars() {\n        if chars.contains(&c) {\n            return Some(c.to_string());\n        }\n        chars.push(c);\n    }\n    None\n}", "retrieval_text": "/// Write a rsthon function to find the first repeated character in a given string.\nfn first_repeated_char(str1: String) -> Option<String> {\n", "task": "mbpp_602_first_repeated_char"}
{"content": "/// Write a function to reverse words seperated by spaces in a given string.\nfn reverse_words(s: String) -> String {\n    s.split_whitespace().rev().collect::<Vec<&str>>().join(\" \")\n}", "retrieval_text": "/// Write a function to reverse words seperated by spaces in a given string.\nfn reverse_words(s: String) -> String {\n", "task": "mbpp_604_reverse_words"}
{"content": "/// Write a function to check if the given integer is a prime number.\nfn prime_num(num: isize) -> bool {\n    if num >= 1 {\n        for i in 2..num / 2 {\n            if num % i == 0 {\n                return false;\n            }\n        }\n        true\n    } else {\n        false\n    }\n}", "retrieval_text": "/// Write a function to check if the given integer is a prime number.\nfn prime_num(num: isize) -> bool {\n", "task": "mbpp_605_prime_num"}
{"content": "/// Write a function to convert degrees to radians.\nfn radian_degree(degree: isize) -> f64 {\n    let pi: f64 = std::f64::consts::PI;\n    return degree as f64 * pi / 180.;\n}", "retrieval_text": "/// Write a function to convert degrees to radians.\nfn radian_degree(degree: isize) -> f64 {\n", "task": "mbpp_606_radian_degree"}
{"content": "/// Write a rsthon function which takes a vector and returns a vector with the same elements, but the k'th element removed.\nfn remove_kth_element(list1: Vec<isize>, L: isize) -> Vec<isize> {\n    let mut new_vector = vec![];\n    for i in 0..list1.len() {\n        if i != L as usize - 1 {\n            new_vector.push(list1[i]);\n        }\n    }\n    new_vector\n}", "retrieval_text": "/// Write a rsthon function which takes a vector and returns a vector with the same elements, but the k'th element removed.\nfn remove_kth_element(list1: Vec<isize>, L: isize) -> Vec<isize> {\n", "task": "mbpp_610_remove_kth_element"}
{"content": "/// Write a function which given a matrix represented as a vector of vectors returns the max of the n'th column.\nfn max_of_nth(test_list: Vec<Vec<isize>>, N: isize) -> isize {\n    let res = test_list.iter().map(|x| x[N as usize]).max().unwrap();\n    return res;\n}", "retrieval_text": "/// Write a function which given a matrix represented as a vector of vectors returns the max of the n'th column.\nfn max_of_nth(test_list: Vec<Vec<isize>>, N: isize) -> isize {\n", "task": "mbpp_611_max_of_nth"}
{"content": "/// Write a function to find the cumulative sum of all the values that are present in the given vector of vectors.\nfn cummulative_sum(test_list: Vec<Vec<isize>>) -> isize {\n    let result: isize = test_list.iter().fold(0, |acc, x| acc + x.iter().sum::<isize>());\n    result\n}", "retrieval_text": "/// Write a function to find the cumulative sum of all the values that are present in the given vector of vectors.\nfn cummulative_sum(test_list: Vec<Vec<isize>>) -> isize {\n", "task": "mbpp_614_cummulative_sum"}
{"content": "/// Write a function which takes two tuples of the same length and performs the element wise modulo.\nfn tuple_modulo(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n    let (x1, y1, z1, w1) = test_tup1;\n    let (x2, y2, z2, w2) = test_tup2;\n    let res = (x1 % x2, y1 % y2, z1 % z2, w1 % w2);\n    res\n}", "retrieval_text": "/// Write a function which takes two tuples of the same length and performs the element wise modulo.\nfn tuple_modulo(test_tup1: (isize, isize, isize, isize), test_tup2: (isize, isize, isize, isize)) -> (isize, isize, isize, isize) {\n", "task": "mbpp_616_tuple_modulo"}
{"content": "/// Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.\nfn min_Jumps(steps: (isize, isize), d: isize) -> f64 {\n    let a = steps.0;\n    let b = steps.1;\n    if d >= b {\n        return (d + b - 1) as f64 / b as f64;\n    }\n    if d == 0 {\n        return 0.0;\n    }\n    if d == a {\n        return 1.0;\n    }\n    2.0\n}", "retrieval_text": "/// Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.\nfn min_Jumps(steps: (isize, isize), d: isize) -> f64 {\n", "task": "mbpp_617_min_Jumps"}
{"content": "/// Write a function to divide two vectors element wise.\nfn div_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<f64> {\n    nums1\n        .into_iter()\n        .zip(nums2.into_iter())\n        .map(|(num1, num2)| num1 as f64 / num2 as f64)\n        .collect()\n}", "retrieval_text": "/// Write a function to divide two vectors element wise.\nfn div_list(nums1: Vec<isize>, nums2: Vec<isize>) -> Vec<f64> {\n", "task": "mbpp_618_div_list"}
{"content": "/// Write a function to move all the numbers to the end of the given string.\nfn move_num(test_str: String) -> String {\n  let mut res = \"\".to_string();\n  let mut dig = \"\".to_string();\n  for ele in test_str.chars() {\n    if ele.is_digit(10) {\n      dig += &ele.to_string();\n    } else {\n      res += &ele.to_string();\n    }\n  }\n  res += &dig;\n  res\n}", "retrieval_text": "/// Write a function to move all the numbers to the end of the given string.\nfn move_num(test_str: String) -> String {\n", "task": "mbpp_619_move_num"}
{"content": "/// Write a function to compute the n-th power of each number in a vector.\nfn nth_nums(nums: Vec<isize>, n: isize) -> Vec<isize> {\n    let mut output = Vec::new();\n    for num in nums {\n        output.push(num.pow(n as u32));\n    }\n    output\n}", "retrieval_text": "/// Write a function to compute the n-th power of each number in a vector.\nfn nth_nums(nums: Vec<isize>, n: isize) -> Vec<isize> {\n", "task": "mbpp_623_nth_nums"}
{"content": "/// Write a rsthon function to convert a given string to uppercase.\nfn is_upper(string: String) -> String {\n    string.to_uppercase()\n}", "retrieval_text": "/// Write a rsthon function to convert a given string to uppercase.\nfn is_upper(string: String) -> String {\n", "task": "mbpp_624_is_upper"}
{"content": "/// Write a rsthon function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.\nfn triangle_area(r: isize) -> Option<isize> {\n    if r < 0 {\n        return None;\n    }\n    Some(r * r)\n}", "retrieval_text": "/// Write a rsthon function to find the area of the largest triangle that can be inscribed in a semicircle with a given radius.\nfn triangle_area(r: isize) -> Option<isize> {\n", "task": "mbpp_626_triangle_area"}
{"content": "/// Write a rsthon function to find the smallest missing number from a sorted vector of natural numbers.\nfn find_First_Missing(array: Vec<isize>) -> isize {\n    if (array[0] != 0) {\n        return 0\n    }\n    let mut start = 0;\n    let mut end = array.len() - 1;\n    while start <= end {\n        let mid = (start + end) / 2;\n        if (array[mid] != mid as isize) {\n            if mid > 0 && array[mid - 1] == (mid - 1) as isize {\n                return mid as isize;\n            } else {\n                end = mid - 1;\n            }\n        } else {\n            start = mid + 1;\n        }\n    }\n    return end as isize + 1;\n}", "retrieval_text": "/// Write a rsthon function to find the smallest missing number from a sorted vector of natural numbers.\nfn find_First_Missing(array: Vec<isize>) -> isize {\n", "task": "mbpp_627_find_First_Missing"}
{"content": "/// Write a rsthon function to find even numbers from a vector of numbers.\nfn Split(list: Vec<isize>) -> Vec<isize> {\n    let mut ev_li = Vec::new();\n    for i in list {\n        if i % 2 == 0 {\n            ev_li.push(i);\n        }\n    }\n    ev_li\n}", "retrieval_text": "/// Write a rsthon function to find even numbers from a vector of numbers.\nfn Split(list: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_629_Split"}
{"content": "/// Write a function to extract all the adjacent coordinates of the given coordinate tuple.\nfn get_coordinates(test_tup: (isize, isize)) -> Vec<Vec<isize>> {\n    let mut coordinates: Vec<Vec<isize>> = vec![];\n    let mut i = test_tup.0 - 1;\n    let mut j = test_tup.1 - 1;\n    while i <= test_tup.0 + 1 {\n        j = test_tup.1 - 1;\n        while j <= test_tup.1 + 1 {\n            coordinates.push(vec![i, j]);\n            j += 1;\n        }\n        i += 1;\n    }\n    coordinates\n}", "retrieval_text": "/// Write a function to extract all the adjacent coordinates of the given coordinate tuple.\nfn get_coordinates(test_tup: (isize, isize)) -> Vec<Vec<isize>> {\n", "task": "mbpp_630_get_coordinates"}
{"content": "/// Write a function to replace whitespaces with an underscore and vice versa in a given string.\nfn replace_spaces(text: String) -> String {\n  let mut result = String::new();\n  for c in text.chars() {\n    if c == ' ' {\n      result.push('_');\n    } else if c == '_' {\n      result.push(' ');\n    } else {\n      result.push(c);\n    }\n  }\n  result\n}", "retrieval_text": "/// Write a function to replace whitespaces with an underscore and vice versa in a given string.\nfn replace_spaces(text: String) -> String {\n", "task": "mbpp_631_replace_spaces"}
{"content": "/// Write a rsthon function to move all zeroes to the end of the given vector.\nfn move_zero(num_list: Vec<isize>) -> Vec<isize> {\n    let mut a = Vec::new();\n    let mut x = Vec::new();\n    for i in 0..num_list.len() {\n        if num_list[i] == 0 {\n            a.push(0);\n        } else {\n            x.push(num_list[i]);\n        }\n    }\n    x.extend(a);\n    x\n}", "retrieval_text": "/// Write a rsthon function to move all zeroes to the end of the given vector.\nfn move_zero(num_list: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_632_move_zero"}
{"content": "/// Write a rsthon function to find the sum of xor of all pairs of numbers in the given vector.\nfn pair_xor_Sum(arr: Vec<isize>, n: isize) -> isize {\n    let mut ans: isize = 0;\n\n    for i in 0..n as usize {\n        for j in i + 1..n as usize {\n            ans = ans + (arr[i] ^ arr[j]);\n        }\n    }\n    ans\n}", "retrieval_text": "/// Write a rsthon function to find the sum of xor of all pairs of numbers in the given vector.\nfn pair_xor_Sum(arr: Vec<isize>, n: isize) -> isize {\n", "task": "mbpp_633_pair_xor_Sum"}
{"content": "/// Write a function to sort the given vector.\nfn heap_sort(iterable: Vec<isize>) -> Vec<isize> {\n    let mut h = Vec::new();\n    for value in iterable {\n        h.push(value);\n    }\n    h.sort();\n    h\n}", "retrieval_text": "/// Write a function to sort the given vector.\nfn heap_sort(iterable: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_635_heap_sort"}
{"content": "/// Write a function to check whether the given amount has no profit and no loss\nfn noprofit_noloss(actual_cost: isize, sale_amount: isize) -> bool {\n  sale_amount == actual_cost\n}", "retrieval_text": "/// Write a function to check whether the given amount has no profit and no loss\nfn noprofit_noloss(actual_cost: isize, sale_amount: isize) -> bool {\n", "task": "mbpp_637_noprofit_noloss"}
{"content": "/// Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter.\nfn sample_nam(sample_names: Vec<String>) -> isize {\n    let mut len: isize = 0;\n    let names = sample_names\n        .iter()\n        .filter(|el| el.chars().next().unwrap().is_uppercase())\n        .collect::<Vec<&String>>();\n    for name in names {\n        len += name.len() as isize;\n    }\n    return len;\n}", "retrieval_text": "/// Write a function to sum the length of the names of a given vector of names after removing the names that start with a lowercase letter.\nfn sample_nam(sample_names: Vec<String>) -> isize {\n", "task": "mbpp_639_sample_nam"}
{"content": "/// Write a function to find the nth nonagonal number.\nfn is_nonagonal(n: isize) -> isize {\n    (n * (7 * n - 5)) / 2\n}", "retrieval_text": "/// Write a function to find the nth nonagonal number.\nfn is_nonagonal(n: isize) -> isize {\n", "task": "mbpp_641_is_nonagonal"}
{"content": "/// Write a rsthon function to reverse a vector upto a given position.\nfn reverse_Array_Upto_K(input: Vec<isize>, k: isize) -> Vec<isize> {\n    let mut temp = Vec::new();\n    for i in (0..(k as usize)).rev() {\n        temp.push(input[i]);\n    }\n    for i in (k as usize..input.len()) {\n        temp.push(input[i]);\n    }\n    temp\n}", "retrieval_text": "/// Write a rsthon function to reverse a vector upto a given position.\nfn reverse_Array_Upto_K(input: Vec<isize>, k: isize) -> Vec<isize> {\n", "task": "mbpp_644_reverse_Array_Upto_K"}
{"content": "/// Given a square matrix of size N*N given as a vector of vectors, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing paths. Average is computed as total cost divided by the number of cells visited in the path.\nfn maxAverageOfPath(cost: Vec<Vec<isize>>) -> f64 {\n    let n = cost.len();\n    let mut dp = vec![vec![0; n]; n];\n    dp[0][0] = cost[0][0];\n    for i in 1..n {\n        dp[i][0] = dp[i - 1][0] + cost[i][0];\n    }\n    for j in 1..n {\n        dp[0][j] = dp[0][j - 1] + cost[0][j];\n    }\n    for i in 1..n {\n        for j in 1..n {\n            dp[i][j] = std::cmp::max(dp[i - 1][j], dp[i][j - 1]) + cost[i][j];\n        }\n    }\n    let sum = dp[n - 1][n - 1];\n    let num_cells = (2 * n) - 1;\n    (sum as f64) / (num_cells as f64)\n}", "retrieval_text": "/// Given a square matrix of size N*N given as a vector of vectors, where each cell is associated with a specific cost. A path is defined as a specific sequence of cells that starts from the top-left cell move only right or down and ends on bottom right cell. We want to find a path with the maximum average over all existing paths. Average is computed as total cost divided by the number of cells visited in the path.\nfn maxAverageOfPath(cost: Vec<Vec<isize>>) -> f64 {\n", "task": "mbpp_721_maxAverageOfPath"}
{"content": "/// The input is defined as two vectors of the same length. Write a function to count indices where the vectors have the same values.\nfn count_same_pair(nums1: Vec<isize>, nums2: Vec<isize>) -> isize {\n    let mut result = 0;\n\n    for i in 0..nums1.len() {\n        if nums1[i] == nums2[i] {\n            result += 1;\n        }\n    }\n\n    result\n}", "retrieval_text": "/// The input is defined as two vectors of the same length. Write a function to count indices where the vectors have the same values.\nfn count_same_pair(nums1: Vec<isize>, nums2: Vec<isize>) -> isize {\n", "task": "mbpp_723_count_same_pair"}
{"content": "/// Write a function takes as input two vectors [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].\nfn sum_list(lst1: Vec<isize>, lst2: Vec<isize>) -> Vec<isize> {\n    return lst1.iter().zip(lst2.iter()).map(|(x, y)| x + y).collect();\n}", "retrieval_text": "/// Write a function takes as input two vectors [a_1,...,a_n], [b_1,...,b_n] and returns [a_1+b_1,...,a_n+b_n].\nfn sum_list(lst1: Vec<isize>, lst2: Vec<isize>) -> Vec<isize> {\n", "task": "mbpp_728_sum_list"}
{"content": "/// Write a function to find the lateral surface area of a cone given radius r and the height h.\nfn lateralsurface_cone(r: isize, h: isize) -> f64 {\n    // Calculate the lateral surface area using the provided formula\n    // and return the result\n    let l = f64::sqrt(r as f64 * r as f64 + h as f64 * h as f64);\n    let LSA = std::f64::consts::PI * r as f64 * l;\n    return LSA\n}", "retrieval_text": "/// Write a function to find the lateral surface area of a cone given radius r and the height h.\nfn lateralsurface_cone(r: isize, h: isize) -> f64 {\n", "task": "mbpp_731_lateralsurface_cone"}
{"content": "/// Write a function to replace all occurrences of spaces, commas, or dots with a colon.\nfn replace_specialchar(text: String) -> String {\n    let mut new_string = String::new();\n    for ch in text.chars() {\n        match ch {\n            ' ' => new_string.push(':'),\n            ',' => new_string.push(':'),\n            '.' => new_string.push(':'),\n            _ => new_string.push(ch),\n        }\n    }\n    new_string\n}", "retrieval_text": "/// Write a function to replace all occurrences of spaces, commas, or dots with a colon.\nfn replace_specialchar(text: String) -> String {\n", "task": "mbpp_732_replace_specialchar"}
{"content": "/// Write a function to find the index of the first occurrence of a given number in a sorted vector.\nfn find_first_occurrence(A: Vec<isize>, x: isize) -> isize {\n    let mut left = 0;\n    let mut right = A.len() - 1;\n    let mut result = -1;\n    while left <= right {\n        let mid = (left + right) / 2;\n        if A[mid] == x {\n            result = mid as isize;\n            right = mid - 1;\n        } else if x < A[mid] {\n            right = mid - 1;\n        } else {\n            left = mid + 1;\n        }\n    }\n    result\n}", "retrieval_text": "/// Write a function to find the index of the first occurrence of a given number in a sorted vector.\nfn find_first_occurrence(A: Vec<isize>, x: isize) -> isize {\n", "task": "mbpp_733_find_first_occurrence"}
{"content": "/// Write a function to calculate the geometric sum of n-1. https://www.w3resource.com/rsthon-exercises/data-structures-and-algorithms/rsthon-recursion-exercise-9.php\nfn geometric_sum(n: isize) -> f64 {\n    if n < 0 {\n        0.0\n    } else {\n        1.0 / (2.0f64.powf(n as f64)) + geometric_sum(n - 1)\n    }\n}", "retrieval_text": "/// Write a function to calculate the geometric sum of n-1. https://www.w3resource.com/rsthon-exercises/data-structures-and-algorithms/rsthon-recursion-exercise-9.php\nfn geometric_sum(n: isize) -> f64 {\n", "task": "mbpp_738_geometric_sum"}
{"content": "/// Write a rsthon function to check whether all the characters are same or not.\nfn all_Characters_Same(s: String) -> bool {\n    let n = s.len();\n    for i in 1..n {\n        if s.chars().nth(i).unwrap() != s.chars().nth(0).unwrap() {\n            return false;\n        }\n    }\n    true\n}", "retrieval_text": "/// Write a rsthon function to check whether all the characters are same or not.\nfn all_Characters_Same(s: String) -> bool {\n", "task": "mbpp_741_all_Characters_Same"}
{"content": "/// Write a function to rotate a given vector by specified number of items to the right direction. https://www.geeksforgeeks.org/rsthon-program-right-rotate-vector-n/\nfn rotate_right(list: Vec<isize>, m: isize) -> Vec<isize> {\n    let mut result = list.clone();\n    let m = (list.len() as isize + m) % list.len() as isize;\n    result.rotate_right(m as usize);\n    result\n}", "retrieval_text": "/// Write a function to rotate a given vector by specified number of items to the right direction. https://www.geeksforgeeks.org/rsthon-program-right-rotate-vector-n/\nfn rotate_right(list: Vec<isize>, m: isize) -> Vec<isize> {\n", "task": "mbpp_743_rotate_right"}
{"content": "/// Write a function to find the longest common subsequence for the given three string sequence. https://www.geeksforgeeks.org/lcs-longest-common-subsequence-three-strings/\nfn lcs_of_three(X: String, Y: String, Z: String) -> isize {\n    let m = X.len();\n    let n = Y.len();\n    let o = Z.len();\n    let mut L = vec![vec![vec![0; o + 1]; n + 1]; m + 1];\n    for i in 0..m + 1 {\n        for j in 0..n + 1 {\n            for k in 0..o + 1 {\n                if i == 0 || j == 0 || k == 0 {\n                    L[i][j][k] = 0;\n                } else if X.chars().nth(i - 1) == Y.chars().nth(j - 1) && X.chars().nth(i - 1) == Z.chars().nth(k - 1) {\n                    L[i][j][k] = L[i - 1][j - 1][k - 1] + 1;\n                } else {\n                    L[i][j][k] = std::cmp::max(\n                        std::cmp::max(L[i - 1][j][k], L[i][j - 1][k]),\n                        L[i][j][k - 1],\n                    );\n                }\n            }\n        }\n    }\n    L[m][n][o]\n}", "retrieval_text": "/// Write a function to find the longest common subsequence for the given three string sequence. https://www.geeksforgeeks.org/lcs-longest-common-subsequence-three-strings/\nfn lcs_of_three(X: String, Y: String, Z: String) -> isize {\n", "task": "mbpp_747_lcs_of_three"}
{"content": "/// Write a function to check if the given vector represents min heap or not. https://www.geeksforgeeks.org/how-to-check-if-a-given-vector-represents-a-binary-heap/\nfn check_min_heap(arr: Vec<isize>) -> bool {\n    let n = arr.len();\n    for i in 0..n / 2 {\n        let left_child = 2 * i + 1;\n        let right_child = 2 * i + 2;\n        if left_child < n && arr[i] > arr[left_child] {\n            return false;\n        }\n        if right_child < n && arr[i] > arr[right_child] {\n            return false;\n        }\n    }\n    true\n}", "retrieval_text": "/// Write a function to check if the given vector represents min heap or not. https://www.geeksforgeeks.org/how-to-check-if-a-given-vector-represents-a-binary-heap/\nfn check_min_heap(arr: Vec<isize>) -> bool {\n", "task": "mbpp_751_check_min_heap"}
{"content": "/// Write a function to find the nth jacobsthal number. https://www.geeksforgeeks.org/jacobsthal-and-jacobsthal-lucas-numbers/ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ...\nfn jacobsthal_num(n: isize) -> isize {\n    let mut dp = vec![0; (n + 1) as usize];\n    dp[0] = 0;\n    dp[1] = 1;\n    for i in 2..=n {\n        dp[i as usize] = dp[i as usize - 1] + 2 * dp[i as usize - 2];\n    }\n    dp[n as usize]\n}", "retrieval_text": "/// Write a function to find the nth jacobsthal number. https://www.geeksforgeeks.org/jacobsthal-and-jacobsthal-lucas-numbers/ 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341, 683, 1365, 2731, ...\nfn jacobsthal_num(n: isize) -> isize {\n", "task": "mbpp_752_jacobsthal_num"}
{"content": "/// Write a function to find minimum k records from tuple vector. https://www.geeksforgeeks.org/rsthon-find-minimum-k-records-from-tuple-vector/ - in this case a verbatim cors of test cases\nfn min_k(test_list: Vec<(String, isize)>, K: isize) -> Vec<(String, isize)> {\n    // sort the vector by the second value (the time) in ascending order\n    let mut sorted_vec = test_list;\n    sorted_vec.sort_by(|a, b| a.1.cmp(&b.1));\n\n    // return the first K records\n    sorted_vec[..K as usize].to_vec()\n}", "retrieval_text": "/// Write a function to find minimum k records from tuple vector. https://www.geeksforgeeks.org/rsthon-find-minimum-k-records-from-tuple-vector/ - in this case a verbatim cors of test cases\nfn min_k(test_list: Vec<(String, isize)>, K: isize) -> Vec<(String, isize)> {\n", "task": "mbpp_753_min_k"}
{"content": "/// Write a function to count the pairs of reverse strings in the given string vector. https://www.geeksforgeeks.org/rsthon-program-to-count-the-pairs-of-reverse-strings/\nfn count_reverse_pairs(test_list: Vec<String>) -> isize {\n    let mut res = 0;\n    for i in 0..test_list.len() {\n        for j in i..test_list.len() {\n            if test_list[j] == test_list[i].chars().rev().collect::<String>() {\n                res += 1;\n            }\n        }\n    }\n    res\n}", "retrieval_text": "/// Write a function to count the pairs of reverse strings in the given string vector. https://www.geeksforgeeks.org/rsthon-program-to-count-the-pairs-of-reverse-strings/\nfn count_reverse_pairs(test_list: Vec<String>) -> isize {\n", "task": "mbpp_757_count_reverse_pairs"}
{"content": "/// Write a rsthon function to check whether a vector of numbers contains only one distinct element or not.\nfn unique_Element(arr: Vec<isize>) -> bool {\n    let s = arr.iter().collect::<std::collections::HashSet<_>>();\n    if (s.len() == 1) {\n        return true;\n    } else {\n        return false;\n    }\n}", "retrieval_text": "/// Write a rsthon function to check whether a vector of numbers contains only one distinct element or not.\nfn unique_Element(arr: Vec<isize>) -> bool {\n", "task": "mbpp_760_unique_Element"}
{"content": "/// Write a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12.\nfn check_monthnumber_number(monthnum3: isize) -> bool {\n    if monthnum3 == 4 || monthnum3 == 6 || monthnum3 == 9 || monthnum3 == 11 {\n        true\n    } else {\n        false\n    }\n}", "retrieval_text": "/// Write a function to check whether the given month number contains 30 days or not. Months are given as number from 1 to 12.\nfn check_monthnumber_number(monthnum3: isize) -> bool {\n", "task": "mbpp_762_check_monthnumber_number"}
{"content": "/// Write a rsthon function to count number of digits in a given string.\nfn number_ctr(str: String) -> isize {\n    let mut ctr = 0;\n    for i in str.chars() {\n        if i.is_ascii_digit() {\n            ctr += 1;\n        }\n    }\n    ctr\n}", "retrieval_text": "/// Write a rsthon function to count number of digits in a given string.\nfn number_ctr(str: String) -> isize {\n", "task": "mbpp_764_number_ctr"}
{"content": "/// Write a function to return a vector of all pairs of consecutive items in a given vector.\nfn pair_wise(l1: Vec<isize>) -> Vec<(isize, isize)> {\n    let mut temp = vec![];\n\n    for i in 0..l1.len() - 1 {\n        let current_element = l1[i];\n        let next_element = l1[i + 1];\n        temp.push((current_element, next_element));\n    }\n\n    temp\n}", "retrieval_text": "/// Write a function to return a vector of all pairs of consecutive items in a given vector.\nfn pair_wise(l1: Vec<isize>) -> Vec<(isize, isize)> {\n", "task": "mbpp_766_pair_wise"}
{"content": "/// Write a rsthon function to count the number of pairs whose sum is equal to \u2018sum\u2019. The funtion gets as input a vector of numbers and the sum,\nfn get_pairs_count(arr: Vec<isize>, sum: isize) -> isize {\n    let mut count = 0;\n    for i in 0..arr.len() {\n        for j in i + 1..arr.len() {\n            if arr[i] + arr[j] == sum {\n                count += 1;\n            }\n        }\n    }\n    count\n}", "retrieval_text": "/// Write a rsthon function to count the number of pairs whose sum is equal to \u2018sum\u2019. The funtion gets as input a vector of numbers and the sum,\nfn get_pairs_count(arr: Vec<isize>, sum: isize) -> isize {\n", "task": "mbpp_767_get_pairs_count"}
{"content": "/// Write a rsthon function to find the sum of fourth power of first n odd natural numbers.\nfn odd_num_sum(n: isize) -> isize {\n    let mut sm: isize = 0;\n    for i in 1..=n {\n        let j: isize = (2 * i - 1);\n        sm = sm + (j * j * j * j);\n    }\n    sm\n}", "retrieval_text": "/// Write a rsthon function to find the sum of fourth power of first n odd natural numbers.\nfn odd_num_sum(n: isize) -> isize {\n", "task": "mbpp_770_odd_num_sum"}
{"content": "/// Write a function to check if the given expression is balanced or not. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/\nfn check_expression(exp: String) -> bool {\n    let mut stack = Vec::new();\n    for ch in exp.chars() {\n        match ch {\n            '(' | '{' | '[' => stack.push(ch),\n            ')' | '}' | ']' => {\n                if stack.is_empty() {\n                    return false;\n                }\n                let top = stack.pop().unwrap();\n                if (top == '(' && ch != ')') || (top == '{' && ch != '}') || (top == '[' && ch != ']') {\n                    return false;\n                }\n            }\n            _ => panic!(\"Unexpected character {}\", ch),\n        }\n    }\n    stack.is_empty()\n}", "retrieval_text": "/// Write a function to check if the given expression is balanced or not. https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/\nfn check_expression(exp: String) -> bool {\n", "task": "mbpp_771_check_expression"}
{"content": "/// Write a function to remove all the words with k length in the given string.\nfn remove_length(test_str: String, K: isize) -> String {\n    let temp: Vec<&str> = test_str.split(' ').collect();\n    let res: Vec<&str> = temp.into_iter().filter(|&w| w.len() != K as usize).collect();\n    res.join(\" \")\n}", "retrieval_text": "/// Write a function to remove all the words with k length in the given string.\nfn remove_length(test_str: String, K: isize) -> String {\n", "task": "mbpp_772_remove_length"}
{"content": "/// Write a function to count those characters which have vowels as their neighbors in the given string.\nfn count_vowels(test_str: String) -> isize {\n    let mut res: isize = 0;\n    let vow_list: Vec<char> = ['a', 'e', 'i', 'o', 'u'].iter().map(|&x| x).collect();\n    for i in 1..test_str.len() - 1 {\n        if !vow_list.contains(&test_str.chars().nth(i).unwrap())\n            && (vow_list.contains(&test_str.chars().nth(i - 1).unwrap())\n                || vow_list.contains(&test_str.chars().nth(i + 1).unwrap()))\n        {\n            res += 1;\n        }\n    }\n    if !vow_list.contains(&test_str.chars().nth(0).unwrap())\n        && test_str.chars().nth(1).unwrap() == 'a' || test_str.chars().nth(1).unwrap() == 'e'\n            || test_str.chars().nth(1).unwrap() == 'i'\n            || test_str.chars().nth(1).unwrap() == 'o'\n            || test_str.chars().nth(1).unwrap() == 'u'\n    {\n        res += 1;\n    }\n    if !vow_list.contains(&test_str.chars().nth(test_str.len() - 1).unwrap())\n        && test_str.chars().nth(test_str.len() - 2).unwrap() == 'a'\n            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'e'\n            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'i'\n            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'o'\n            || test_str.chars().nth(test_str.len() - 2).unwrap() == 'u'\n    {\n        res += 1;\n    }\n    res\n}", "retrieval_text": "/// Write a function to count those characters which have vowels as their neighbors in the given string.\nfn count_vowels(test_str: String) -> isize {\n", "task": "mbpp_776_count_vowels"}
{"content": "/// Write a rsthon function to find the sum of non-repeated elements in a given vector.\nfn find_sum(arr: Vec<isize>) -> isize {\n    let mut arr = arr.clone();\n    arr.sort();\n    let mut sum = arr[0];\n    for i in 0..arr.len()-1 {\n        if arr[i] != arr[i+1] {\n            sum += arr[i+1];\n        }\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the sum of non-repeated elements in a given vector.\nfn find_sum(arr: Vec<isize>) -> isize {\n", "task": "mbpp_777_find_sum"}
{"content": "/// Write a rsthon function to check whether the count of divisors is even. https://www.w3resource.com/rsthon-exercises/basic/rsthon-basic-1-exercise-24.php\nfn count_divisors(n: isize) -> bool {\n    let mut count = 0;\n    for i in 1..=((n as f32).sqrt() as isize) + 2 {\n        if n % i == 0 {\n            if n / i == i {\n                count = count + 1\n            } else {\n                count = count + 2\n            }\n        }\n    }\n    count % 2 == 0\n}", "retrieval_text": "/// Write a rsthon function to check whether the count of divisors is even. https://www.w3resource.com/rsthon-exercises/basic/rsthon-basic-1-exercise-24.php\nfn count_divisors(n: isize) -> bool {\n", "task": "mbpp_781_count_divisors"}
{"content": "/// Write a function to find the product of first even and odd number of a given vector.\nfn mul_even_odd(list1: Vec<isize>) -> isize {\n    match (list1.iter().filter(|&&x| x % 2 == 0).next(), list1.iter().filter(|&&x| x % 2 != 0).next()) {\n        (Some(x), Some(y)) => x * y,\n        _ => -1,\n    }\n}", "retrieval_text": "/// Write a function to find the product of first even and odd number of a given vector.\nfn mul_even_odd(list1: Vec<isize>) -> isize {\n", "task": "mbpp_784_mul_even_odd"}
{"content": "/// Write a function to locate the right insertion point for a specified value in sorted order.\nfn right_insertion(a: Vec<isize>, x: isize) -> isize {\n    let index = a.binary_search(&x).unwrap_or_else(|x| x);\n    index as isize\n}", "retrieval_text": "/// Write a function to locate the right insertion point for a specified value in sorted order.\nfn right_insertion(a: Vec<isize>, x: isize) -> isize {\n", "task": "mbpp_786_right_insertion"}
{"content": "/// Write a rsthon function to check whether every even index contains even numbers of a given vector.\nfn even_position(nums: Vec<isize>) -> bool {\n    // Loop through the vector and check if every even index contains even numbers.\n    for i in 0..nums.len() {\n        if i % 2 == 0 && nums[i] % 2 != 0 {\n            return false;\n        }\n    }\n\n    true\n}", "retrieval_text": "/// Write a rsthon function to check whether every even index contains even numbers of a given vector.\nfn even_position(nums: Vec<isize>) -> bool {\n", "task": "mbpp_790_even_position"}
{"content": "/// Write a rsthon function to count the number of vectors in a given number of vectors.\nfn count_list(input_list: Vec<Vec<isize>>) -> isize {\n    input_list.len() as isize\n}", "retrieval_text": "/// Write a rsthon function to count the number of vectors in a given number of vectors.\nfn count_list(input_list: Vec<Vec<isize>>) -> isize {\n", "task": "mbpp_792_count_list"}
{"content": "use std::collections::HashMap;\n\n/// Write function to find the sum of all items in the given HashMap.\nfn return_sum(dict: HashMap<String, isize>) -> isize {\n    let mut sum = 0;\n    for v in dict.values() {\n        sum += v;\n    }\n    sum\n}", "retrieval_text": "use std::collections::HashMap;\n\n/// Write function to find the sum of all items in the given HashMap.\nfn return_sum(dict: HashMap<String, isize>) -> isize {\n", "task": "mbpp_796_return_sum"}
{"content": "/// Write a rsthon function to find the sum of a vector.\nfn _sum(arr: Vec<isize>) -> isize {\n    let mut sum = 0;\n    for i in arr {\n        sum += i;\n    }\n    sum\n}", "retrieval_text": "/// Write a rsthon function to find the sum of a vector.\nfn _sum(arr: Vec<isize>) -> isize {\n", "task": "mbpp_798__sum"}
{"content": "/// Write a function to that rotate left bits by d bits a given number. We assume that the number is 32 bit.\nfn left_rotate(n: isize, d: isize) -> isize {\n    // let bits = 32 as isize;\n    (n << d) | (n >> (32 - d))\n}", "retrieval_text": "/// Write a function to that rotate left bits by d bits a given number. We assume that the number is 32 bit.\nfn left_rotate(n: isize, d: isize) -> isize {\n", "task": "mbpp_799_left_rotate"}
{"content": "/// Write a function to remove all whitespaces from a string.\nfn remove_all_spaces(text: String) -> String {\n    text.replace(\" \", \"\")\n}", "retrieval_text": "/// Write a function to remove all whitespaces from a string.\nfn remove_all_spaces(text: String) -> String {\n", "task": "mbpp_800_remove_all_spaces"}
{"content": "/// Write a rsthon function to count the number of equal numbers from three given integers.\nfn test_three_equal(x: isize, y: isize, z: isize) -> isize {\n    match [x, y, z].iter().collect::<std::collections::HashSet<_>>().len() {\n        3 => 0,\n        2 => 4 - 2,\n        1 => 4 - 1,\n        _ => panic!(\"unexpected number of numbers\")\n    }\n}", "retrieval_text": "/// Write a rsthon function to count the number of equal numbers from three given integers.\nfn test_three_equal(x: isize, y: isize, z: isize) -> isize {\n", "task": "mbpp_801_test_three_equal"}
{"content": "/// Write a rsthon function to count the number of rotations required to generate a sorted vector. https://www.geeksforgeeks.org/count-of-rotations-required-to-generate-a-sorted-vector/\nfn count_rotation(arr: Vec<isize>) -> isize {\n    // loop over the vector\n    for i in 1..arr.len() {\n        // if arr[i] < arr[i - 1] then return i\n        if arr[i] < arr[i - 1] {\n            return i as isize;\n        }\n    }\n    // if no rotations then return 0\n    return 0;\n}", "retrieval_text": "/// Write a rsthon function to count the number of rotations required to generate a sorted vector. https://www.geeksforgeeks.org/count-of-rotations-required-to-generate-a-sorted-vector/\nfn count_rotation(arr: Vec<isize>) -> isize {\n", "task": "mbpp_802_count_rotation"}
{"content": "/// Write a function to check whether the given number is a perfect square or not. https://www.geeksforgeeks.org/check-if-given-number-is-perfect-square-in-cpp/\nfn is_perfect_square(n: isize) -> bool {\n    let mut i = 1;\n    while i * i <= n {\n        if n % i == 0 && n / i == i {\n            return true;\n        }\n        i += 1;\n    }\n    false\n}", "retrieval_text": "/// Write a function to check whether the given number is a perfect square or not. https://www.geeksforgeeks.org/check-if-given-number-is-perfect-square-in-cpp/\nfn is_perfect_square(n: isize) -> bool {\n", "task": "mbpp_803_is_perfect_square"}
{"content": "/// Write a function to check whether the product of numbers in a vector is even or not.\nfn is_product_even(arr: Vec<isize>) -> bool {\n    for i in arr {\n        if i % 2 == 0 {\n            return true;\n        }\n    }\n    false\n}", "retrieval_text": "/// Write a function to check whether the product of numbers in a vector is even or not.\nfn is_product_even(arr: Vec<isize>) -> bool {\n", "task": "mbpp_804_is_product_even"}
{"content": "/// Write a function that returns the vector in a vector of vectors whose sum of elements is the highest.\nfn max_sum_list(lists: Vec<Vec<isize>>) -> Vec<isize> {\n    let mut max_sum_vec = vec![];\n    let mut max_sum = 0;\n\n    for v in lists.iter() {\n        let sum: isize = v.iter().sum();\n        if sum > max_sum {\n            max_sum = sum;\n            max_sum_vec = v.clone();\n        }\n    }\n\n    max_sum_vec\n}", "retrieval_text": "/// Write a function that returns the vector in a vector of vectors whose sum of elements is the highest.\nfn max_sum_list(lists: Vec<Vec<isize>>) -> Vec<isize> {\n", "task": "mbpp_805_max_sum_list"}
{"content": "/// Write a function to find maximum run of uppercase characters in the given string.\nfn max_run_uppercase(test_str: String) -> isize {\n    let mut cnt = 0;\n    let mut res = 0;\n    for c in test_str.chars() {\n        if c.is_uppercase() {\n            cnt += 1;\n        } else {\n            res = cnt;\n            cnt = 0;\n        }\n    }\n    if test_str.chars().last().unwrap().is_uppercase() {\n        res = cnt;\n    }\n    res as isize\n}", "retrieval_text": "/// Write a function to find maximum run of uppercase characters in the given string.\nfn max_run_uppercase(test_str: String) -> isize {\n", "task": "mbpp_806_max_run_uppercase"}
{"content": "/// Write a rsthon function to find the first odd number in a given vector of numbers.\nfn first_odd(nums: Vec<isize>) -> isize {\n    match nums.iter().find(|&&el| el % 2 != 0) {\n        Some(x) => *x,\n        None => -1,\n    }\n}", "retrieval_text": "/// Write a rsthon function to find the first odd number in a given vector of numbers.\nfn first_odd(nums: Vec<isize>) -> isize {\n", "task": "mbpp_807_first_odd"}
{"content": "/// Write a function to check if the given tuples contain the k or not.\nfn check_K(test_tup: Vec<isize>, K: isize) -> bool {\n    test_tup.contains(&K)\n}", "retrieval_text": "/// Write a function to check if the given tuples contain the k or not.\nfn check_K(test_tup: Vec<isize>, K: isize) -> bool {\n", "task": "mbpp_808_check_K"}
{"content": "/// Write a function to check if each element of second tuple is smaller than its corresponding element in the first tuple.\nfn check_smaller(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> bool {\n  test_tup1.0 > test_tup2.0 && test_tup1.1 > test_tup2.1 && test_tup1.2 > test_tup2.2\n}", "retrieval_text": "/// Write a function to check if each element of second tuple is smaller than its corresponding element in the first tuple.\nfn check_smaller(test_tup1: (isize, isize, isize), test_tup2: (isize, isize, isize)) -> bool {\n", "task": "mbpp_809_check_smaller"}