[output] | function randomString() { let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let string = ""; for (let i = 0; i < 10; i++) { string += characters.charAt(Math.floor(Math.random() * characters.length)); } return string; } [instruction] | What code should be written to generate a random string with 10 characters in JavaScript? [input] |
[output] | even_list = [x for x in my_list if x % 2 == 0] [instruction] | Rewrite the given Python code snippet using list comprehensions . [input] | even_list = [] for x in my_list: if x % 2 == 0: even_list.append(x)
[output] | Random random = new Random(); int[] numbers = new int[5]; for(int i = 0; i < 5; i++) { numbers[i] = random.nextInt(); } [instruction] | What code should be used to generate 5 random numbers in Java? [input] |
[output] | <div class="container" id="welcome"> <h1>Welcome!</h1> </div> [instruction] | Edit the following HTML code to add an attribute and its value [input] | <div class="container"> <h1>Welcome!</h1> </div>
[output] | def store_and_emit(data): stored_data = data def emit_stored_data(): return stored_data return emit_stored_data [instruction] | Write a callback function for the following requirements [input] | This callback should be able to store the input emit it when triggered
[output] | public int FindCommonElement(int[] arr1, int[] arr2) { HashSet<int> set = new HashSet<int>(); foreach (int item in arr1) { set.Add(item); } List<int> commons = new List<int>(); foreach (int item in arr2) { if (set.Contains(item)) commons.A [instruction] | Create a C# method to find the third common element in two arrays [input] | arr1: [8, 15, 20, 7, 2] arr2: [5, 6, 7, 9, 8]
[output] | Recursion is a programming technique that allows a function to call itself repeatedly until a certain condition is met. This allows for a clear solution to problems that involve repeated cycles of steps in their execution. Recursion also helps to solve complex problems by breaking them down into sim [instruction] | Explain the effect of using recursion as a programming technique [input] |
[output] | name = condition ? value1 : value2; [instruction] | Assign a value to `name` by using the ternary operator [input] | let name;
[output] | Some potential input parameters for a Machine Learning model include numeric features, categorical features, text features, external features, and data derived from benchmark datasets. [instruction] | Suggest a few input parameters for a Machine Learning model [input] |
[output] | A possible API endpoint for a user profile could be `GET /users/:id` which returns the profile information associated with the given user ID. [instruction] | Suggest an API endpoint for a user profile [input] |
[output] | const age: number; [instruction] | Edit the code to correctly define the type of `age` [input] | const age;
[output] | class Area: def __init__(self): pass def calculate_area_rectangle(self, length, width): return length * width def calculate_area_triangle(self, base, height): return 0.5 * base * height def calculate_area_circle(self, radius): return 3.14 * radius** [instruction] | Create a new Python class called Area to calculate the area of different shapes. [input] |
[output] | import re def extract_phone_numbers(text): phones = re.findall("\(\d{3}\) \d{3}\-\d{4}",text) return phones print(extract_phone_numbers(text)) # Output ['(202) 555-0123', '(703) 555-9876'] [instruction] | Extract the phone numbers from a string of text [input] | text = "My number is (202) 555-0123 and my friend's number is (703) 555-9876"
[output] | class Node: def __init__(self, data): self.data = data self.left = None self.right = None def inOrderTraversal(root): if root is not None: inOrderTraversal(root.left) print(root.data) inOrderTraversal(root.right) root = Node(1) root.le [instruction] | Implement a in-order traversal of a binary tree in Python. [input] |
[output] | def generate_DNA_weight(DNA): # Initialize the weights dict weights = { "G": 57.02, "A": 71.04, "T": 89.09, "C": 103.01 } # Calculate the weight weight = 0.0 for character in DNA: weight += weights[character] return weight [instruction] | Create a function to generate the weight of a given sequence of DNA [input] | DNA = "GTCATCTGAG"
[output] | def min_coins(amount): # list of coin denominations coins = [1, 5, 10, 25] min_coins = 0 i = len(coins) - 1 while(amount > 0): if (amount >= coins[i]): amount -= coins[i] min_coins += 1 else: i -= 1 return min_coins # Outpu [instruction] | Find the minimum number of coins required to make a given amount [input] | amount = 93
[output] | #!/bin/sh echo "Hello World!" [instruction] | Create a shell script for printing Hello World. [input] |
[output] | #include <stdio.h> int isPrime(int n) { if (n <= 1) return 0; for (int i = 2; i < n; i++) if (n % i == 0) return 0; return 1; } int main() { int n; printf("Enter an integer: "); scanf("%d", &n); if (isPrime(n)) [instruction] | Write a C code snippet to check if an input number is prime or not. [input] | The number is 17
[output] | function showMessage() { console.log('Hello World!'); } [instruction] | Write a JavaScript function to display the message "Hello World!". [input] |
[output] | const obj = {Name: 'John', Age: 25}; return obj; [instruction] | Construct a JSON object with the given parameters and return the object. [input] | Name=John Age=25
[output] | arr = [1, 2, 3, 4] for i in range(len(arr)): print(arr[i]) [instruction] | Construct a for loop to access each element of the given array. [input] | [1, 2, 3, 4]
[output] | num = 8 if num % 2 == 0: print('The number is divisible by 2.') [instruction] | Modify the code below to check if the number is divisible by 2. [input] | num = 8
[output] | """ def isUnivalTree(root): is_uni = True if root is None: return is_uni else: val = root.val if root.left: is_uni &= root.left.val == val if root.right: is_uni &= root.right.val == val is_uni &= isUnivalTree(root.left) [instruction] | Create an algorithm to check if a binary tree is univalued. [input] |
[output] | """ def nthFromLast(head, n): # Initialize slow and fast pointers slow = head fast = head # Move fast pointer n-1 times while (n > 0): if (fast == None): return None fast = fast.next n = n - 1 # Move both slow and fast poin [instruction] | Design an algorithm for finding the nth node from the tail of a linked list. [input] |
[output] | class Rectangle: def __init__(self, width, height): self.width = width self.height = height def get_area(self): return self.width * self.height [instruction] | Create a class in Python named 'Rectangle' which can compute the area of a rectangle. [input] |
[output] | """ def isSubstring(string, sub): l1 = len(string) l2 = len(sub) if l2> l1: return False # Sliding window approach for i in range(l1): if string[i:i+l2] == sub : return True return False """ [instruction] | Design an algorithm to check if a string contains a given substring. [input] |
[output] | def get_values(d): return list(d.values()) [instruction] | Suppose we have a dictionary with keys (1,2,3). Create a function to return the values of the dictionary. [input] | d = {1: "one", 2: "two", 3: "three"}
[output] | def exchange_first_last(lst): first_item = lst[0] last_item = lst[-1] lst[0] = last_item lst[-1] = first_item return lst [instruction] | Write a function that exchanges the first and last elements of a list. [input] |
[output] | def reverse_list(lst): n = len(lst) for i in range(n // 2): lst[i], lst[n-i-1] = lst[n-i-1], lst[i] return lst [instruction] | Reverse a given list without using any predefined functions. [input] |
[output] | def add_two_numbers(a, b): return a + b [instruction] | Suggest a valid Python code to add two numbers [input] |