[output] | def fibonacci_series(n): if n == 0: return a = 0 b = 1 print(a, end=" ") print(b, end=" ") for i in range(2,n): c = a + b a = b b = c print(b, end=" ") fibonacci_series(N) [instruction] | Write a script that prints the first N numbers in a Fibonacci series. [input] | N = 10
[output] | import java.util.HashSet; public class RemoveDuplicates { public static int[] removeDuplicates(int arr[]) { // HashSet for removing duplicates HashSet<Integer> set = new HashSet<>(); // adding elements to HashSet for(int i=0; i<arr.length; i++) [instruction] | Create a Java program that removes duplicate elements from an array. [input] | int arr[] = {12, 11, 12, 11, 13, 11};
[output] | # k-nearest neighbor algorithm def knn(k, data, targets, query): # find k nearest neighbors of the query indices = get_neighbors(k, data, query) # find most common label among the neighbors counts = {} for index in indices: label = targets[index] counts[label] = counts.get(label, 0) + [instruction] | Implement a k-nearest neighbors algorithm to predict point labels. [input] |
[output] | def is_a_power_of(x, y): if x == y: return True if x > y and y != 0: return is_a_power_of(x/y, y) else: return False power_of = is_a_power_of(x, y) [instruction] | Create a function which takes two parameters and returns true if the second parameter is a power of the first parameter. [input] | x = 16 y = 4
[output] | def count_distinct_words(sentence): distinct_words = set([word.lower() for word in sentence.split()]) return len(distinct_words) print(count_distinct_words("This is a test sentence.")) # Outputs: 4 [instruction] | Write an algorithm in Python to find the number of distinct words in a given sentence. [input] | "This is a test sentence."
[output] | #!/bin/bash if [ -z $1 ]; then echo "Please provide a URL as an argument" else curl -O $1 fi [instruction] | Write a Bash script for downloading a web page from the internet. [input] |
[output] | function downloadData(url) { return new Promise((resolve, reject) => { // Code to download data if (/* success */) { resolve(data) } else { reject(err) } }) } [instruction] | Convert the following JS code from a callback to a promise. [input] | function downloadData(url, callback) { // Code to download data if (/* success */) { callback(null, data) } else { callback(err, null) } }
[output] | sendRequest(url) { // Code to send request } requests = []; // Array to keep track of requests makeRequest(url) { if (!requests.includes(url)) { // Check if request doesn't already exist sendRequest(url); requests.push(url); // Add request to list } } [instruction] | Edit the following JS code to include a check to avoid creating duplicate requests. [input] | sendRequest(url) { // Code to send request } makeRequest(url) { sendRequest(url); }
[output] | <html> <head> <title>Facts about Fluffy</title> </head> <body> <h1>Fluffy the Cat</h1> <ul> <li>Age: 8</li> <li>Weight: 10 lbs</li> <li>Fur Color: Orange</li> </ul> </body> </html> [instruction] | Write an HTML page to display facts about a specific animal. [input] | Animal: Cat Name: Fluffy Age: 8 Weight: 10 lbs Fur Color: Orange
[output] | SELECT name FROM Students WHERE grade >= 7; [instruction] | Create a MySQL query that returns all the names of the students with a grade greater than or equal to 7. [input] | Table: Students Columns: student_id, name, grade
[output] | function getData() { // Code to fetch data return new Promise((resolve, reject) => { // Fetch data if (/* success */) { resolve(data) } else { reject(err) } }) } [instruction] | Edit the following JavaScript code to make the function asynchronous. [input] | function getData() { // Code to fetch data }
[output] | #include <iostream> using namespace std; // Function to demonstrate printing pattern void pyramid(int n) { // outer loop to handle number of rows // n in this case for (int i=0; i<n; i++) { // inner loop to handle number of columns // values changin [instruction] | Implement a function in C++ to print a pyramid of stars [input] |
[output] | import socket def get_ip(hostname): return socket.gethostbyname(hostname) print(get_ip('google.com')) [instruction] | Write a Python program to get the IP address from a given hostname [input] | google.com
[output] | SELECT * FROM students WHERE age BETWEEN 22 AND 28; [instruction] | Write a code to select all columns from a table named 'students' where the age is between 22 and 28 [input] |
[output] | func filter_array(_ numbers: [Int], filter_num: Int) -> [Int] { var resultArr = [Int]() for i in 0..<numbers.count { if numbers[i] < filter_num { resultArr.append(numbers[i]) } } return resultArr } filter_array([4, 5, 8, 11, 7], filter_num: 7) // returns [instruction] | Implement a Swift function to filter an array of numbers by a given filter number [input] | [4, 5, 8, 11, 7], filter_num = 7
[output] | <html> <head> <title> My Web Page </title> </head> <body> <h1> Heading </h1> <h2> Subheading </h2> <form> ... </form> <button> Button </button> </body> </html> [instruction] | Design a web page with the following HTML elements: (1) Heading, (2) Subheading, (3) Form, (4) Button. [input] |
[output] | SELECT * FROM Users WHERE age > 20; [instruction] | Write an SQL query to retrieve all rows in a table that match a certain criteria. [input] | Table: Users name | age ------|------ John | 20 Pete | 22 Alex | 18
[output] | s = tf('s'); H = 1/(s^4 + 2.39125*s^3 + 2.37238*s^2 + 0.857723*s + 0.147902); [instruction] | Design a fourth-order Butterworth low-pass filter. [input] |
[output] | db.collection.find({city: 'New York'}); [instruction] | Create a MongoDB query to find all documents that have a field called 'city' with a value of 'New York' [input] |
[output] | <div id="main-content"></div> [instruction] | Write an HTML code for a div tag with an id attribute of 'main-content'. [input] |
[output] | def evaluate_expression(expression): return eval(expression) print(evaluate_expression(expression)) [instruction] | Write a Python code snippet to evaluate an expression stored as a string. [input] | expression = '2+2*2'
[output] | SELECT * FROM records WHERE start_date >= '<date1>' AND end_date <= '<date2>'; [instruction] | Create a database query in SQL to filter records within a particular range. [input] | Table Name: records Attributes: id (INTEGER), name (TEXT), start_date (DATE), end_date (DATE)
[output] | 40 [instruction] | Find the largest value in an array of numbers. [input] | [5, 9, 40, 0.5, 3]
[output] | import urllib url = 'https://www.google.com/search?q=Covid-19+Pandemic' urllib.request.urlopen(url) [instruction] | Generate a URL to search the desired content on Google using Python. [input] | Search Keyword: Covid-19 Pandemic
[output] | [(1.4142135623730951, 0.7853981633974483), (4.47213595499958, 0.4636476090008061)] [instruction] | Convert an array from its x-coordinate values to an array of polar coordinates. [input] | [(1, 1), (4, 2)]
[output] | def init2DArray(rows, cols): # initialize the array arr = [[0 for i in range(cols)] for j in range(rows)] return arr [instruction] | Initialize a 2D array with `0`s. [input] |
[output] | def greatest_element(arr): # loop through elements of 1D array for i in range(len(arr)): max_element = arr[i][0] # loop through elements of 2D array for j in range(len(arr[i])): if arr[i][j] > max_element: max_element = arr[i][j] [instruction] | Given a 2D array, replace every element with the greatest element on its row. [input] | [[6, 2, 9], [3, 8, 7], [1, 4, 5]]
[output] | def even_nums_square(nums): for i in range(len(nums)): # check for even number if nums[i] % 2 == 0: # square the number nums[i] = nums[i] * nums[i] return nums [instruction] | In a given list, replace the even numbers by their square. [input] | [1, 2, 3, 4, 5, 6]
[output] | data = [(1, 5), (3, 4)] [instruction] | Consider the given list of tuples, remove the third element if it exists. [input] | data = [(1, 5), (3, 4), (2, 6, 4)]
[output] | filtered_list = list(filter(predicate, numbers)) #=> [2, 4, 6] [instruction] | Construct a lambda function to filter a given list based on a given predicate. [input] | numbers = [1, 2, 3, 4, 5, 6] predicate = lambda x: x % 2 == 0