instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Modify the following Javascript code to check if a given number is a twin prime or not. A twin prime is a prime number that is either 2 less or 2 more than another prime number. | codefeedback |
Create an HTML page to display a table with 2 columns: Description and Price. The table must have a fixed header that remains visible while scrolling. The Description column must be sortable in ascending and descending order. The Price column must display a currency symbol and format the numbers with comma separators. ... | codefeedback |
Create a Python script that takes in two optional command line parameters:
- A string representing a file name, with a default value of "data.txt".
- An integer representing the maximum number of lines to read from the file, with a default value of 100.
The script should read the specified number of lines from the f... | codefeedback |
Create a class called “Car” in Java with the following attributes and methods. The Car class should have an additional attribute called "color" which represents the color of the car. The color attribute should be a String type. The Car class should also have a method called "startEngine" which starts the engine of the ... | codefeedback |
Create a function in Python that takes two parameters and calculates the Employee Bonus depending on the hours worked.
hours - 14
hourly_rate - 17
However, in addition to calculating the bonus, the function should also check if the hours worked is within the valid range of 0 to 40. If the hours worked is less than 0 o... | codefeedback |
Generate a correct JavaScript code to subtract two numbers using bitwise operators.
391, 198 | codefeedback |
Develop a jQuery program to toggle the visibility of multiple divs on a webpage. The program should allow the user to toggle the visibility of each div individually by clicking on a corresponding button. Additionally, the program should keep track of the current visibility state of each div, so that when the page is re... | codefeedback |
Normalize the following data set while also removing any negative values and sorting the resulting list in descending order.
Input: [1000, 75, 16, -200, 24]
Output: [1000, 75, 24, 16] | codefeedback |
Compare the two strings and output the number of characters that are different between the two strings. The program should also provide the positions of the differing characters within the strings.
String A: Hello there
String B: Hi everyone | codefeedback |
Create an exponential moving average function in R that accepts a vector of numbers as input and returns a vector of the same length containing the exponential moving average values. The function should also include an optional parameter for specifying the smoothing factor (alpha) used in the calculation. If the parame... | codefeedback |
Write a Python program to check if a string contains at least three consecutive special characters. | codefeedback |
Create an Angular app with a login page and registration page. The registration page should include a form with fields for username, password, and email. Implement validation to ensure that the password is at least 8 characters long and contains at least one uppercase letter, one lowercase letter, and one special chara... | codefeedback |
Create a query that returns the top 5 cities with the highest population, but only include cities that are located in countries with a GDP per capita greater than $50,000. | codefeedback |
You are given an array of numbers. Create a function to check if the array contains duplicate values. Your function should also return the indices of all duplicate values found. The input array will have a length of at most 1000. | codefeedback |
You are given an array of strings. Write a Python script to sort the array in alphabetical order. However, you are not allowed to use any built-in sorting functions or methods. Instead, you need to implement your own sorting algorithm. | codefeedback |
Create a program to remove all duplicate elements from a list and return a new list with the unique elements. Your program should also maintain the order of the original list while removing the duplicates. Additionally, your program should have a time complexity of O(n) and space complexity of O(n), where n is the numb... | codefeedback |
Create an algorithm to implement a binary search that can handle a list of integers in ascending order and efficiently find the position of a given target number. The algorithm should have a time complexity of O(log n) and should not use any built-in search functions or libraries. | codefeedback |
Train a recursive neural network to classify whether a sentence is positive or negative sentiment, taking into account the intensity of the sentiment. | codefeedback |
Categorize the sentiment of each sentence in a given text as positive, neutral, or negative. Additionally, determine the overall sentiment of the entire text by analyzing the sentiment of individual sentences. | codefeedback |
Filter the following array of numbers so that only the prime numbers remain.
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | codefeedback |
Write a SQL query to find all teachers who have taught at least 5 different subjects and have more than 10 years of experience. | codefeedback |
Edit the given HTML code to add a footnote section that dynamically generates footnotes for each paragraph. The footnotes should be numbered in ascending order starting from 1. The footnotes should be displayed at the bottom of the page in a separate section.
<code>
<!DOCTYPE html>
<html>
<head>
<title>Example</ti... | codefeedback |
Program a function in JavaScript to remove adjacent duplicates from the given array. The array may contain both numbers and strings.
Example:
```javascript
removeAdjacentDuplicates([2, 3, 3, 3, 6, 9, 9]); // [2, 3, 6, 9]
removeAdjacentDuplicates(['a', 'b', 'b', 'c', 'c', 'c']); // ['a', 'b', 'c']
```
Note: The func... | codefeedback |
Using Java, create a program to find the highest value in this array, but with the following additional constraints:
1. You cannot use any built-in sorting or searching functions such as Arrays.sort() or Arrays.binarySearch().
2. You cannot use any additional data structures such as ArrayList or LinkedList to help wit... | codefeedback |
Create a function which accepts a string and prints out each word with the count of its characters. However, you must use a recursive approach to solve this problem. Additionally, if the string contains any special characters or numbers, you should ignore them and only consider the words. Lastly, you should handle case... | codefeedback |
Design a SQL database to store the information of teachers, including their personal details, educational qualifications, teaching experience, and courses they are currently teaching. Implement appropriate data types, constraints, and indexes to ensure efficient querying and data integrity. Additionally, include a feat... | codefeedback |
Given a JSON object, output an object with keys sorted in descending order based on the length of the key. If two keys have the same length, sort them alphabetically. If two keys have the same length and alphabetical order, sort them based on the number of vowels in the key. If two keys have the same length, alphabetic... | codefeedback |
Define an F# array and initialize it with prime numbers from 0 to 10 | codefeedback |
Design a Python class to represent geometric shapes with the following constraints:
- The class should have methods to calculate the area and perimeter of the shapes.
- The class should support different types of shapes such as rectangle, circle, and triangle.
- The class should handle input validation for the shape di... | codefeedback |
Create a loop to delete all elements in a linked list, but also ensure that the loop is efficient and does not have a time complexity higher than O(n), where n is the number of elements in the linked list. | codefeedback |
Create a JavaScript code snippet to check if a given number is a prime number. | codefeedback |
Change the provided dataset into a 3-dimensional tensor and normalize the pixel values between 0 and 1, in order to feed it into a Convolutional Neural Network model. The dataset contains 50,000 color images of size 256x256. Additionally, implement data augmentation by randomly applying horizontal and vertical flips to... | codefeedback |
Create a webhook in Python to listen to webhook requests and validate the incoming requests using HMAC-SHA256 authentication. | codefeedback |
Compute the Shannon entropy of a given probability distribution.
Distribution: [0.15, 0.35, 0.5] | codefeedback |
Remove duplicates from the given list and return a new list. The input list may contain integers, floats, strings, and nested lists. The output list should maintain the original order of elements in the input list.
Example:
Input: [2, 3, 4, 2, 3, 5, 4.5, "apple", "banana", "apple", [1, 2, 3], [2, 3, 4]]
Output: [2, 3,... | codefeedback |
Write code to implement the Binary Search algorithm in Python.
## Requirements:
- The time complexity of the solution should be O(log n), where n is the length of the input list.
- The space complexity of the solution should be O(1), i.e., the solution should not use any additional data structures that scale with the ... | codefeedback |
Create a program in C++ that takes an input integer and checks whether it is odd or even. The program should also handle the case where the input is not a valid integer. Additionally, the program should only use bitwise operations to determine if the number is odd or even. | codefeedback |
Generate a Python code to convert list of strings to list of integers. The code should handle situations where the input list contains both integers and non-integer strings. Any non-integer strings should be skipped and not included in the final list of integers. The converted list should be sorted in ascending order. ... | codefeedback |
You are provided with a list of integers and a given number. Generate Python code that detects if the given number is in the list or not. Additionally, you need to ensure that the code has a time complexity of O(log n), where n is the length of the list. The list will always be sorted in ascending order. Return True if... | codefeedback |
You need to create a Python function to remove duplicate elements from a given list while maintaining the original order of elements. The function should return the updated list.
[11,46,70,23, 11, 33, 46]
#Constraints and Requirements#
1. The function should have a time complexity of O(n), where n is the length of the... | codefeedback |
Create a Python code that takes in two strings and finds all common characters from the strings. The code should handle cases where there are multiple occurrences of a character in a string and should return a dictionary where the keys are the common characters and the values are the number of occurrences of that chara... | codefeedback |
Create a Python code to find all uncommon characters between two strings, ensuring that the code can handle strings of up to 1000 characters in length. The code should also be optimized to find the uncommon characters in O(n) time complexity, where n is the length of the longer string. | codefeedback |
You need to create a Python function to detect if a given number is prime or not. However, you are not allowed to use any built-in functions or libraries to check for prime numbers. You must implement the prime-checking logic from scratch using only basic programming constructs. | codefeedback |
Write a loop to print all prime numbers from 1 to N, where N is a positive integer input by the user. | codefeedback |
Create a Python function to sort a list of strings based on a given alphabetical order. The alphabetical order is defined by a dictionary where each letter is associated with a unique integer value. The strings in the list can contain any printable ASCII characters. The sorting should be performed in a way that the str... | codefeedback |
Construct a function that prints the first n terms in a Fibonacci sequence, but also checks if each term is a prime number. If a term is prime, print "prime" next to it. | codefeedback |
Help debug this code snippet by adding comments with the appropriate error messages.
Add the following constraints:
1. The name should not be empty.
2. The name should only contain alphabets.
3. The length of the name should be at most 10 characters. | codefeedback |
Can you build a linear regression model with a minimum R-squared value of 0.8 to predict the housing prices in the given dataset? The dataset contains 15 columns with 3,000 records, and you are required to include at least 3 additional variables in your model, selected from a list of 10 potential predictor variables pr... | codefeedback |
Using the inspect module, create a program that counts the number of lines of code in a specific function within a module. The program should prompt the user to enter the name of the module and the name of the function they want to analyze. The program should then display the total number of lines of code within that f... | codefeedback |
Create a function that selects all the div tags within a document and returns their attributes (id, class, and style) in a dictionary format.
Example input:
```
<html>
<body>
<div id="div1" class="box" style="color: red;"></div>
<div id="div2" class="container" style="background-color: blue;"></div>
</bod... | codefeedback |
Write an algorithm to find the smallest missing positive number greater than or equal to K from a given list of integers. The algorithm should also have a time complexity of O(n) and should not use extra space. Return -1 if there is no missing positive number greater than or equal to K in the list.
Example:
Input: [3,... | codefeedback |
Get a user input and check if the input is a palindrome. The input should not exceed 100 characters and should only contain alphabetic characters. | codefeedback |
Write a python program to get all possible permutations of a given set of characters, but the resulting permutations should only contain characters that are prime numbers. | codefeedback |
Write an algorithm to insert a new element in a given sorted array, but you are not allowed to use any built-in sorting functions or libraries. | codefeedback |
Use class inheritance to create an object in Java and demonstrate the use of abstract methods. | codefeedback |
Write a Python script to take two lists and output the common elements of the given lists. The script should handle cases where the input lists may contain duplicates. Additionally, the script should only output unique common elements, even if they occur multiple times in the input lists. Finally, the script should be ... | codefeedback |
Generate a random string using C#.
String length: 15
Allowed characters: uppercase letters, lowercase letters, digits, and special characters: !@#$%^&*()
Provide a piece of erroneous code as a reference to increase misdirection:
```
Random rnd = new Random();
string randomString = "";
for (int i = 0; i < 15; i++)
{
... | codefeedback |
Create a while loop in Java to find and break at the first prime number greater than 1000. | codefeedback |
Convert this C code to Java. Implement a class called "MathUtils" that contains a method called "addTwoNumbers" with the following signature: "public static int addTwoNumbers(int a, int b)". The method should return the sum of the two input integers. You are not allowed to use the "+" operator or any built-in mathemati... | codefeedback |
Create an HTML website with navigation, logo, and footer. The navigation should include a dropdown menu with at least three options. The logo should be an image that is displayed in the center of the page and should resize based on the screen size. The footer should include social media icons that link to the respectiv... | codefeedback |
How would you access the value of the key 'name' in the following dictionary if the dictionary is stored inside a list and the list is nested within another dictionary? | codefeedback |
Create a function to capitalize all the words of a sentence. The function should have a time complexity of O(n) and should not use any built-in string manipulation functions or regular expressions.
sentence = "this is a test" | codefeedback |
Please preprocess this data using Python. The input data will be a list of dictionaries, where each dictionary represents a person's information. Each person will have the following attributes: "name" (string), "age" (integer), "gender" (string), "city" (string), and "hobbies" (list of strings).
The output should be ... | codefeedback |
Implement quick sort on an array of strings. The strings will contain only lowercase letters and will have a maximum length of 100 characters. The input array will have a maximum length of 10,000. The implementation should be able to handle this worst-case scenario efficiently.
unsorted_strings = ["apple", "banana", "... | codefeedback |
Create a SQL query to find all users who have a premium account and have made at least 10 purchases in the last month. | codefeedback |
Implement a code that checks if a given sentence is a palindrome.
Sentence: "A man, a plan, a canal, Panama!" | codefeedback |
Provide a code for creating a function which receives an array of characters, sorts them in descending order, and prints the sorted array.
Additional Requirement: The code should not use any built-in sorting functions or libraries.
['D', 'C', 'B', 'A'] | codefeedback |
Compute the maximum subarray sum for the given array. Find the subarray that has the largest sum, and also has a length greater than or equal to 3.
Array: [-2,1,-3,4,-1,2,1,-5,4] | codefeedback |
Write a code for creating an array with values from 0 to n, where each element in the array is a string representation of the corresponding number. The array should only contain odd numbers.
n = 5 | codefeedback |
Increase the difficulty by adding additional requirements and constraints to the test.
Rewritten Test:
Implement a function called `string_compressor` that takes in a string as input and returns a compressed version of the string using the following rules:
1. The compressed string should consist of repeated character... | codefeedback |
Order the following array of dictionaries by their "priority" key. Additionally, tasks with a priority of 1 should be placed at the beginning of the list, and tasks with a priority of 10 should be placed at the end of the list. | codefeedback |
Using a while loop, print the first 100 prime numbers. | codefeedback |
Design a loop in Python to find the maximum value from a given array. The array can contain duplicate elements and can have a maximum length of 10^6. The time complexity of the solution should be O(n), where n is the length of the array. | codefeedback |
Create a code which prints a multiplication table of a given size.
The size should be an odd number between 3 and 11, inclusive.
The code should generate the multiplication table using nested loops, without using any built-in multiplication functions or operators.
The time complexity of the code should be O(n^2), where... | codefeedback |
Rewrite the following code as a MySQL query, but also include the total number of athletes in each team.
SELECT team, count(*) AS num_athletes,
(SELECT count(*) FROM athletes) AS total_athletes
FROM athletes
GROUP BY team | codefeedback |
Implement a code which reverses a given string without using any built-in string reversal functions.
String: "Hello World"
Additional constraints:
- The solution should have a time complexity of O(n), where n is the length of the string.
- The solution should use constant space complexity, i.e., no additional data str... | codefeedback |
Generate an HTML table to display the countries, their population, and the percentage of the world population they make up. The table should be sorted in descending order of population. Additionally, the table should only display countries with a population greater than 100 million. | codefeedback |
Find all the prime factors of a given integer, where the integer can be as large as 10^9.
1000000000 | codefeedback |
Generate a list of integers up to the given number n, but only include prime numbers in the list.
50 | codefeedback |
Write a code which takes two strings and prints its longest common subsequence.
String1: "ABCDGH"
String2: "AEDFHR"
Add an additional constraint: The code should have a time complexity of O(n*m), where n is the length of the first string and m is the length of the second string.
#Reasoning Steps#
1. Initialize a 2D a... | codefeedback |
Create a Python class to encode a string of characters using a Caesar cipher. Your implementation should include a method to handle both encryption and decryption. Additionally, the Caesar cipher should have a variable shift value that can be set by the user. The shift value should be an integer between 1 and 25, and a... | codefeedback |
Suggest an algorithm for finding the maximum sum for all subarrays in an array of integers. The array may contain both positive and negative numbers.
Provide a piece of erroneous code as a reference to increase misdirection.
arr = [2, 3, -5, 4]
#Erroneous Code#
def max_sum_subarray(arr):
max_sum = 0
curr_sum... | codefeedback |
Generate a list that contains all the Armstrong numbers within a given range, where the range is specified as two integers separated by a comma. The first integer represents the lower bound of the range and the second integer represents the upper bound of the range. The Armstrong numbers should be in ascending order wi... | codefeedback |
Fill in the blanks in the following SQL query to select the names of customers who have placed more than one order, and have made at least one order in the current year.
SELECT customer_name
FROM Orders
WHERE order_count > 1
AND customer_id IN (
SELECT customer_id
FROM Orders
WHERE YEAR(order_date) = ... | codefeedback |
Create a function called check_restaurant_availability that returns True if a restaurant is open on a given day and False if it's closed. The function should take two parameters: a dictionary representing the restaurant's status for each day of the week and a string representing the day for which the availability shoul... | codefeedback |
Create a custom min-heap data structure in Python that supports the following operations:
1. Insertion: Insert an element into the heap while maintaining the min-heap property.
2. Deletion: Remove the minimum element from the heap while maintaining the min-heap property.
3. Peek: Return the minimum element in the heap ... | codefeedback |
Can you write a function that returns the sum of the positive even elements of a given array, excluding any elements that are divisible by 3? The function should handle both positive and negative integers.
arr = [2, 3, 4, 5, -6] | codefeedback |
Create a JavaScript function which takes a string and returns the longest word in it, excluding any words that contain the letter "e". For example, given the string "This is an example string", the function should return "string". | codefeedback |
How can you fill a 2D array with zeros using a single loop and without using any built-in functions or methods? | codefeedback |
Generate 5 random prime numbers between 1 and 100. | codefeedback |
Given an unsorted array of integers, sort it using the quick sort algorithm. The array will contain both positive and negative numbers. The output should be in ascending order. If there are duplicate numbers, they should be placed next to each other in the sorted array. Implement the quick sort algorithm from scratch w... | codefeedback |
Simulate a fair coin toss using Python. Implement a function called `coin_toss()` that takes no parameters and returns either "Heads" or "Tails" with equal probability. Additionally, the function should keep track of the number of times it has been called and print it out each time it is called. The function should als... | codefeedback |
What is the difference between a static method and an instance method in Python? Explain with examples how each type of method can be used in object-oriented programming. | codefeedback |
Find all unique values in a given dataset and return them in descending order based on the frequency of occurrence. If two values have the same frequency, return them in ascending alphabetical order.
dataset = [['A', 4], ['B', 5], ['A', 3], ['C', 2], ['B', 5], ['A', 3], ['D', 1], ['E', 2], ['F', 4]]
Example Output:
[... | codefeedback |
Clean up the following HTML string so it can be rendered properly.
HTML string:
<div>
<h1>This is a header</h1>
<p>This is a paragraph</p>
</div>
Erroneous code reference:
<div>
<h1>This is a header</h2>
<p>This is a paragraph<p>
</div> | codefeedback |
Rewrite the selection sort algorithm in Python without using any additional variables for swapping elements. Instead, use only array indexing to perform the swap operation. | codefeedback |
How can we convert a sql query with complex joins and subqueries into pandas code, using only vectorized operations? | codefeedback |
Define a function to calculate the product of three numbers, with the condition that all three numbers must be unique. | codefeedback |
Compare two dictionaries for equality and return the result. The order of the key-value pairs should not affect the result.
a = {1:4, 2:5, 3:6}
b = {2:5, 3:6, 1:4, 4:7} | codefeedback |
Create a function that takes a string as input and prints each letter of the string on a separate line. Additionally, you should also print the index of each letter in the original string.
Example:
Input: "Hello World"
Output:
H - Index: 0
e - Index: 1
l - Index: 2
l - Index: 3
o - Index: 4
(space) - Index: 5
W - Inde... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.