[output] | def gcd(a, b) if b == 0 return a else return gcd(b, a % b) end end a = 10 b = 20 puts gcd(a,b) [instruction] | Generate a Ruby script to find the GCD of two given numbers. [input] |
[output] | .model small .data number dw 2,4,6,8,10,12,14,16,18,20 ,22,24,26,28,30,32,34,36,38,40 ,42,44,46,48,50,52,54,56,58,60 sum dw 0 .code main proc mov ax,@data mov ds,ax lea si,number mov cx,30 loop1: mov ax,[si] mov bx,2 mul b [instruction] | Create an assembly language program to sum 30 odd integers. [input] |
[output] | print("Hello, World!") [instruction] | Create a Swift program to print out the following: “Hello, World!” [input] |
[output] | def Fibonacci_number(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==1: return 0 # Second Fibonacci number is 1 elif n==2: return 1 else: return Fibonacci_number(n-1)+Fibonacci_number(n-2) [instruction] | Design a function that takes a number, n, and returns the n’th Fibonacci number. Remember that the Fibonacci sequence begins with 0, 1, and each subsequent number is the sum of the previous two numbers. [input] |
[output] | def count_substring(string, sub_string): count = 0 #Loop over the length of string for i in range(0, len(string)): # If a part of string matches with sub_string #increment count if (string[i:i+ len(sub_string)] ==sub_string): count += 1 [instruction] | Find the number of times the substring “ab” appears in the given string. [input] | text = "abraacadabrabracabracabracabra"
[output] | def is_anagram(string1, string2): # remove whitespaces string1 = string1.replace(" ","") string2 = string2.replace(" ","") # check length if len(string1) != len(string2): return False # create counters counter = {} for letter in string1: if letter i [instruction] | Create a function that takes two strings and returns a boolean representing whether or not the strings are anagrams of one another. [input] |
[output] | <html> <head> <title>Welcome</title> </head> <body> <h1>Hello World!</h1> </body> </html> [instruction] | Generate the HTML output for a page that has a title of "Welcome" and a body with a single header of "Hello World!". [input] |
[output] | def max_subarray(arr): max_so_far = 0 max_ending_here = 0 for i in range(len(arr)): max_ending_here = max_ending_here + arr[i] if max_ending_here < 0: max_ending_here = 0 if (max_so_far < max_ending_here): max_so_far = max_ending_here [instruction] | Design an algorithm to find the maximum subarray of an array of numbers. [input] |
[output] | def minWindow(s, t): # Initialize with None minWindowLength = None leftIndex = 0 # Balance will act as alphabet to store the occurrence of each character in t balance = {} for char in t: if char not in balance: balance[char] = 1 else [instruction] | Solve the following problem [input] | Given two strings s and t, find the minimum window in s which will contain all the characters in t.
[output] | def sort(arr): n = len(arr) # Various loops to sort the array for i in range(n): min_idx = i for j in range(i+1, n): if arr[min_idx] > arr[j]: min_idx = j arr[i], arr[min_idx] = arr[min_idx], arr[i] return arr [instruction] | Create a sorting algorithm [input] |
[output] | div { width:500px; height:500px; background-color:white; border-radius: 10px; border: 0.2px solid red; text-align:center; } [instruction] | Generate an appropriate CSS code to fulfill the following purpose [input] | Define a 500px x 500px div with rounded corners, a white background, a 0.2px red border, and text aligned to the center.
[output] | SELECT customer_name, COUNT(order_id) FROM orders GROUP BY customer_name ORDER BY COUNT(order_id) DESC LIMIT 1; [instruction] | Create an sql query to find the following [input] | Find the customer who has placed the highest number of orders.
[output] | def twoSum(N, arr): for i in range(len(arr)): for j in range(i+1, len(arr)): if arr[i] + arr[j] == N: return (arr[i], arr[j]) [instruction] | Construct an algorithm to fulfill the following purpose [input] | Find the two numbers that add up to a given number N.
[output] | print(' [instruction] | How would you print a big "Hello World" on the console output? [input] |
[output] | SELECT Name FROM Movies WHERE Release_Year > YEAR(CURDATE()) - 10; [instruction] | Design a SQL query to retrieve the names of movies released in the last 10 years. [input] |
[output] | const ItemList = ({ items }) => ( <ul> {items.map(item => ( <li>{`${item.name}: ${item.price}`}</li> ))} </ul> ); [instruction] | Create a UI component in ReactJs to render a list of items from an array of objects. [input] | const items = [ { name: "Apple", price: 12.99 }, { name: "Orange", price: 5.99 }, { name: "Banana", price: 3.99 }, ];
[output] | public class BankAccount { private String name; private String accountNumber; private double balance; public BankAccount(String name, String accountNumber, double balance) { this.name = name; this.accountNumber = accountNumber; this.balance = balance; } [instruction] | Design a class in Java to represent a bank account that has a balance, a name, and an account number. [input] |
[output] | import itertools def perms(lst): perm = itertools.permutations(lst) for i in list(perm): print(i) [instruction] | Generate a permutation of a given list of numbers. [input] |
[output] | const express = require('express'); /* Class for generating a RESTful API with Node.js */ class Api { constructor() { this.app = express(); } //Method for creating a route route(url, handler) { this.app.get(url, handler); } //Method for running the app [instruction] | Design a Node.js class to create a RESTful API. [input] |
[output] | div { width: 50%; padding: 30px; font-size: 20px; background-color: #EEE; border: 1px solid black; } [instruction] | Create a CSS style sheet to apply the following styles to a div element. [input] |
[output] | https://online-store.example.com [instruction] | Generate a unique URL for an online store. [input] |
[output] | The output of the code snippet is 10, as 2 and 6 (the two even numbers in the array) are added together to give 10. [instruction] | Find the output of the following .NET Core code snippet. [input] | int[] numbers = {2, 3, 5, 7}; var result = numbers.Where(x => x % 2 == 0).Sum();
[output] | const readFileAsync = function (file) { return new Promise((resolve, reject) => { fs.readFile(file, 'utf8', (err, data) => { if (err) reject(err); else resolve(data); }); }); } const dataPromise = readFileAsync('data.json'); dataPromise.then(data => { // do something with data }) [instruction] | Rewrite the following Node.js code using promises [input] | fs.readFile('data.json', 'utf8', (err, data)) => { if (err) throw err; // do something with data }
[output] | Assembly language is a low-level programming language that provides a symbolic representation of the machine instructions for a specific processor or family of processors. It is typically used when writing code for embedded systems, or when the target processor and/or instruction set of the program [instruction] | Explain the concept of assembly language. [input] |
[output] | def sum_odd_nums(n): total = 0 for i in range(1, n+1): if i % 2 != 0: total += i return total [instruction] | Use conditionals and a for loop to return the sum of all odd numbers up to a given number. [input] |
[output] | import random def random_permutation(input_list): n = len(input_list) for i in range( n - 1 ): j = random.randint(i, n-1) input_list[i], input_list[j] = input_list[j], input_list[i] return input_list [instruction] | Write a function to generate a random permutation of a given array. [input] | [1, 2, 3, 4, 5]
[output] | 3.0 [instruction] | Find the logarithm (base 10) of a number. [input] | 1000
[output] | dictionary = {4:4, 8:8, 12:12, 16:16} [instruction] | Store a list of elements in a dictionary, making each element the key and itself the value. [input] | list = [4, 8, 12, 16]
[output] | result = [[19, 22], [43, 50]] [instruction] | Multiply two matrices and return the resulting matrix. [input] | Matrix A = [[1, 2], [3, 4]] Matrix B = [[5, 6], [7, 8]]
[output] | [9, 8, 5, 2, 1] [instruction] | How would you display the below list in descending order? [input] | [2, 5, 8, 9, 1]