instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Evaluate a mathematical expression given as a string. The expression can contain parentheses and the following operators: addition (+), subtraction (-), multiplication (*), and division (/). The expression can also contain floating-point numbers. #Example Input/Output# Input: "2 + 3 * (5 - 1) / 2" Output: 8.0 Input: ...
codefeedback
Create a new Java program that prints out all the prime numbers between 2 and 1000, but without using any built-in methods or libraries for prime number generation or checking. You must implement your own algorithm for determining whether a number is prime or not.
codefeedback
Construct an algorithm for reversing a string without using any built-in string reversal functions or methods. The algorithm should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).
codefeedback
Compare two arrays and output the result in Boolean. However, instead of comparing the arrays directly, you need to compare the arrays while ignoring any duplicate elements and taking into account the order of the remaining elements. Additionally, the comparison should only consider the elements that are multiples of a...
codefeedback
Write an algorithm to generate a random string of length n, where each character in the string can be a lowercase letter, an uppercase letter, or a digit.
codefeedback
Write an R function to print the contents of a dataframe. The function should also display the total number of rows and columns in the dataframe, and print an error message if the dataframe is empty.
codefeedback
Develop a DFS algorithm in Python that can find all possible paths from a starting node to a target node in a directed graph.
codefeedback
What is the maximum number of elements that can be stored in an array in C++ if the array is allocated on the stack?
codefeedback
Develop a code in C for printing the elements of a linked list in reverse order.
codefeedback
Create an identifier in Python that starts with an underscore followed by the letter 'a' and ends with a number between 1 and 10 (inclusive).
codefeedback
Write a function in JavaScript that returns the longest item in the array. However, you are not allowed to use the built-in array methods such as `sort()` or `reduce()`. The function should also handle cases where the array contains non-string elements, such as numbers or booleans, and return the longest string.
codefeedback
How would you create a program in C++ to calculate the average of a set of numbers, where the set size is not known in advance?
codefeedback
Calculate the factorial of 8 using a recursive function and ensure that the function is implemented in a separate module.
codefeedback
In Python, you have a set called `my_set` containing the elements `1, 2, 3, 4, 5`. How do you retrieve the 3rd element of `my_set`?
codefeedback
Implement a function in AngularJS to register a new user with the following requirements: 1. The function should validate that the username is unique and not already taken by another user in the system. 2. The function should validate that the password meets the following criteria: a. Minimum length of 8 characters....
codefeedback
Construct a JavaScript program that displays the current date and time in a specific timezone, considering daylight saving time adjustments.
codefeedback
Create a SQL query to select the customers that have placed orders of price greater than 1000 and have also placed orders in the last 30 days.
codefeedback
Construct a MySQL table for an online store. Table name: online_store Fields: item_type (string), item_location (string), price (integer), item_name (string), quantity (integer). #Erroneous Code Reference# Include a piece of code that tries to insert a row into the table with incorrect data types for the fields, resu...
codefeedback
Create a table in the given MySQL database with 4 columns. However, the database connection is not established correctly and needs to be fixed before proceeding. Database Name: my_db Table Name: my_table Fields: column_1 (string), column_2 (integer), column_3 (string), column_4 (integer).
codefeedback
Convert the given hexadecimal color code to RGB format, without using any built-in functions or libraries. The input will always be a valid hexadecimal color code. The output should be a string in the format "RGB(x, y, z)" where x, y, and z are integers representing the red, green, and blue components of the color resp...
codefeedback
Write a Python program to print the right angled triangle using asterisks, but the base and height of the triangle must be provided by the user as input. The program should handle invalid input and display appropriate error messages.
codefeedback
Generate a Ruby loop to find the sum of numbers 1 to 100.
codefeedback
Generate an array containing the next n numbers in the Fibonacci sequence, but exclude any numbers that are divisible by 3.
codefeedback
Create a SQL query to find all books in the "fiction" genre whose titles contain the word "cat" and have an average rating of at least 4.0.
codefeedback
Create a dictionary from a list of tuples, where the key is the first element of the tuple and the value is the second element of the tuple. However, if the first element of the tuple is a string, the value should be converted to uppercase before being added to the dictionary. If the first element is an integer, the va...
codefeedback
Using list comprehension, create a list which contains multiples of 5 from 0 to 100 (inclusive) but only if the number is divisible by both 2 and 3.
codefeedback
Generate a SQL query to select all authors who have written at least 5 books and have an average rating of their books higher than 4.0.
codefeedback
Create a function to sort a list of dictionaries alphabetically in Python based on a specific key in each dictionary.
codefeedback
Suggest an appropriate algorithm to filter out unwanted words from a given paragraph of text, but with the additional requirement of ignoring case sensitivity while filtering.
codefeedback
Write a SQL query to find the names of the top 10 earning authors, considering only the authors who have published at least 5 books. SELECT a.Name FROM Authors a JOIN Books b ON a.AuthorID = b.AuthorID GROUP BY a.AuthorID, a.Name HAVING COUNT(b.BookID) >= 5 ORDER BY SUM(b.Earnings) DESC LIMIT 10
codefeedback
Generate a code to find the power of n to m. The code should handle edge cases where n or m can be negative, and should return an error message if n is negative and m is not an integer. Additionally, the code should check if n or m is greater than 1000, and if so, use a more efficient algorithm to calculate the power. ...
codefeedback
Suggest an appropriate approach to sort an array of numbers in ascending order using JavaScript, without using any built-in sorting functions or libraries. Additionally, provide a piece of erroneous code as a reference to increase misdirection.
codefeedback
Create a code to calculate the most frequent character in a given string, but exclude any punctuation characters and consider only alphabetic characters. s = "Hello, world!"
codefeedback
Create a program that capitalizes the first letter of every word in a sentence, excluding any conjunctions such as "and" or "but".
codefeedback
Generate a regular expression to extract the domain from an email address, ensuring that the domain name follows the rules of a valid domain name. A valid domain name: 1. Consists of alphanumeric characters (a-z, A-Z, 0-9) and hyphens (-). 2. Cannot start or end with a hyphen. 3. Can have multiple levels separated by ...
codefeedback
Print all the prime numbers in the range of 2 to n, where n can be as large as 10^6.
codefeedback
Given a text string, generate a Python code snippet to find the number of occurrences of a given word. However, the code snippet should exclude any occurrences of the word that are inside a quoted string. For example, if the given text string is: "The quick brown fox jumped over the lazy dog. The lazy dog said, 'I am ...
codefeedback
Create a class called Cat to represent a type of pet. The Cat class should have the following attributes and methods: Attributes: - name: a string that represents the name of the cat - age: an integer that represents the age of the cat - breed: a string that represents the breed of the cat - color: a string that repre...
codefeedback
Print the square of the first 100 prime numbers.
codefeedback
Generate a SQL query to retrieve all active users whose last login was within the last 7 days, ordered by their registration date in descending order.
codefeedback
What is the minimum educational requirements and practical experience needed to become a highly skilled AI Engineer?
codefeedback
Output the lexicographical order of a given array of strings. The array may contain duplicate strings, and the output should remove any duplicate values. Also, the output should be in descending order instead of ascending order. words = ["apple", "banana", "cherry", "banana", "apple"]
codefeedback
Design an algorithm to calculate the maximum profit for buying/selling any number of shares of a company's stock. Share Prices = [9, 11, 8, 5, 7, 10] Note: You can only make one transaction at a time, and you must sell the shares before buying again. Time Complexity Requirement: O(n) Space Complexity Requirement: O(...
codefeedback
Go through the following list of car models, and print out only the names of all-electric vehicles. Additionally, if a car model has a range of less than 200 miles per charge, do not include it in the output. Tesla Model 3 (Range: 263 miles per charge) Tesla Model X (Range: 328 miles per charge) Toyota Corolla (Range:...
codefeedback
Create a Python script to add a new field of “car color” to the given JSON object, but also check if the value of "car color" is a valid color name (e.g. red, blue, green). If the color is not valid, raise an exception with an appropriate error message.
codefeedback
Create a Python script to convert the given JSON object into an XML document, while also encrypting the XML data using a symmetric encryption algorithm such as AES. The encrypted XML data should then be saved into a file with a dynamically generated name based on the current date and time.
codefeedback
Create a Python program to find the average of the given numbers in the list. Additionally, handle any possible input errors or exceptions that may occur during the execution of the program.
codefeedback
Construct a SQL query to find all the customers who live in California, have more than 5 reviews, and have made at least 3 purchases in the last month.
codefeedback
How can we store data persistently on the user's machine while ensuring data security and minimizing storage space usage?
codefeedback
Explain this JavaScript code snippet that utilizes higher-order functions and closures to create a reusable greeting function. ```javascript function createGreeting(greeting) { return function(name) { console.log(greeting + ' ' + name); } } const sayHello = createGreeting('Hello'); sayHello('John'); // Shoul...
codefeedback
Create an SQL query to select the "firstname" and "lastname" of the customers with an orderid of 30, and display the total number of orders placed by each customer.
codefeedback
Create a program in Java to create a scientific calculator that has the ability to perform advanced mathematical operations such as finding the square root, calculating exponential values, and performing trigonometric functions (sine, cosine, tangent).
codefeedback
How can we prevent memory leaks in Java when using multi-threading?
codefeedback
Rewrite the `proxy` function in JavaScript to create a proxy object that adds an additional layer of validation to any target object. The proxy object should perform the following tasks: 1. Track the number of times a property on the target object is accessed. 2. Track the number of times a property on the target obje...
codefeedback
Write a web crawler for a specific website that can handle dynamic content and can extract data from multiple pages. To increase the difficulty, you can also consider the following modifications: 1. Implement a mechanism to handle website authentication or login requirements before crawling. 2. Introduce rate limiting...
codefeedback
Write a JavaScript function that takes in two arrays of equal length, and returns a new array that contains only the unique elements from both arrays, in ascending order. Example: Input: [1, 2, 3, 4], [3, 4, 5, 6] Output: [1, 2, 3, 4, 5, 6] Constraints: - The input arrays will always have equal lengths. - The input a...
codefeedback
You need to write a regular expression that will match any string containing only the letters 'a', 'b', and 'c', in any order.
codefeedback
Create an HTML page with a heading, a paragraph, and a button that says "Click Here". - Upon clicking the button, change the background color of the page to a randomly generated color. - Implement a timer that counts down from 10 seconds when the button is clicked. - After the timer reaches 0, disable the button. -...
codefeedback
Write a function in Ruby that takes in two strings and returns a new string that contains both strings with a space in between them. However, you are not allowed to use any built-in string manipulation methods such as `+`, `concat`, or `<<` to concatenate the strings. You must implement your own logic to achieve the de...
codefeedback
Write a JavaScript program that will console log the first 20 numbers of the Fibonacci sequence, where each number is a prime number.
codefeedback
Generate an HTML form with three fields "username", "password" and "confirm password". Implement client-side validation for the following requirements: 1. The username field should accept alphanumeric characters only and should be between 5 and 15 characters long. 2. The password field should accept a minimum of 8 char...
codefeedback
You need to modify the existing code to implement a sorting algorithm. The code should take an array of integers as input and sort them in ascending order. The time complexity of your solution should be O(nlogn), where n is the size of the input array. int[] arr = {5, 10, 3, 7, 1};
codefeedback
You need to create a JavaScript program that will find the factorial of a given number stored in the variable x. The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 is calculated as 5 * 4 * 3 * 2 * 1 = 1
codefeedback
Construct a regular expression that will match only strings that contain a number and start with a lowercase letter.
codefeedback
You need to write a function that takes an array of integers and returns the count of prime numbers in the array.
codefeedback
Write an HTML program to display a table with a list of names and ages of people. The program should also include a button next to each person's name that, when clicked, will remove that person from the table. names = ["John", "Dylan", "Mary"], ages = [20, 15, 18]
codefeedback
Write a code that prints the even numbers from 100 to 0 in descending order. Additionally, you need to skip any numbers that are divisible by 5.
codefeedback
Develop a Java program that counts the frequency of a given word in a sentence, taking into consideration that the sentence can contain multiple lines and the word can be present in different cases (e.g., "Code", "CODE", "code"). Input: sentence = "I am learning to Code.\nCode is fun to learn.\nI love coding!", word = ...
codefeedback
Create an SQL query that will return a table containing name and email columns from a table called "users" where the name begins with the given name parameter, and the email domain is "gmail.com".
codefeedback
Rewrite the following Python function to include a try/except block. The function should handle the case when either num1 or num2 is not a valid integer and raise a custom exception called "InvalidInputError". Additionally, the function should handle the case when the multiplication operation results in an overflow and...
codefeedback
Build a React component to render a header with the text "My Website" and a dynamic background color that changes every time the component is re-rendered. The background color should be randomly selected from a predefined list of colors. Additionally, implement a feature where the header text fades in slowly when the c...
codefeedback
Debug the following program and make it function correctly. Additionally, modify the program to count the number of unique words in the given text. def count_unique_words(text): words = text.split() unique_words = set(words) count = 0 for word in unique_words: count += 1 return count strin...
codefeedback
Write a function that parses a given URL into its component parts, including the protocol, domain, path, and any query parameters. Example: Input: url = "https://www.example.com/articles/first-article?category=tech&sort=desc" Output: { "protocol": "https", "domain": "www.example.com", "path": "/articles/first-...
codefeedback
Read a given text and classify each sentence as true or false. text = "The sky is blue, the sea is blue. The grass is green." # Reference Erroneous Code # text = "The sky is blue. The sea is green, the grass is blue."
codefeedback
Create a program that takes an angle in degrees as input and generates a 3x3 rotation matrix using the given angle. Additionally, implement a function to multiply two 3x3 matrices together. To solve this problem, you need to understand the concept of rotation matrices and matrix multiplication. 1. Start by obtaining ...
codefeedback
Given a string, find the length of the longest word that can be formed by rearranging the characters of the string.
codefeedback
Implement a function that prints all prime numbers up to the provided number, but with the following additional requirements: 1. Use the Sieve of Eratosthenes algorithm to generate the prime numbers. 2. Handle the case when the provided number is less than 2, and print an appropriate error message. 3. Optimize the alg...
codefeedback
Create a function to generate a list of prime numbers between 2 and n, where n is a positive integer greater than 2. The function should also implement the Sieve of Eratosthenes algorithm to optimize the generation of prime numbers.
codefeedback
Design a database with tables and columns representing customers, orders, products, and payment transactions. Implement a system that allows customers to place orders, add products to the orders, and make payments for the orders. The system should also keep track of the total order amount, calculate any applicable disc...
codefeedback
Generate a random string of length 10 consisting of letters (both uppercase and lowercase) and numbers, without using any built-in functions or libraries.
codefeedback
Given a binary search tree, write a code to search for a given value in the tree.
codefeedback
Construct a code that takes a list of words as input and changes the case of each item in the list, while also removing any duplicate words. The code should maintain the order of the words in the list. The input list can contain words with varying lengths and special characters. Example: Input: ["Cat", "dog", "APPLE",...
codefeedback
Generate python code to replace each character in a string with the next character in the alphabet, but ignore vowels and only replace consonants.
codefeedback
Write a code to sum all the values of the following dictionary, but only consider the values that are even numbers. If there are no even numbers in the dictionary, return 0.
codefeedback
Create a loop that takes a given number as input and outputs its prime factors, but with the additional requirement that the loop must use a recursive function to find the prime factors.
codefeedback
You are working on an e-commerce platform and need to keep track of the list of items purchased by each customer. In order to efficiently manage this information, you need to determine the most appropriate data structure to use. Describe in detail the data structure you would choose and explain why it is the best choi...
codefeedback
Merge two binary trees t1 and t2 into a new binary tree. The merged tree should have the following properties: 1. The value of a node in the merged tree is the sum of the values of the corresponding nodes in t1 and t2. 2. If a node exists in one tree but not in the other, the corresponding node in the merged tree shou...
codefeedback
Given a set of strings s, find an algorithm to determine if the set is a palindrome. The strings in the set are composed of only lowercase English alphabets and the maximum length of each string is 100. The palindrome test should be case-insensitive, meaning that strings that are the same when their case is ignored sho...
codefeedback
Write a function to determine if a given string is a valid English word or not, considering the following additional requirements: - The function should have a time complexity of O(n), where n is the length of the input string. - The function should use a Trie data structure to efficiently store and retrieve words. - T...
codefeedback
Create a function in C# which takes a string as an input and returns a boolean value indicating if the string is a palindrome or not. However, the function should also ignore any non-alphanumeric characters (such as spaces, punctuation, and symbols) and should be case-insensitive. For example: - If the input string is...
codefeedback
Given two sorted arrays nums1 and nums2, combine their elements into a single array that is sorted. However, the combined array should not contain any duplicate elements. If there are duplicate elements in either of the input arrays, they should only appear once in the combined array. Example: nums1 = [1, 2, 3, 3, 4, ...
codefeedback
Given two unsorted arrays, merge them in a sorted form without using any extra space. #Instructions# Write a function merge_arrays(nums1, nums2) that takes in two unsorted arrays, nums1 and nums2, and merges them in a sorted form without using any extra space. The merged array should be returned as the result. #Examp...
codefeedback
Create a bar chart on the webpage to display the data, where each bar represents a data point. The height of each bar should correspond to the value of the data point. The chart should also include axis labels and a title. The data should be retrieved from an external API and updated in real-time on the chart. The char...
codefeedback
Implement selection sort algorithm to sort an array of integers in Java. arr = [5, 8, 2, 7, 1, 9, 3, 6, 4] Your task is to sort the array in ascending order using the selection sort algorithm. The selection sort algorithm works by dividing the input array into two parts: the sorted part and the unsorted part. In each...
codefeedback
Write a C++ statement to create an array of 10 elements, where all elements are non-negative integers and have a maximum value of 100.
codefeedback
Write a SQL query to print out the names and ages of employees in the Employees table who are older than 25, sorted in descending order of age. Employees table is defined as: (employee_id int, first_name varchar(255), last_name varchar(255), age int). In addition to the above requirement, add the following: 1. Exclu...
codefeedback
Write a Java method named "reverseString" that takes in a string variable "str" as a parameter and returns the reverse of the input string. The method should handle both uppercase and lowercase characters. The returned string should have the first letter capitalized and the rest of the letters in lowercase. The input s...
codefeedback
Create a function to search a given string for the first vowel, while ignoring any vowels that are immediately followed by a consonant. The function should also return the index position of the vowel in the string.
codefeedback
What is the best way to store user input in JavaScript when the input consists of multiple fields with different data types and the input needs to be validated and sanitized before storage?
codefeedback
Write an HTML program to capture the entered text in an input box and validate that it meets the following criteria: - The text must contain at least one uppercase letter and one lowercase letter - The text must include at least one special character (!, @, #, $, %, &, or *) - The text must be at least 8 characters lon...
codefeedback