Dataset Viewer
Auto-converted to Parquet Duplicate
qid
int64
602
974
title
stringclasses
332 values
language
stringclasses
16 values
text
stringlengths
38
251
signature_with_docstring
stringlengths
61
354
signature
stringlengths
8
162
arguments
stringclasses
150 values
solution
stringclasses
332 values
question_info
stringlengths
1.14k
4.26k
602
MBPP/602
C++
Write a c++ function to find the first repeated character in a given string.
/** * Write a c++ function to find the first repeated character in a given string. */ string firstRepeatedChar(string str1) {
string firstRepeatedChar(string str1) {
['str1']
def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: return c return "None"
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstRepeatedChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the first repeated character in a given string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string str1, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(str1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("abcabc", "a"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("abc", "None"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("123123", "1"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "a", "inputs": {"str1": "abcabc"}}, {"idx": 1, "outputs": "None", "inputs": {"str1": "abc"}}, {"idx": 2, "outputs": "1", "inputs": {"str1": "123123"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
603
MBPP/603
C++
Write a function to get a lucid number smaller than or equal to n.
/** * Write a function to get a lucid number smaller than or equal to n. */ vector<int> getLudic(int n) {
vector<int> getLudic(int n) {
['n']
def get_ludic(n): ludics = [] for i in range(1, n + 1): ludics.append(i) index = 1 while(index != len(ludics)): first_ludic = ludics[index] remove_index = index + first_ludic while(remove_index < len(ludics)): ludics.remove(ludics[remove_index]) remove_index = remove_index + first_ludic - 1 index += 1 return ludics
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getLudic', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to get a lucid number smaller than or equal to n.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(int n, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, {1, 2, 3, 5, 7}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(25, {1, 2, 3, 5, 7, 11, 13, 17, 23, 25}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(45, {1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 2, 3, 5, 7], "inputs": {"n": 10}}, {"idx": 1, "outputs": [1, 2, 3, 5, 7, 11, 13, 17, 23, 25], "inputs": {"n": 25}}, {"idx": 2, "outputs": [1, 2, 3, 5, 7, 11, 13, 17, 23, 25, 29, 37, 41, 43], "inputs": {"n": 45}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
604
MBPP/604
C++
Write a function to reverse words in a given string.
/** * Write a function to reverse words in a given string. */ string reverseWords(string s) {
string reverseWords(string s) {
['s']
def reverse_words(s): return ' '.join(reversed(s.split()))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseWords', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to reverse words in a given string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string s, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("python program", "program python"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("java language", "language java"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("indian man", "man indian"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "program python", "inputs": {"s": "python program"}}, {"idx": 1, "outputs": "language java", "inputs": {"s": "java language"}}, {"idx": 2, "outputs": "man indian", "inputs": {"s": "indian man"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
605
MBPP/605
C++
Write a function to check if the given integer is a prime number.
/** * Write a function to check if the given integer is a prime number. */ bool primeNum(int num) {
bool primeNum(int num) {
['num']
def prime_num(num): if num >=1: for i in range(2, num//2): if (num % i) == 0: return False else: return True else: return False
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'primeNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if the given integer is a prime number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int num, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(13, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(7, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(-1010, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"num": 13}}, {"idx": 1, "outputs": true, "inputs": {"num": 7}}, {"idx": 2, "outputs": false, "inputs": {"num": -1010}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
606
MBPP/606
C++
Write a function to convert degrees to radians.
/** * Write a function to convert degrees to radians. */ double radianDegree(int degree) {
double radianDegree(int degree) {
['degree']
import math def radian_degree(degree): radian = degree*(math.pi/180) return radian
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'radianDegree', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to convert degrees to radians.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(double actual, double expected){\n return abs(actual - expected) < 1e-09;\n}\n\nstring driver(int degree, double expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(degree), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(90, 1.5707963267948966); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(60, 1.0471975511965976); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(120, 2.0943951023931953); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1.5707963267948966, "inputs": {"degree": 90}}, {"idx": 1, "outputs": 1.0471975511965976, "inputs": {"degree": 60}}, {"idx": 2, "outputs": 2.0943951023931953, "inputs": {"degree": 120}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
608
MBPP/608
C++
Write a c++ function to find nth bell number.
/** * Write a c++ function to find nth bell number. */ int bellNumber(int n) {
int bellNumber(int n) {
['n']
def bell_Number(n): bell = [[0 for i in range(n+1)] for j in range(n+1)] bell[0][0] = 1 for i in range(1, n+1): bell[i][0] = bell[i-1][i-1] for j in range(1, i+1): bell[i][j] = bell[i-1][j-1] + bell[i][j-1] return bell[n][0]
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'bellNumber', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find nth bell number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 15); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"n": 2}}, {"idx": 1, "outputs": 5, "inputs": {"n": 3}}, {"idx": 2, "outputs": 15, "inputs": {"n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
609
MBPP/609
C++
Write a c++ function to find minimum possible value for the given periodic function.
/** * Write a c++ function to find minimum possible value for the given periodic function. */ int floorMin(int a, int b, int n) {
int floorMin(int a, int b, int n) {
['a', 'b', 'n']
def floor_Min(A,B,N): x = max(B - 1,N) return (A*x) // B
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'floorMin', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find minimum possible value for the given periodic function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, 20, 30, 15); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(1, 2, 1, 0); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(11, 10, 9, 9); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 15, "inputs": {"a": 10, "b": 20, "n": 30}}, {"idx": 1, "outputs": 0, "inputs": {"a": 1, "b": 2, "n": 1}}, {"idx": 2, "outputs": 9, "inputs": {"a": 11, "b": 10, "n": 9}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
610
MBPP/610
C++
Write a c++ function to remove the k'th element from a given vector.
/** * Write a c++ function to remove the k'th element from a given vector. */ vector<int> removeKthElement(vector<int> list1, int l) {
vector<int> removeKthElement(vector<int> list1, int l) {
['list1', 'l']
def remove_kth_element(list1, L): return list1[:L-1] + list1[L:]
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeKthElement', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to remove the k\'th element from a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> list1, int l, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list1, l), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 1, 2, 3, 4, 4, 5, 1}, 3, {1, 1, 3, 4, 4, 5, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4}, 4, {0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10}, 5, {10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 1, 3, 4, 4, 5, 1], "inputs": {"list1": [1, 1, 2, 3, 4, 4, 5, 1], "l": 3}}, {"idx": 1, "outputs": [0, 0, 1, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], "inputs": {"list1": [0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4], "l": 4}}, {"idx": 2, "outputs": [10, 10, 15, 19, 18, 17, 26, 26, 17, 18, 10], "inputs": {"list1": [10, 10, 15, 19, 18, 18, 17, 26, 26, 17, 18, 10], "l": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
611
MBPP/611
C++
Write a function to find the maximum of nth column from the given tuple vector.
/** * Write a function to find the maximum of nth column from the given tuple vector. */ int maxOfNth(vector<vector<int>> test_list, int n) {
int maxOfNth(vector<vector<int>> test_list, int n) {
['test_list', 'n']
def max_of_nth(test_list, N): res = max([sub[N] for sub in test_list]) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOfNth', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the maximum of nth column from the given tuple list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> test_list, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{5, 6, 7}, {1, 3, 5}, {8, 9, 19}}, 2, 19); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{6, 7, 8}, {2, 4, 6}, {9, 10, 20}}, 1, 10); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{7, 8, 9}, {3, 5, 7}, {10, 11, 21}}, 1, 11); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 19, "inputs": {"test_list": [[5, 6, 7], [1, 3, 5], [8, 9, 19]], "n": 2}}, {"idx": 1, "outputs": 10, "inputs": {"test_list": [[6, 7, 8], [2, 4, 6], [9, 10, 20]], "n": 1}}, {"idx": 2, "outputs": 11, "inputs": {"test_list": [[7, 8, 9], [3, 5, 7], [10, 11, 21]], "n": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
614
MBPP/614
C++
Write a function to find the cumulative sum of all the values that are present in the given tuple vector.
/** * Write a function to find the cumulative sum of all the values that are present in the given tuple vector. */ int cummulativeSum(vector<vector<int>> test_list) {
int cummulativeSum(vector<vector<int>> test_list) {
['test_list']
def cummulative_sum(test_list): res = sum(map(sum, test_list)) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'cummulativeSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the cumulative sum of all the values that are present in the given tuple list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> test_list, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{1, 3}, {5, 6, 7}, {2, 6}}, 30); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{2, 4}, {6, 7, 8}, {3, 7}}, 37); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{3, 5}, {7, 8, 9}, {4, 8}}, 44); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 30, "inputs": {"test_list": [[1, 3], [5, 6, 7], [2, 6]]}}, {"idx": 1, "outputs": 37, "inputs": {"test_list": [[2, 4], [6, 7, 8], [3, 7]]}}, {"idx": 2, "outputs": 44, "inputs": {"test_list": [[3, 5], [7, 8, 9], [4, 8]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
615
MBPP/615
C++
Write a function to find average value of the numbers in a given tuple of tuples.
/** * Write a function to find average value of the numbers in a given tuple of tuples. */ vector<float> averageTuple(vector<vector<int>> nums) {
vector<float> averageTuple(vector<vector<int>> nums) {
['nums']
def average_tuple(nums): result = [sum(x) / len(x) for x in zip(*nums)] return result
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageTuple', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find average value of the numbers in a given tuple of tuples.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<float> actual, vector<float> expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> nums, vector<float> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{10, 10, 10, 12}, {30, 45, 56, 45}, {81, 80, 39, 32}, {1, 2, 3, 4}}, {30.5, 34.25, 27.0, 23.25}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{1, 1, -5}, {30, -15, 56}, {81, -60, -39}, {-10, 2, 3}}, {25.5, -18.0, 3.75}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{100, 100, 100, 120}, {300, 450, 560, 450}, {810, 800, 390, 320}, {10, 20, 30, 40}}, {305.0, 342.5, 270.0, 232.5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [30.5, 34.25, 27.0, 23.25], "inputs": {"nums": [[10, 10, 10, 12], [30, 45, 56, 45], [81, 80, 39, 32], [1, 2, 3, 4]]}}, {"idx": 1, "outputs": [25.5, -18.0, 3.75], "inputs": {"nums": [[1, 1, -5], [30, -15, 56], [81, -60, -39], [-10, 2, 3]]}}, {"idx": 2, "outputs": [305.0, 342.5, 270.0, 232.5], "inputs": {"nums": [[100, 100, 100, 120], [300, 450, 560, 450], [810, 800, 390, 320], [10, 20, 30, 40]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
616
MBPP/616
C++
Write a function to perfom the modulo of tuple elements in the given two tuples.
/** * Write a function to perfom the modulo of tuple elements in the given two tuples. */ vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) {
vector<int> tupleModulo(vector<int> test_tup1, vector<int> test_tup2) {
['test_tup1', 'test_tup2']
def tuple_modulo(test_tup1, test_tup2): res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'tupleModulo', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to perfom the modulo of tuple elements in the given two tuples.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup1, vector<int> test_tup2, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup1, test_tup2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5, 6}, {5, 6, 7, 5}, {0, 4, 5, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({11, 5, 6, 7}, {6, 7, 8, 6}, {5, 5, 6, 1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({12, 6, 7, 8}, {7, 8, 9, 7}, {5, 6, 7, 1}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [0, 4, 5, 1], "inputs": {"test_tup1": [10, 4, 5, 6], "test_tup2": [5, 6, 7, 5]}}, {"idx": 1, "outputs": [5, 5, 6, 1], "inputs": {"test_tup1": [11, 5, 6, 7], "test_tup2": [6, 7, 8, 6]}}, {"idx": 2, "outputs": [5, 6, 7, 1], "inputs": {"test_tup1": [12, 6, 7, 8], "test_tup2": [7, 8, 9, 7]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
617
MBPP/617
C++
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.
/** * 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. */ float minJumps(int a, int b, int d) {
float minJumps(int a, int b, int d) {
['a', 'b', 'd']
def min_Jumps(a, b, d): temp = a a = min(a, b) b = max(temp, b) if (d >= b): return (d + b - 1) / b if (d == 0): return 0 if (d == a): return 1 else: return 2
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'minJumps', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// 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.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(int a, int b, int d, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, d), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(3, 4, 11, 3.5); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 4, 0, 0.0); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(11, 14, 11, 1.0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 3.5, "inputs": {"a": 3, "b": 4, "d": 11}}, {"idx": 1, "outputs": 0, "inputs": {"a": 3, "b": 4, "d": 0}}, {"idx": 2, "outputs": 1, "inputs": {"a": 11, "b": 14, "d": 11}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
618
MBPP/618
C++
Write a function to divide two vectors using map and lambda function.
/** * Write a function to divide two vectors using map and lambda function. */ vector<double> divList(vector<int> nums1, vector<int> nums2) {
vector<double> divList(vector<int> nums1, vector<int> nums2) {
['nums1', 'nums2']
def div_list(nums1,nums2): result = map(lambda x, y: x / y, nums1, nums2) return list(result)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'divList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to divide two lists using map and lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<double> actual, vector<double> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums1, vector<int> nums2, vector<double> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums1, nums2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({4, 5, 6}, {1, 2, 3}, {4.0, 2.5, 2.0}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({3, 2}, {1, 4}, {3.0, 0.5}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({90, 120}, {50, 70}, {1.8, 1.7142857142857142}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [4.0, 2.5, 2.0], "inputs": {"nums1": [4, 5, 6], "nums2": [1, 2, 3]}}, {"idx": 1, "outputs": [3.0, 0.5], "inputs": {"nums1": [3, 2], "nums2": [1, 4]}}, {"idx": 2, "outputs": [1.8, 1.7142857142857142], "inputs": {"nums1": [90, 120], "nums2": [50, 70]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
619
MBPP/619
C++
Write a function to move all the numbers in it to the given string.
/** * Write a function to move all the numbers in it to the given string. */ string moveNum(string test_str) {
string moveNum(string test_str) {
['test_str']
def move_num(test_str): res = '' dig = '' for ele in test_str: if ele.isdigit(): dig += ele else: res += ele res += dig return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveNum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to move all the numbers in it to the given string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string test_str, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_str), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("I1love143you55three3000thousand", "Iloveyouthreethousand1143553000"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Avengers124Assemble", "AvengersAssemble124"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Its11our12path13to14see15things16do17things", "Itsourpathtoseethingsdothings11121314151617"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Iloveyouthreethousand1143553000", "inputs": {"test_str": "I1love143you55three3000thousand"}}, {"idx": 1, "outputs": "AvengersAssemble124", "inputs": {"test_str": "Avengers124Assemble"}}, {"idx": 2, "outputs": "Itsourpathtoseethingsdothings11121314151617", "inputs": {"test_str": "Its11our12path13to14see15things16do17things"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
620
MBPP/620
C++
Write a function to find the largest subset where each pair is divisible.
/** * Write a function to find the largest subset where each pair is divisible. */ int largestSubset(vector<int> a, int n) {
int largestSubset(vector<int> a, int n) {
['a', 'n']
def largest_subset(a, n): dp = [0 for i in range(n)] dp[n - 1] = 1; for i in range(n - 2, -1, -1): mxm = 0; for j in range(i + 1, n): if a[j] % a[i] == 0 or a[i] % a[j] == 0: mxm = max(mxm, dp[j]) dp[i] = 1 + mxm return max(dp)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'largestSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the largest subset where each pair is divisible.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 3, 6, 13, 17, 18}, 6, 4); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({10, 5, 3, 15, 20}, 5, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({18, 1, 3, 6, 13, 17}, 6, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 4, "inputs": {"a": [1, 3, 6, 13, 17, 18], "n": 6}}, {"idx": 1, "outputs": 3, "inputs": {"a": [10, 5, 3, 15, 20], "n": 5}}, {"idx": 2, "outputs": 4, "inputs": {"a": [18, 1, 3, 6, 13, 17], "n": 6}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
621
MBPP/621
C++
Write a function to increment the numeric values in the given strings by k.
/** * Write a function to increment the numeric values in the given strings by k. */ vector<string> incrementNumerics(vector<string> test_list, int k) {
vector<string> incrementNumerics(vector<string> test_list, int k) {
['test_list', 'k']
def increment_numerics(test_list, K): res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list] return res
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'incrementNumerics', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to increment the numeric values in the given strings by k.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<string> actual, vector<string> expected){\n return actual == expected;\n}\n\nstring driver(vector<string> test_list, int k, vector<string> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, k), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({"MSM", "234", "is", "98", "123", "best", "4"}, 6, {"MSM", "240", "is", "104", "129", "best", "10"}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"Dart", "356", "is", "88", "169", "Super", "6"}, 12, {"Dart", "368", "is", "100", "181", "Super", "18"}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"Flutter", "451", "is", "44", "96", "Magnificent", "12"}, 33, {"Flutter", "484", "is", "77", "129", "Magnificent", "45"}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": ["MSM", "240", "is", "104", "129", "best", "10"], "inputs": {"test_list": ["MSM", "234", "is", "98", "123", "best", "4"], "k": 6}}, {"idx": 1, "outputs": ["Dart", "368", "is", "100", "181", "Super", "18"], "inputs": {"test_list": ["Dart", "356", "is", "88", "169", "Super", "6"], "k": 12}}, {"idx": 2, "outputs": ["Flutter", "484", "is", "77", "129", "Magnificent", "45"], "inputs": {"test_list": ["Flutter", "451", "is", "44", "96", "Magnificent", "12"], "k": 33}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
622
MBPP/622
C++
Write a function to find the median of two sorted vectors of same size.
/** * Write a function to find the median of two sorted vectors of same size. */ float getMedian(vector<int> arr1, vector<int> arr2, int n) {
float getMedian(vector<int> arr1, vector<int> arr2, int n) {
['arr1', 'arr2', 'n']
def get_median(arr1, arr2, n): i = 0 j = 0 m1 = -1 m2 = -1 count = 0 while count < n + 1: count += 1 if i == n: m1 = m2 m2 = arr2[0] break elif j == n: m1 = m2 m2 = arr1[0] break if arr1[i] <= arr2[j]: m1 = m2 m2 = arr1[i] i += 1 else: m1 = m2 m2 = arr2[j] j += 1 return (m1 + m2)/2
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getMedian', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the median of two sorted arrays of same size.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(float actual, float expected){\n return abs(actual - expected) < 1e-06;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int n, float expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 12, 15, 26, 38}, {2, 13, 17, 30, 45}, 5, 16.0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 4, 8, 9}, {7, 13, 19, 28}, 4, 8.5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({3, 6, 14, 23, 36, 42}, {2, 18, 27, 39, 49, 55}, 6, 25.0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 16.0, "inputs": {"arr1": [1, 12, 15, 26, 38], "arr2": [2, 13, 17, 30, 45], "n": 5}}, {"idx": 1, "outputs": 8.5, "inputs": {"arr1": [2, 4, 8, 9], "arr2": [7, 13, 19, 28], "n": 4}}, {"idx": 2, "outputs": 25.0, "inputs": {"arr1": [3, 6, 14, 23, 36, 42], "arr2": [2, 18, 27, 39, 49, 55], "n": 6}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
623
MBPP/623
C++
Write a function to find the n-th power of individual elements in vector using lambda function.
/** * Write a function to find the n-th power of individual elements in vector using lambda function. */ vector<int> nthNums(vector<int> nums, int n) {
vector<int> nthNums(vector<int> nums, int n) {
['nums', 'n']
def nth_nums(nums,n): nth_nums = list(map(lambda x: x ** n, nums)) return nth_nums
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'nthNums', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the n-th power of individual elements in a list using lambda function.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums, int n, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 2, {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({10, 20, 30}, 3, {1000, 8000, 27000}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({12, 15}, 5, {248832, 759375}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 4, 9, 16, 25, 36, 49, 64, 81, 100], "inputs": {"nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "n": 2}}, {"idx": 1, "outputs": [1000, 8000, 27000], "inputs": {"nums": [10, 20, 30], "n": 3}}, {"idx": 2, "outputs": [248832, 759375], "inputs": {"nums": [12, 15], "n": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
624
MBPP/624
C++
Write a c++ function to convert the given string to upper case.
/** * Write a c++ function to convert the given string to upper case. */ string isUpper(string string_arg0) {
string isUpper(string string_arg0) {
['string_arg0']
def is_upper(string): return (string.upper())
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isUpper', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to convert the given string to upper case.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("person", "PERSON"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("final", "FINAL"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Valid", "VALID"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "PERSON", "inputs": {"string_arg0": "person"}}, {"idx": 1, "outputs": "FINAL", "inputs": {"string_arg0": "final"}}, {"idx": 2, "outputs": "VALID", "inputs": {"string_arg0": "Valid"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
625
MBPP/625
C++
Write a c++ function to interchange first and last elements in a given vector.
/** * Write a c++ function to interchange first and last elements in a given vector. */ vector<int> swapList(vector<int> newlist) {
vector<int> swapList(vector<int> newlist) {
['newlist']
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'swapList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to interchange first and last elements in a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> newlist, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(newlist), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3}, {3, 2, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 4}, {4, 2, 3, 4, 1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6}, {6, 5, 4}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [3, 2, 1], "inputs": {"newlist": [1, 2, 3]}}, {"idx": 1, "outputs": [4, 2, 3, 4, 1], "inputs": {"newlist": [1, 2, 3, 4, 4]}}, {"idx": 2, "outputs": [6, 5, 4], "inputs": {"newlist": [4, 5, 6]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
626
MBPP/626
C++
Write a c++ function to find the largest triangle that can be inscribed in the semicircle.
/** * Write a c++ function to find the largest triangle that can be inscribed in the semicircle. */ int triangleArea(int r) {
int triangleArea(int r) {
['r']
def triangle_area(r) : if r < 0 : return -1 return r * r
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'triangleArea', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the largest triangle that can be inscribed in the semicircle.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int r, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(r), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(0, 0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(-1, -1); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(2, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 0, "inputs": {"r": 0}}, {"idx": 1, "outputs": -1, "inputs": {"r": -1}}, {"idx": 2, "outputs": 4, "inputs": {"r": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
627
MBPP/627
C++
Write a c++ function to find the smallest missing number from the given vector.
/** * Write a c++ function to find the smallest missing number from the given vector. */ int findFirstMissing(vector<int> array, int start, int end_arg2) {
int findFirstMissing(vector<int> array, int start, int end_arg2) {
['array', 'start', 'end_arg2']
def find_First_Missing(array,start,end): if (start > end): return end + 1 if (start != array[start]): return start; mid = int((start + end) / 2) if (array[mid] == mid): return find_First_Missing(array,mid+1,end) return find_First_Missing(array,start,mid)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findFirstMissing', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the smallest missing number from the given array.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> array, int start, int end_arg2, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(array, start, end_arg2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({0, 1, 2, 3}, 0, 3, 4); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({0, 1, 2, 6, 9}, 0, 4, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 5, 8, 9}, 0, 4, 0); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 4, "inputs": {"array": [0, 1, 2, 3], "start": 0, "end_arg2": 3}}, {"idx": 1, "outputs": 3, "inputs": {"array": [0, 1, 2, 6, 9], "start": 0, "end_arg2": 4}}, {"idx": 2, "outputs": 0, "inputs": {"array": [2, 3, 5, 8, 9], "start": 0, "end_arg2": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
628
MBPP/628
C++
Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'.
/** * Write a function to replace all spaces in the given string with character * vector item * vector item * vector item * vector item '%20'. */ string replaceSpaces(string string_arg0) {
string replaceSpaces(string string_arg0) {
['string_arg0']
MAX=1000; def replace_spaces(string): string=string.strip() i=len(string) space_count=string.count(' ') new_length = i + space_count*2 if new_length > MAX: return -1 index = new_length-1 string=list(string) for f in range(i-2, new_length-2): string.append('0') for j in range(i-1, 0, -1): if string[j] == ' ': string[index] = '0' string[index-1] = '2' string[index-2] = '%' index=index-3 else: string[index] = string[j] index -= 1 return ''.join(string)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to replace all spaces in the given string with character * list item * list item * list item * list item \'%20\'.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("My Name is Dawood", "My%20Name%20is%20Dawood"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("I am a Programmer", "I%20am%20a%20Programmer"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("I love Coding", "I%20love%20Coding"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "My%20Name%20is%20Dawood", "inputs": {"string_arg0": "My Name is Dawood"}}, {"idx": 1, "outputs": "I%20am%20a%20Programmer", "inputs": {"string_arg0": "I am a Programmer"}}, {"idx": 2, "outputs": "I%20love%20Coding", "inputs": {"string_arg0": "I love Coding"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
629
MBPP/629
C++
Write a c++ function to find even numbers from a mixed vector.
/** * Write a c++ function to find even numbers from a mixed vector. */ vector<int> split(vector<int> list) {
vector<int> split(vector<int> list) {
['list']
def Split(list): ev_li = [] for i in list: if (i % 2 == 0): ev_li.append(i) return ev_li
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'split', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find even numbers from a mixed list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 5}, {2, 4}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6, 7, 8, 0, 1}, {4, 6, 8, 0}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({8, 12, 15, 19}, {8, 12}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [2, 4], "inputs": {"list": [1, 2, 3, 4, 5]}}, {"idx": 1, "outputs": [4, 6, 8, 0], "inputs": {"list": [4, 5, 6, 7, 8, 0, 1]}}, {"idx": 2, "outputs": [8, 12], "inputs": {"list": [8, 12, 15, 19]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
630
MBPP/630
C++
Write a function to extract all the adjacent coordinates of the given coordinate tuple.
/** * Write a function to extract all the adjacent coordinates of the given coordinate tuple. */ vector<vector<int>> getCoordinates(vector<int> test_tup) {
vector<vector<int>> getCoordinates(vector<int> test_tup) {
['test_tup']
def adjac(ele, sub = []): if not ele: yield sub else: yield from [idx for j in range(ele[0] - 1, ele[0] + 2) for idx in adjac(ele[1:], sub + [j])] def get_coordinates(test_tup): res = list(adjac(test_tup)) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'getCoordinates', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to extract all the adjacent coordinates of the given coordinate tuple.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<vector<int>> actual, vector<vector<int>> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup, vector<vector<int>> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({3, 4}, {{2, 3}, {2, 4}, {2, 5}, {3, 3}, {3, 4}, {3, 5}, {4, 3}, {4, 4}, {4, 5}}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5}, {{3, 4}, {3, 5}, {3, 6}, {4, 4}, {4, 5}, {4, 6}, {5, 4}, {5, 5}, {5, 6}}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({5, 6}, {{4, 5}, {4, 6}, {4, 7}, {5, 5}, {5, 6}, {5, 7}, {6, 5}, {6, 6}, {6, 7}}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]], "inputs": {"test_tup": [3, 4]}}, {"idx": 1, "outputs": [[3, 4], [3, 5], [3, 6], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6]], "inputs": {"test_tup": [4, 5]}}, {"idx": 2, "outputs": [[4, 5], [4, 6], [4, 7], [5, 5], [5, 6], [5, 7], [6, 5], [6, 6], [6, 7]], "inputs": {"test_tup": [5, 6]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
631
MBPP/631
C++
Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
/** * Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex. */ string replaceSpaces(string text) {
string replaceSpaces(string text) {
['text']
import re text = 'Python Exercises' def replace_spaces(text): text =text.replace (" ", "_") return (text) text =text.replace ("_", " ") return (text)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replaceSpaces', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string text, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("Jumanji The Jungle", "Jumanji_The_Jungle"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("The Avengers", "The_Avengers"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Fast and Furious", "Fast_and_Furious"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Jumanji_The_Jungle", "inputs": {"text": "Jumanji The Jungle"}}, {"idx": 1, "outputs": "The_Avengers", "inputs": {"text": "The Avengers"}}, {"idx": 2, "outputs": "Fast_and_Furious", "inputs": {"text": "Fast and Furious"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
632
MBPP/632
C++
Write a c++ function to move all zeroes to the end of the given vector.
/** * Write a c++ function to move all zeroes to the end of the given vector. */ vector<int> moveZero(vector<int> num_list) {
vector<int> moveZero(vector<int> num_list) {
['num_list']
def move_zero(num_list): a = [0 for i in range(num_list.count(0))] x = [ i for i in num_list if i != 0] x.extend(a) return (x)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveZero', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to move all zeroes to the end of the given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> num_list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 0, 2, 0, 3, 4}, {1, 2, 3, 4, 0, 0}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 2, 0, 0, 4, 0, 5, 0}, {2, 3, 2, 4, 5, 0, 0, 0, 0}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({0, 1, 0, 1, 1}, {1, 1, 1, 0, 0}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 2, 3, 4, 0, 0], "inputs": {"num_list": [1, 0, 2, 0, 3, 4]}}, {"idx": 1, "outputs": [2, 3, 2, 4, 5, 0, 0, 0, 0], "inputs": {"num_list": [2, 3, 2, 0, 0, 4, 0, 5, 0]}}, {"idx": 2, "outputs": [1, 1, 1, 0, 0], "inputs": {"num_list": [0, 1, 0, 1, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
633
MBPP/633
C++
Write a c++ function to find the sum of xor of all pairs of numbers in the given vector.
/** * Write a c++ function to find the sum of xor of all pairs of numbers in the given vector. */ int pairOrSum(vector<int> arr, int n) {
int pairOrSum(vector<int> arr, int n) {
['arr', 'n']
def pair_OR_Sum(arr,n) : ans = 0 for i in range(0,n) : for j in range(i + 1,n) : ans = ans + (arr[i] ^ arr[j]) return ans
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'pairOrSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of xor of all pairs of numbers in the given array.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({5, 9, 7, 6}, 4, 47); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({7, 3, 5}, 3, 12); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 3}, 2, 4); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 47, "inputs": {"arr": [5, 9, 7, 6], "n": 4}}, {"idx": 1, "outputs": 12, "inputs": {"arr": [7, 3, 5], "n": 3}}, {"idx": 2, "outputs": 4, "inputs": {"arr": [7, 3], "n": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
634
MBPP/634
C++
Write a c++ function to find the sum of fourth power of first n even natural numbers.
/** * Write a c++ function to find the sum of fourth power of first n even natural numbers. */ int evenPowerSum(int n) {
int evenPowerSum(int n) {
['n']
def even_Power_Sum(n): sum = 0; for i in range(1,n + 1): j = 2*i; sum = sum + (j*j*j*j); return sum;
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'evenPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of fourth power of first n even natural numbers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 272); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 1568); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 5664); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 272, "inputs": {"n": 2}}, {"idx": 1, "outputs": 1568, "inputs": {"n": 3}}, {"idx": 2, "outputs": 5664, "inputs": {"n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
635
MBPP/635
C++
Write a function to push all values into a heap and then pop off the smallest values one at a time.
/** * Write a function to push all values into a heap and then pop off the smallest values one at a time. */ vector<int> heapSort(vector<int> iterable) {
vector<int> heapSort(vector<int> iterable) {
['iterable']
import heapq as hq def heap_sort(iterable): h = [] for value in iterable: hq.heappush(h, value) return [hq.heappop(h) for i in range(len(h))]
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'heapSort', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to push all values into a heap and then pop off the smallest values one at a time.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> iterable, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(iterable), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 3, 5, 7, 9, 2, 4, 6, 8, 0}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({25, 35, 22, 85, 14, 65, 75, 25, 58}, {14, 22, 25, 25, 35, 58, 65, 75, 85}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 1, 9, 5}, {1, 5, 7, 9}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "inputs": {"iterable": [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]}}, {"idx": 1, "outputs": [14, 22, 25, 25, 35, 58, 65, 75, 85], "inputs": {"iterable": [25, 35, 22, 85, 14, 65, 75, 25, 58]}}, {"idx": 2, "outputs": [1, 5, 7, 9], "inputs": {"iterable": [7, 1, 9, 5]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
636
MBPP/636
C++
Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not.
/** * Write a c++ function to check if roots of a quadratic equation are reciprocal of each other or not. */ string checkSolution(int a, int b, int c) {
string checkSolution(int a, int b, int c) {
['a', 'b', 'c']
def Check_Solution(a,b,c): if (a == c): return ("Yes"); else: return ("No");
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSolution', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(int a, int b, int c, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, c), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 0, 2, "Yes"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(2, -5, 2, "Yes"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 2, 3, "No"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Yes", "inputs": {"a": 2, "b": 0, "c": 2}}, {"idx": 1, "outputs": "Yes", "inputs": {"a": 2, "b": -5, "c": 2}}, {"idx": 2, "outputs": "No", "inputs": {"a": 1, "b": 2, "c": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
637
MBPP/637
C++
Write a function to check whether the given amount has no profit and no loss
/** * Write a function to check whether the given amount has no profit and no loss */ bool noprofitNoloss(int actual_cost, int sale_amount) {
bool noprofitNoloss(int actual_cost, int sale_amount) {
['actual_cost', 'sale_amount']
def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noprofitNoloss', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check whether the given amount has no profit and no loss\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(int actual_cost, int sale_amount, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(actual_cost, sale_amount), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(1500, 1200, false); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(100, 100, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(2000, 5000, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": false, "inputs": {"actual_cost": 1500, "sale_amount": 1200}}, {"idx": 1, "outputs": true, "inputs": {"actual_cost": 100, "sale_amount": 100}}, {"idx": 2, "outputs": false, "inputs": {"actual_cost": 2000, "sale_amount": 5000}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
638
MBPP/638
C++
Write a function to calculate wind chill index.
/** * Write a function to calculate wind chill index. */ int windChill(int v, int t) {
int windChill(int v, int t) {
['v', 't']
import math def wind_chill(v,t): windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16) return int(round(windchill, 0))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'windChill', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to calculate wind chill index.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int v, int t, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(v, t), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(120, 35, 40); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(40, 70, 86); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(10, 100, 116); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 40, "inputs": {"v": 120, "t": 35}}, {"idx": 1, "outputs": 86, "inputs": {"v": 40, "t": 70}}, {"idx": 2, "outputs": 116, "inputs": {"v": 10, "t": 100}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
639
MBPP/639
C++
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.
/** * 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. */ int sampleNam(vector<string> sample_names) {
int sampleNam(vector<string> sample_names) {
['sample_names']
def sample_nam(sample_names): sample_names=list(filter(lambda el:el[0].isupper() and el[1:].islower(),sample_names)) return len(''.join(sample_names))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sampleNam', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<string> sample_names, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(sample_names), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({"sally", "Dylan", "rebecca", "Diana", "Joanne", "keith"}, 16); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"php", "res", "Python", "abcd", "Java", "aaa"}, 10); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"abcd", "Python", "abba", "aba"}, 6); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 16, "inputs": {"sample_names": ["sally", "Dylan", "rebecca", "Diana", "Joanne", "keith"]}}, {"idx": 1, "outputs": 10, "inputs": {"sample_names": ["php", "res", "Python", "abcd", "Java", "aaa"]}}, {"idx": 2, "outputs": 6, "inputs": {"sample_names": ["abcd", "Python", "abba", "aba"]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
640
MBPP/640
C++
Write a function to remove the parenthesis area in a string.
/** * Write a function to remove the parenthesis area in a string. */ string removeParenthesis(vector<string> items) {
string removeParenthesis(vector<string> items) {
['items']
import re def remove_parenthesis(items): for item in items: return (re.sub(r" ?\([^)]+\)", "", item))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'removeParenthesis', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to remove the parenthesis area in a string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(vector<string> items, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(items), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({"python (chrome)"}, "python"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({"string(.abc)"}, "string"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({"alpha(num)"}, "alpha"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "python", "inputs": {"items": ["python (chrome)"]}}, {"idx": 1, "outputs": "string", "inputs": {"items": ["string(.abc)"]}}, {"idx": 2, "outputs": "alpha", "inputs": {"items": ["alpha(num)"]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
641
MBPP/641
C++
Write a function to find the nth nonagonal number.
/** * Write a function to find the nth nonagonal number. */ int isNonagonal(int n) {
int isNonagonal(int n) {
['n']
def is_nonagonal(n): return int(n * (7 * n - 5) / 2)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'isNonagonal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the nth nonagonal number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, 325); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(15, 750); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(18, 1089); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 325, "inputs": {"n": 10}}, {"idx": 1, "outputs": 750, "inputs": {"n": 15}}, {"idx": 2, "outputs": 1089, "inputs": {"n": 18}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
643
MBPP/643
C++
Write a function that matches a word containing 'z', not at the start or end of the word.
/** * Write a function that matches a word containing 'z', not at the start or end of the word. */ string textMatchWordzMiddle(string text) {
string textMatchWordzMiddle(string text) {
['text']
import re def text_match_wordz_middle(text): patterns = '\Bz\B' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'textMatchWordzMiddle', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function that matches a word containing \'z\', not at the start or end of the word.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string text, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("pythonzabc.", "Found a match!"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("xyzabc.", "Found a match!"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(" lang .", "Not matched!"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Found a match!", "inputs": {"text": "pythonzabc."}}, {"idx": 1, "outputs": "Found a match!", "inputs": {"text": "xyzabc."}}, {"idx": 2, "outputs": "Not matched!", "inputs": {"text": " lang ."}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
644
MBPP/644
C++
Write a c++ function to reverse vector upto a given position.
/** * Write a c++ function to reverse vector upto a given position. */ vector<int> reverseArrayUptoK(vector<int> input, int k) {
vector<int> reverseArrayUptoK(vector<int> input, int k) {
['input', 'k']
def reverse_Array_Upto_K(input, k): return (input[k-1::-1] + input[k:])
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'reverseArrayUptoK', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to reverse an array upto a given position.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> input, int k, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(input, k), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4, 5, 6}, 4, {4, 3, 2, 1, 5, 6}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({4, 5, 6, 7}, 2, {5, 4, 6, 7}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({9, 8, 7, 6, 5}, 3, {7, 8, 9, 6, 5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [4, 3, 2, 1, 5, 6], "inputs": {"input": [1, 2, 3, 4, 5, 6], "k": 4}}, {"idx": 1, "outputs": [5, 4, 6, 7], "inputs": {"input": [4, 5, 6, 7], "k": 2}}, {"idx": 2, "outputs": [7, 8, 9, 6, 5], "inputs": {"input": [9, 8, 7, 6, 5], "k": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
645
MBPP/645
C++
Write a function to find the product of it’s kth index in the given tuples.
/** * Write a function to find the product of it’s kth index in the given tuples. */ int findKProduct(vector<vector<int>> test_list, int k) {
int findKProduct(vector<vector<int>> test_list, int k) {
['test_list', 'k']
def get_product(val) : res = 1 for ele in val: res *= ele return res def find_k_product(test_list, K): res = get_product([sub[K] for sub in test_list]) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findKProduct', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the product of it’s kth index in the given tuples.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<int>> test_list, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list, k), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{5, 6, 7}, {1, 3, 5}, {8, 9, 19}}, 2, 665); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{6, 7, 8}, {2, 4, 6}, {9, 10, 20}}, 1, 280); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{7, 8, 9}, {3, 5, 7}, {10, 11, 21}}, 0, 210); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 665, "inputs": {"test_list": [[5, 6, 7], [1, 3, 5], [8, 9, 19]], "k": 2}}, {"idx": 1, "outputs": 280, "inputs": {"test_list": [[6, 7, 8], [2, 4, 6], [9, 10, 20]], "k": 1}}, {"idx": 2, "outputs": 210, "inputs": {"test_list": [[7, 8, 9], [3, 5, 7], [10, 11, 21]], "k": 0}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
646
MBPP/646
C++
Write a c++ function to count number of cubes of size k in a cube of size n.
/** * Write a c++ function to count number of cubes of size k in a cube of size n. */ int noOfCubes(int n, int k) {
int noOfCubes(int n, int k) {
['n', 'k']
def No_of_cubes(N,K): No = 0 No = (N - K + 1) No = pow(No, 3) return No
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'noOfCubes', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count number of cubes of size k in a cube of size n.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int k, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, k), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 1, 8); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(5, 2, 64); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 1, 1); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 8, "inputs": {"n": 2, "k": 1}}, {"idx": 1, "outputs": 64, "inputs": {"n": 5, "k": 2}}, {"idx": 2, "outputs": 1, "inputs": {"n": 1, "k": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
647
MBPP/647
C++
Write a function to split a string at uppercase letters.
/** * Write a function to split a string at uppercase letters. */ vector<string> splitUpperstring(string text) {
vector<string> splitUpperstring(string text) {
['text']
import re def split_upperstring(text): return (re.findall('[A-Z][^A-Z]*', text))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'splitUpperstring', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to split a string at uppercase letters.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<string> actual, vector<string> expected){\n return actual == expected;\n}\n\nstring driver(string text, vector<string> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(text), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("PythonProgramLanguage", {"Python", "Program", "Language"}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("PythonProgram", {"Python", "Program"}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("ProgrammingLanguage", {"Programming", "Language"}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": ["Python", "Program", "Language"], "inputs": {"text": "PythonProgramLanguage"}}, {"idx": 1, "outputs": ["Python", "Program"], "inputs": {"text": "PythonProgram"}}, {"idx": 2, "outputs": ["Programming", "Language"], "inputs": {"text": "ProgrammingLanguage"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
648
MBPP/648
C++
Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector.
/** * Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given vector. */ vector<int> exchangeElements(vector<int> lst) {
vector<int> exchangeElements(vector<int> lst) {
['lst']
from itertools import zip_longest, chain, tee def exchange_elements(lst): lst1, lst2 = tee(iter(lst), 2) return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'exchangeElements', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> lst, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(lst), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({0, 1, 2, 3, 4, 5}, {1, 0, 3, 2, 5, 4}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({5, 6, 7, 8, 9, 10}, {6, 5, 8, 7, 10, 9}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({25, 35, 45, 55, 75, 95}, {35, 25, 55, 45, 95, 75}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 0, 3, 2, 5, 4], "inputs": {"lst": [0, 1, 2, 3, 4, 5]}}, {"idx": 1, "outputs": [6, 5, 8, 7, 10, 9], "inputs": {"lst": [5, 6, 7, 8, 9, 10]}}, {"idx": 2, "outputs": [35, 25, 55, 45, 95, 75], "inputs": {"lst": [25, 35, 45, 55, 75, 95]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
649
MBPP/649
C++
Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range.
/** * Write a c++ function to calculate the sum of the numbers in vector between the indices of a specified range. */ int sumRangeList(vector<int> nums, int m, int n) {
int sumRangeList(vector<int> nums, int m, int n) {
['nums', 'm', 'n']
def sum_Range_list(nums, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += nums[i] return sum_range
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sumRangeList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums, int m, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums, m, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12}, 8, 10, 29); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5}, 1, 2, 5); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 0, 1, 2, 5, 6}, 4, 5, 11); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 29, "inputs": {"nums": [2, 1, 5, 6, 8, 3, 4, 9, 10, 11, 8, 12], "m": 8, "n": 10}}, {"idx": 1, "outputs": 5, "inputs": {"nums": [1, 2, 3, 4, 5], "m": 1, "n": 2}}, {"idx": 2, "outputs": 11, "inputs": {"nums": [1, 0, 1, 2, 5, 6], "m": 4, "n": 5}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
650
MBPP/650
C++
Write a c++ function to check whether the given two vectors are equal or not.
/** * Write a c++ function to check whether the given two vectors are equal or not. */ bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) {
bool areEqual(vector<int> arr1, vector<int> arr2, int n, int m) {
['arr1', 'arr2', 'n', 'm']
def are_Equal(arr1,arr2,n,m): if (n != m): return False arr1.sort() arr2.sort() for i in range(0,n - 1): if (arr1[i] != arr2[i]): return False return True
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'areEqual', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether the given two arrays are equal or not.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr1, vector<int> arr2, int n, int m, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr1, arr2, n, m), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3}, {3, 2, 1}, 3, 3, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 1, 1}, {2, 2, 2}, 3, 3, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({8, 9}, {4, 5, 6}, 2, 3, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"arr1": [1, 2, 3], "arr2": [3, 2, 1], "n": 3, "m": 3}}, {"idx": 1, "outputs": false, "inputs": {"arr1": [1, 1, 1], "arr2": [2, 2, 2], "n": 3, "m": 3}}, {"idx": 2, "outputs": false, "inputs": {"arr1": [8, 9], "arr2": [4, 5, 6], "n": 2, "m": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
651
MBPP/651
C++
Write a function to check if one tuple is a subset of another tuple.
/** * Write a function to check if one tuple is a subset of another tuple. */ bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) {
bool checkSubset(vector<int> test_tup1, vector<int> test_tup2) {
['test_tup1', 'test_tup2']
def check_subset(test_tup1, test_tup2): res = set(test_tup2).issubset(test_tup1) return (res)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkSubset', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check if one tuple is a subset of another tuple.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> test_tup1, vector<int> test_tup2, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_tup1, test_tup2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 4, 5, 6}, {5, 10}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4}, {5, 6}, false); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({7, 8, 9, 10}, {10, 8}, true); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"test_tup1": [10, 4, 5, 6], "test_tup2": [5, 10]}}, {"idx": 1, "outputs": false, "inputs": {"test_tup1": [1, 2, 3, 4], "test_tup2": [5, 6]}}, {"idx": 2, "outputs": true, "inputs": {"test_tup1": [7, 8, 9, 10], "test_tup2": [10, 8]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
652
MBPP/652
C++
Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column.
/** * Write a function to flatten the given tuple matrix into the tuple vector with each tuple representing each column. */ string matrixToList(vector<vector<vector<int>>> test_list) {
string matrixToList(vector<vector<vector<int>>> test_list) {
['test_list']
def matrix_to_list(test_list): temp = [ele for sub in test_list for ele in sub] res = list(zip(*temp)) return (str(res))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'matrixToList', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(vector<vector<vector<int>>> test_list, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(test_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{{4, 5}, {7, 8}}, {{10, 13}, {18, 17}}, {{0, 4}, {10, 1}}}, "[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{{5, 6}, {8, 9}}, {{11, 14}, {19, 18}}, {{1, 5}, {11, 2}}}, "[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{{6, 7}, {9, 10}}, {{12, 15}, {20, 21}}, {{23, 7}, {15, 8}}}, "[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "[(4, 7, 10, 18, 0, 10), (5, 8, 13, 17, 4, 1)]", "inputs": {"test_list": [[[4, 5], [7, 8]], [[10, 13], [18, 17]], [[0, 4], [10, 1]]]}}, {"idx": 1, "outputs": "[(5, 8, 11, 19, 1, 11), (6, 9, 14, 18, 5, 2)]", "inputs": {"test_list": [[[5, 6], [8, 9]], [[11, 14], [19, 18]], [[1, 5], [11, 2]]]}}, {"idx": 2, "outputs": "[(6, 9, 12, 20, 23, 15), (7, 10, 15, 21, 7, 8)]", "inputs": {"test_list": [[[6, 7], [9, 10]], [[12, 15], [20, 21]], [[23, 7], [15, 8]]]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
654
MBPP/654
C++
Write a function to find the perimeter of a rectangle.
/** * Write a function to find the perimeter of a rectangle. */ int rectanglePerimeter(int l, int b) {
int rectanglePerimeter(int l, int b) {
['l', 'b']
def rectangle_perimeter(l,b): perimeter=2*(l+b) return perimeter
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'rectanglePerimeter', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the perimeter of a rectangle.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int l, int b, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l, b), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(10, 20, 60); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(10, 5, 30); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(4, 2, 12); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 60, "inputs": {"l": 10, "b": 20}}, {"idx": 1, "outputs": 30, "inputs": {"l": 10, "b": 5}}, {"idx": 2, "outputs": 12, "inputs": {"l": 4, "b": 2}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
655
MBPP/655
C++
Write a c++ function to find the sum of fifth power of n natural numbers.
/** * Write a c++ function to find the sum of fifth power of n natural numbers. */ int fifthPowerSum(int n) {
int fifthPowerSum(int n) {
['n']
def fifth_Power_Sum(n) : sm = 0 for i in range(1,n+1) : sm = sm + (i*i*i*i*i) return sm
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'fifthPowerSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the sum of fifth power of n natural numbers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 33); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(4, 1300); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(3, 276); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 33, "inputs": {"n": 2}}, {"idx": 1, "outputs": 1300, "inputs": {"n": 4}}, {"idx": 2, "outputs": 276, "inputs": {"n": 3}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
656
MBPP/656
C++
Write a c++ function to find the minimum sum of absolute differences of two vectors.
/** * Write a c++ function to find the minimum sum of absolute differences of two vectors. */ int findMinSum(vector<int> a, vector<int> b, int n) {
int findMinSum(vector<int> a, vector<int> b, int n) {
['a', 'b', 'n']
def find_Min_Sum(a,b,n): a.sort() b.sort() sum = 0 for i in range(n): sum = sum + abs(a[i] - b[i]) return sum
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMinSum', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the minimum sum of absolute differences of two arrays.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> a, vector<int> b, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(a, b, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({3, 2, 1}, {2, 1, 3}, 3, 0); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, {4, 5, 6}, 3, 9); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({4, 1, 8, 7}, {2, 3, 6, 5}, 4, 6); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 0, "inputs": {"a": [3, 2, 1], "b": [2, 1, 3], "n": 3}}, {"idx": 1, "outputs": 9, "inputs": {"a": [1, 2, 3], "b": [4, 5, 6], "n": 3}}, {"idx": 2, "outputs": 6, "inputs": {"a": [4, 1, 8, 7], "b": [2, 3, 6, 5], "n": 4}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
657
MBPP/657
C++
Write a c++ function to find the first digit in factorial of a given number.
/** * Write a c++ function to find the first digit in factorial of a given number. */ int firstDigit(int n) {
int firstDigit(int n) {
['n']
import math def first_Digit(n) : fact = 1 for i in range(2,n + 1) : fact = fact * i while (fact % 10 == 0) : fact = int(fact / 10) while (fact >= 10) : fact = int(fact / 10) return math.floor(fact)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'firstDigit', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the first digit in factorial of a given number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(5, 1); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(10, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(7, 5); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1, "inputs": {"n": 5}}, {"idx": 1, "outputs": 3, "inputs": {"n": 10}}, {"idx": 2, "outputs": 5, "inputs": {"n": 7}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
658
MBPP/658
C++
Write a function to find the item with maximum occurrences in a given vector.
/** * Write a function to find the item with maximum occurrences in a given vector. */ int maxOccurrences(vector<int> list1) {
int maxOccurrences(vector<int> list1) {
['list1']
def max_occurrences(list1): max_val = 0 result = list1[0] for i in list1: occu = list1.count(i) if occu > max_val: max_val = occu result = i return result
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxOccurrences', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the item with maximum occurrences in a given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> list1, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(list1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({2, 3, 8, 4, 7, 9, 8, 2, 6, 5, 1, 6, 1, 2, 3, 4, 6, 9, 1, 2}, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 3, 5, 7, 1, 3, 13, 15, 17, 5, 7, 9, 1, 11}, 1); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 2, 4, 5, 1, 1, 1}, 1); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"list1": [2, 3, 8, 4, 7, 9, 8, 2, 6, 5, 1, 6, 1, 2, 3, 4, 6, 9, 1, 2]}}, {"idx": 1, "outputs": 1, "inputs": {"list1": [1, 3, 5, 7, 1, 3, 13, 15, 17, 5, 7, 9, 1, 11]}}, {"idx": 2, "outputs": 1, "inputs": {"list1": [1, 2, 3, 2, 4, 5, 1, 1, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
659
MBPP/659
C++
Write a c++ function to print duplicants from vector of integers.
/** * Write a c++ function to print duplicants from vector of integers. */ vector<int> repeat(vector<int> x) {
vector<int> repeat(vector<int> x) {
['x']
def Repeat(x): _size = len(x) repeated = [] for i in range(_size): k = i + 1 for j in range(k, _size): if x[i] == x[j] and x[i] not in repeated: repeated.append(x[i]) return repeated
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'repeat', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to print duplicants from a list of integers.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> x, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(x), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20}, {20, 30, -20, 60}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({-1, 1, -1, 8}, {-1}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 1, 2}, {1, 2}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [20, 30, -20, 60], "inputs": {"x": [10, 20, 30, 20, 20, 30, 40, 50, -20, 60, 60, -20, -20]}}, {"idx": 1, "outputs": [-1], "inputs": {"x": [-1, 1, -1, 8]}}, {"idx": 2, "outputs": [1, 2], "inputs": {"x": [1, 2, 3, 1, 2]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
660
MBPP/660
C++
Write a c++ function to choose points from two ranges such that no point lies in both the ranges.
/** * Write a c++ function to choose points from two ranges such that no point lies in both the ranges. */ vector<int> findPoints(int l1, int r1, int l2, int r2) {
vector<int> findPoints(int l1, int r1, int l2, int r2) {
['l1', 'r1', 'l2', 'r2']
def find_Points(l1,r1,l2,r2): x = min(l1,l2) if (l1 != l2) else -1 y = max(r1,r2) if (r1 != r2) else -1 return (x,y)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findPoints', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to choose points from two ranges such that no point lies in both the ranges.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(int l1, int r1, int l2, int r2, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(l1, r1, l2, r2), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(5, 10, 1, 5, {1, 10}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(3, 5, 7, 9, {3, 9}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(1, 5, 2, 8, {1, 8}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [1, 10], "inputs": {"l1": 5, "r1": 10, "l2": 1, "r2": 5}}, {"idx": 1, "outputs": [3, 9], "inputs": {"l1": 3, "r1": 5, "l2": 7, "r2": 9}}, {"idx": 2, "outputs": [1, 8], "inputs": {"l1": 1, "r1": 5, "l2": 2, "r2": 8}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
661
MBPP/661
C++
Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
/** * Write a function to find the maximum sum that can be formed which has no three consecutive elements present. */ int maxSumOfThreeConsecutive(vector<int> arr, int n) {
int maxSumOfThreeConsecutive(vector<int> arr, int n) {
['arr', 'n']
def max_sum_of_three_consecutive(arr, n): sum = [0 for k in range(n)] if n >= 1: sum[0] = arr[0] if n >= 2: sum[1] = arr[0] + arr[1] if n > 2: sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])) for i in range(3, n): sum[i] = max(max(sum[i-1], sum[i-2] + arr[i]), arr[i] + arr[i-1] + sum[i-3]) return sum[n-1]
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'maxSumOfThreeConsecutive', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the maximum sum that can be formed which has no three consecutive elements present.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(vector<int> arr, int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(arr, n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({100, 1000, 100, 1000, 1}, 5, 2101); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({3000, 2000, 1000, 3, 10}, 5, 5013); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3, 4, 5, 6, 7, 8}, 8, 27); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2101, "inputs": {"arr": [100, 1000, 100, 1000, 1], "n": 5}}, {"idx": 1, "outputs": 5013, "inputs": {"arr": [3000, 2000, 1000, 3, 10], "n": 5}}, {"idx": 2, "outputs": 27, "inputs": {"arr": [1, 2, 3, 4, 5, 6, 7, 8], "n": 8}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
662
MBPP/662
C++
Write a function to sort vector in map.
/** * Write a function to sort vector in map. */ map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) {
map<string,vector<int>> sortedDict(map<string,vector<int>> dict1) {
['dict1']
def sorted_dict(dict1): sorted_dict = {x: sorted(y) for x, y in dict1.items()} return sorted_dict
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'sortedDict', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to sort a list in a dictionary.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(map<string,vector<int>> actual, map<string,vector<int>> expected){\n return actual == expected;\n}\n\nstring driver(map<string,vector<int>> dict1, map<string,vector<int>> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(dict1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({{"n1", {2, 3, 1}}, {"n2", {5, 1, 2}}, {"n3", {3, 2, 4}}}, {{"n1", {1, 2, 3}}, {"n2", {1, 2, 5}}, {"n3", {2, 3, 4}}}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({{"n1", {25, 37, 41}}, {"n2", {41, 54, 63}}, {"n3", {29, 38, 93}}}, {{"n1", {25, 37, 41}}, {"n2", {41, 54, 63}}, {"n3", {29, 38, 93}}}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({{"n1", {58, 44, 56}}, {"n2", {91, 34, 58}}, {"n3", {100, 200, 300}}}, {{"n1", {44, 56, 58}}, {"n2", {34, 58, 91}}, {"n3", {100, 200, 300}}}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": {"n1": [1, 2, 3], "n2": [1, 2, 5], "n3": [2, 3, 4]}, "inputs": {"dict1": {"n1": [2, 3, 1], "n2": [5, 1, 2], "n3": [3, 2, 4]}}}, {"idx": 1, "outputs": {"n1": [25, 37, 41], "n2": [41, 54, 63], "n3": [29, 38, 93]}, "inputs": {"dict1": {"n1": [25, 37, 41], "n2": [41, 54, 63], "n3": [29, 38, 93]}}}, {"idx": 2, "outputs": {"n1": [44, 56, 58], "n2": [34, 58, 91], "n3": [100, 200, 300]}, "inputs": {"dict1": {"n1": [58, 44, 56], "n2": [91, 34, 58], "n3": [100, 200, 300]}}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
663
MBPP/663
C++
Write a function to find the largest possible value of k such that k modulo x is y.
/** * Write a function to find the largest possible value of k such that k modulo x is y. */ int findMaxVal(int n, int x, int y) {
int findMaxVal(int n, int x, int y) {
['n', 'x', 'y']
import sys def find_max_val(n, x, y): ans = -sys.maxsize for k in range(n + 1): if (k % x == y): ans = max(ans, k) return (ans if (ans >= 0 and ans <= n) else -1)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'findMaxVal', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to find the largest possible value of k such that k modulo x is y.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int x, int y, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n, x, y), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(15, 10, 5, 15); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(187, 10, 5, 185); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(16, 11, 1, 12); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 15, "inputs": {"n": 15, "x": 10, "y": 5}}, {"idx": 1, "outputs": 185, "inputs": {"n": 187, "x": 10, "y": 5}}, {"idx": 2, "outputs": 12, "inputs": {"n": 16, "x": 11, "y": 1}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
664
MBPP/664
C++
Write a c++ function to find the average of even numbers till a given even number.
/** * Write a c++ function to find the average of even numbers till a given even number. */ int averageEven(int n) {
int averageEven(int n) {
['n']
def average_Even(n) : if (n% 2!= 0) : return ("Invalid Input") return -1 sm = 0 count = 0 while (n>= 2) : count = count+1 sm = sm+n n = n-2 return sm // count
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'averageEven', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to find the average of even numbers till a given even number.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(int n, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver(2, 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver(4, 3); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver(100, 51); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"n": 2}}, {"idx": 1, "outputs": 3, "inputs": {"n": 4}}, {"idx": 2, "outputs": 51, "inputs": {"n": 100}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
665
MBPP/665
C++
Write a c++ function to shift first element to the end of given vector.
/** * Write a c++ function to shift first element to the end of given vector. */ vector<int> moveLast(vector<int> num_list) {
vector<int> moveLast(vector<int> num_list) {
['num_list']
def move_last(num_list): a = [num_list[0] for i in range(num_list.count(num_list[0]))] x = [ i for i in num_list if i != num_list[0]] x.extend(a) return (x)
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'moveLast', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to shift first element to the end of given list.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(vector<int> actual, vector<int> expected){\n return actual == expected;\n}\n\nstring driver(vector<int> num_list, vector<int> expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(num_list), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({1, 2, 3, 4}, {2, 3, 4, 1}); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({2, 3, 4, 1, 5, 0}, {3, 4, 1, 5, 0, 2}); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({5, 4, 3, 2, 1}, {4, 3, 2, 1, 5}); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": [2, 3, 4, 1], "inputs": {"num_list": [1, 2, 3, 4]}}, {"idx": 1, "outputs": [3, 4, 1, 5, 0, 2], "inputs": {"num_list": [2, 3, 4, 1, 5, 0]}}, {"idx": 2, "outputs": [4, 3, 2, 1, 5], "inputs": {"num_list": [5, 4, 3, 2, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
666
MBPP/666
C++
Write a function to count occurrence of a character in a string.
/** * Write a function to count occurrence of a character in a string. */ int countChar(string string_arg0, char char_arg1) {
int countChar(string string_arg0, char char_arg1) {
['string_arg0', 'char_arg1']
def count_char(string,char): count = 0 for i in range(len(string)): if(string[i] == char): count = count + 1 return count
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'countChar', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to count occurrence of a character in a string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, char char_arg1, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, char_arg1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("Python", \'o\', 1); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("little", \'t\', 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("assert", \'s\', 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 1, "inputs": {"string_arg0": "Python", "char_arg1": "o"}}, {"idx": 1, "outputs": 2, "inputs": {"string_arg0": "little", "char_arg1": "t"}}, {"idx": 2, "outputs": 2, "inputs": {"string_arg0": "assert", "char_arg1": "s"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
667
MBPP/667
C++
Write a c++ function to count number of vowels in the string.
/** * Write a c++ function to count number of vowels in the string. */ int checkVow(string string_arg0, string vowels) {
int checkVow(string string_arg0, string vowels) {
['string_arg0', 'vowels']
def Check_Vow(string, vowels): final = [each for each in string if each in vowels] return(len(final))
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkVow', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to count number of vowels in the string.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(int actual, int expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, string vowels, int expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, vowels), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("corner", "AaEeIiOoUu", 2); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("valid", "AaEeIiOoUu", 2); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("true", "AaEeIiOoUu", 2); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": 2, "inputs": {"string_arg0": "corner", "vowels": "AaEeIiOoUu"}}, {"idx": 1, "outputs": 2, "inputs": {"string_arg0": "valid", "vowels": "AaEeIiOoUu"}}, {"idx": 2, "outputs": 2, "inputs": {"string_arg0": "true", "vowels": "AaEeIiOoUu"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
668
MBPP/668
C++
Write a c++ function to replace multiple occurence of character by single.
/** * Write a c++ function to replace multiple occurence of character by single. */ string replace(string string_arg0, char char_arg1) {
string replace(string string_arg0, char char_arg1) {
['string_arg0', 'char_arg1']
import re def replace(string, char): pattern = char + '{2,}' string = re.sub(pattern, char, string) return string
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'replace', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to replace multiple occurence of character by single.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string string_arg0, char char_arg1, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(string_arg0, char_arg1), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("peep", \'e\', "pep"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("Greek", \'e\', "Grek"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("Moon", \'o\', "Mon"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "pep", "inputs": {"string_arg0": "peep", "char_arg1": "e"}}, {"idx": 1, "outputs": "Grek", "inputs": {"string_arg0": "Greek", "char_arg1": "e"}}, {"idx": 2, "outputs": "Mon", "inputs": {"string_arg0": "Moon", "char_arg1": "o"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
669
MBPP/669
C++
Write a function to check whether the given ip address is valid or not using regex.
/** * Write a function to check whether the given ip address is valid or not using regex. */ string checkIp(string ip) {
string checkIp(string ip) {
['ip']
import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$''' def check_IP(Ip): if(re.search(regex, Ip)): return ("Valid IP address") else: return ("Invalid IP address")
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'checkIp', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a function to check whether the given ip address is valid or not using regex.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(string actual, string expected){\n return actual == expected;\n}\n\nstring driver(string ip, string expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(ip), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver("192.168.0.1", "Valid IP address"); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver("110.234.52.124", "Valid IP address"); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver("366.1.2.2", "Invalid IP address"); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": "Valid IP address", "inputs": {"ip": "192.168.0.1"}}, {"idx": 1, "outputs": "Valid IP address", "inputs": {"ip": "110.234.52.124"}}, {"idx": 2, "outputs": "Invalid IP address", "inputs": {"ip": "366.1.2.2"}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
670
MBPP/670
C++
Write a c++ function to check whether a sequence of numbers has a decreasing trend or not.
/** * Write a c++ function to check whether a sequence of numbers has a decreasing trend or not. */ bool decreasingTrend(vector<int> nums) {
bool decreasingTrend(vector<int> nums) {
['nums']
def decreasing_trend(nums): if (sorted(nums)== nums): return True else: return False
{'entry_cls_name': 'Solution', 'extension': 'cpp', 'entry_fn_name': 'decreasingTrend', 'test_code': '#include <algorithm>\n#include <assert.h>\n#include <cstdlib>\n#include <iostream>\n#include <map>\n#include <set>\n#include <string>\n#include <tuple> \n#include <unordered_map>\n#include <vector>\n#include <math.h>\n#include <cmath>\n#include <bits/stdc++.h>\n#include <numeric>\n#include <functional>\n\nusing namespace std;\n// Question Prompt (NOT what is passed to the model)\n// Write a python function to check whether a sequence of numbers has a decreasing trend or not.\n//\n// SOLUTION CODE\n// ============================================\nPLACEHOLDER_CODE_BODY\n\n// TESTING CODE \n// ============================================\nbool validateSolution(bool actual, bool expected){\n return actual == expected;\n}\n\nstring driver(vector<int> nums, bool expected){\n try\n {\n if (validateSolution(PLACEHOLDER_FN_NAME(nums), expected)){\n return "PASSED";\n }\n return "FAILED";\n }\n catch (const std::overflow_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::runtime_error& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (const std::exception& exception_obj)\n {\n return typeid(exception_obj).name();\n }\n catch (...)\n {\n return "UNK_ERROR";\n }\n}\n\nint main() {\n string result = "";\n\n result = driver({-4, -3, -2, -1}, true); \n cout << "TEST-" << 0 << "..."\n << result\n << "\\n";\n\n result = driver({1, 2, 3}, true); \n cout << "TEST-" << 1 << "..."\n << result\n << "\\n";\n\n result = driver({3, 2, 1}, false); \n cout << "TEST-" << 2 << "..."\n << result\n << "\\n";\n\n return 0;\n}', 'test_list': '[{"idx": 0, "outputs": true, "inputs": {"nums": [-4, -3, -2, -1]}}, {"idx": 1, "outputs": true, "inputs": {"nums": [1, 2, 3]}}, {"idx": 2, "outputs": false, "inputs": {"nums": [3, 2, 1]}}]', 'test_case_ids': ['0', '1', '2'], 'commands': [['g++', '__FILENAME__', '-o', 'main.exe'], ['./main.exe']], 'timeouts': [10, 10]}
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
13