[output] | \d{3}-\d{3}-\d{4} [instruction] | Create a regular expression to match a valid phone number (ex. 123-456-7890). [input] |
[output] | def createArray(n): return [0] * n [instruction] | Design a function for creating an array with n elements and each element with the value of 0. [input] |
[output] | The maximum depth of a binary tree of size n is log2(n). [instruction] | What is the maximum depth of a binary tree of size n? [input] |
[output] | def arrayToMatrix(array): n = int(len(array)**0.5) matrix = [] for i in range(n): matrix.append(array[i*n:(i+1)*n]) return matrix [instruction] | Convert a given array of numbers into a square matrix. [input] | Given array = [1, 2, 3, 4]
[output] | def char_frequency(string): freq = {} for c in string: if c in freq: freq[c] += 1 else: freq[c] = 1 for c, count in freq.items(): print('{0} : {1}'.format(c, count)) [instruction] | Write a code snippet that prints out the number of times each character appears in a given string. [input] | Given string = "welcome"
[output] | def generate_permutations(string): if len(string) == 1: return [string] all_perms = [] for i, c in enumerate(string): other_chars = string[:i] + string[i+1:] other_perms = generate_permutations(other_chars) for perm in other_perms: all_perms. [instruction] | Design an algorithm that prints all the permutations of a given string. [input] |
[output] | public static int binarySearch(int[] arr, int target) { int left = 0; int right = arr.length - 1; while (left <= right) { int mid = left + (right - left)/2; if (arr[mid] == target) { return mid; } else if (arr[mid] < target) { left [instruction] | Write a Java program for binary search. [input] |
[output] | <!DOCTYPE html> <html> <head> <title>Welcome to Python Programming</title> </head> <body> <h1>Welcome to Python Programming</h1> </body> </html> [instruction] | Create a web page with the headline "Welcome to Python programming". [input] |
[output] | def get_unique_elements(lst): return list(set(lst)) unique_list = get_unique_elements([2, 4, 5, 2, 4, 8]) print(unique_list) # output the list with only unique elements [instruction] | Write a function that takes a list as a parameter and returns only the unique elements in the given list. [input] | [2, 4, 5, 2, 4, 8]
[output] | my_tuple = (1, 2, 3, 4, 5) [instruction] | Create a variable that contains a tuple of integers. [input] |
[output] | import numpy as np matrix = np.zeros((4,3)) print(matrix) # Output the matrix of zeros [instruction] | Create a matrix of zeros with shape 4x3 using the NumPy library. [input] |
[output] | from twilio.rest import Client # Your Account SID from twilio.com/console account_sid = "XXXXXXXXXXXXXXXXXXXXXXX" # Your Auth Token from twilio.com/console auth_token = "XXXXXXXXXXXXXXXXXXXXXXX" client = Client(account_sid, auth_token) message = client.messages.create( to="+123456789", [instruction] | Write a code to send a message "Hello World!" using the Twilio API. [input] |
[output] | for i in range(0, len(array), 3): print(array[i]) [instruction] | Construct a for loop that prints out every third element of a given array. [input] | Array: [1, 2, 3, 4, 5, 6, 7]
[output] | def calculate_total_amount(products, prices): total_amount = 0 for i in range(len(products)): total_amount = total_amount + (products[i] * prices[i]) return total_amount [instruction] | Develop a function to calculate the total amount of the order for an online store. [input] | ProductA: 15 ProductB: 10 PriceForProductA: 5 PriceForProductB: 10
[output] | # Calculate the roots of the given equation def quadratic_roots(a, b, c): # Calculate the discriminant discriminant = b**2 - 4*a*c # Calculate root1 and root2 root1 = (-b + discriminant**0.5)/(2*a) root2 = (-b - discriminant**0.5)/(2*a) return root1, root2 [instruction] | Calculate the roots of a quadratic equation given its coefficients. [input] | Coefficients: 4, 3, 1
[output] | 1100.01 [instruction] | Convert the following floating-point number to its binary representation. [input] | Number: 12.25
[output] | employee = { 'name': 'John Doe', 'age': 25, 'role': 'Sales Manager', } [instruction] | Create a Python dictionary to store employee details. [input] | Name: John Doe Age: 25 Role: Sales Manager
[output] | <html> <head> <title>Employee Details</title> </head> <body> <h1>Employee Details</h1> <p>Name: Oliver Smith</p> <p>Age: 35</p> <p>Role: Marketing Executive</p> </body> </html> [instruction] | Create an HTML page to display the employee details. [input] | Employee Name: Oliver Smith Age: 35 Role: Marketing Executive
[output] | import java.util.Hashtable; public class HashtableExample { public static void main(String args[]) { Hashtable<Integer, String> ht = new Hashtable<Integer, String>(); ht.put(1, "Code"); ht.put(2, "Learn"); ht.put(3, "Project"); ht.put(4, "Universi [instruction] | Create a Hashtable in Java to store a list of key-value pair. [input] |
[output] | function isSortedAscending(arr) { for (let i = 0; i < (arr.length - 1); i++) { if (arr[i] > arr[i + 1]) { return false; } } return true; } [instruction] | Using JavaScript, create an algorithm to check if an array of numbers is sorted in ascending order. [input] |
[output] | <?php function toUrlSafeString($str) { $str = strtolower($str); $str = preg_replace('/\s/', '-', $str); $str = preg_replace('/\W/', '', $str); return $str; } [instruction] | Write a PHP program to convert a string to a URL safe string. [input] |
[output] | for i in range(1, 9): print(i, end=' ') [instruction] | Write a code to print all numbers between a given range in the format shown below [input] | Start = 1; End = 8;
[output] | def insertion_sort(list): for i in range(1, len(list)): key = list[i] j = i -1 while j >=0 and list[j] > key: list[j+1] = list[j] j -= 1 list[j+1] = key return list [instruction] | Create a function to perform insertion sorting [input] | list = [5, 3, 8, 7, 1]
[output] | def xor(A, B): if (A == B): return 0 else: return 1 [instruction] | Write a code to compute the XOR of two bits [input] | A = 1; B = 0;
[output] | def sequential_search(arr, x): for i in range(len(arr)): if arr[i] == x: return i return -1 [instruction] | Write a function to implement the sequential search algorithm [input] | arr = [8, 2, 5, 6, 9]
[output] | def fibonacci(num): first = 0 second = 1 for i in range(num): temp = first first = second second = temp + second return first [instruction] | Rewrite this program to use an embedded loop instead of recursion: def fibonacci(num): if num == 0: return 0 elif num == 1: return 1 else: return fibonacci(num-1) + fibonacci(num-2) [input] |
[output] | sorted_string = ''.join(sorted(string)) [instruction] | You are given a string and you want to sort all characters in the string alphabetically. [input] |
[output] | CREATE TABLE myTable ( id INTEGER, name VARCHAR(255), city VARCHAR(255) ); [instruction] | Create a SQL table with the following schema: id (integer), name (string), city (string). [input] |
[output] | def word_count(str): return len(str.split(' ')) [instruction] | You are given a string and you want to count the number of words in it. [input] |
[output] | [[12,4,3],[7,5,8]] [instruction] | Given a matrix of size NxM, make a code that prints the transpose of the matrix. [input] | [[12,7],[4,5],[3,8]]