instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Create a JavaScript function that calculates the average of the even numbers between 1 and n in an array. The function should handle scenarios where the array may contain non-numeric values, and should ignore those values when calculating the average. Additionally, the function should throw an error if the array contai...
codefeedback
Write a Java code to read a string from the user and print it reversed, but only for strings that contain at least one special character (e.g. !@#$%^&*). If the input string does not contain any special characters, the program should prompt the user to enter a different string. The solution should also handle both uppe...
codefeedback
Write a Node.js code to get a list of the most starred Node.js repositories on GitHub in the last month, while excluding repositories that have less than 1000 stars and have been forked more than 50 times. Additionally, sort the repositories based on the number of open issues they have, in descending order.
codefeedback
Create a CSS class to style an anchor tag with the following specifications: 1. The anchor tag should have a background color of #ff0000. 2. The anchor tag should have a font size of 16 pixels. 3. The anchor tag should have a padding of 10 pixels on all sides. 4. The anchor tag should have a text color of #ffffff. 5. W...
codefeedback
Write an SQL query to find all customers who have not placed any orders in the last 30 days, and whose last name starts with the letter 'S'.
codefeedback
Create a JSON object to represent a profile deleted from a social platform. The JSON object should include the following information: 1. User ID: A unique identifier for the user's profile (string). 2. Username: The username associated with the profile (string). 3. Email: The email address associated with the profile ...
codefeedback
Write an HTML program to display a web page with a table, a heading, and a div. The table should have at least 10 rows and 10 columns, and each cell should contain a different color. The heading should have a font size of 24px, be centered on the page, and have a gradient background color that transitions from one colo...
codefeedback
Write a Node.js server program to handle HTTP requests to a web page. Additionally, implement error handling for any internal server errors and send a customized error message to the client. The error message should include the specific error code and a stack trace of the error.
codefeedback
Create a SQL query to find the names, addresses, and email addresses of customers who have made at least 3 orders, with each order containing at least 2 different products and the total price of all products in each order is more than $200. Additionally, the query should only consider orders placed in the last 6 months...
codefeedback
What MySQL query can be used to retrieve the most recent record in a table that satisfies a specific condition, while excluding records with null values, and ordering the results in descending order based on a timestamp column? Additionally, the query should only return records where the value in a separate column is g...
codefeedback
Write a function in Java to generate all possible strings of length n drawn from 0–9, where each digit can only appear once in each string. The function should also calculate and return the sum of all the generated strings as an integer. Example: Input: n = 3 Output: {"012", "021", "102", "120", "201", "210"} Sum: 114
codefeedback
Suggest a MySql query to check if a given table contains a record with specified column values, while also considering the following constraints: 1. The table should have an additional column called "email" of type VARCHAR(255). 2. The record should have a unique identifier column called "id" of type INT. 3. The speci...
codefeedback
Write a Python program to calculate the sum of all multiples of 3 and 5 between 1 and a given number, excluding any multiples that are divisible by both 3 and 5. Additionally, if the given number is divisible by both 3 and 5, exclude it from the sum. For example, if the given number is 20, the program should calculate...
codefeedback
Generate a code to take in a list of sentences, totaling no more than 1000 words, and output the longest sentence. The code should also exclude any sentences that contain numbers or special characters. Additionally, the code should also ignore any sentence that is a question or contains the word "and". The code should ...
codefeedback
Write an SQL query to find the products that have not been ordered by any customers, and have not been shipped yet. Consider products that have been ordered but not shipped yet as well. Additionally, include products that have been shipped but have not been paid for. TABLE products Columns: * product_id (integer) * ...
codefeedback
Create a JavaScript function that takes an array of integers as input and returns a new array where each element is the product of all the elements in the original array except the current element. The function should have a time complexity of O(n) and a space complexity of O(1). For example: Input: [1, 2, 3, 4] Outpu...
codefeedback
Create a web application that allows users to register for an account. The registration form should include the following fields: - First Name - Last Name - Email - Password - Confirm Password The application should enforce the following validation rules: 1. All fields are required and cannot be empty. 2. The email f...
codefeedback
Describe two ways to prevent SQL injection attacks in a multi-threaded web application while ensuring data integrity and minimizing performance impact, using only native database functionality and without relying on any third-party libraries or frameworks.
codefeedback
Describe the purpose, syntax, and time complexity of the 'forEach' method in JavaScript. Provide an example usage of the method and explain its limitations compared to other iteration methods available in JavaScript. Additionally, explain how the 'forEach' method can be used in conjunction with arrow functions and demo...
codefeedback
Create a Python script to scrape HTML data from a website and store it in a database. The script should include the following steps: 1. Accept a user input for the URL of the website to scrape. 2. Check if the URL is valid and accessible. If not, display an error message and terminate the program. 3. Establish a conne...
codefeedback
Write an algorithm for sorting a single-linked list in descending order, using only constant extra space.
codefeedback
Write a program that counts the number of occurrences of a character in a given string. The program should handle multiple characters to count and return the total count of all the characters. Additionally, the program should also ignore case sensitivity while counting the occurrences. String: "Hello World", Characters...
codefeedback
Update the code so that it only prints out the lines which contain the word “print” and start with a lowercase letter. Additionally, the code should remove any leading or trailing whitespace from the lines before checking for the desired pattern. src_code = """if x == 1: print "hello" if y == 2: Print "world" pr...
codefeedback
Write a Python function called `check_divisibility` which takes a positive integer as an argument and print "even" if the number is divisible by 4 and not divisible by 3, print "odd" if the number is divisible by 3 and not divisible by 4, print "both" if the number is divisible by both 4 and 3, and print "neither" if t...
codefeedback
Design an algorithm to classify a large collection of text documents into a specific number of topics, while considering their semantic meaning and contextual relevance. You are required to implement the algorithm in a programming language of your choice. The algorithm should perform the following steps: 1. Preprocess...
codefeedback
Update the code to ensure that an error is raised if the input is the wrong type and the age provided is not a prime number. Additionally, modify the function to return the sum of all prime numbers between 0 and the given age, instead of just adding 5 to the age. def age_calc(age): if not isinstance(age, int): ...
codefeedback
Rewrite the code to find the maximum value in an array and return it. However, you are not allowed to use any built-in functions or methods for finding the maximum value, such as max() or sort(). You must find the maximum value using only loops and conditional statements.
codefeedback
Add a parameter to the function to calculate the area of a triangle, given the lengths of all three sides and the radius of the inscribed circle. The function should return the area of the triangle using the formula A = rs, where A is the area, r is the radius of the inscribed circle, and s is the semi-perimeter of the...
codefeedback
Make a function which takes an array of numbers as an argument and returns the sum of all the numbers that are divisible by 3, have a remainder of 1 when divided by 4, and are greater than 10. Provide a piece of erroneous code as a reference: ```python def find_sum(numbers): sum = 0 for num in numbers: ...
codefeedback
Implement a program in Java that simulates a garbage collector. The program should have the following requirements: 1. The program should allocate memory dynamically using a custom memory allocator. 2. The program should track the allocated memory and the objects within it. 3. The program should implement a garbage co...
codefeedback
Write a function to find the average of given numbers using a list, but you are not allowed to use any built-in functions or libraries that calculate the sum or average. You must implement the calculations manually. The list may contain duplicate numbers. Additionally, you are not allowed to use any loops or recursion....
codefeedback
What is the time complexity of finding the sum of all the elements in a pandas dataframe with n columns and m rows?
codefeedback
Using SQL, write a query to find the total salary of employees whose salary is greater than the average salary of all employees in the Employee table, and have joined the company within the last 6 months.
codefeedback
Write a Python function that takes a list of integers as input and returns a new list containing only the even integers from the original list. The function should use the yield keyword to generate each even integer one at a time. Additionally, the function should raise an exception if any of the integers in the origin...
codefeedback
Suggest an efficient algorithm to implement a stack with two queues, ensuring constant time complexity for the push, pop, and top operations. Additionally, the stack should have a maximum capacity of N elements, where N is a positive integer. However, you are now required to implement the stack using only one queue in...
codefeedback
Compute the factorial of a given number in Java, ensuring that the solution includes the usage of at least one loop structure. Example: Input: 5 Output: 120 Note: The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n.
codefeedback
Develop a for loop to write a program that prints the first 1000 prime numbers. Additionally, implement a function that checks whether a given number is prime or not, and use this function within your loop to determine the prime numbers. Furthermore, optimize your program to minimize the time complexity of the prime nu...
codefeedback
Change the HTML element to have a font size of 10px, display the text in uppercase, and reverse the order of the characters. <p>!dlroW olleH</p>
codefeedback
Create a recursive function in Java to print out the Fibonacci sequence up to the Nth term, where N is given as an input to the function. The function should have a time complexity of O(N^2). In addition to printing the sequence, modify the function to return the sum of all the terms in the Fibonacci sequence up to th...
codefeedback
Explain the concept and usage of a try-except block in Python, and provide an example of handling multiple exceptions in a single block. Additionally, provide an example of how to handle nested exceptions within the try-except block.
codefeedback
Alter the code to include a break statement in the loop. Additionally, add a conditional statement that only breaks the loop when the number is greater than 5. Modify the code to also keep track of the sum of all the numbers that are printed. Finally, print the sum after the loop has ended. ```python sum = 0 for i in r...
codefeedback
Create a user-defined function in C# to find the roots of a fourth-order polynomial with complex coefficients.
codefeedback
Develop a class in Python to print the name and age of the user, where the name must be in uppercase and the age must be a random number between 18 and 35. Additionally, the program should calculate and print the year the user will turn 50 years old.
codefeedback
Implement a Wiki page title search using Python, where the search string is case-sensitive and must be at least 3 characters long. The program should display the top 3 search results based on relevance, considering the number of incoming links, the page views, and the user ratings of each result. Additionally, the prog...
codefeedback
Parse an HTML table and extract all the rows. Each row should be stored as a dictionary, with the column headers as the keys and the cell values as the corresponding values. Example input: ``` <table> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> <tr> <td>...
codefeedback
Write a class in Java that contains two methods to add and subtract two numbers. However, the methods should only accept integers as input and should throw an exception if any other data type is passed. Additionally, the subtract method should throw an exception if the second number is greater than the first number. Th...
codefeedback
Create a script to count the number of vowels, consonants, digits and special characters in a string, while ignoring any whitespace characters. The script should also handle multiple string inputs and return the counts for each input separately. Additionally, implement a feature to calculate and display the percentage ...
codefeedback
Create a function that takes in a positive integer as input and determines whether it is a prime number or not. A prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself.
codefeedback
Convert the following number from decimal to hexadecimal using bitwise operations only. 743
codefeedback
Create a function to do a binary search on a sorted list of integers. The function should take two parameters: the list of integers and the target integer to search for. If the target integer is found in the list, the function should return its index. If the target integer is not found, the function should return -1. ...
codefeedback
Given a list of strings containing alphanumeric characters, special characters, and spaces, write a program that prints out the strings in uppercase without using built-in string manipulation functions (such as str.upper()), list comprehension, or any additional libraries/modules. The program should handle strings of a...
codefeedback
Generate a random unique ID consisting of 10 alphanumeric characters (including both uppercase and lowercase letters) and store it in a variable. The ID should start with a letter and should not contain any repeating characters. Additionally, the ID should not include any vowels (a, e, i, o, u) or the letters 'l' and '...
codefeedback
Reverse the given list using python, but you are not allowed to use the built-in reverse() function, and you must also use recursion to solve the problem.
codefeedback
Write a loop that prints the numbers from 10 to 1 in reverse order, each on its own line. Additionally, the loop should only print the even numbers and skip the odd numbers.
codefeedback
Generate a List Comprehension that returns a list containing the first 5 prime numbers, but exclude any prime numbers that are palindromic and have a prime number of digits.
codefeedback
Write a routine that takes in a JSON string and outputs the longest word found inside, but also counts the number of occurrences of each character in the word. For example, given the JSON string '{"John": 56, "Ann":64, "Victor": 23}', the routine should output: - Longest word: "Victor" - Character occurrences in "Vict...
codefeedback
Write a program that takes the current month and year as input and outputs the month that is 18 months after the given month and year.
codefeedback
Given a list of integers, remove all duplicated entries and sort the remaining numbers in descending order. The input list can contain up to 10^6 elements. Additionally, the sorting algorithm used must have a time complexity of O(n log n) or better. num_list = [12, 24, 12, 5, 8, 24]
codefeedback
Design a try/except block that takes in a user-entered number and prints whether it is a prime number or not. The code should have a time complexity of O(sqrt(n)) and should not use any external libraries or functions to check for prime numbers.
codefeedback
Find the physical address of a given memory location in a virtual memory system, considering the memory hierarchy and the translation process from virtual to physical addresses. Implement a function that takes a virtual address as input and returns the corresponding physical address. The function should handle page fau...
codefeedback
Generate a function to identify prime numbers between 0 and n, where n can be a large number (up to 10^9). The function should have a time complexity of O(sqrt(n)). #Erroneous Code# def is_prime(n): if n <= 1: return False for i in range(2, n): if n % i == 0: return False return...
codefeedback
Use PyTorch to write a function that predicts a class label based on five numerical features. The function should include a data preprocessing step that scales the input features between 0 and 1. Additionally, the function should output the predicted class probabilities instead of just the predicted class label. The fu...
codefeedback
Convert a given integer to its equivalent hexadecimal value, using recursion. Example: num = 67 Step 1: Start Step 2: Initialize an empty string, hex_value Step 3: Create a dictionary to map decimal values to their equivalent hexadecimal characters: hex_map = {0: '0', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7...
codefeedback
Write a recursive function in C++ to calculate the sum of all odd numbers between 1 and n, where n is a positive integer less than or equal to 1000. #Difficulty Level: Hard
codefeedback
Generate a Fibonacci sequence with a given length that only contains prime numbers and each number in the sequence is greater than the previous one. length = 15
codefeedback
Generate a C++ code to filter out an array containing prime numbers. Additionally, include error handling to detect and handle cases where the input array is empty or contains negative numbers.
codefeedback
Implement a recursive factorial function in Python with an additional constraint: the function must use tail recursion.
codefeedback
In this C++ program, there is an error. Please identify and fix the mistake. Additionally, you need to implement error handling to display a custom error message if the program encounters any runtime errors. Your solution should also include proper exception handling for specific types of errors, such as divide by zero...
codefeedback
Create an HTML page that displays a table displaying the first 1000 prime numbers.
codefeedback
Write a binarySearch() method in JavaScript to find an item in a sorted array. The method should have a time complexity of O(log n) and a space complexity of O(1).
codefeedback
Explain how recursion works and provide a recursive function in Python that calculates the factorial of a given number. Additionally, the function should handle negative input and raise an exception if the input is not an integer.
codefeedback
Create a Python class to work with complex numbers. The class should have methods to add, subtract, multiply, and divide complex numbers. Additionally, the class should have a method to calculate the magnitude and phase angle of a complex number. The magnitude should be rounded to two decimal places. The phase angle sh...
codefeedback
You need to design a database for a school where multiple students can have multiple tutors for multiple subjects. Additionally, each tutor can have multiple students for each subject they teach. However, there is a new requirement that each student can only have one tutor for a particular subject. What is the best way...
codefeedback
Create a class that detects if a given String contains the longest palindrome substring. The class should return the length of the longest palindrome substring found. The algorithm should have a time complexity of O(n^2) and a space complexity of O(1). Additionally, the algorithm should be able to handle inputs with s...
codefeedback
Construct an algorithm to calculate the GCD of two numbers using recursion and without using any built-in functions or libraries. Additionally, you should implement the algorithm in a language that does not support recursion by default, such as C or Java.
codefeedback
Create a function in Python that adds a new item to the beginning of a list. However, the new item should only be added if it is not already present in the list. If the item is already present, raise a custom exception called "ItemAlreadyExistsError" with an appropriate error message. Additionally, modify the function...
codefeedback
You have a list of employee records. Each record contains the employee's name, age, salary and department. Write an algorithm to sort the list by salary in descending order. Additionally, make sure that employees with the same salary are further sorted by age in ascending order.
codefeedback
Create a JavaScript program to find the area of a triangle using Heron's formula given the three sides, a, b and c. Additionally, the program should check if the triangle is a right-angled triangle by comparing the squares of the three sides and display a message if it is. The program should also ensure that the user i...
codefeedback
Create a class in Python with methods "add" and "find" to add a value to a dictionary and find the value in it, respectively. The "find" method should be able to handle a nested dictionary structure, where the keys are strings and the values can be either strings or nested dictionaries. The "find" method should return ...
codefeedback
You need to design a web page with a search bar that returns clickable results. Construct an algorithm to structure the web page. The search bar should support autocomplete functionality, suggesting search terms as the user types. Additionally, the search results should be dynamically updated as the user types, without...
codefeedback
Write a code that takes a sentence as input and prints the longest word in that sentence. However, the code should ignore any words that contain duplicate letters. Additionally, the code should also ignore any words that contain the letter 'e'.
codefeedback
Create a function to delete the last occurrence of a specific item from a singly linked list given the head of the list and the item to be deleted.
codefeedback
Write a C++ program that adds two given numbers and stores the result in a variable named "sum". The program should also display the sum in both decimal and binary formats. Additional requirements: 1. The program should not use any arithmetic operators (+, -, *, /, etc.) to perform the addition operation. 2. The progr...
codefeedback
Implement a function to calculate the total amount of money earned from a given array of stock prices, with the additional requirement that the function should only include the stock prices that were bought and sold on consecutive days. The function should also account for transaction fees, where a fixed fee of $0.50 i...
codefeedback
Write a function to find the closest pair of points in a given array of points. The function should have a time complexity of O(n log n) and should not use any additional data structures.
codefeedback
Construct an algorithm to find all possible combinations of a string of characters. Each combination should be printed in reverse order. The algorithm should have a time complexity of O(n^2 * n!), where n is the length of the string.
codefeedback
Write a function that takes in a list of numbers and creates a new list with only the prime numbers from the list. The function should also sort the resulting list in descending order. numbers = [2, 3, 4, 5, 6, 7, 8, 9]
codefeedback
Create a Python function that generates a random number between two specified numbers. However, the function should throw an exception if the lower bound is greater than or equal to the upper bound. The function should also check if the generated number is divisible by 3, and if not, keep generating random numbers unti...
codefeedback
Write a function that finds the largest prime number in an array of integers. The array can contain duplicate values, and the function should handle cases where there are multiple largest prime numbers in the array.
codefeedback
Assume an array contains elements from 1 to 100. You need to find the missing element. However, the array may also contain duplicate elements. Find the missing element while accounting for duplicates. arr = [1, 2, 4, 6, 7, 8, 10, 11, 12, 13, 15, 15, 15] Rewritten Test: Assume an array contains elements from 1 to 100...
codefeedback
Change the following Python code to convert the list to a dictionary of key-value pairs. Each key should be the corresponding element in the list, and each value should be a list containing the index of the element in the original list, the square of the element, and the cube of the element. The resulting dictionary sh...
codefeedback
Create a function that allows users to sign up for your feature using their username and password. The function should also include the following validations: 1. The username should be at least 10 characters long, should not contain any special characters, and should not be a common username found in a predefined list...
codefeedback
Create an array of integers with values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Sort the array in descending order using a bubble sort algorithm.
codefeedback
Produce a function that takes in an array of numbers and returns an array with all the prime numbers in it. The function should also handle negative numbers and floating-point numbers correctly. Additional requirements: 1. The function should handle extremely large numbers (greater than 10^15) efficiently and accurate...
codefeedback
Write a SQL query to select the title, price, and average rating of books where the price is greater than $50, the average rating is greater than 4, and the number of ratings is greater than 100. Additionally, the query should exclude books that have a genre of "Fiction". The result should be sorted in descending order...
codefeedback
Create a JavaScript program to spread a given array into subarrays of the given size, without using any built-in array methods such as slice or splice. The program should also ensure that each subarray has exactly the given size, except for the last subarray which may have a smaller size if necessary. Additionally, the...
codefeedback
Create a Node.js web server with the Express module that listens on port 3000 and returns "Hello, World!" as the response to any incoming GET request. Additionally, implement a middleware that logs the timestamp and IP address of each incoming request to a separate log file. Furthermore, add error handling to your se...
codefeedback
Create an array of 15 non-repeating random integers between 1 and 2000, where each integer is divisible by 7 and not divisible by 3. Additionally, the array should be sorted in ascending order.
codefeedback
Create a method that returns the count of all elements in an array that are larger than the given value x and their sum. If the array is empty or x is not provided, the method should return 0. Erroneous code reference: ``` def count_and_sum_elements(array, x): if not array or not x: return "Invalid input" ...
codefeedback
Create a function which returns a string of the given string in uppercase and in reverse order. The input string should contain only alphabetical characters, have a length of at least 5, and should not contain any repeating characters.
codefeedback