[output] | #include<iostream> using namespace std; int main() { int num = 54321; int reversed = 0; while(num != 0) { reversed = reversed * 10 + num % 10; num /= 10; } cout << "Reversed Number: " << reversed << endl; return 0; } [instruction] | Write a C++ program to print a decimal number in reverse [input] |
[output] | def func(arg1, arg2): if arg2 is None: arg2 = "default" pass [instruction] | Unwrap the function parameter with default argument. [input] | def func(arg1, arg2="default"): pass
[output] | True [instruction] | Detect if the given URL contains a query string. [input] | url = https://www.example.com/?food=burger
[output] | temp = a a = b b = temp [instruction] | Swap the values of the two given numbers using a temporary variable. [input] | a = 1 b = 2
[output] | class Vehicle: def __init__(self, name, color, max_speed): self.name = name self.color = color self.max_speed = max_speed [instruction] | Create a class named “Vehicle” that has 3 instance variables. [input] |
[output] | [print(v1, v2) for (v1, v2) in my_list] [instruction] | Create a list comprehension that prints each pair in a given list of tuples. [input] | my_list = [("apple", "red"), ("banana", "yellow")]
[output] | my_list = list(set(my_list)) [instruction] | Modify the given list to include only unique items. [input] | my_list = [1, 2, 2, 3, 3, 4]
[output] | my_dict = dict(my_tuple) [instruction] | Create a dictionary with the key-value pairs of the given tuple. [input] | my_tuple = (("a", 1), ("b", 2), ("c", 3))
[output] | def most_common(arr): freq = {} # Count the frequency of each element for el in arr: if el not in freq: freq[el] = 1 else: freq[el] += 1 # Find the maximum frequency max_freq = -1 for el, freq in freq.items(): [instruction] | Write a Python algorithm to find the most common value in an array. [input] | arr = [1, 2, 3, 3, 3, 3, 4, 4, 5]
[output] | import argparse parser = argparse.ArgumentParser() parser.add_argument("--print_hello", help="print hello, world", action="store_true") if __name__ == "__main__": args = parser.parse_args() if args.print_hello: print("Hello, world.") [instruction] | Define a command line application that prints “Hello, world.” [input] |
[output] | sum = 0 for num in range(10): sum += num print(sum) [instruction] | Rewrite the following code snippet so that it is compatible with Python 3 [input] | sum = 0 for num in range(10): sum = sum + num print sum
[output] | wish. [instruction] | Output the last two words in the following string [input] | I only have one wish.
[output] | def find_max(a, b, c): if a >= b and a >= c: return a elif b >= a and b >= c: return b else: return c [instruction] | Update the following function so that it returns the greatest among three numbers [input] | def find_max(a, b): if a > b: return a else: return b
[output] | def authentication(username,password): if username == "username" and password == "password": print ("Login successful") else: print ("Incorrect username or password") username = input("Enter your username: ") password = input("Enter your password: ") authentication(use [instruction] | Write a user authentication code in Python [input] |
[output] | arr_1 = [2,3,4] arr_2 = [1,2,3] sum = 0 for i in range(len(arr_1)): sum += arr_1[i] + arr_2[i] print("The sum of the two arrays is",sum) [instruction] | Output the sum of the following two arrays [input] | arr_1 = [2,3,4] arr_2 = [1,2,3]
[output] | One way to secure user passwords is to use a secure hash algorithm such as bcrypt, scrypt, etc. to hash the passwords before storing them in the database. This ensures that even if the passwords are exposed, they will not be easily readable. Furthermore, it is important to use a secure server and to [instruction] | Suggest a way to secure user passwords [input] |
[output] | One way to optimize memory usage is to use strategic data structures like hash tables and trees that can store data in a more space-efficient manner. Additionally, one can use code optimization techniques such as code reuse and memory caching to reduce memory usage. One should also think carefully a [instruction] | Suggest a technique to optimize memory usage [input] |
[output] | arr = [2, 3, 4, 5] for i in arr: if i % 2 == 0: print(i) # Output: 2 4 [instruction] | Combine a loop and a conditional statement to output the following [input] | [2, 3, 4, 5]
[output] | 𝜎 = √((∑(x - mean)^2)/n) [instruction] | Fill in the blanks to calculate the standard deviation of an array using the formula. [input] |
[output] | def evaluate(expr): return eval(expr) print(evaluate('3 + 2 * 4')) # Output 11 [instruction] | Develop a function to evaluate the following expression. [input] | 3 + 2 * 4
[output] | The Manacher’s Algorithm is an ideal algorithm to find the longest palindrome in a given string. This algorithm utilizes dynamic programming to find the longest palindrome in linear time complexity by iterating through the string and checking whether a substring is a palindrome or not. [instruction] | Identify an ideal algorithm to find the longest palindrome in a given string. [input] |
[output] | happy = [1, 0, 0, 0] angry = [0, 1, 0, 0] [instruction] | Suggest a vector representation for the following phrases. [input] | happy, angry
[output] | x = a + b y = x + (c - b) z = x + (d - b) [instruction] | Implement source-to-source transformation of the following code. [input] | x = a + b y = a + c z = b + d
[output] | Three ways to optimize a database are database normalization, indexing, and partitioning. Database normalization involves restructuring a database schema into multiple tables and establishing referential integrity. Indexing is a technique used to speed up the retrieval of data from a table. Partitio [instruction] | Describe three ways to optimize a given database. [input] |
[output] | A question-answering system is an AI Assistant that can identify questions in a given sentence. It utilizes natural language processing techniques such as language models, semantic analysis, and lookup tables to analyze the given sentence and extract out the questions. [instruction] | Develop an AI Assistant to identify questions in a given sentence. [input] |
[output] | public class School { private String name; private List<Student> students; //constructor, getters, setters, and other methods public void addStudent(Student student) { students.add(student); } } public class Student { private String name; private int age; [instruction] | Create classes in Java to represent a school and its students. [input] |
[output] | def add_num(arr, num): return [x + num for x in arr] [instruction] | Write a function, which given an array and a number, returns the array with the number added. [input] | arr = [1, 2, 3, 4] num = 10
[output] | new_list = [x**2 for x in list] [instruction] | Create a new list where the elements are the square of the elements in the given list. [input] | list = [1, 2, 3, 4]
[output] | class Person: def __init__(self, name, age): self.name = name self.age = age def get_name(self): return self.name def get_age(self): return self.age [instruction] | Create a class with two methods, one to return the name and the other to return the age. [input] |
[output] | for x in range(4, 15): print(x) [instruction] | Using the code, update the variable to count from 4 to 14. [input] | x = 4