instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a class for a Rectangle with attributes for its length and width. Ensure that the length and width attributes are positive integers. If the length or width is not a positive integer, raise a ValueError with an appropriate error message.
Implement methods to calculate the area, perimeter, diagonal, and a new met... | codefeedback |
Design a function to calculate the distance between two points in a 3-D space. The points are represented as tuples of three integers, where each integer represents the coordinate along a different axis. The function should return the distance as a floating-point number rounded to two decimal places.
The formula to ca... | codefeedback |
Write an R code to identify DNA motifs of a given gene sequence, where a motif is defined as a consecutive subsequence of length greater than or equal to 4 that contains at least two occurrences of the letters "A", "C", "G", and "T" in a specific order. The input gene sequence can contain multiple motifs and may have a... | codefeedback |
Write a program that generates an HTML code for a webpage containing three interactive buttons. Each button should change its color when clicked and display an alert message when hovered over. The HTML code should be structured using appropriate tags and attributes. Additionally, the program should also include a form ... | codefeedback |
Construct a Node program to merge two sorted arrays in descending order and remove all elements that are divisible by 3. | codefeedback |
Suggest an in-place sorting algorithm to sort a list in ascending order, but with the constraint that you cannot use any built-in sorting functions or methods. The algorithm should have a time complexity of O(nlogn) and should use constant space. You can only use basic arithmetic and logical operations. The input list ... | codefeedback |
Construct a C# class to output the twin prime numbers up to n, where n is a prime number itself. Twin prime numbers are pairs of prime numbers that differ by 2, such as (3, 5), (11, 13), and (17, 19). The output should be sorted in ascending order. | codefeedback |
Construct a Java class to execute a binary search on a sorted array of integers and return the index of the target element. Implement the binary search algorithm without using any built-in search functions or libraries. The algorithm should have a time complexity of O(log n) and should be able to handle arrays with up ... | codefeedback |
Generate a Perl script to check for palindromes in a sentence.
The script should take user input for a sentence and determine if it is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, disregarding spaces, punctuation, and capitalizat... | codefeedback |
Sort the given list using the quicksort algorithm. However, you are not allowed to use any built-in sorting functions or libraries. You must implement the quicksort algorithm from scratch. Additionally, you are not allowed to use recursion in your implementation. You must use an iterative approach to implement the quic... | codefeedback |
Create a responsive CSS code to design an expandable menu with nested submenus. The menu should have a toggle button that expands and collapses the submenus when clicked. Additionally, the design should include hover effects for each menu item and a smooth transition animation when expanding or collapsing the submenus.... | codefeedback |
Write a python function called "capitalize_array" that takes in an array called "A" as a parameter. The function should capitalize the first letter of each word in the array and return the modified array.
Example:
Input: ['hello', 'world']
Output: ['Hello', 'World']
Note: You are not allowed to use any built-in Pytho... | codefeedback |
Edit the given code to fix the bug and increase the difficulty:
```python
def calculate_tax(price):
tax_rate = 0.20
total = price + (price * tax_rate)
# Apply a discount of 10% if the price is greater than $1000
if price > 1000:
discount = price * 0.10
total -= discount
# ... | codefeedback |
Edit the given code snippet to make it calculate the median instead of the average, ensuring that the code can handle both even and odd number of elements in the list. Additionally, you should optimize the code to have a time complexity of O(nlogn). The input list, x, will always be a list of integers and will have at ... | codefeedback |
Create an HTML table with the given list of student's marks. Each student has multiple subject marks. The table should display the student names, subjects, and marks in a structured format. Additionally, the table should be sortable by student name and subject in ascending or descending order. The table should also inc... | codefeedback |
Implement a function to solve a given cubic equation.
4x^3 + 2x^2 + 5x + 1 = 0 | codefeedback |
Write a code snippet to count the occurrence of the number 4 in an array called arr, but this time, you need to do it without using the built-in count function or any other function that directly solves the problem.
arr = [1, 4, 2, 4, 5]
Additional constraints:
- You cannot use any additional data structures to solve... | codefeedback |
Generate a code snippet to perform an element-wise multiplication of two NumPy arrays named A and B, where A and B are both 2-dimensional arrays with shape (3, 3). The elements of A and B should be randomly generated integers between 1 and 100.
Example:
A = [[32, 67, 18],
[99, 43, 86],
[52, 77, 25]]
B = [[26... | codefeedback |
Write the SQL query to delete all tables from a given database. Additionally, ensure that the query only deletes tables whose names start with the letter 'A' and have at least 10 columns.
database: testdb | codefeedback |
Generate a code snippet to find the top 3 highest numbers from an array A without using any sorting algorithm. The array A can have a maximum of 1000 elements. A = [9, 4, 18, 24, 7, 22, 11]
You are also not allowed to use any built-in functions or libraries that directly solve the problem. You need to come up with you... | codefeedback |
Select the most efficient and space optimized approach for compressing a given list of strings while ensuring that the compressed strings can be decompressed accurately. Additionally, the compressed strings should be sorted in ascending order based on their original lengths, and the compression algorithm should be able... | codefeedback |
Generate a code snippet to sort the students alphabetically by their last name in the following list, while also implementing a secondary sorting condition to sort the students by their first name in case two students have the same last name. If the first names are also the same, sort them based on their length of firs... | codefeedback |
Create an HTML table with the following requirements:
- The table must have a fixed width of 800 pixels.
- The table must have a border of 1 pixel.
- The table must have a header row with bold text.
- The table must have alternating background colors for each row.
- The table must have a maximum of 10 rows.
- The table... | codefeedback |
Write a Bash script that takes a directory path as an argument and runs multiple commands on all files within that directory. Each command should be executed sequentially, and the script should only consider files with a ".txt" extension. The script should also log the output of each command to a separate file named af... | codefeedback |
Given two matrices A and B, subtract matrix B from matrix A and store the result in matrix C.
A = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[10, 11, 12],
[13, 14, 15],
[16, 17, 18]]
To solve this problem, follow these steps:
1. Create an empty matrix C of the same size as A and B.
2. Iterate ove... | codefeedback |
Design and implement an efficient and scalable algorithm to perform advanced Natural Language Processing techniques, such as tokenization, lemmatization, and part-of-speech tagging, on a large volume of text data. The algorithm should be able to handle potential misspellings or variations in language. Additionally, pro... | codefeedback |
Modify the following SQL statement to select only the rows with prices greater than 100 and quantities less than 50. Ensure that the result is ordered by the product name in descending order. However, the table "products" has been changed to "items" and the column "product_name" has been renamed to "name". SELECT * FRO... | codefeedback |
Classify the sentiment of the following sentence as positive, negative, or neutral: "I am utterly devastated and heartbroken to be here, and my sadness knows no bounds." | codefeedback |
Identify the most suitable programming language and framework to create a highly secure, scalable, and high-performance web application that integrates real-time communication using web sockets and incorporates machine learning algorithms for personalized user recommendations. The application must support concurrent us... | codefeedback |
Create a random matrix using NumPy where the elements have 5 decimal places and are between -10 and 10. Additionally, compute and print the following statistics of the matrix elements: the sum of the positive elements, the product of the negative elements, the average of the absolute values of the elements, and the sta... | codefeedback |
Design an AI system for user authentication that can handle multiple authentication methods, including passwords, biometrics, and two-factor authentication. The system should be able to detect and prevent various types of attacks, such as brute force attacks, dictionary attacks, and phishing attempts. Additionally, dis... | codefeedback |
Generate a timestamp based on the current date and time in the format "YYYY-MM-DD HH:MM:SS", ensuring that the timestamp is in the UTC timezone and includes milliseconds. | codefeedback |
Design and implement a parallel algorithm to process a large dataset consisting of integers. The algorithm should compute the sum of all prime numbers in the dataset and return the result. Ensure that the algorithm utilizes all available CPU cores efficiently.
Additionally, the algorithm should also compute the produc... | codefeedback |
Create a function in Python that takes in an array of integers as input. Implement a sorting algorithm of your choice to sort the array in ascending order. Then, modify the sorting algorithm to also remove any duplicate elements from the array. Finally, calculate the sum of the first five elements in the sorted and mod... | codefeedback |
Sort the following array in descending order using JavaScript: [3, 7, 2, 9, 1, 5]. Additionally, you are not allowed to use the built-in sort() function. | codefeedback |
Suggest the most appropriate approach to train a neural network model with a large dataset while optimizing for computational efficiency and reducing overfitting. The model should also be able to handle imbalanced classes, and discuss methods to address this issue. Furthermore, evaluate the model's performance using ap... | codefeedback |
Edit the following C code so it runs correctly and outputs the square of the final score. Additionally, modify the program to take user input for the score and implement error handling for invalid input.
#include <stdio.h>
int main(){
int score;
printf("Enter your score: ");
if (scanf("%d", &score) != 1)... | codefeedback |
Design a SQL query to find the names, ages, and departments of the employees who have an age of 30 or more, joined the company before the year 2010, and have a salary greater than $50,000. The result should be ordered by the employee's last name in ascending order and then by the department name in ascending order.
Tab... | codefeedback |
Write a JavaScript code that gets the URL of a web page and extracts the domain name from it. Your code should handle URLs with subdomains and top-level domains with multiple parts, such as ".co.uk" or ".com.au". Additionally, the code should validate the extracted domain name to ensure it follows the proper formatting... | codefeedback |
Generate XML code for the following information about a student and their courses, with the added requirement of including the course instructor's information.
Student Name: John Doe
Student ID: 123456
Course: Computer Science
Course Code: CS101
Course Grade: A
Instructor Name: Jane Smith
Instructor ID: 789012 | codefeedback |
Debug the following PHP code which tries to connect to a remote host and retrieve data from a database. There are multiple errors in the code that need to be fixed.
$host = "myserver.com";
$user = "admin";
$password = "123456";
$database = "mydatabase";
// Create a connection object
$conn = new mysql_connect($host, $... | codefeedback |
Design a SQL query to select the top 5 movies based on the number of 'likes', the average rating of the movie, and the release year. Display the movie name, total number of likes, average rating, and the release year. Additionally, exclude movies with a rating lower than 7.5 and only consider movies released in the las... | codefeedback |
Given a list of strings in Python, convert it into a dictionary where the keys are the strings themselves and the values are the count of unique characters in each string. For example, for the input ["apple", "banana", "cherry"], the output should be {'apple': 4, 'banana': 3, 'cherry': 5}. | codefeedback |
Rewrite the given JavaScript code to make it compatible with older browsers. Additionally, ensure that the output is sorted in alphabetical order. The code should also check if the array "colors" contains any duplicates and remove them before sorting. | codefeedback |
Generate a Python dictionary that contains information about multiple students. Each student should have the following attributes:
- Name (string)
- Age (integer)
- Grade (string)
- Subjects (list of strings)
- Average score (float)
The dictionary should be structured as follows:
{
"student1": {
"name": "J... | codefeedback |
Write a JavaScript function that takes an array of numbers and returns an array containing only the even numbers. The function should have a time complexity of O(n) and should not use any built-in JavaScript methods such as filter or map. Additionally, the function should not use any loops or recursion. | codefeedback |
Create a class in Java called Student that stores six pieces of data: name, id, major, gpa, a list of courses taken, and a list of extracurricular activities. Additionally, implement a method to calculate the overall grade of the student based on the grades obtained in each course. The overall grade should be calculate... | codefeedback |
Edit the following HTML page to add a new heading and a link. The heading should have a font size of 24 pixels and be aligned to the right side of the page. The link should have a hover effect that changes the background color to a gradient from red to blue. The link should also open in a new tab when clicked. Addition... | codefeedback |
Define a function that searches for a specific element in an array, but the array can now contain duplicate elements. Additionally, the function should return the index of the first occurrence of the element if it is found, otherwise it should return -1. The function should also take into consideration that the array m... | codefeedback |
Explain the concept of expression-oriented programming in Java and provide an example of erroneous code that demonstrates the potential challenges and complexities associated with this programming paradigm. Additionally, describe the benefits and limitations of using expression-oriented programming in Java. | codefeedback |
Code a solution that prints out the string "Hello, [name]!" using string interpolation in JavaScript. The solution should handle cases where the name is provided in a different format, such as all lowercase or all uppercase, and still output the name with the first letter capitalized and the rest in lowercase. The solu... | codefeedback |
Using the following PHP array, output each name in its own bold tags. Additionally, the output should be sorted in descending order alphabetically. | codefeedback |
You are given a list of integers. Write a program to determine the fraction of numbers in the list that are multiples of 3 and have a digit sum greater than 10. The list may contain up to 10^6 integers, where each integer can range from -10^6 to 10^6. The fraction should be represented as a decimal rounded to 4 decimal... | codefeedback |
Calculate the Euclidean distance between two points (x1, y1) and (x2, y2). The Euclidean distance is defined as the square root of the sum of the squares of the differences between corresponding coordinates.
For example, for the points (5, 3) and (8, 12), the Euclidean distance would be √[(8-5)² + (12-3)²] = √[3² + 9... | codefeedback |
Edit the following HTML code to allow Google Chrome to accurately render the page. The table must have a border of 1 pixel and a cellpadding of 5 pixels. Additionally, the text in each table cell must be aligned to the center. The table must also have alternating row colors, with one row being white and the next row be... | codefeedback |
You are given a string s, output the length of the longest substring with no repeating characters. If there are multiple substrings with the same maximum length, output the length of the substring that appears first in the original string.
Example:
Input: s = "abcabcbb"
Output: 3
Explanation: The longest substring wi... | codefeedback |
You are given an array of positive integers and an integer k. Output the maximum sum of k consecutive elements in the array, such that the sum is divisible by a given number m. The time complexity of your solution should be O(n), where n is the length of the array.
array = [2, 3, 5, 7, 8, 10, 12, 15, 18]
k=4
m=3 | codefeedback |
Rewrite the XML string to include additional nested elements and attributes. The task is to locate and erase all text nodes from the modified XML string. Additionally, all `<div>` elements should have a new attribute called "id" with a unique integer value. Finally, the `<span>` elements should be moved outside of the ... | codefeedback |
Rewrite the CSS styling for the HTML structure in Task 2 to make the webpage responsive for different screen sizes. Additionally, implement a toggle button that allows users to switch between light and dark themes. | codefeedback |
Create a C program to print the prime numbers from 1 to 100, except for any number that is a perfect square. Additionally, for any prime number that is a palindrome, print "PalindromePrime" instead of the number. For any number that is both a prime number and a perfect square, print "PerfectSquarePrime" instead of the ... | codefeedback |
Generate a valid CSS rule to center align the text with the class "heading_text", set the font size to 24 pixels, and add a subtle animation that fades the text in and out. | codefeedback |
Create a function in R for converting a string into uppercase, while also removing any digits present in the string and sorting the resulting characters in alphabetical order. The function should also handle punctuation marks and special characters, and remove them from the string before converting it to uppercase and ... | codefeedback |
## Problem ##
Implement a function `create_nim_board(n, k)` that creates a Nim game board with size `n`, where `n` is an integer greater than 1.
The Nim game board is a row of `n` boxes, with each box initially containing a certain number of stones. The goal of the game is to remove all the stones from the board.
The... | codefeedback |
Create a PHP class to represent a student with the following data fields: first name, last name, age, GPA. Additionally, the student class should have the following methods:
1. `getFullName()` - This method should return the full name of the student (first name + last name). The full name should be in Title Case forma... | codefeedback |
Create an HTML page that has a responsive navigation bar, two sections, a footer, and a link to a website.
The navigation bar should have a logo on the left side and three navigation items on the right side. It should collapse into a hamburger menu on smaller screens.
The first section should have a heading, a subhe... | codefeedback |
Write a function in Python for sorting a given list of positive integers in ascending order, using the Bubble Sort algorithm. The function should also calculate and return the number of comparisons and swaps performed during the sorting process. Additionally, the function should handle duplicate numbers in the list, en... | codefeedback |
Design an SQL query to select the first and last name of all users who are over the age of 25, have made at least 3 purchases in the last month, and have a total purchase amount greater than $100. | codefeedback |
Write a SQL query to find the name, average value, and total number of transactions for each customer, as well as the percentage of transactions that have a value greater than the average value. Additionally, include the following:
1. Calculate the average value and total number of transactions separately for each cus... | codefeedback |
Create a dictionary with the keys of the students' IDs and their corresponding grades as the values. The student IDs are unique and will always be integers. The grades are represented as floating-point numbers between 0 and 100.
Write a function that takes in two lists, student_ids and grades, and returns the dictiona... | codefeedback |
Given a list of strings, return a new list with only the strings that contain both the letters "e" and "o" and have a length greater than 5. The returned list should be sorted in descending order based on the number of occurrences of the letter "e" in each string. If two or more strings have the same number of occurren... | codefeedback |
Write a Bash shell script to print the unique elements in the given array, while also ensuring that the output is sorted in ascending order. Additionally, you are not allowed to use any built-in array manipulation functions or commands. The input array can have up to 1000 elements, and you must solve the problem using ... | codefeedback |
Write a function in any programming language that takes in a search query as input and generates an HTML code that embeds a Google Search page inside an iframe. The function should also allow for customization of the iframe dimensions, such as width and height. Additionally, the function should include error handling t... | codefeedback |
Edit the given C++ code for reversing a given string. The code should also ignore any whitespace characters, punctuation marks, and special characters in the string, and reverse only the alphanumeric characters. Additionally, the code should reverse the case of each alphabetic character in the string. | codefeedback |
Search and delete a specific record from the given SQL table "products" where the record's ID is a prime number between 10 and 100, ensuring that the deletion is only allowed if the record has not been modified in the last 48 hours and the product's price is higher than $100. | codefeedback |
Design a CSS style sheet for a given HTML table that includes the following requirements:
1. Each cell should have a unique background color based on its position in the table. For example, the first cell in each row should have a background color of red, the second cell should have a background color of blue, and so ... | codefeedback |
Write a JSP code snippet to implement a binary search algorithm on an array of integers. The array should be sorted in ascending order before performing the search. Additionally, display the number of comparisons made during the search process. | codefeedback |
Construct a while loop to print out all prime numbers between 1 and 1000 in reverse order. | codefeedback |
Assign values to the given array of length 10, where each element should be a prime number greater than 100, and print it in descending order using a Java program. | codefeedback |
Sort the numbers in an ascending order in the given array, ensuring that the solution is implemented using a recursive algorithm and has a time complexity of O(n log n). Additionally, the implementation should be done without using any built-in sorting functions or data structures. The array can contain both positive a... | codefeedback |
Suggest a LINQ query to retrieve fields "name" and "date" from an array of objects, but only for objects where the name starts with the letter "J", the date is in the year 20, and the name contains at least 5 characters. | codefeedback |
Construct an IF-ELSE statement that tests whether a given number is positive, negative, or zero, and prints the result accordingly. The program should also handle erroneous inputs where the given number is not a valid integer.
to_test = "10" | codefeedback |
Generate a valid C++ code to implement a doubly linked list with the following operations:
1. Insertion of a new node at the beginning of the list with time complexity O(1).
2. Deletion of a node from the end of the list with time complexity O(1).
3. Finding the length of the list with time complexity O(n).
4. Reversin... | codefeedback |
Create an HTML form that contains the following fields:
- A text input field for the user's name.
- A radio button group for the user to select their gender.
- A dropdown menu for the user to select their age range (e.g. 18-25, 26-35, etc.).
- A checkbox for the user to agree to the terms and conditions.
When the form... | codefeedback |
Place the missing parenthesis in the given algorithm, ensuring that the start and end variables are updated correctly based on the condition. Additionally, you need to handle the scenario where the value of k is greater than the remaining elements in the array, ensuring that end does not exceed the length of the array. | codefeedback |
Get the sum of all positive integers in the given array, but without using any loops or built-in functions. The time complexity should be O(n), where n is the number of elements in the array.
int[] numbers = {-1,2,-3,4,5,6,-7,8,9};
int sum = numbers[1] + numbers[3] + numbers[4] + numbers[5] + numbers[7] + numbers[8];
... | codefeedback |
Create a SQL query for finding all books written by a given author, but also include the average rating for each book, the total number of copies sold for each book, and the average price of each book. Additionally, sort the results in descending order of the average rating. | codefeedback |
Given a sorted array of integers and an integer value, figure out whether the given value is present in the array or not using a binary search algorithm. If the value is present, return the index at which it is found. If the value is not present, return the index at which it should be inserted to maintain the sorted or... | codefeedback |
Create a mapping of keys and values from a given dictionary, ensuring that all keys are uppercase and all values are positive integers.
Given dictionary: {"apple":3, "banana":5, "cherry":7, "date":11}
Additional requirements: The mapping should only include keys starting with a vowel and the sum of all values should be... | codefeedback |
Write a PHP script to find the 5th element of an array. The array must contain at least 10 elements and the 5th element must be greater than or equal to 50. Additionally, the script must handle the case where the 5th element is not present in the array and display an error message.
$arr = array(14,32,25,19,55,89,130,7... | codefeedback |
Given a string of words, calculate the number of unique words. The string may contain special characters, punctuation marks, and numbers. Additionally, the case sensitivity should be taken into account when determining uniqueness.
String str = "This is a test, to see how many unique words are in this string! 123"; | codefeedback |
Write a Python function that accepts a list of numbers and returns the sum of all odd numbers present in the list. If the list is empty or does not contain any odd numbers, the function should return 0. The function should also handle cases where the input list contains non-integer elements, ignoring them and consideri... | codefeedback |
Generate the output for this algorithm with the given input. Your solution should use a recursive approach.
Input: array = [5, 4, 1, 2, 6]
Output:
8
*Note: The solution should not use any built-in sorting functions or loops.
*Rewritten Test Difficulty:*
In addition to generating the output for the algorithm, modify... | codefeedback |
Suggest an algorithm to find the pair of values in an array that has the maximum sum, without using any built-in sum or pair-related functions. The algorithm should have a time complexity of O(n^2) or better.
arr = [2, 3, 5, 7, 9, 4, 6]
Additional requirements:
1. The algorithm should handle arrays with duplicate val... | codefeedback |
Construct a MySQL query to select the book titles and authors' names from the table "Books" where the book's publication year is greater than 2000 and the price is less than $50. Additionally, sort the results in descending order based on the book's publication year. | codefeedback |
Create a JavaScript class for a customer address book with the following functionalities:
1. Ability to add a new customer to the address book. The time complexity of adding a customer should be O(1).
2. Ability to update an existing customer's information. The time complexity of updating a customer's information shou... | codefeedback |
Write a function in JavaScript to sort an array of objects based on a selected key. The selected key can be either "name" or "age". The function should sort the array in descending order based on the selected key. If two objects have the same value for the selected key, they should be sorted based on the reverse alphab... | codefeedback |
Determine the accuracy of a model trained on a given dataset, while also calculating various performance metrics such as precision, recall, and F1 score. Additionally, provide a detailed confusion matrix to analyze the model's performance across different classes. However, there is a bug in the code that needs to be fi... | codefeedback |
Write a SQL query to fetch records from the table Persons where the city is either Dallas or Chicago, and the Lastname starts with the letter 'S'. Additionally, the ID should be greater than 100, and the Firstname should not contain any numbers.
Table name: Persons
Fields: ID (integer), Lastname (varchar), Firstname ... | codefeedback |
Create a Python program that takes two strings as input and finds the length of their longest common subsequence. Additionally, the program should also print out all possible longest common subsequences for the given input strings.
You may assume that the input strings only contain lowercase letters.
Example:
Input:... | codefeedback |
Create a JavaScript function that recursively traverses the DOM and changes the color of a given element and all its child elements according to the following requirements:
1. The function should accept two parameters: the target element and the desired color.
2. The function should be able to handle elements with mul... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.