instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Create an array in JavaScript to store integers from 1 to 100, but ensure that the array only contains prime numbers.
codefeedback
Find out the number of odd numbers that are greater than 10 and less than 100 in an array of integers, while also considering the following conditions: 1. Exclude any negative numbers present in the array. 2. Implement the solution using a nested loop structure. 3. Instead of checking each element individually, create ...
codefeedback
Introduce a condition to change the background color of a given HTML page to green when the user clicks a button. Additionally, upon clicking the button, the background color should gradually transition from the current color to green over a period of 3 seconds. However, the transition should not use any CSS properti...
codefeedback
Increase the difficulty by adding multiple constraints to the function: 1. The function should be implemented using recursion instead of a loop. 2. The function should have a time complexity of O(n) where n is the length of the input. 3. The function should not use any built-in sorting or searching functions. 4. The fu...
codefeedback
Write a JavaScript program to find the longest common prefix string amongst two given strings, while also ensuring that the common prefix is at least 5 characters long and is followed by a digit. For example, given the strings "hello123" and "hello456", the program should return "hello".
codefeedback
Generate a working C program to accept a sentence as an input and count the occurrences of each letter in the sentence. Additionally, implement a feature to ignore case sensitivity and count both uppercase and lowercase occurrences of each letter as separate counts. Modify the program to also exclude any special charac...
codefeedback
Write a shell script to perform a binary search of a sorted array [2, 4, 6, 8, 10] and return the index of the first occurrence of the target element. The array may contain duplicate elements and the target element may also be a duplicate.
codefeedback
Write a code to construct the following diamond pattern using a given number of rows. However, this time the number of rows can be any positive integer. Example: Input: 8 Output: * *** ***** ******* ********* ******* ***** ***
codefeedback
Display the multiplication table for a given number. However, for each row, only display the products that are prime numbers and greater than 10. num = 9
codefeedback
Write a Python function that takes a string as an argument and checks if it contains the word “Python” in a case-insensitive manner and with all occurrences of the word “Python” replaced with the word “Programming”. If the string does not contain the word “Python”, the function should return the original string. Addit...
codefeedback
Write a function that takes a list of strings and joins them together with a pipe (|), but only for strings that start with a vowel. The resulting string should also be reversed. However, the function should have a time complexity of O(n) and space complexity of O(1). words = ["Apple", "App", "Application", "Applicati...
codefeedback
Generate a working React component to parse GEDCOM data and display the parsed data in a hierarchical structure. Additional requirements: 1. The component should handle nested GEDCOM data. 2. The parsed data should be displayed in a tree-like structure, with each level of the hierarchy represented by a nested list. 3....
codefeedback
Create a function to sort an array of numbers from least to greatest. You are not allowed to use any built-in sorting functions or libraries. The input array will always contain at least 2 numbers and at most 10^6 numbers. All numbers in the array will be distinct and will be in the range of -10^9 to 10^9.
codefeedback
Create a function that reverses a string without using any built-in functions or data structures (such as arrays or lists) and without using any variables or loops. Your solution should have a time complexity of O(n), where n is the length of the string. Your function should take a string as input and return the rever...
codefeedback
Generate a script to print out the sum of all even numbers in a given list, but also handle the case when the list contains non-numeric elements. Additionally, the script should ignore any duplicates of even numbers in the list and only consider the first occurrence of each even number for the sum calculation. Exampl...
codefeedback
Suppose you are given two lists A and B, where A contains n integers and B contains m integers (m < n). Your task is to determine if B's elements are all present in A, in the same order as they appear in B. Additionally, you need to find the starting index of the first occurrence of B in A. Write a function named `fin...
codefeedback
Write a program that takes a list of employee names and a new job title as input, and updates the job title for all the employees in the list. The program should first prompt the user to enter the number of employees in the list. Then, it should ask the user to enter the names of each employee, one by one. After that,...
codefeedback
Create a new class named 'Book' with the following fields: - Title: a string representing the title of the book (1 <= length <= 100) - Author: a string representing the author of the book (1 <= length <= 100) - Publisher: a string representing the publisher of the book (1 <= length <= 100) - ISBN: a string representing...
codefeedback
Create a python script to check if a substring exists in a given string. The substring should be case-sensitive and must be a contiguous sequence of characters. The program should also count the number of occurrences of the substring in the given string and display the positions (index) where the substring occurs. The ...
codefeedback
Create an algorithm that uses a hash table to detect if an element is a duplicate. The algorithm should also return the frequency of each duplicate element in the array. Additionally, the algorithm should handle cases where the array contains negative numbers and floating-point numbers. The input array can have a maxim...
codefeedback
Create a program that implements an autocomplete or predictive search feature. The program should support multiple languages and handle diacritics, such as accents and umlauts. Additionally, the program should take into account the frequency of word usage and prioritize suggestions based on popularity. The autocomplete...
codefeedback
Write a JavaScript program to generate and print a multiplication table up to a specified number. The program should prompt the user to enter the number of rows and columns for the multiplication table, ensuring that the input is a positive integer. The program should then calculate and display the multiplication table...
codefeedback
Design an SQL query to select the top 10 most popular movies from a given movie table. The popularity of a movie is determined by the number of times it has been rented, favorited, and rated. In addition to selecting the top 10 most popular movies, also display the title, release year, average rating, and the number o...
codefeedback
Write a Python function to filter a given list of strings and return the list with the strings having length greater than the given number. The function should also ignore any strings that contain special characters. Additionally, the function should remove any duplicate strings from the resulting list. list = ['Examp...
codefeedback
Create a web page to display two input fields to enter two numbers. Add a third input field for the user to select an operation to perform on the numbers (such as addition, subtraction, multiplication, or division). Implement the logic to perform the selected operation on the two numbers and display the result on the w...
codefeedback
Create a function to merge two sorted lists and remove duplicates. The function should have a time complexity of O(n+m), where n and m are the lengths of the two input lists. The merged list should also be sorted in ascending order. Provide an erroneous code as a reference to increase misdirection. #Erroneous Code# d...
codefeedback
Create a React component which shows a list of items with a delete button for each item. Additionally, implement a feature where the user can undo the deletion of an item by clicking on an "Undo" button. The component should also track the number of times each item has been deleted and display it next to the item.
codefeedback
Write a function that takes an English sentence as input and generates a response that includes a unique id. The unique id should be a combination of the current date and time, in the format of "YYYY-MM-DD_HH:MM:SS". Additionally, the function should handle the following requirements: 1. The function should ensure tha...
codefeedback
Create a program in Python that will take in a list of strings and print out each unique string in the list. Additionally, the program should ignore case sensitivity when determining uniqueness. The program should also handle cases where the input list contains both strings and integers. Lastly, the program should only...
codefeedback
Use a convolutional neural network with backpropagation to predict the price of a car based on its make, model, year of manufacture, engine displacement, horsepower, and fuel efficiency. The make can be one of the following: 'Mazda', 'Volkswagen', 'Chevrolet', 'Ford', or 'Toyota'. The model can be one of the following:...
codefeedback
Create a function to convert an XML string to a JSON object. The function should handle nested XML elements and attributes. The XML string may contain multiple root elements. The function should return the JSON object in a compact form, without any unnecessary white spaces or line breaks. Additionally, the function sho...
codefeedback
Write a function that takes a string representing a human readable date in the format "Day, Month Day, Year" and converts it to the ISO 8601 format "YYYY-MM-DD". For example, if the input is "Sunday, April 7th, 2020", the output should be "2020-04-07". You need to handle the following cases: - The input can be in any...
codefeedback
Write a SQL query to select the employee names, their department, and the total salary of each department, but only for departments where the total salary is above the average salary of all departments.
codefeedback
Create a program in Python that will take a list of strings and output a list containing the lengths of each string. Additionally, the program should sort the list of strings in descending order based on the length of each string. The program should also remove any duplicate strings from the input list before performin...
codefeedback
Write a C++ program for calculating the power of a number with a time complexity of O(logn). You are given a base and an exponent. The base can be any positive integer and the exponent can be any non-negative integer. You need to calculate the power of the base raised to the exponent using the Binary Exponentiation m...
codefeedback
Create a class definition in Python that represents a stack data structure. The class should have the following methods: 1. `push(item)`: Adds an item to the top of the stack. 2. `pop()`: Removes and returns the item at the top of the stack. If the stack is empty, it should return None. 3. `peek()`: Returns the item a...
codefeedback
Write a MySQL query to select the names, phone numbers, and addresses of people whose age is greater than 30, whose addresses are located in a specific city, and whose phone numbers have a specific prefix.
codefeedback
Write a Python program that connects to a MongoDB database hosted on a remote server using a specific port number and authentication credentials. Additionally, the program should implement a connection pool to efficiently manage multiple database connections and handle concurrent requests.
codefeedback
Write a script in JavaScript for converting temperature from Celsius to Kelvin. The script should also be able to convert temperature from Kelvin to Celsius. The script should take the following inputs: 1. The temperature value to be converted. 2. A string indicating the unit of the temperature value ("C" for Celsius ...
codefeedback
Write a function in Python that takes two parameters, a list of integers and a target integer. The function should return the number of times the target integer appears in the list. The list will always have at least 100 elements and will not exceed 1000 elements. The target integer will always be within the range of -...
codefeedback
Write a JavaScript program to validate whether a given phone number is valid. The phone number should follow the following format: - It should consist of 10 digits. - It can have an optional country code at the beginning, which should be preceded by a plus sign (+). - It can have an optional area code, which should b...
codefeedback
Write a CSS selector to select all the links in a web page that have a specific class name, are contained within a specific div element, and are direct children of that div element.
codefeedback
Write a Ruby method that takes an array of strings as a parameter, removes any duplicate elements in the array, sorts the remaining elements alphabetically in reverse order, and returns a string with the sorted elements separated by semicolons.
codefeedback
Create an HTML page to display the output of a JavaScript greeting message. message: Welcome! Requirements: - The greeting message should be displayed in a heading element with a font size of 24px. - The background color of the HTML page should be set to light blue. - The greeting message should be displayed in the cen...
codefeedback
Re-write the following code using only the filter() function and ensure that the result is sorted in descending order. numbers = range(10) evens = filter(lambda x: x % 2 == 0, numbers)
codefeedback
Write a Python script that takes a string as input and outputs a string with the same characters in reverse order, while ignoring any whitespace characters and punctuation marks. The script should also check if the resulting string is a palindrome (reads the same forwards and backwards), and if it is, it should append ...
codefeedback
Create a program that uses a loop to generate 25 random prime numbers between 0 and 100, but exclude the prime numbers that are divisible by 5.
codefeedback
Explain the concept of a dining philosophers problem and propose a solution to prevent deadlock in this scenario. Additionally, provide a piece of erroneous code that attempts to solve the problem, but actually introduces a subtle bug leading to deadlock. Explain the bug and how it can be fixed.
codefeedback
Write a Java class to implement a priority queue data structure that has a constant time complexity of O(1) for both insertion and deletion operations. Additionally, the priority queue should support the following operations: - Increase Priority: Given an element in the priority queue, increase its priority to a higher...
codefeedback
Implement a recursive algorithm to count the number of elements that are divisible by k and have a remainder of 1 when divided by m in a two-dimensional array. The array will contain positive integers only. Example: [[5, 8, 11], [14, 17, 20]], k = 3, m = 2
codefeedback
Write a SQL statement to join table1 and table2 on the "name" column, but also include only the rows where the "age" column in table1 is greater than 25. Additionally, exclude any rows where the "status" column in table2 is equal to "inactive".
codefeedback
Explain the differences between the List and the Set data structures in terms of implementation, operations, and use cases. Provide specific examples of scenarios where using one data structure would be more advantageous than the other. Additionally, discuss the time and space complexity of various operations on both d...
codefeedback
Generate a MySQL query to fetch a specified number of records starting from a given ID, but only if the records have a certain condition met. Additionally, the records should be sorted based on a specific column in descending order. 5 25 Condition: the value in the 'status' column is 'active' Sort column: '...
codefeedback
Given an array of strings "words", write a code to remove all the words which are greater than 5 characters in length. If a word has more than 5 characters, replace it with the reverse of the word. Finally, sort the updated array in descending order based on the length of the words and print the updated array. words =...
codefeedback
Create a C++ program to print all the even numbers of a given range between 1 and 100, but exclude the numbers divisible by both 3 and 5.
codefeedback
Please implement the function `weighted_median(data, weights)` that takes two lists as input: `data` - a list of positive integers, and `weights` - a list of positive integers corresponding to each number in the data list. The function should return the weighted median. In a weighted median calculation, each number in...
codefeedback
Debug the code to fix the error, but you can only use recursion. Additionally, the output should be reversed. def hi_it(name): if name == "": return "" return hi_it(name[1:]) + name[0] hi_it("John")
codefeedback
Explain the difference between shallow copying and deep copying in Python, and provide detailed examples to illustrate when each method is appropriate to use. Additionally, discuss the advantages and disadvantages of using each method in different scenarios.
codefeedback
Design a JavaScript program to find the factorial of an integer, but ensure that the program includes error handling for non-integer inputs and displays a helpful error message. Additionally, the program should be optimized to handle large inputs efficiently. Find the factorial of 50.
codefeedback
Given a list of numbers, write a program that finds all the numbers that are divisible by both 3 and 5. Additionally, for each number found, calculate the product of its digits and display the result. For example, given the list: myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] The p...
codefeedback
Remove all occurrences of a specific character in the given string, but do not use any built-in string manipulation functions or libraries.
codefeedback
Compile a Java program using the command line, ensuring that it uses an external library and multiple packages. Additionally, the program should implement an algorithm that sorts an array of integers in descending order using a custom comparator. The custom comparator should consider the parity of the integers, sorting...
codefeedback
Insert code to reverse a list in place without using any built-in reverse or swap functions. Your solution should have a time complexity of O(n), where n is the length of the list. arr = [1,2,3,4] # Additional Constraints: - You are not allowed to use any additional data structures or libraries. - You are not allowed...
codefeedback
Construct a factorial function in JavaScript that takes in two inputs x and y as parameters. The function should calculate the factorial of x and return the result. Additionally, the function should only accept positive integer values for x and y. If any of the inputs are invalid, the function should throw an error wit...
codefeedback
Given a 2D array, return the sums of all columns. However, the time complexity of your solution must be O(n), where n is the total number of elements in the array. Erroneous code: ```python def sum_columns(arr): # Initialize the sums list sums = [] # Get the number of columns num_cols = len(arr[0]...
codefeedback
Given a collection of strings, sort the strings by their length in descending order. If two or more strings have the same length, sort them in lexicographically ascending order. Return the sorted list of strings. Example: Input: ["a", "abc", "defg"] Output: ["defg", "abc", "a"] Note: - The input list will not be empt...
codefeedback
Given a list of strings and a target string, return a list of strings which contain the target string as a substring. The target string must be at least 3 characters long. Example: Input: list_of_strings = ["cat", "dog", "rat", "bat"] target_string = "at" Output: ["cat", "rat", "bat"] Explanation: In the given exam...
codefeedback
Make a program that prints the elements of a given array in reverse order, but with the following additional constraints: you cannot use the built-in reverse() function or any other built-in functions that directly reverse an array, you cannot use any additional data structures (such as a new array or stack) to reverse...
codefeedback
Find all duplicates in an array of positive integers where each integer is between 1 and 10^6, inclusive. The array may contain up to 10^9 elements. Return the duplicates in descending order. arr = [1000000, 2, 400000, 2, 1000000, 500000]
codefeedback
Calculate the sum of every third element in an array. However, the elements must be skipped in a specific pattern. Start by skipping 2 elements, then 3 elements, then 4 elements, and so on. Repeat this pattern until the end of the array is reached. arr = [1, 5, 4, 8, 10, 12, 6, 2, 7, 3, 9, 11] For example, the sum wo...
codefeedback
Generate a dictionary with ten key-value pairs where the keys are strings and the values are lists of integers. Each list should contain at least five random numbers. Additionally, ensure that the keys are alphanumeric and have a length of exactly five characters.
codefeedback
You need to compute the sum of the squares of all positive numbers stored in an array `arr`, where the array elements are limited to integers between -100 and 100. The array size is limited to a maximum of 1000 elements. If the array does not contain any positive numbers, the program should return 0. For example, giv...
codefeedback
Create a program to generate a random password of length n (input by the user) consisting of both alphabets (both uppercase and lowercase) and numbers. The password should also contain at least one special character (!@#$%^&*()-_=+~`[]{}|;:,<.>/?) and should not have any repeated characters. Additionally, the program s...
codefeedback
Create a program to encode a message with the Caesar cipher encryption algorithm. The message can contain both uppercase and lowercase letters, and the shift value should be randomly generated within the range of 1 to 26. Additionally, the program should allow the user to input multiple messages to be encoded, and it s...
codefeedback
Write a code to simulate a random walk in two-dimensional space. - The number of steps in the x-direction (x_steps) and the y-direction (y_steps) can vary between 10 and 1000. - The initial starting position is (0, 0) and the maximum coordinate value in any direction is 100. - At each step, the walker can move up, dow...
codefeedback
Create a function that takes two parameters and merge them into a single object. However, you are not allowed to use the built-in functions or methods in the programming language to achieve this task. Additionally, the merged object should have all keys from both input objects, and in case of duplicate keys, the value ...
codefeedback
Generate a python program to create a n-dimensional array filled with randomly generated integers between a given range. The range should be specified by the user as two input numbers. Additionally, the program should prompt the user to enter the number of dimensions for the array. The program should then prompt the us...
codefeedback
Create a web page with a form that takes a user's name and birthdate. Calculate the user's age based on the birthdate and display a personalized greeting based on the age. Additionally, implement a validation check to ensure that the user's birthdate is entered in the format "YYYY-MM-DD" and that the entered date is no...
codefeedback
You need to find the number of words in a sentence, remove any duplicate words from the sentence, and then sort the words in alphabetical order. Additionally, you need to handle any punctuation marks present in the sentence. sentence = "The quick brown fox jumps over the lazy dog, but the dog is not interested."
codefeedback
Write a program that takes a string as input and outputs a sentence in the following format: "Hello, [name]! How are you doing today?" Additional Requirements: 1. The program should check if the input string contains only alphabetic characters. If it contains any other characters, the program should display an error m...
codefeedback
Create a web service to convert a given list of temperatures from Celsius to Fahrenheit, while also checking for any invalid temperature inputs and handling them appropriately. The input list may contain both valid and invalid temperature values. Invalid temperature values can be defined as temperatures below -273.15°...
codefeedback
You need to extract a part of the string from the starting to the 5th character and from the 7th to the 25th character, while ignoring any whitespace characters within those positions. Additionally, you need to remove any special characters (e.g., punctuation marks, symbols) from the extracted substring. The extracted ...
codefeedback
Sort an array of integers using the bubble sort technique in descending order. The array can contain up to 10^6 elements. The time complexity of the solution should be O(n^2), and the space complexity should be O(1). Example: Input: [8, 6, 7, 5, 4, 3, 1] Output: [8, 7, 6, 5, 4, 3, 1]
codefeedback
Write a function that takes a string as input and reverses it. However, you are not allowed to use any built-in functions or methods for string manipulation (e.g. reverse(), slice(), etc.). You can only use basic string operations and loops. The time complexity of your solution should be O(n), where n is the length of...
codefeedback
Create a Python class called Employee which contains the employee id, name, and salary. The salary should be a float value with a maximum of 2 decimal places. The employee id should be a unique integer between 1000 and 9999. The employee name should be a string of length between 3 and 20 characters, and should not cont...
codefeedback
Implement a function to solve the following equation: x^4+y^4=z^4
codefeedback
Given a string, write code to remove all the consecutive characters and output the new string. The new string should also have all the non-consecutive characters in the original string, but in reverse order. The code should be implemented using recursion. Additional Requirements: 1. The function should be named "remov...
codefeedback
Write a function to convert an array of strings to an array of floats, but with the following additional requirements: - The function should ignore any strings that cannot be directly converted to floats, and return only the converted floats. - If a string can be converted to a float, but the float is not a whole numbe...
codefeedback
Create a program that takes in two lists and prints out a new list with the elements from the first list followed by the elements from the second list, without using any built-in functions or methods such as append() or extend(). Additionally, the program should sort the new list in descending order. The program should...
codefeedback
Preprocess a given document, removing stopwords and punctuations, and converting all words to lowercase. Additionally, implement a feature to identify and remove any duplicated words in the document. document = "Hello! This is a test document for preprocessing. The document contains duplicate words like hello and is. ...
codefeedback
Write a code to implement a round-robin scheduling algorithm with the following additional constraints: 1. Each process has a priority assigned to it, represented by a positive integer value. The priority determines the order in which the processes are executed. Lower values indicate higher priority. 2. In addition t...
codefeedback
Given a list of n options, each with a unique ID, write a function to compute the number of ways for a host to select k items from the list, where k <= n. 1. Create a function called "computeWays" that takes in two parameters: the list of options and the value of k. 2. Initialize a variable called "totalWays" to 0 to ...
codefeedback
Design an algorithm to eliminate duplicate elements in a given array while maintaining the order of the remaining elements. However, now the array can contain duplicate elements and you need to remove all occurrences of the duplicates. Array: [1, 5, 1, -2, 5] Additional requirements: 1. The algorithm should have a ti...
codefeedback
Given an array of integers, remove all the duplicated elements from the array and return the distinct array. Additionally, the returned array should be sorted in non-decreasing order. nums=[3, 4, 5, 5, 6, 6, 6, 7] #Rewritten Test#
codefeedback
You are given a string of tasks. Split the string into a list of tasks. However, some tasks may have additional instructions enclosed in parentheses. Remove these instructions before adding the task to the list. Additionally, if a task has multiple sets of instructions enclosed in parentheses, remove all of them before...
codefeedback
Search a list of strings to find a specific string and return its index. However, the search term may contain wildcards, represented by asterisks (*), which can match any number of characters (including zero). Implement a function that takes in the list of strings and the search term, and returns the index of the first...
codefeedback
You are given a string of words. Count how many words the string contains. The string may contain punctuation marks, numbers, and special characters. Additionally, words can be separated by multiple spaces or other whitespace characters. Ignore any leading or trailing whitespace characters in the string. Example: Inpu...
codefeedback
Write a function that takes an array of integers and multiplies them together. The function should handle negative numbers and should return the product as a floating-point number. If the array is empty, the function should return 1. Additionally, the function should handle the case where the product exceeds the range ...
codefeedback
Write a function to generate an array of all possible permutations of N numbers, where N is a positive integer. The numbers in the array can range from 1 to N. The function should have a time complexity of O(N!) and a space complexity of O(N!). #Reasoning# To solve this problem, we can use backtracking. We start with...
codefeedback
Given a number N, find the square root of N using the Newton-Raphson method. The program should also handle complex numbers and provide the square root in its polar form.
codefeedback