← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 438/668
🔀 랜덤
불러오는 중…

[output] | function longestCommonPrefix(str1, str2) { let prefix = ''; let min_len = Math.min(str1.length, str2.length); for (let i = 0; i < min_len; i++) { if (str1[i] === str2[i]) { prefix += str1[i]; } else { break; } } return prefix; } let [instruction] | Write a JavaScript program to find the longest common prefix string amongst two given strings? [input] | "hello" and "heaven"

[output] | #!/bin/bash arr=(2 3 6 8 10) target=8 function binary_search() { left=0 right=${#arr[@]}-1 while [ $left -le $right ] do mid=$(( ($left+$right)/2 )) if [ ${arr[$mid]} -eq $target ] then echo "Number found at position: $(($mid+1))" return elif [ [instruction] | Write a shell script to perform a binary search of an array [input] | [2, 3, 6, 8, 10], 8

[output] | <!DOCTYPE html> <html> <head> <title>Input fields</title> </head> <body> <h1>Input fields to enter two numbers</h1> <form> <p>Enter the first number:<p> <input type="number" name="number1"><br><br> <p>Enter the second number:</p> <input type="number" name [instruction] | Create a web page to display two input fields to enter the two numbers [input] |

[output] | UPDATE employees SET JobTitle = 'Software Engineer' WHERE Name = 'John' [instruction] | Generate a SQL query to update the job title for all the employees with name 'John' [input] |

[output] | def contains_python(string): if "Python" in string: return True else: return False print(contains_python(text)) # False [instruction] | Write a Python function that takes a string as an argument and checks if it contains the word “Python”. [input] | text = "This sentence does not contain the word Python"

[output] | def sort_array(arr): # Loop through the array, swap each element until it is in order (ascending) for i in range(len(arr) - 1): for j in range(i + 1, len(arr)): if arr[i] > arr[j]: temp = arr[i] arr[i] = arr[j] arr[j] = temp # Return the sorted array [instruction] | Create a process to sort an array of numbers from least to greatest. [input] | arr = [3, 4, 12, 1, 5, 85]

[output] | def detect_duplicate(array): # Create a hash table to store elements in the array hash_table = dict() # Iterate through the array, check if the elements are already stored in the hash table # If the elements are already stored in the hash table, return True for element in array: [instruction] | Create an algorithm that uses a hash table to detect if an element is a duplicate. [input] | array = [2, 3, 4, 5, 6, 3]

[output] | def reverse_string(string): # Create an empty string rev_string = "" # Iterate through the string and build the reversed string for char in string: rev_string = char + rev_string # Return the reversed string return rev_string print(reverse_string(string)) # dlrow olleH [instruction] | Create a process to reverse a string without using any built-in functions. [input] | string = "Hello world"

[output] | def num_mult_table(num): # Iterate through the numbers from 1 to 10 for i in range(1,11): # Print the multiplication table for the given number print("{} x {} = {}".format(num, i, num*i)) num_mult_table(num) # Output # 6 x 1 = 6 # 6 x 2 = 12 # 6 x 3 = 18 # 6 x 4 = 24 # 6 [instruction] | Display the multiplication table for a given number. [input] | num = 6

[output] | def autocomplete(user_input, words): # Store the output words in a list output = [] # Iterate through the words and check if the user input matches the beginning of the word for word in words: if word.startswith(user_input): output.append(word) # Return the output wor [instruction] | Create a program that implements an autocomplete or predictive search feature. [input] | words = ["Apple", "App", "Application", "Applications", "Apples", "Ace", "Acer"]

[output] | def join_strings_with_pipe(words): # Join the words with a pipe return "|".join(words) print(join_strings_with_pipe(words)) # Apple|App|Application|Applications|Apples|Ace|Acer [instruction] | Write a function that takes a list of strings and joins them together with a pipe (|). [input] | words = ["Apple", "App", "Application", "Applications", "Apples", "Ace", "Acer"]

[output] | def double_even_numbers(lst): # Iterate through the list and double the even numbers double_lst = [] for num in lst: if num % 2 == 0: double_lst.append(num * 2) else: double_lst.append(num) # Return the new list return double_lst print(double_even_numbers(l [instruction] | Given a list of integers, return a new list with even numbers doubled. [input] | lst = [1, 2, 3, 4, 5, 6]

[output] | from collections import Counter def most_frequent_letter(string): # Count the letter frequency words = Counter(string) # Identify the most frequent letter most_common = words.most_common(1)[0][0] # Return the most frequent letter return most_common print(most_frequent_lette [instruction] | Write a function to identify the most frequent letter in a string. [input] | string = "Hello Universe"

[output] | def get_sum_of_evens(numbers): sum_of_evens = 0 for num in numbers: if num % 2 == 0: sum_of_evens += num return sum_of_evens numbers = [2, 4, 5, 6, 7, 8] print(get_sum_of_evens(numbers)) [instruction] | Generate a script to print out the sum of all even numbers in a given list [input] | [2, 4, 5, 6, 7, 8]

[output] | def is_substring(s1, s2): return s2 in s1 [instruction] | Create a python script to check if a substring exists in a given string [input] |

[output] | public static double calculateAverage(int[] array) { double sum = 0; for(int i = 0; i < array.length; i++) { sum += array[i]; } return sum / array.length; } [instruction] | Write a function in Java which takes an array of integers and calculates the average value. [input] |

[output] | SELECT title, count(*) as cnt FROM movie_table GROUP BY title ORDER BY cnt DESC LIMIT 10; [instruction] | Design an SQL query to select the top 10 most popular movies from a given movie table. [input] |

[output] | import React from 'react'; const ItemList = (props) => { return ( <div> {props.items.map((item) => ( <div key={item.id} className="item"> {item.name} <button className="delete-btn" onClick={() => props.onDeleteItem(item.id)} [instruction] | Create a React component which shows a list of items with a delete button for each item. [input] |

[output] | import pandas as pd from sklearn.linear_model import LinearRegression # load data data = pd.read_csv('cars.csv') # create feature matrix X = data[['make', 'model']] # set target variable y = data['price'] # one-hot encode categorical make and model data X = pd.get_dummies(X, columns=['make', 'mo [instruction] | Use linear regression to predict the price of a car based on its make and model. [input] | make = ['Mazda', 'Volkswagen', 'Chevrolet'] model = ['3', 'PASSAT', 'Malibu']

[output] | <?php function check_equal($num1, $num2) { if($num1 == $num2){ return true; } else{ return false; } } $num1 = 5; $num2 = 5; $result = check_equal($num1,$num2); if($result) { echo "Numbers are equal"; } else { echo "Numbers are not equal"; } ?> [instruction] | Design a PHP program to check whether two given numbers are equal or not. [input] |

[output] | const MongoClient = require('mongodb').MongoClient; const assert = require('assert'); // Connection URL const url = 'mongodb://localhost:27017'; // Database Name const dbName = 'QuotesDB'; // Create a new MongoClient const client = new MongoClient(url); // Use connect method to connect to the Serv [instruction] | Using MongoDB and Node.js, create an API to post a new quote to a given collection. [input] | quote = "A journey of a thousand miles begins with a single step."

[output] | def merge_lists(list1, list2): merged_list = list1 + list2 return list(dict.fromkeys(merged_list)) [instruction] | Create a function to merge two lists and remove duplicates. [input] | list1 = [1, 3, 5, 7] list2 = [2, 3, 8, 10]

[output] | for(var i = 1; i <= 10; i++) { for(var j = 1; j <= 10; j++) { console.log(i + " x " + j + " = " + (i*j)); } } [instruction] | Write a JavaScript program to generate and print multiplication table up to 10. [input] |

[output] | return "I'm doing great, thank you for asking!" [instruction] | Write an instruction for a GPT model to generate a response when it is given a given an English sentence as input. [input] | "How are you today?"

[output] | def filter_list(list, length): return [string for string in list if len(string) > length] [instruction] | Write a Python function to filter a given list of strings and return the list with the strings having length greater than the given number. [input] | list = ['Example', 'cat', 'dog', 'hello', 'word'] length = 4

[output] | import xmltodict def xmlToJsonObject(xmlStr): return xmltodict.parse(xmlStr) [instruction] | Create a function to convert an XML string to a JSON object. [input] |

[output] | def subtract_numbers(num1, num2): return num1 - num2 [instruction] | Write a Python function to subtract two given numberss. [input] |

[output] | [instruction] | Check the human readable date and convert it to the ISO 8601 format. [input] | Monday, April 7th, 2020

[output] | 5 [instruction] | Read the given list and return the last element. [input] | mylist = [1,2,3,4,5]

[output] | uniquelist = [] for string in mylist: if string not in uniquelist: uniquelist.append(string) print(uniquelist) [instruction] | Create a program in Python that will take in a list of strings and print out each unique string in the list. [input] | mylist = ["Hello", "World", "Hello", "WDI", "Class"]

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프