instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Edit the code to create a program to print all the leap years between 1900 and 2100. Additionally, create a function called "is_leap_year" that takes a year as an argument and returns True if it is a leap year and False otherwise. # Additional requirements: 1. The program should be able to handle negative years as inp...
codefeedback
Create an HTML/CSS web page from the following text content, while using flexbox to arrange the content in a specific layout. The layout should include a header, a sidebar, and a main content area, with the main content area taking up 70% of the width and the sidebar taking up 30% of the width. The header should have a...
codefeedback
Given a large dataset containing the values of two variables, x and y, find the correlation coefficient between them using the least squares method. The program should handle missing values in the input data appropriately. The time complexity of the solution should be O(n), where n is the size of the dataset. Addition...
codefeedback
Construct a function with two parameters to return the sum of the squares of the parameters. However, the function should also check if the sum of the squares is a perfect square number. If it is, return the sum of the squares; otherwise, return -1. The function should have a time complexity of O(1) and a space comple...
codefeedback
Write a function in a programming language of your choice that implements a closure. The closure should take in two arguments, a string and a number, and return a new function that concatenates the string with a given number of exclamation marks. For example, if the input to the closure is "Hello" and 3, the returned f...
codefeedback
Implement a sorting algorithm in Python without using any built-in sorting functions or methods. Provide a detailed explanation of how your algorithm works and analyze its time complexity.
codefeedback
Replace all occurrences of the character 'a' with the underscore symbol in a string, while preserving the original case of the string. Additionally, only replace the 'a' characters that are immediately preceded and followed by a vowel. Return the modified string. sample_string = "thisAAisAasampleAAstring"
codefeedback
Create a tuple of strings where each string is a palindrome and contains at least one special character or number.
codefeedback
Given a string of text, write a python script to remove all non-alphanumeric characters and convert all uppercase letters to lowercase. Additionally, sort the resulting string in reverse alphabetical order. #Example# Input: "Hello, World!" Output: "wroollh"
codefeedback
Given a linked list, write a program to delete a given node. The given node is guaranteed to be in the linked list. In addition to fixing the error in the code provided, please also implement the following additional requirements: 1. Modify the `delete_node` function to handle cases where the given node is the last n...
codefeedback
Implement a JavaScript function that takes two strings as parameters and replaces all occurrences of the first string with the second, but only if the first string is surrounded by a pair of square brackets [] and the second string is surrounded by a pair of curly braces {}. Additionally, the function should ignore any...
codefeedback
Given two strings, s1 and s2, write a program to return the longest common substring between them. The strings may contain uppercase and lowercase letters, numbers, and special characters. s1 = 'abcdefGHIJK123!@#' s2 = 'fghijkGHIJK456!@#' # Erroneous Code Reference # def longest_common_substring(s1, s2): m = len(...
codefeedback
Write a function that selects the first element from a list, squares it, and returns the square root of the squared element. Use the given list: list = [1, 2, 3, 4]. Ensure that the function returns the result rounded to the nearest whole number.
codefeedback
Extract the last four characters from a text string and display them in reverse order. The text string must contain at least one uppercase letter and one special character. The reversed last four characters should be displayed in lowercase. text = "This is a sample text"
codefeedback
Modify the code snippet below to insert the element 'z' into the beginning of an array, but you are not allowed to use any built-in array methods such as 'unshift' or 'splice'. arr = ['a', 'b', 'c', 'd', 'e']
codefeedback
Create a dictionary with two given lists, where the length of list1 and list2 is the same and each element in list1 is a string consisting of only lowercase alphabetic characters, and each element in list2 is a positive integer not exceeding 100, and the sum of all integers in list2 is a prime number.
codefeedback
You have been given a list of strings. Write a code to generate a new list containing only the strings with length less than 6 characters and containing at least one uppercase letter. Additionally, sort the new list in descending order based on the length of the strings. If two strings have the same length, sort them i...
codefeedback
Write a code to generate the fibonacci series for the first n numbers, but the code should be written in a functional programming style using recursion. Additionally, the code should not use any loops or mutable variables. #Additional Reasoning Steps# 1. Implement a recursive function that takes an integer n as input ...
codefeedback
Assign a value to each of the variables, x = ? and y = ?, such that x + y = 7. Additionally, the value of x must be a prime number, the value of y must be a multiple of 3, and the sum of the digits of y must be equal to the number of factors of x.
codefeedback
You have been given a list of integers. Write a code to generate a new list of integers containing only the prime numbers from the original list. Your code should not use any built-in functions or libraries to check if a number is prime. Instead, you should implement a function that uses bitwise operations to determine...
codefeedback
Write a function in JavaScript that generates an array of length N, where N is a positive random integer between 100 and 1000. Each element in the array should be a positive random integer between 1 and 1000. Additionally, the function should ensure that no two consecutive elements in the array are equal.
codefeedback
Write a code to count the occurrences of a particular element in a given list, while ignoring any occurrences within nested sublists. Additionally, the code should only consider elements that are of a specific data type. The list may contain elements of various data types such as integers, strings, and dictionaries. I...
codefeedback
Create a PHP function that trims a string and removes all leading and trailing whitespace, as well as any whitespace between words. $string = " Hello World "; The function should return the string "Hello World" after removing all leading and trailing whitespace and collapsing any consecutive whitespace between w...
codefeedback
Create a function to convert a given integer to a Roman numeral string in Python. The function should handle negative numbers and zero. #Additional Requirements# 1. The function should be able to handle integers up to 3999. 2. The function should not use any built-in Python libraries or functions for converting intege...
codefeedback
You have been given a list of user details (Names, Addresses etc) along with their occupations. Write a code to filter out the users whose age is more than 21 and whose occupations are not 'Engineer'. Additionally, you need to sort the filtered users by their addresses in ascending order. The filtered list should only ...
codefeedback
Create a JavaScript object which contains a key-value pair representing "name" and "lucy", but the value should be encrypted using a custom encryption algorithm that you have to implement. The algorithm should use a combination of bitwise operations, mathematical calculations, and a substitution cipher to encrypt the v...
codefeedback
Evaluate the following expression: 2x + 3y - 7z, where x, y, and z are integers within the range of -100 to 100 (inclusive). x = 5, y = -1, z = 8 #Erroneous Code# z = 0 x = 5 y = -1 result = 2x + 3y - 7z What is the value of the variable 'result'?
codefeedback
Explain the difference between the INNER JOIN, LEFT JOIN, and RIGHT JOIN operations in SQL and provide an example of when each would be used. Additionally, provide a piece of erroneous code that attempts to use these join operations and explain the mistake made in the code.
codefeedback
Write a bash command to view the amount of free disk space on your computer, but you are not allowed to use the "df" command and you must only use built-in bash commands.
codefeedback
Create a code to find the largest prime number from a list of given numbers in HTML. The code should have a time complexity of O(n log n) and should not use any built-in functions or libraries for finding prime numbers. Additionally, the code should use an optimized algorithm to improve the efficiency of prime number d...
codefeedback
Create a function in C to edit a string. The function should correct all occurrences of two or more consecutive spaces, tabs, or a combination of spaces and tabs with a single space. The function should also handle cases where there are multiple consecutive tabs or a combination of tabs and spaces. Additionally, the fu...
codefeedback
Write a Python program to identify all prime numbers within a given range. The program should accept two integers as input, representing the lower and upper bounds of the range, and output a list of all prime numbers within that range. The program should have a time complexity of O(n√m), where n is the size of the rang...
codefeedback
Output the string "Programming is Fun" when you run the code. The code should be written in Python and should utilize a recursive function. The input string should be reversed before outputting the result. However, you are not allowed to use any built-in string reversal functions or methods (e.g., `reverse()` or slici...
codefeedback
Given a 2-dimensional array of integers, print the elements across each row in reverse order. Additionally, the program should ignore any duplicate elements in each row and only print unique elements.
codefeedback
Given a paragraph element with an HTML Id attribute, write a JavaScript function that dynamically changes the font color of the paragraph element based on a specified condition. The condition should be that if the paragraph element contains a certain word or phrase, the font color should be changed to a specific color....
codefeedback
Read an array of numbers, where the length of the array is between 1 and 10^6 (inclusive), and output an array with all the even numbers in ascending order. The array can contain positive and negative integers ranging from -10^12 to 10^12. #Reasoning Steps# 1. Read the length of the array, ensuring it is between 1 and...
codefeedback
When given a list of words, output the longest word that contains only unique characters. If there are multiple words with the same length and unique characters, output the word that appears first in the list. Return an empty string if the input list is empty or if all the words in the list have the same length and con...
codefeedback
Implement a function 'convert_to_upper()' in JavaScript that converts a given string to uppercase and returns the reversed string. The function should also remove any special characters from the string before converting it to uppercase and reversing it. string = "Hello, World!"
codefeedback
Using a given array of numbers, create a function to display the frequency of each number and also identify the numbers with the highest and lowest frequencies. Additionally, ensure that the function runs in O(n) time complexity, where n is the length of the input array.
codefeedback
Write a program that takes a sentence as input and replaces all vowels with asterisks. The program should then return the modified sentence.
codefeedback
Create a function in JavaScript that takes an array and returns a new array containing the elements in reverse order. Additionally, the function should not use any built-in JavaScript array methods (such as `reverse()`, `map()`, or `slice()`) to achieve this. The function should also have a time complexity of O(n), whe...
codefeedback
Write a function in Java that takes a string as an argument and returns the length of the longest word in the string. The function should also exclude any punctuation marks or special characters from consideration when determining the longest word. Additionally, the function should handle cases where the string may con...
codefeedback
Write a Python program to find the longest substring in a given string which has no repeating characters, starts with a vowel, and ends with a consonant.
codefeedback
Write a regular expression that matches any string containing a sequence of exactly five consecutive digits.
codefeedback
Perform the following calculation without using the multiplication operator: Multiply two given numbers, a and b, where a and b are positive integers. The time complexity should be less than O(n), where n is the number of bits in the binary representation of the larger number. The space complexity should be less than O...
codefeedback
Increase the difficulty of the given programming test by considering multiple lists of words and numbers as input, and creating a program to print out the unique words and unique numbers for each list, while also keeping track of the frequency of each unique word. Example Input: List 1: ['cat', 'elephant', 'dog', '15...
codefeedback
Given a list of integers and a specified value, write a code to remove all numbers that are divisible by the specified value from the list. The code should also remove any duplicates that occur in the list. Example: Input: List: [1, 6, 4, 9, 5, 8, 2] Value: 3 Output: Modified List: [1, 4, 5, 8, 2]
codefeedback
Write a class and its constructor in Python for a vehicle object that has the fields 'type', 'make', 'model', 'color', 'year' and 'mileage'. The class should have methods to update the year and mileage of the vehicle. The constructor should validate the input values for each field to ensure they are of the correct data...
codefeedback
Create an HTML form with three text inputs, one for email, one for a password, and one for a confirmation password. Add client-side validation to check if the email input is a valid email address format (e.g. contains an "@" symbol and a valid domain name). Implement password strength validation to ensure that the pass...
codefeedback
Create a script to find the longest palindrome in a given sentence, considering only alphanumeric characters and ignoring any punctuation or whitespace. The script should return the longest palindrome, its length, and its starting and ending indices within the sentence. The script should also handle the case where mult...
codefeedback
Write a C++ program to take two numbers from the user and display the sum. However, the input numbers must be in Roman numeral format and the output must be displayed in binary format. Additionally, the program should include error handling to ensure that the user enters valid Roman numeral inputs.
codefeedback
Design a code to divide two integers without using division operator and with a time complexity of O(log N), where N is the number of digits in the dividend. The dividend and divisor will be positive integers only. Example: Input: Dividend: 123456789 Divisor: 987654321 Output: 0
codefeedback
Write a program that simulates a bot that can play tic-tac-toe against a human player. The bot should be able to make intelligent moves and attempt to win the game. The program should include a graphical user interface for the players to interact with. Additionally, the program should implement an algorithm to detect ...
codefeedback
Create a web page that contains a header, a sidebar, and a main content area. The header should have a navigation menu with at least three items, and the sidebar should contain a list of categories. The main content area should have a dynamically generated grid of images, with each image having a caption and a link to ...
codefeedback
Rearrange the following code segments to sort an array of integers in descending order using the insertion sort algorithm. array = [3, 5, 7, 1, 2]; A. for(let i=1; i<array.length; i++) B. let current = array[i]; C. let j = i-1; D. while(j >= 0 && array[j] < current) E. array[j+1] = array[j]; F. array[j+1] = current;
codefeedback
Build a code to print out all unique permutations of the characters in a given string without using recursion. The input string can have duplicate characters, and the code should handle these duplicates correctly. Additionally, the code should be able to handle input strings of length up to 10^6 efficiently.
codefeedback
Given a string of text, print the count of all the unique words. The text will only contain alphabetic characters and spaces. You need to handle cases where multiple spaces appear consecutively as well. The solution should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(...
codefeedback
Write a loop in SQL for selecting all customer names that are not 'Bob' and have made more than 5 purchases, while also considering the total amount spent by each customer.
codefeedback
Write a SQL query for retrieving the address of the oldest customer in the database who has made at least 10 purchases in the past month.
codefeedback
Write an algorithm to find the longest sub string without repeating characters in a given string. However, the algorithm should also consider whitespace characters as potential repeating characters. Example: string = 'abc abcbb' #Erroneous Code Reference# string = 'a bcd efg' Note: The provided erroneous code is inc...
codefeedback
Write a function in Java that calculates the median from an array of integers. The array will always have an odd number of elements. The function should have a time complexity of O(n) and a space complexity of O(1). arr = [7, 22, 21, 19, 17, 24, 28] Note: The array will always be sorted in ascending order.
codefeedback
Generate a random probability distribution with mean 0 and standard deviation 1, such that the values are limited to a specified range and follow a specific probability distribution, in Python.
codefeedback
Create a function in R which returns the number of rows in a dataframe. Additionally, the function should handle the case where the input is not a dataframe and return an appropriate error message. The function should also check if the dataframe has at least one non-NA value in each column and return a warning message ...
codefeedback
Create a function in R to check if a string contains at least two uppercase letters, two lowercase letters, two numbers, and two special characters. If the string meets this requirement, return the last seven characters of the string. Otherwise, return an error message.
codefeedback
Fill in the blank to generate a SHA-512 hash in JavaScript, using a library or algorithm other than the built-in crypto module or SHA-3 family.
codefeedback
Sort a given list of strings in descending order by length in Python, and return the sorted list. However, the sort operation should be done in-place without using any built-in sorting functions or methods. The time complexity of the solution should be less than O(n^2), where n is the length of the list. Additionally, ...
codefeedback
Write a JavaScript function that takes an array and a value as input and inserts the value at the beginning of the array. The function should have a time complexity of O(1) and should not use any built-in array methods like unshift() or splice(). Additionally, the function should only use a constant amount of memory an...
codefeedback
Write a function in SQL to get the average salary of all engineers whose designation is "Senior Software Engineer", whose years of experience is greater than 5, and who belong to the department "Technology".
codefeedback
Store this JSON data into a database of your choice while handling additional functionalities and potential errors. You are given a JSON array containing information about multiple people. Each person has the following attributes: "name" (string), "age" (integer), and "city" (string). Your task is to store this data i...
codefeedback
Design a data structure to store a list of names of the student with their respective grades in a class. Each student can have multiple grades for different subjects. Each grade should be associated with the subject name as well. The data structure should support the following additional requirements: 1. Each student s...
codefeedback
Write JavaScript code to print the message "Hello World" after 5 seconds. However, you are not allowed to use any built-in JavaScript timers or delay functions such as setTimeout or setInterval.
codefeedback
Write a Java method to find the index of a given string in an array of strings. Additionally, if the string is not found in the array, return -1. You are not allowed to use any built-in functions or libraries that directly solve the problem. In addition to the original requirements, you are now required to implement t...
codefeedback
Create a class in Java called "MathUtils" and define two float variables called "num1" and "num2". Implement four methods called "add", "subtract", "multiply", and "divide" which takes two float parameters and returns the sum, difference, product, and quotient respectively. The methods should be able to handle edge cas...
codefeedback
Write a C program to print the numbers from 1 to 100, with the following conditions: - The program should not use any loops or conditional statements. - The program should only use recursion and bitwise operations to determine the output for each number. - The program should use a maximum of 5 lines of code. - The pro...
codefeedback
Write a function to classify a text as positive, negative, or neutral based on the sentiment score, where positive scores indicate positive sentiment, negative scores indicate negative sentiment, and scores close to zero indicate neutral sentiment. text = "This product exceeded all my expectations and I couldn't be hap...
codefeedback
Define a function called find_sum that takes a list of numbers and returns the sum of the positive numbers in the list. Additionally, implement a check to ensure that the input list contains only numeric values. If any non-numeric values are found, raise a ValueError with an appropriate error message. # Erroneous Cod...
codefeedback
Compile a C++ program, called "my_program", that prompts the user to enter a positive integer less than or equal to 10 and then calculates the factorial of that number using recursion. The program should display the factorial as the output. The program should also validate the user input to ensure it is a positive inte...
codefeedback
Perform sentiment analysis on this text using a machine learning algorithm. The algorithm should be trained on a large dataset of hotel reviews and be able to accurately classify the sentiment of the given text as positive, negative, or neutral. The algorithm should also provide a confidence score for its prediction. T...
codefeedback
Generate an array with all the prime numbers from 1 to 1000, where each prime number should be stored as an object with the following properties: - "value": the prime number itself - "digits": an array containing the individual digits of the prime number in ascending order
codefeedback
Compute the value of the expression given below using recursion. (2^3) + 5 - (4 * 2) Note: The input expression will always be a valid arithmetic expression consisting of integers and the operators '+', '-', '*', and '^'.
codefeedback
Rewrite the code to include a condition that terminates the loop if the value of 'i' exceeds 10. Additionally, print the value of 'i' along with the message "Something is wrong!" on each iteration.
codefeedback
Retrieve the index of the first occurrence of a given item in a sorted array that contains only unique non-negative integer and float values. The function should use a recursive binary search algorithm with a time complexity of O(log n) and be able to handle arrays with up to 10^6 elements. If the item is not found, th...
codefeedback
Use the following array to generate an HTML table. Each table row should have a unique ID, starting from 1 and incrementing by 1 for each row. The 'Name' column should be displayed in uppercase letters, and the 'Age' column should be displayed in bold. Additionally, the table should have a border of 1 pixel and a backg...
codefeedback
Create a function that prints a table using a given dictionary, where the dictionary can have an arbitrary number of keys and values of any data type. The function should handle dictionaries with a large number of keys and values efficiently, without using excessive memory or running time. Additional requirements: 1....
codefeedback
Create a program in JavaScript that takes in a positive integer and returns the sum of its digits. However, you must use recursion to solve this problem. Additionally, the program should handle negative integers by converting them to positive before finding the sum of their digits. The program should also handle decima...
codefeedback
Use Python to write a code that displays a multiplication table of a given number, but the table should only display the multiplication results for prime numbers less than or equal to the given number. Additionally, the code should implement a function that checks whether a given number is prime, and use this function ...
codefeedback
Create a python function that will convert a string to all uppercase and remove all punctuation marks from the string. Additionally, you should remove any duplicate characters from the resulting string. # Constraints: - The input string will only contain alphabetic characters, spaces, and punctuation marks. - The outp...
codefeedback
Suggest a SQL query to find the percentage of the total mark of a student, but this time there are multiple students and their marks are stored in a separate table. The tables have the following structure: Table "students": - student_id (integer) - student_name (string) Table "marks": - mark_id (integer) - student_id...
codefeedback
Create a function in JavaScript to replace all instances of a specified word in a string with "peanut butter". However, ensure that the replacement is case-sensitive, meaning that only exact matches of the specified word should be replaced. Additionally, make sure that the function handles edge cases such as empty stri...
codefeedback
Create a second level navigation menu using HTML, CSS, and JavaScript. - The menu should have a main navigation bar with at least 7 top-level menu items. - When a user hovers over a top-level menu item, a sub-menu should appear with at least 5 sub-menu items. - The sub-menu items should be displayed in a dropdown styl...
codefeedback
Using Java, make a program that finds out the smallest common denominator between two numbers, where both numbers are guaranteed to be within the range of 1 to 1,000,000. Additionally, the program should be able to handle large numbers efficiently and have a time complexity of O(sqrt(N)), where N is the larger of the t...
codefeedback
Create an array of size N, where N is a positive integer provided as input, containing random integers between -1000 to 1000 using the function **np.random.randint**. Calculate and return the sum of all the negative integers in the array. Additionally, calculate and return the product of all the positive integers in th...
codefeedback
Generate XML tags for the given list of strings. Each XML tag should include an attribute called "id" with a unique value for each tag. The unique values should be generated using a specific pattern: "tag_<index>", where <index> starts at a random number between 1 and 10 and increments by a random number between 2 and ...
codefeedback
Construct a function that can generate a unique identifier, but the identifiers must be exactly 10 characters long and contain a combination of letters (both uppercase and lowercase) and numbers. The function should also be able to generate at least 100 million unique identifiers per second, while ensuring that no two ...
codefeedback
Suggest an efficient way to find the number of occurrences of a time value in a given array, while also determining the positions of each occurrence in the array. array = ["10:00 AM", "11:30 AM", "10:00 AM", "8:30 AM", "10:00 AM"] Note: You cannot use built-in functions or libraries for time/date manipulation. Your s...
codefeedback
Using Java, create a class constructor for a 3D vector that also includes methods to perform common vector operations such as addition, subtraction, scalar multiplication, dot product, cross product, and normalization. The time complexity of each method should be optimized to be as efficient as possible, with a maximum...
codefeedback
Create a function in JavaScript that takes in a string and returns true if the string meets the following criteria: - Contains at least 2 digits - Contains at least 2 special characters - Contains at least 2 capital letters - Contains no consecutive repeating characters The function should have a time complexity of O(...
codefeedback
Find the number at the given index in an array, but now the array is sorted in descending order and contains only prime numbers. array = [19, 17, 13, 11, 7, 5, 3, 2], index = 5
codefeedback
Write a function in Python which can generate a random string consisting of lowercase letters, uppercase letters, numbers and symbols. The generated string should have a length between 15 and 25 characters, inclusive. Additionally, the string must contain at least two lowercase letters, two uppercase letters, two numbe...
codefeedback
Create an object-oriented program in Java which can display the current date and time, while also implementing the Observer pattern. Additionally, modify the program to allow multiple observers to subscribe to the subject and receive updates when the date and time change.
codefeedback