42 lines
4.8 KiB
JSON
42 lines
4.8 KiB
JSON
{
|
|
"0": {
|
|
"text": "Write a function to remove the matching tuples from the given two lists.",
|
|
"code": "function remove_matching_tuple(test_list1, test_list2){\n // Result list to store non-matching items\n result = []\n getListLen(test_list1, len1)\n getListLen(test_list2, len2)\n startLoop(i, 0, len1)\n itemFromList(test_list1, i, current_item)\n found = False\n startLoop(j, 0, len2)\n itemFromList(test_list2, j, check_item)\n if(current_item, check_item, \"=\")\n found = True\n end()\n endLoop()\n if(found, False, \"=\")\n variableToList(current_item, result)\n end()\n endLoop()\n return(result)\n}"
|
|
},
|
|
"1": {
|
|
"text": "Write a function to find the number of elements present in the given list.",
|
|
"code": "function find_lists(input_list){\n getListLen(input_list, list_len)\n return(list_len)\n}"
|
|
},
|
|
"2": {
|
|
"text": "Write a function to find the first natural number whose factorial is divisible by x.",
|
|
"code": "function first_Factorial_Divisible_Number(x){\n i = 1\n fact = 1\n result = 1\n startLoop(i, 1, x)\n fact = fact * i\n remainder = fact % x\n if(remainder, 0, \"=\")\n result = i\n i = x\n end()\n endLoop()\n return(result)\n}"
|
|
},
|
|
"3": {
|
|
"text": "Write a function to find the largest number that can be formed with the given list of digits.",
|
|
"code": "function find_Max_Num(arr){\n // Sort the array in descending order\n getListLen(arr, n)\n // Bubble sort descending\n startLoop(i, 0, n)\n startLoop(j, 0, n)\n itemFromList(arr, j, val_j)\n next_idx = j + 1\n itemFromList(arr, next_idx, val_next)\n if(val_j, val_next, \"<\")\n // Swap\n arr[j] = val_next\n arr[next_idx] = val_j\n end()\n endLoop()\n endLoop()\n // Build the number\n itemFromList(arr, 0, num)\n startLoop(k, 1, n)\n itemFromList(arr, k, digit)\n num = num * 10 + digit\n endLoop()\n return(num)\n}"
|
|
},
|
|
"4": {
|
|
"text": "Write a function to check if the triangle is equilateral or not.",
|
|
"code": "function check_equilateral(x, y, z){\n if(x, y, \"=\")\n if(y, z, \"=\")\n return(True)\n end()\n end()\n return(False)\n}"
|
|
},
|
|
"5": {
|
|
"text": "Write a function to count the occurrences of the first element of each tuple in the given list of tuples.",
|
|
"code": "function sort_on_occurence(lst){\n // Build a JSON object counting occurrences of first elements\n counts = {}\n getListLen(lst, lst_len)\n startLoop(i, 0, lst_len)\n itemFromList(lst, i, current_tuple)\n itemFromList(current_tuple, 0, key)\n variableFromJSON(counts, key, existing)\n if(existing, None, \"=\")\n AddvariableToJSON(key, 1, counts)\n else()\n new_count = existing + 1\n AddvariableToJSON(key, new_count, counts)\n end()\n endLoop()\n return(counts)\n}"
|
|
},
|
|
"6": {
|
|
"text": "Write a function to check if a given number is one less than twice its reverse.",
|
|
"code": "function rev(num){\n rev_num = 0\n startLoop(i, 1, num)\n if(num, 0, \">\")\n remainder = num % 10\n rev_num = rev_num * 10 + remainder\n num = num // 10\n end()\n endLoop()\n return(rev_num)\n}\n\nfunction check(n){\n reversed_n = rev(n)\n twice_rev = 2 * reversed_n\n expected = n + 1\n if(twice_rev, expected, \"=\")\n return(True)\n end()\n return(False)\n}"
|
|
},
|
|
"7": {
|
|
"text": "Write a function to convert a list of multiple integers into a single integer.",
|
|
"code": "function multiple_to_single(L){\n getListLen(L, list_len)\n result = 0\n startLoop(i, 0, list_len)\n itemFromList(L, i, digit)\n result = result * 10 + digit\n endLoop()\n return(result)\n}"
|
|
},
|
|
"8": {
|
|
"text": "Write a function that checks if a word exists at the end of a string, with optional punctuation.",
|
|
"code": "function text_match_word(text){\n // Use getRegex to find a word at the end of the string with optional punctuation\n pattern = \"\\\\w+\\\\S*$\"\n getRegex(text, pattern, match_result)\n if(match_result, None, \"!=\")\n addVar(output, \"Found a match!\")\n else()\n addVar(output, \"Not matched!\")\n end()\n return(output)\n}"
|
|
},
|
|
"9": {
|
|
"text": "Write a function to find the sum of numbers in a list between the indices of a specified range.",
|
|
"code": "function sum_range_list(list1, m, n){\n sum_range = 0\n end_idx = n + 1\n startLoop(i, m, end_idx)\n itemFromList(list1, i, current_val)\n sum_range = sum_range + current_val\n endLoop()\n return(sum_range)\n}"
|
|
}
|
|
} |