instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create an algorithm for finding the factorial of a number using a for loop, without using the multiplication operator (*) or any built-in factorial functions. | codefeedback |
Generate a function in Python to print all prime numbers in a given range, where the range can be as large as 10^6. | codefeedback |
Explain the different scenarios in which a return statement can be encountered in a function, and describe what happens in each case. | codefeedback |
Create a function that takes in three parameters, x, y, and z, and returns the maximum value. If any of the parameters are negative, the function should return the absolute value of the maximum value. If all three parameters are zero, the function should return zero.
x = 8, y = -4, z = 12 | codefeedback |
Develop an algorithm to find the smallest element in a given array of integers using recursion. The algorithm should also keep track of the index of the smallest element and return it as well. The array may contain duplicates and the algorithm should handle this case efficiently. | codefeedback |
Create a new Keras model with the given input shape and output layer, but ensure that the model has a custom activation function in one of its hidden layers. The input shape is (10, 20, 3) and the number of classes is 2. | codefeedback |
Write a JavaScript function that returns 'true' if a given string is a palindrome and all the characters in the string are alphanumeric (letters and numbers), and 'false' otherwise. | codefeedback |
Rock-paper-scissors is a classic two player game. Create a program to generate all the possible outcomes of individual rounds in Rock Paper Scissors. Your program should also keep track of the total number of wins, losses, and draws for each player after a given number of rounds. | codefeedback |
Create an HTML page that displays the name, address, email, and phone number of a given user. Additionally, implement a form on the page that allows the user to update their information.
Name: John Doe
Address: 123 Main Street
Email: john@example.com
Phone: 987654321
Please ensure that the form properly validates t... | codefeedback |
Code an R function to compute the running total of a given array of numbers, but with the constraint that the function should not use any built-in looping or iteration functions (such as for loops or while loops). | codefeedback |
Compare the performance of quicksort, mergesort and heapsort on an unsorted array of size 1000, considering that the input array can contain duplicate elements. | codefeedback |
Show an example of using the Python module, os, to create a directory and then delete it. | codefeedback |
Generate an appropriate function in Java to check if a given number is a Strong Armstrong number. A Strong Armstrong number is a number that is equal to the sum of the factorial of its digits. The function should have a time complexity of O(log n) and a space complexity of O(1). | codefeedback |
Create a Django model class to represent a User. The User should have the following fields:
- First name (maximum length of 30 characters)
- Last name (maximum length of 30 characters)
- Email (maximum length of 50 characters, unique)
- Password (minimum length of 8 characters, at least one uppercase letter, one lowerc... | codefeedback |
Create a web page to display a result of a dictionary containing all countries in the world and its corresponding capital in three columns. Implement the sorting feature to allow users to sort the countries and capitals in ascending or descending order based on their names. Additionally, include a search bar that allow... | codefeedback |
Given a sorted array of size n, create a program to return the kth smallest element. Your program should have a time complexity of O(log n) and should not use any additional space. | codefeedback |
Define a function to merge two sorted arrays into a single sorted array, while ensuring a time complexity of O(n log n), where n is the total number of elements in both arrays.
arr1 = [1, 3, 5, 7]
arr2 = [2, 4, 6, 8] | codefeedback |
Write a script to identify the even numbers in the given PHP array, while ensuring that the solution uses a recursive approach and does not use any built-in PHP functions for filtering or iteration. The input array may contain up to 1000 elements, and the script should handle this efficiently.
$arr = [1, 2, 3, 4, 5, 6... | codefeedback |
Write a script to create a new array with only the odd numbers from the given array. The script should be optimized to have a time complexity of O(n), where n is the length of the input array. Additionally, the script should not use any built-in array filtering functions (e.g., filter, map) or additional data structure... | codefeedback |
Construct a program to shuffle the content of a list using the Fisher-Yates algorithm. | codefeedback |
Construct a convolutional neural network (CNN) with 5-layers to classify handwritten digits from the MNIST dataset. The network should have the following architecture:
1. Convolutional layer with 32 filters, each of size 3x3, using ReLU activation function.
2. Max pooling layer with pool size of 2x2.
3. Convolutional ... | codefeedback |
What does the position argument of the re.sub() method do and what is the time complexity of using this argument in a large input string? | codefeedback |
Write a function to perform vector addition for two 1D arrays. The function should also handle cases where the lengths of the two arrays are not equal.
[3, 4], [5, 6]
Example input:
[3, 4, 5], [5, 6]
Expected output: [8, 10, 5]
Example input:
[1, 2, 3], [4, 5, 6, 7]
Expected output: [5, 7, 9, 7] | codefeedback |
Create a function in JavaScript that takes in an array of strings and performs a bubble sort on it, sorting the strings in ascending order. The function should return the sorted array. | codefeedback |
Create a 3x4 NumPy array of random integers from 0 to 5, where each row should have at least one unique value. | codefeedback |
Generate a random alphanumeric string of length 20 using JavaScript. The string must contain at least 5 uppercase letters, 5 lowercase letters, 5 digits, and 5 special characters. | codefeedback |
Write a SQL query that returns the names of people who have a higher salary than their manager, while also considering employees who have the same salary as their manager. | codefeedback |
Develop a function to replace all consecutive whitespaces in a given string with a single space. However, the function should also ignore any whitespaces at the beginning or end of the string. | codefeedback |
Create a program that implements a queue with the following constraints and requirements:
- The queue must be implemented using a circular array.
- The program should include functions to enqueue an element, dequeue an element, and display the elements in the queue.
- The enqueue function should check if the queue is f... | codefeedback |
Create an assembly language program to sort a given array in descending order.
arr = [10, 6, 13, 2, 9, 4, 11, 8, 5, 7] | codefeedback |
Generate a code to extract the key-value pairs from a JSON string, where the JSON string may contain nested objects and arrays. Additionally, handle cases where the JSON string is malformed or contains invalid characters. | codefeedback |
Create a function to determine if a given String contains a valid US phone number, with the additional constraint that the phone number must be in the format "(XXX) XXX-XXXX" and the first digit of the area code cannot be 0 or 1. | codefeedback |
Read the code and determine if it will cause a memory leak. Consider that the code should be able to handle cases where the array size is not known in advance and the array needs to be dynamically resized. Additionally, the code should be efficient in terms of memory usage and minimize the number of reallocations. | codefeedback |
Create a function to perform recursive binary search in a sorted array. Your function should handle arrays of any size and should return the index of the target element if found, or -1 if the target is not present. Additionally, your function should have a time complexity of O(log n) and should not use any built-in sea... | codefeedback |
Write a Python program that adds two numbers and multiplies them. The program should also check if the sum of the two numbers is a prime number.
Input:
Two integers, a and b (1 <= a, b <= 100)
Output:
- The sum of the two numbers.
- The product of the two numbers.
- "Prime" if the sum is a prime number, "Not Prime" o... | codefeedback |
Rebuild the provided code using CSS flexbox and ensure that the left and right div elements have equal widths. | codefeedback |
Create a list containing the cubes of the first 10 prime numbers, excluding 2. | codefeedback |
Write a JavaScript function to get the date of the first Monday of a given month and year. The input should be the month (as a number, where January is 1 and December is 12) and the year. | codefeedback |
Write a function that uses recursion to return the factorial of a given number. | codefeedback |
Write a code to calculate the maximum, minimum, and average of ten numbers.
number_list = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
In addition to calculating the maximum, minimum, and average of the given numbers, you need to also calculate the sum of the numbers and the product of the numbers.
#Expected Output#
Maximum:... | codefeedback |
Given an XML document with nested nodes, parse the document and store the node names, attributes, and values in a list of dictionaries. Additionally, the attributes should be sorted in ascending order. | codefeedback |
Write a SQL query to list all employees who earn more than $1000 per month, reside in Texas, and have been with the company for at least 3 years. | codefeedback |
Construct a Huffman tree for the following set of characters, taking into consideration that the maximum number of characters is 50 and the frequencies of the characters are given as a range instead of a specific value.
Character | Frequency Range
G | 5-15
P | 9-19
T | 12-22 | codefeedback |
Given a list of strings and a single character, write a Python function to return the count of strings containing that character. Each string in the list should be considered case-insensitive. The function should ignore any strings that contain special characters or numbers. If the character is a vowel, the function sh... | codefeedback |
Write a PHP function that takes in an array of integers and returns the sum of all numbers. The function should have a time complexity of O(n) and a space complexity of O(1).
```php
function sumArray($nums) {
$sum = 0;
foreach($nums as $num) {
$sum += $num;
}
return $sum;
}
$nums = [1, 5, 10, 15, 20];
ech... | codefeedback |
Construct a decision tree for a given dataset of employees' performance based on their age, income, car ownership, and years of experience.
Age Range | Income Range | Car Ownership | Years of Experience | Performance
0-25 | 0-25k | No | 0-2 | Poor
26-45 | 0-25k | ... | codefeedback |
Design a Django web application to store user profiles, ensuring that each user profile must have a unique email address and a password with at least 8 characters. Additionally, implement a feature that allows users to reset their passwords by sending a verification code to their registered email address. | codefeedback |
Write a Python program to calculate the hypotenuse of a right triangle with base and height of 8 and 6 respectively. The program should also display the area of the triangle. | codefeedback |
Write a SQL query to identify the number of medicines sold per day between two dates, considering different categories of medicines and the quantity sold for each category. | codefeedback |
Write an SQL query to identify the product with the most sales quantities in a given dataset, where the sales quantities are only counted for weekdays (Monday to Friday) and for products that have a unit price greater than $100. | codefeedback |
Given a dataset containing multiple columns (Name, Age, Gender, Class, and Subject) of 2,000 students, write a Java program to output a new dataset that only contains the "Name", "Age", and "Class" columns, for students who are older than 18 years old and are enrolled in the Science subject. The output dataset should b... | codefeedback |
Create a JavaScript function to convert a date string of the form "DD/MM/YYYY" to a different string format, "Weekday, Month dd yyyy", where the input date is always in the range from "01/01/1900" to "31/12/2099". The function should handle leap years correctly. "14/08/2020" | codefeedback |
Given an array of numbers, write a C program to insert a given number "x" at the index "i" and push back all the previous numbers by 1. The array should have a maximum length of 10^6. You are not allowed to use any additional data structures. The program should have a time complexity of O(n), where n is the length of t... | codefeedback |
Generate a random string with the specified length n, where n is a positive integer less than or equal to 100. | codefeedback |
Create a C language function to convert a string in camelCase to a string in PascalCase. The function should have the following signature:
```c
char* convertCamelToPascal(char* str);
```
The function should take a null-terminated string `str` in camelCase and convert it to PascalCase. The function should return a dyn... | codefeedback |
Write a code to search a list of integers and print the index of the first matched item. The list may contain duplicate values. Find the index of the first occurrence of the target integer. If the target integer does not exist in the list, print -1.
nums=[4, 7, 1, 2, 5, 7], target=7 | codefeedback |
Design a Swift program to determine the number of days between two dates, considering leap years and different months having different numbers of days. The program should also handle invalid dates and provide appropriate error messages.
date1 = Date(year: 2019, month: 10, day: 15)
date2 = Date(year: 2020, month: 5, da... | codefeedback |
Using JavaScript, create a function to output all the divisors of a given number, without the number itself. The function should also handle negative numbers and decimals. The divisors should be returned in ascending order and as an array. Additionally, the function should include error handling to check if the input i... | codefeedback |
Given a positive integer n, print out an nxn matrix filled with numbers counting up from 1 to n x n. Each number should be replaced with its corresponding letter in the English alphabet. For example, 1 should be replaced with "A", 2 with "B", and so on.
Sample Input:
5
Sample Output:
A B C D E
F G H I J
K L M N O
P Q... | codefeedback |
Create an algorithm to compress a string by removing consecutive duplicate characters and count the number of times each character appears consecutively.
string = "aabcccccaaa"
Example:
Input: "aabcccccaaa"
Output: "a2b1c5a3"
Constraints:
- The input string will contain only uppercase and lowercase letters.
- The inp... | codefeedback |
Generate a function in Python that takes a number and a list as input and finds the number of occurrences of the number in the list. The function should handle cases where the number is a float, and return an error message if the number is not a valid float. Additionally, the function should ignore any occurrences of t... | codefeedback |
Rewrite this function in Python to take advantage of list comprehensions and ensure that the resulting list only contains positive numbers. Additionally, the function should sort the resulting list in descending order before returning it. | codefeedback |
Create a script in Python to convert fahrenheit temperatures to celsius, ensuring that the program can handle temperature inputs as floating-point numbers and round the converted temperature to the nearest integer. Additionally, the program should validate the user input, prompting them to re-enter the temperature if i... | codefeedback |
Solve the following non-linear programming problem:
Maximize 2x^2 + 3y^3
Subject to:
x^2 + 3y^2 ≤ 120
x + 2y^3 ≤ 100
x ≥ 0, y ≥ 0 | codefeedback |
Explain the algorithm used in linear search and provide a step-by-step implementation in a programming language of your choice. Additionally, discuss the time and space complexity of the algorithm and suggest possible optimizations to improve its performance. | codefeedback |
Convert the given vector into a 3x2 matrix. Each element in the matrix should be the sum of the corresponding element in the vector and its index. The matrix should be sorted in descending order. The vector should only contain positive integers. | codefeedback |
Create an HTML form to take input of a student's name, address, and contact information (phone number and email address). Implement validation on the form fields to ensure that the name and address fields are not left blank, the phone number is in a valid format, and the email address is valid. Display appropriate erro... | codefeedback |
Initialize a new array to 0 of size 10. The array must now be implemented using a linked list data structure instead of a regular array. | codefeedback |
Create an API using Node.js that returns the average height of all users from a MySQL database. Additionally, implement functionality to allow users to filter the average height based on a specified age range. | codefeedback |
Store a large dataset consisting of multiple columns in a database using SQL. The dataset should include various types of data such as names, ages, addresses, phone numbers, and email addresses. Ensure that the database is properly normalized to eliminate redundancy and ensure data integrity. The dataset should be effi... | codefeedback |
Create a list of strings from a given string where each string consists of consecutive characters that are not vowels. Let str = "hello world!" | codefeedback |
What feature of an Object-Oriented Programming language allows its objects to share tasks and data? Provide a detailed explanation of how this feature works and its importance in object-oriented programming. | codefeedback |
Explain what is linear regression and provide a Python code implementation that includes preprocessing steps such as handling missing values and categorical features, as well as evaluating the model using cross-validation. | codefeedback |
Write a SQL query to find the highest selling product in each state for the past month. Only include states that have made at least 1000 sales in the past month.
Sales(state, product, revenue, date) | codefeedback |
Write a code to parse a URL and return the domain name. You need to handle various scenarios such as different protocols (e.g. HTTP, HTTPS), different subdomains, and query parameters.
For example:
- Input: "https://example.com/page?param1=value1¶m2=value2"
- Output: "example.com"
In addition, you should handle t... | codefeedback |
Implement a function that copies a 2D array and returns the copied array.
The original array is as follows:
array = [[1, 2, 3], [4, 5, 6]]
The function should perform the following steps:
1. Create an empty list called 'copy_array' to store the copied array.
2. Iterate over each row in the original array using a for l... | codefeedback |
Write a Python function that takes in a dictionary and returns a new dictionary that only includes key-value pairs where the key starts with a vowel and the value is a list of integers. Additionally, the function should sort the keys in the new dictionary alphabetically. | codefeedback |
Create a PHP script to display the current date and day in a specified time zone, while also displaying the current time in 24-hour format. The script should also include error handling for invalid time zones and should only allow the use of built-in PHP date functions. | codefeedback |
Construct a HTML page which displays a table with all unique words of a given string, sorted in descending order based on their frequency. The frequency of a word is the number of times it appears in the given string. If two or more words have the same frequency, they should be sorted alphabetically.
Example:
For the ... | codefeedback |
Create a program in Python to print the first 10 multiples of a number.
The program should prompt the user to enter a number and validate that the input is a positive integer greater than 0. If the input is not valid, the program should display an error message and prompt the user to enter a valid number again.
Once a ... | codefeedback |
Create a HTML page that displays a dynamic animation of a red circle moving across the screen in a sinusoidal pattern. The circle should gradually change its size and color based on the mouse's position on the page. Additionally, implement a feature that allows the user to click on the circle and drag it around the scr... | codefeedback |
Construct a loop in Python that iterates through each row of a dataframe and performs the following operations for each row:
1. Print the index of the current row.
2. Print the values of all columns in the current row.
3. Calculate the sum of all numerical values in the current row.
4. Check if any missing values exist... | codefeedback |
Compose a function in C to display the result of raising a number to a positive power, considering the number may be a floating-point number and the power may be a negative integer. | codefeedback |
Generate code in C++ for performing Bubble Sort on an array of integers. Implement the sorting algorithm using a recursive approach and ensure that the code handles arrays of up to 10,000 elements efficiently. | codefeedback |
Create a function that takes in a list of strings and sorts it by the reverse order of its length. The function should also remove any duplicate strings from the list before sorting. The resulting sorted list should then be converted to all uppercase letters. Finally, the function should return the sorted and converted... | codefeedback |
Develop an algorithm in Java to compute the Fibonacci sequence, but with the following additional requirements:
1. The algorithm should be able to handle very large input values for n (e.g., n > 10^9).
2. The algorithm should have a time complexity of O(log n).
3. The algorithm should use a recursive approach without u... | codefeedback |
Write a Python program to calculate the sum of all prime numbers up to the given number. | codefeedback |
Write a code that allows a user to search an array of objects by any parameter, but the search must be case-sensitive and should consider only the first letter of each parameter. For example, searching for 'J' should return an object with the name starting with 'J', but searching for 'j' should not return any result. A... | codefeedback |
Create a function to identify whether a given number is a power of two.
num = 10
#Additional Instructions#
1. Your function should have a time complexity of O(1) and a space complexity of O(1).
2. You cannot use any built-in math or bitwise operators (e.g., log, pow, &, <<, etc.).
3. You cannot use any loops or recurs... | codefeedback |
Given a number n, count the total number of digit only divisors of n that are also prime numbers.
n = 100
#Explanation#
In the given test, we are counting the total number of digit only divisors of 100. The digit only divisors of 100 are 1, 2, 4, and 5. However, only 2 and 5 are prime numbers. Therefore, the output w... | codefeedback |
Write a code to find the shortest possible palindrome where the resulting palindrome must contain at least one uppercase letter. The code should work for any given string and should not use any built-in string manipulation functions or libraries. The input string will have a maximum length of 100 characters. | codefeedback |
Edit the following code so that it prints an appropriate error message when attempting to divide by zero, and also ensures that both num1 and num2 are positive integers. | codefeedback |
Create a class in JavaScript called "Person" that includes a constructor, a method for changing the greeting, and a method for saying the greeting. The class should also have a static variable that keeps track of the total number of Person objects created.
Additionally, create a subclass called "Student" that extends ... | codefeedback |
Implement a function in Python to convert a given sentence into title case, ensuring that all articles, prepositions, and coordinating conjunctions are lowercase unless they are the first or last word of the sentence. The function should also handle contractions and hyphenated words correctly. This is a sample sentence... | codefeedback |
Design a SQL query to select students older than 25 years from a database, who have a GPA higher than 3.5. | codefeedback |
Design a JavaScript function to convert the given number in scientific notation. The input number can have a maximum of 10 decimal places and can be in the range of 10^(-10) to 10^(10). The output should be a string representation of the number in scientific notation, with the exponent limited to a maximum of 5 digits. | codefeedback |
Create a MongoDB query to get all the documents from the collection where the state is 'CA' and the city is 'San Francisco'. | codefeedback |
Write a Java program to print out all possible combinations of the numbers from 0 to 9 in ascending order, without using any loop statements. | codefeedback |
Design a Python program to identify odd numbers in a given range and store them in a list.
The range should be specified by the user.
# Erroneous code reference #
Additionally, the program should check if the user input for the range is valid. If the user enters a non-numeric value or a negative value, the program sho... | codefeedback |
Create a MySQL query to find all users whose first name starts with 'J', last name starts with 'D', and the sum of the ASCII values of their first name and last name is a prime number. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.