instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Create a function that given a string of words, counts the frequency of each word and returns a dictionary with the word as the key and the frequency as the value. The function should handle different cases of words (e.g. "Hello" and "hello" should be treated as the same word). Additionally, the function should ignore ...
codefeedback
Given a list of positive integers, construct a function that returns the highest and the lowest numbers. The function should also check if the highest number is divisible by the lowest number. If it is divisible, the function should return a tuple with the highest number as the first element and the lowest number as th...
codefeedback
Write a program to print the following data structure in an easily readable format, while also ensuring that the output is sorted in alphabetical order based on the keys. The program should reverse the order of the values in the "languages" key and include the total number of characters in the "name" key. Constraints...
codefeedback
You are given two dictionaries, `dict1` and `dict2`, containing key-value pairs. Create a new dictionary, `combined_dict`, that combines the key-value pairs from both dictionaries. If a key exists in both dictionaries, the value from `dict2` should overwrite the value from `dict1` in the `combined_dict`. Return the fin...
codefeedback
Find the starting index of each occurrence of the word "Hello" in the given string, case insensitive. However, exclude any occurrences where "Hello" is followed immediately by a punctuation mark (., !, ?, etc.). string = "Hello World! Hello there, Hello!"
codefeedback
Create a function that prints out an ASCII art of a unicorn with a rainbow-colored mane and tail, using only a single line of code.
codefeedback
Given a list of integers, append the elements of another list to it. The second list should only contain prime numbers and must be sorted in descending order. The resulting list should not have any duplicate elements and should be sorted in ascending order. The total number of elements in the resulting list should not ...
codefeedback
Define a function to calculate the median of a given array of numbers. The array will always have an odd number of elements, and you are not allowed to use any built-in functions or libraries to find the median. Additionally, you are not allowed to use any loops or recursion in your implementation.
codefeedback
Given a string of words, what is the most efficient way to replace all occurrences of the word "a" with "the" while preserving the original word order and case? word_string = "I am learning a lot of new things! A cat is sitting on a mat." #Erroneous Code Reference# word_string = word_string.replace("a", "the") #Expe...
codefeedback
Define a callback in JavaScript to be used with the onclick event. The callback should only execute if the user has clicked the button exactly five times within a 3-second interval and the button is pressed using the right mouse button.
codefeedback
Write a SQL query to sort a table in descending order by its "Date" column, and then in ascending order by its "Name" column. Additionally, the query should exclude any rows where the "Status" column is equal to "Inactive".
codefeedback
Using the list of numbers, create a filter in Python that removes all odd numbers from the list and sorts the remaining even numbers in descending order. Additionally, the filter should only include numbers that are divisible by 3. The final filtered list should be converted to a string, where each number is separated ...
codefeedback
What are the different ways to loop through a list in Python? Implement a function that takes in a list of integers and returns the sum of all even numbers using a for loop. # Revised Test # Implement a function called `sum_of_even_numbers` that takes in a list of integers and returns the sum of all even numbers in th...
codefeedback
Provide an implementation of a program that generates a random password of length N, where N is a positive integer provided by the user. The password should consist of a combination of uppercase letters, lowercase letters, digits, and special characters. The program should also include a function that checks the streng...
codefeedback
Create a type alias for a function pointer in C, and explain the difference between a function pointer and a regular function declaration. Additionally, provide an example of how to use the function pointer type alias in a program. In addition to the previous requirements, please also explain the concept of callback f...
codefeedback
Develop a function in JavaScript to calculate the volume of a sphere. The function should take the radius of the sphere as a parameter and return the volume. The radius can be a floating-point number. The formula for calculating the volume of a sphere is (4/3) * π * radius^3. Example: calculateSphereVolume(10); // Ou...
codefeedback
Using JavaScript, create an object named "person" with the following properties: "name" (string value of "John"), "age" (number value between 18 and 65), "gender" (string value of either "male" or "female"), "hobbies" (array of at least 3 string values), and "friends" (array of objects representing friends, where each ...
codefeedback
Write a JavaScript function that converts a string to title case, but only for words that are longer than 5 characters. The function should also ignore common words such as "the", "and", "or", "but", and "is". The converted string should have the first letter of every eligible word capitalized. The input string may con...
codefeedback
What are the advantages and disadvantages of using mutable objects compared to immutable objects in terms of memory management and performance? Provide examples to support your answer.
codefeedback
Create a Python script that removes all whitespace and punctuation marks from a given string, but do not use any built-in string manipulation functions or regular expressions. Additionally, the script should ignore case sensitivity and consider non-English characters in the string. string = " Hèllö, Thérè! "
codefeedback
Create a function to calculate the value of "e" to the nth term using the Taylor series expansion. In mathematics, the value of "e" can be calculated using the formula: e^x = 1 + x/1! + x^2/2! + x^3/3! + ... where x is the input value and n is the number of terms to be calculated. For this problem, the input va...
codefeedback
Increase the difficulty of the given programming test question by adding more complex functionalities to the class and adding additional validations. Create a class called Person with the following variables: name, age, gender, and height. Implement the following methods in the class: 1. getName(): This method should ...
codefeedback
Write a SQL query to show all the students from the database 'students' with a first name starting with 'A', whose last name ends with 'son', and whose student ID is a prime number.
codefeedback
Create an SQL query to calculate the total sales per month for each product, where the product must have at least 100 sales in a month to be included in the result. Additionally, the query should exclude any products that have a price higher than $100 and were sold in a country other than the United States.
codefeedback
Design a user authentication system for a high-security government agency with a login page, logout page, and a registration page. Implement the following advanced features: 1. User Registration: - Allow new users to register by providing a unique username, a strong password (must include at least one uppercase let...
codefeedback
How would you convert a given number in hexadecimal format to binary using bitwise operators and without using any built-in conversion functions? Write a function that takes in a string representing a hexadecimal number and returns a string representing its binary equivalent. Example: hex_to_bin("3E") => "111110" No...
codefeedback
Create a database table called "Users" with 4 columns "Name", "Age", "Address", and "PhoneNumber". Implement a function that allows users to perform the following operations on the table: 1. Insert a new user into the table. 2. Retrieve all users from the table. 3. Update the information of a specific user. 4. Delete a...
codefeedback
What are lambda expressions in Python and how can they be used to sort a list of dictionaries based on a specific key value? Additionally, the program should only use lambda expressions to sort the list, without using any other sorting methods or functions provided by Python's built-in libraries.
codefeedback
Implement a binary min-heap data structure in Python that supports the following operations: 1. Insertion of a new element into the heap. 2. Deletion of the minimum element from the heap. 3. Searching for a specific element in the heap. 4. Merging two min-heaps into one. You must use a list to store the elements of th...
codefeedback
Identify and correct the errors in the following code: 1. The function should be named "multiply_two_numbers" instead of "add_two_numbers". 2. The variables "a" and "b" should be integers. 3. Add a constraint that the input integers "a" and "b" should be within the range of -1000 to 1000. 4. Add a requirement that the...
codefeedback
Sort a given list of objects (integers or strings) in descending order, using only a single line of code. The sorting algorithm used should be quicksort. The list should be sorted in-place, without using any built-in sorting functions or libraries. The time complexity of the sorting algorithm should be O(n log n) and t...
codefeedback
Generate 10 unique random numbers between 5 and 10, inclusive, without using any built-in random number generation functions or libraries. Additionally, ensure that the sum of all the generated numbers is equal to 60.
codefeedback
Implement the function with the input parameters, described below, to calculate the sum of two positive integers greater than or equal to 100. Parameters: a, b (both of type int) Constraints: 100 ≤ a ≤ 1,000 100 ≤ b ≤ 1,000 Requirements: - The function should return the sum of the two integers.
codefeedback
Create a function to parse the given HTML and return an array containing the text content of all the <p> tags that have a class attribute with the value "include", excluding any paragraphs that have a class attribute with the value "exclude".
codefeedback
Edit the code to print out the HTML code for a table with seven columns and seven rows. Each cell in the table should have a unique identifier in the format "cell_rowColumn", where "row" represents the row number (starting from 1) and "Column" represents the column number (starting from 1). Additionally, the table shou...
codefeedback
Compute the centroid of given points using mathematical formulas. Find the centroid only for points that have positive y-coordinates and even x-coordinates. The number of points must be less than or equal to 10 and all points must have distinct x-coordinates. Return the centroid as a tuple rounded to the nearest intege...
codefeedback
Write a C# code to convert a given number to words, but you cannot use any built-in functions or libraries to perform the conversion. Additionally, ensure that the code handles negative numbers correctly and includes a mechanism to handle numbers beyond the range of an integer.
codefeedback
Explain the concept of polymorphism in object-oriented programming and provide a practical example of its implementation in Java. Discuss the advantages and disadvantages of using polymorphism in software development.
codefeedback
Create a program to find the most frequently used word in a given text. The program should now ignore common stop words such as "is", "a", "of", "and", and "in". The text can contain up to 1000 words. Additionally, please implement a feature that allows the program to handle texts containing special characters, punctu...
codefeedback
Construct a balanced binary search tree from the given array of integers. Additional Requirements: 1. The time complexity of constructing the tree should be O(n), where n is the number of integers in the array. 2. The space complexity of constructing the tree should be O(log n), where n is the number of integers in th...
codefeedback
Create a nested for loop that prints the prime numbers from 0 to 100, but also include a piece of erroneous code that needs to be fixed.
codefeedback
Build a function that takes in an array of integers (between -100 and 100, inclusive) and returns the average (rounded to the nearest whole number) of the numbers that are divisible by 3. The function should ignore any negative numbers in the array and consider only the positive numbers. If the array does not contain a...
codefeedback
Create a nested loop that increments a variable from 0 to 10,000. However, the outer loop must start from 1 instead of 0 and the inner loop must only iterate when the outer loop variable is a prime number. Additionally, the program should store all prime numbers encountered during the execution of the loops in a separa...
codefeedback
Create a program to filter out keywords from a given text. The input text will be a string of length n and will contain only alphabetical characters and spaces. The input keywords will be a list of m strings, each of length k. The maximum values for n, m, and k are 10^6. The program should return a new string that is...
codefeedback
Write a function that checks if a given string contains a valid date in the format "MM/DD/YYYY". The function should also account for leap years. #Sample Input/Output# Input: "12/31/2022" Output: True Input: "02/30/2021" Output: False Input: "02/29/2020" Output: True
codefeedback
Create a function in SQL to return the average of all values in a column, but also exclude any rows where the value is less than 10. Additionally, for each excluded row, return the row number in the original table.
codefeedback
Design a function in Java to take an array of numbers and return the smallest one. The array may contain negative numbers and floating-point numbers. Your function should also handle the case when the array is empty and return an appropriate error message.
codefeedback
Design a MySQL query to count the number of occurrences for each letter of the alphabet in a given string, while ignoring the case of the letters and excluding any special characters or numbers. "Hello World 123"
codefeedback
Write a SQL query that will select all the records that match a given date, considering that the date must be within the last 30 days and the records must also satisfy an additional condition: the value in a specific column must be greater than 100.
codefeedback
Create an array with the following elements: 1, 2, 3, 2, 1, 4, 5, 4, 3, 2, 1. Write a function that removes all duplicate elements from the array and returns a new array containing only the unique elements. The function should also sort the elements in descending order.
codefeedback
Construct a function which will take the name of a month as a parameter and return the number of days in that month. The function should also handle leap years and return an error message if an invalid month name is provided. Additionally, the function should take into account different calendar systems such as the Jul...
codefeedback
Implement a function in Python that takes in a list of integers and returns the sum of all even numbers in the list. If there are no even numbers, the function should return 0. Additionally, the function should only use a single loop and should not use any built-in functions or methods for checking if a number is even.
codefeedback
Create a program in PHP to print a multiplication table from 1-10, but exclude the multiples of 3 and 5.
codefeedback
Create a function that creates a random number within a given range (inclusive) and also ensures that the generated number is divisible by a specific value. The function should also take into account any additional constraints specified by the user, such as excluding certain numbers or requiring the generated number to...
codefeedback
Write a Python Class to store a telephone directory's details. The class should be able to handle a large number of entries efficiently, with a maximum time complexity of O(log n) for searching, inserting, and deleting entries, where n is the number of entries in the directory. Additionally, the class should provide a ...
codefeedback
Write a JavaScript function to validate the syntax of an IP address. Additionally, the function should check if the IP address is within a specific range of valid IP addresses. The range of valid IP addresses should be provided as a parameter to the function. The function should also handle IPv6 addresses in addition t...
codefeedback
Rewrite the given function without using the ternary expression and without using any built-in mathematical functions or operators. Additionally, the rewritten function must have a time complexity of O(1).
codefeedback
Create a Python script that retrieves the contents of a given URL and calculates the word frequency in the retrieved text. The URL should be passed as a command-line argument when running the script. The script should handle any errors that may occur, such as invalid URLs or network connectivity issues, and display app...
codefeedback
Write an SQL query to retrieve names, email addresses, and phone numbers from a table called "user_info". The phone numbers should be in a specific format: "+[country code]-[area code]-[phone number]". Additionally, the query should only return users whose email addresses are from a specific domain, "example.com".
codefeedback
Explain what is a median in statistics and write a program that takes a list of numbers as input and outputs the median. Your program should handle both odd and even number of inputs. Additionally, your program should handle cases where the input list may contain duplicates. In such cases, the median should be the ave...
codefeedback
Write a Bash script that creates a directory in the current working directory if it doesn't already exist, and then copies all the files from a specified source directory into the newly created directory. Additionally, the script should exclude any files with a specific extension (e.g. .txt) from being copied. The scri...
codefeedback
Write a JavaScript code snippet that generates a random password with the following criteria: - The password must be 10 characters long. - It must contain at least one uppercase letter, one lowercase letter, one digit, and one special character (!@#$%^&*). - The password should not contain any repeated characters. - Th...
codefeedback
Write a function in Python that takes two strings as input and returns a sorted version of the first string with all occurrences of the letters in the second string removed. The function should have a time complexity of O(n log n), where n is the length of the first string. The space complexity should be O(n), where n ...
codefeedback
Create a program to check if a number lies between two other numbers, but with the following constraints: 1. The program should have a time complexity of O(1) (constant time complexity). 2. The program should use only a constant amount of additional space (O(1) space complexity). 3. The program should be implemented u...
codefeedback
Increase the difficulty of the given programming test question by adding the following requirements: 1. Implement a multi-layer neural network instead of a basic neural network. The network should have at least one hidden layer. 2. Use a different activation function for the hidden layer and output layer (e.g., ReLU f...
codefeedback
Write an Apache Spark code snippet to count the number of elements in an array of integers. The array must contain at least 1000 elements and the count must be calculated in parallel using multiple Spark partitions. Additionally, the count should only include positive integers greater than 10 and should be sorted in de...
codefeedback
Transform the string by swapping all lowercase characters with their respective uppercase characters and vice versa. Additionally, sort the characters in the resulting string in lexicographical order.
codefeedback
Create a responsive web page with a table of 6 columns and a submit button to submit the table data. The table should have alternating row colors and a fixed header that remains visible when scrolling. The submit button should be disabled until all table fields are filled. Additionally, implement client-side validation...
codefeedback
Write a MySQL query to update a table cell. Update the 'salary' value from 20000 to 21000 for the employee with the highest salary in the 'employees' table. Additionally, ensure that the 'salary' value is only updated if it is lower than 25000. However, instead of directly updating the 'salary' value, create a new c...
codefeedback
Develop an AI model to classify emails with spam contents, offensive language, and hate speech content. The model should be able to accurately identify and classify these three categories. To increase the difficulty of this test, you can add the following additional requirements: 1. Implement a feature to handle lang...
codefeedback
Compute the union of two sets A and B using algorithms. You are not allowed to use any built-in functions or libraries for set operations. The input sets can contain duplicate elements and may not be sorted. Your solution should have a time complexity of O(n+m), where n and m are the lengths of sets A and B respectivel...
codefeedback
Rearrange the characters of a given string in the order of their frequency, while ensuring that no two adjacent characters are the same. You are given a string of lowercase English letters. Your task is to rearrange the characters in such a way that the characters with the highest frequency come first, followed by cha...
codefeedback
Create a CSS style sheet to make the text on a page bold, the background yellow, and the font size 20 pixels. Additionally, implement a functionality to change the text color to red when hovering over it with the mouse cursor. The style sheet should only be applied to a specific section of the page with the class name ...
codefeedback
Convert this Python statement into a list comprehension, without using the 'if' statement and without using any built-in functions or methods. for item1 in list1: for item2 in list2: if item1 == item2: result_list.append(item1)
codefeedback
Given a SQL table named 'products', write a query to find all products with names starting with 'T', have a price greater than 100, and have been purchased more than 10 times. Table Name: products Attributes: name, price, quantity_purchased
codefeedback
Please write a program that simulates a web server. The web server should be able to handle multiple client requests simultaneously and return appropriate responses based on the requested resources. Requirements: 1. The web server should support the HTTP GET and POST methods. 2. The server should be able to handle mul...
codefeedback
Write an SQL query to count the number of books of each genre, and display the result along with the genre name, the average rating for each genre, and the author with the highest rated book in that genre. Table Name: books Attributes: id, title, author, genre, rating Note: The rating attribute is a decimal value rang...
codefeedback
Develop a natural language processing model to detect sarcasm in text, taking into consideration various languages and cultural contexts. The model should also be able to identify sarcasm in different mediums such as social media posts, emails, and chat conversations. Additionally, the model should provide an accuracy ...
codefeedback
Write a SQL query to find all customers who have made a purchase on the same date that they made a purchase with a product price greater than 1000. Additionally, sort the result by the total amount spent by each customer in descending order. Table Name: products Attributes: id, name, price Table Name: purchases Attri...
codefeedback
Write a Python program to remove all duplicate tuples from a list of tuples, where each tuple consists of integers. The program should only remove exact duplicate tuples, not tuples that have the same values in a different order. The program should also sort the remaining tuples in descending order based on the sum of ...
codefeedback
Write a function in Python to calculate the sum of all prime numbers in a list, but only for those prime numbers that are greater than 100 and less than 1000. The function should also return the count of prime numbers that meet this criteria. If there are no prime numbers in the list that meet this criteria, the functi...
codefeedback
Edit the following Python code to add a loop to generate a list of numbers from 1 to 100, but only include prime numbers in the list.
codefeedback
Create a function in JavaScript called "printHello" that takes in a number parameter "n". The function should print "Hello" n times using a for loop. However, the function should print "Hello" in reverse order from n to 1. If n is not a positive integer, the function should return an error message. Additionally, the fu...
codefeedback
Write a Java program to create a calculator using Switch statement that supports addition, subtraction, multiplication, division, and exponentiation. The program should also include error handling for invalid inputs, division by zero, and inputs that exceed the maximum and minimum values of integers. Additionally, the ...
codefeedback
Write an R script to find all entries of a data frame where the 'Name column' equals 'John', the 'Age column' is greater than 25, and the 'Height column' is less than 180.
codefeedback
Create an HTML form to take user input with two fields: one for the user's name and another for their email address. Implement form validation to ensure that the name field only accepts alphabetic characters and the email field only accepts valid email addresses in the format "example@example.com". Additionally, displa...
codefeedback
Given a list of numbers, calculate the median value. The numbers in the list are all positive integers and are in the range of 1 to 1000. The length of the list is odd and ranges from 1000 to 5000. The numbers in the list are not sorted and may contain duplicates. Additionally, the algorithm should have a time complexi...
codefeedback
Create a switch statement in JavaScript to print different messages based on the following conditions: 1. If the condition is "Monday", print "It's the first day of the week." 2. If the condition is "Friday", print "It's the last day of the week." 3. If the condition is "Wednesday", print "It's the middle of the week."...
codefeedback
We have a list of integers, write a function in Python to find the second smallest element in the list. However, you are not allowed to use any built-in sorting functions or data structures. The function should have a time complexity of O(n), where n is the length of the list. Provide a piece of erroneous code as a re...
codefeedback
Write a shell script to find the longest string from an array of strings. The script should also exclude any strings that contain digits or special characters. Additionally, the script should find the longest string without using any built-in functions or commands that directly manipulate strings or arrays.
codefeedback
Rewrite the following program using OOP concepts. The Array class should also include a method called "get_element" that returns the value of a specific element in the array. Additionally, the class should have a method called "get_size" that returns the size of the array. ```python class Array: def __init__(self,...
codefeedback
Create a JavaScript program to find the minimum of three numbers, but the numbers must be stored in an array and the program must use recursion to find the minimum.
codefeedback
Identify the HTML tag for the bold text in the given HTML code. You are required to write a program that extracts the bold text from the HTML code and outputs the result. You are not allowed to use any built-in HTML parsing libraries or functions. The program should handle cases where there are multiple occurrences of ...
codefeedback
Write a recursive function to calculate the sum of all prime numbers in an array of numbers. The function should not use any loops or built-in sum functions. array=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
codefeedback
Write a program in C++ that simulates a linked list data structure. The linked list should be implemented using pointer variables only, and should support the following operations: 1. Insert a node at the beginning of the list 2. Insert a node at the end of the list 3. Delete a node from the list 4. Display the elemen...
codefeedback
Modify the program to accept user input of two numbers and an operator (+,-,*,/), and show the result based on the operator provided. The program should also check if the input numbers are within the range of -1000 to 1000. Additionally, the program should validate the user input to ensure that the numbers are integers...
codefeedback
Write a JavaScript function that takes in a string representing a sentence and returns an array of the most common words in the sentence, excluding common stop words. The function should also exclude any words that are less than 3 characters long. The function should return the words in descending order of their freque...
codefeedback
Create an object-oriented program that calculates the cost of a given item including sales tax, import duty, and additional fees based on the item category. Item cost (without tax): $10 Input tax rate: 10% Input import duty rate: 5% Categories and their additional fees: 1. Electronics: 2% handling fee 2. Clothing: 3% ...
codefeedback
You are given an array of integers and you need to find three distinct numbers such that the sum of the three numbers is equal to a given target sum and the first number is negative, the second number is positive, and the third number is zero. The target sum will be provided as an input parameter. # Example nums = [-4...
codefeedback
Write the code to create a class in Python named "Person" that has the following attributes: name (string), age (integer), and gender (string). The age attribute should be restricted to a range between 18 and 100. Additionally, the class should have the following methods: 1. "is_adult" that returns True if the person i...
codefeedback