instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a script to scrape a wikipedia page's html and extract the following information:
1. The title of the page
2. The first paragraph of the page
3. The number of references on the page
You should retrieve the HTML content of the page using the requests library in Python. You are not allowed to use any web scraping ... | codefeedback |
Create a class to represent a blog post in Python with the following requirements:
1. The blog post should have a title, author, and content.
2. The title should be a string and cannot be empty.
3. The author should be a string and cannot be empty.
4. The content should be a string and cannot be empty.
5. The blog post... | codefeedback |
Write a long-running Python script that uses a while loop to continuously read and process data from a live streaming API. The script should implement error handling to handle various exceptions that may occur during the data processing. Additionally, the script should have a mechanism to pause and resume the data proc... | codefeedback |
Compare and contrast JavaScript Objects and Arrays. Additionally, provide an example of how you can access a nested property in an object and retrieve a specific value. | codefeedback |
Edit the following code so that it prints the given value to the console, but now the code must use a loop. System.out.println("Hello World"); 5 | codefeedback |
Design a function in C++ that takes in a vector of integers and returns the maximum number in the vector. The function should also check if the vector contains any duplicates and if so, return the maximum number of times a duplicate appears in the vector. Additionally, the function should handle the case when the vecto... | codefeedback |
Generate the ternary operator for the following expression: x > 0 ? 10 : x < -5 ? 0 : 5.
In this modified test, the ternary operator has an additional condition: if x is less than -5, the result should be 0. This requires the programmer to consider multiple conditions in the ternary operator and handle them accordingl... | codefeedback |
Create a Java program that prints the Fibonacci sequence in the given range. The range should be inputted by the user and it must be validated to ensure that the maximum value is greater than the minimum value. The program should handle invalid input by displaying an error message and prompting the user to input the ra... | codefeedback |
Generate the syntax for initializing an array of integers with the given elements, ensuring that the array has a length of at least 5 and the sum of its elements is divisible by 4.
[1, 2, 3] | codefeedback |
Create a class in C++ that can produce the result of an arithmetic expression with two numbers as input. The arithmetic expression should be in postfix notation. The class should support addition, subtraction, multiplication, and division operations. The input expression should be validated for correct postfix notation... | codefeedback |
Write an algorithm that reverses a string without using any built-in functions or libraries. The algorithm should have a time complexity of O(n) and a space complexity of O(1).
Example:
Input: "Hello World"
Output: "dlroW olleH" | codefeedback |
Write a function that takes in 2 lists, reverses the elements of each list, combines the elements to output a single list, and then sorts the elements in ascending order. | codefeedback |
Suggest an alternative data representation for the following code that can handle duplicate age values.
ages = {"Alice": 24, "Bob": 3, "Carol": 15, "Dave": 15} | codefeedback |
Implement the Caesar Cipher algorithm that shifts the characters in a string by a specified number of spaces. The input string can contain uppercase and lowercase letters, digits, and special characters. The shift value can be any integer between -100 and 100. The output should maintain the case sensitivity of the inpu... | codefeedback |
Compute the probability of each string from the below list. Additionally, implement a function that calculates the probability of a given string occurring in a larger text corpus.
['apple', 'banana', 'watermelon', 'mango']
Text corpus example:
"This is an example text corpus containing various fruits such as apple, ... | codefeedback |
Write a program that takes a string as input and outputs the fifth letter of the string. The program should also handle cases where the string has less than five letters by displaying an appropriate error message. | codefeedback |
Using the heapsort algorithm, sort the following array of numbers in ascending order. Assume the array can contain up to 10^6 elements and the elements can range from -10^9 to 10^9. | codefeedback |
Write a function to encrypt the text with a modified Caesar Cipher.
Modify the original text by:
- Reversing the order of the letters
- Shifting each letter by the ASCII value of the previous letter in the alphabet (e.g. 'a' shifted by 1 becomes 'b', 'b' shifted by 2 becomes 'd', etc.)
The function should take two pa... | codefeedback |
Make a HTTP request to get the content of the given URL. After receiving the response, extract all the HTML tags from the content and count the number of occurrences of each tag. Finally, display the tags along with their respective counts in descending order. | codefeedback |
Write a function that takes in a string and converts it to its hexadecimal representation. The function should ignore any characters that are not alphanumeric and should handle both uppercase and lowercase letters. The output should be a string with lowercase hexadecimal characters. | codefeedback |
Write a function that takes a date and time in the format "YYYY-MM-DD HH:MM:SS" and converts it to the format "DD-MM-YYYY HH:MM". Additionally, handle any potential errors that may occur during the conversion process. | codefeedback |
Use the given string to find the number of occurrences of each letter, disregarding case sensitivity and excluding any non-alphabetic characters.
Hello World | codefeedback |
Sort the given list with size constraint N in increasing order. Additionally, the algorithm should be implemented using only constant space complexity (i.e. no additional data structures are allowed).
N = 4
arr = [8, 7, 6, 5, 4, 1] | codefeedback |
Edit the given JavaScript code so that the output is the sum of the Fibonacci sequence from 1 to "n". | codefeedback |
Calculate the value of "x" in the equation "5x - 12 = 8", where x is an integer between 1 and 10 and satisfies the condition that x^2 - 3x + 2 = 0. | codefeedback |
Create a SQL query that generates the first 10 names starting with "A" and have a length of at least 5 characters. | codefeedback |
What is the 100th prime number that is greater than 1000? | codefeedback |
Create a Ruby program that reverses the characters of a provided string, but ignores any special characters and maintains the original position of those characters.
Input: "Hello, $wo*rld!" | codefeedback |
Determine whether a given string is a palindrome or not, considering alphanumeric characters only and ignoring case sensitivity.
Input: "A man, a plan, a canal: Panama!" | codefeedback |
Write a shell script that exits with a status code of 0 only if the current date is a Monday and the time is between 9:00 AM and 5:00 PM in the timezone of "America/New_York". | codefeedback |
Increase the difficulty of the given programming test by requiring the following additional specifications:
1. Modify the code to remove the use of classes completely. Instead, implement the functionality using pure functions and higher-order functions.
2. The `print_details` function should now return a string inste... | codefeedback |
Write a function that takes two strings and returns True if one of the strings is the other string reversed. The function should have a time complexity of O(n), where n is the length of the strings. The function should not use any built-in string reversal functions or methods.
string_1 = "abcde"
string_2 = "edcba" | codefeedback |
Identify the specific type of error the code has and provide a detailed explanation of why it occurred.
x = 10
y = "10"
z = x + y
#Additional Explanation#
In addition to identifying the type of error, please explain the concept of data type conversion and how it applies to this code. | codefeedback |
Write a code that returns the longest substring of the given string without repeating characters. If multiple substrings with the same length exist, return the first occurring one.
string = "abcabcbb"
# Example Output #
The code should return "abc" as the longest substring without repeating characters.
# Additional ... | codefeedback |
Translate the following JavaScript code into Python.
Given a variable named x with an integer value, write a Python code that will check if x is a positive number and print "x is positive" if it is, otherwise, print "x is not positive". | codefeedback |
Write an SQL query that displays a table of the ten most commonly used words in the given article, excluding common stop words such as "the", "it", and "and". Additionally, include the count of each word and sort the table in descending order based on the word count. | codefeedback |
Create a C program that asks for a user input, adds 10 to the value, and prints the result. However, the program should also validate that the user input is a positive integer between 1 and 100 (inclusive). If the user input is invalid, the program should keep asking for input until a valid input is provided. Additiona... | codefeedback |
Generate a pseudocode for an algorithm to check if a given string is a palindrome. The algorithm should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a class called "BankAccount" with two instance variables "accountNumber" and "balance".
The "accountNumber" should be a randomly generated alphanumeric string of length 10.
The "balance" should be a decimal number with a maximum of 2 decimal places and a minimum value of 0.
The class should have the follow... | codefeedback |
Design a Spring Boot class that provides a bean of type String to the application, but the String must be a palindrome and have at least 10 characters. | codefeedback |
Write a Python function that takes the title of a movie as input and returns its IMDB rating. You can assume that the movie title will be a string and the IMDB rating will be a floating-point number. Additionally, you should handle cases where the movie title does not exist in the IMDB database and return an appropriat... | codefeedback |
Write a Python function that takes in a list of integers and returns a new list containing only the prime numbers from the original list. | codefeedback |
Write a function to reverse a doubly linked list in O(n) time complexity. | codefeedback |
Create a condition statement to check if all elements in a list are unique and are in ascending order. The time complexity should be less than O(n^2). | codefeedback |
Create a class in C++ for a circle which includes radius, diameter, circumference, and area as member variables. Implement member functions to calculate and return the diameter, circumference, and area of the circle. Additionally, include a member function to check if a given point (x, y) lies inside the circle. | codefeedback |
Write a function that takes in an array of positive integers and returns a new array where the elements are reversed, but only for odd integers. If an even integer is encountered, it should remain in its original position. Additionally, the function should sort the resulting array in descending order.
Input Array: [3... | codefeedback |
Design a data structure in Java to store and sort a list of customers by their age and name. Ensure that the sorting algorithm used has a time complexity of O(n log n) or better. | codefeedback |
Design a Java class for a Car which has the following attributes: name, model, year, price, and color.
The Car class should also have the following methods:
1. `getAge()`: This method should calculate and return the age of the car in years based on the current year and the year attribute of the car.
2. `isExpensive(... | codefeedback |
Create a MySQL trigger to store the times for insertion and updating a row in a table. Additionally, ensure that the trigger only captures the time if the inserted or updated row meets a specific condition, which states that the value of a specific column must be greater than a certain threshold. | codefeedback |
Insert 1000 random numbers between 0 and 1000 in a list. | codefeedback |
Create an HTML document with a heading "Heading" and a paragraph with the text "Hello, World!". Additionally, add a button with the label "Click Me" and a text input field where users can enter their name. When the user clicks the button, display a greeting message below the button that says "Hello, {name}!". | codefeedback |
Create an HTML page with a form that verifies if the email address entered is valid or not. Additionally, implement client-side validation to check if the password entered is strong or not. The password should meet the following criteria:
- At least 8 characters long
- Contains at least one uppercase letter
- Contains ... | codefeedback |
Write a custom CSS class to add a 3px solid blue border around a button with text size as 18px. Additionally, add a hover effect that changes the border color to red when the button is hovered over.
To increase the difficulty, you can also include the following requirements:
1. Make the border animate smoothly when t... | codefeedback |
Write a JavaScript function that takes an array of sentences and returns an array of the lengths of each word in those sentences.
#Example Input#
```
['Hello World', 'I love coding']
```
#Example Output#
```
[5, 5, 1, 4, 6, 6]
``` | codefeedback |
Write a Python program to parse a text string given a regular expression and return the matches. However, you must implement the regular expression parsing algorithm from scratch without using any built-in regular expression libraries or functions. | codefeedback |
Create a TensorFlow neural network model to classify animals into 10 categories, where each category represents a specific species of animal. | codefeedback |
What type of optimization algorithm is used in the following snippet of code?
weights = np.random.rand(2, 1)
for epoch in range(100):
predictions = predict(x, weights)
gradients = calcluate_gradients(x, predictions, y)
weights -= gradients * learning_rate
Additionally, the learning_rate is updated every... | codefeedback |
Create a function that takes in a positive integer greater than 1 and returns true if the number is a prime number and false if it is not. The function should also check if the input is within the range of 2 to 10^9, inclusive. | codefeedback |
Rewrite the following code to use a loop instead of recursion. Your solution should have a time complexity of O(n), where n is the length of the input string. Additionally, your solution should use only constant extra space and not create any new strings or data structures. | codefeedback |
Describe in detail how a web server handles a request, including the various components, protocols, and processes involved. Additionally, discuss the potential challenges and optimizations that can be implemented to improve the performance and security of the web server. | codefeedback |
Print out the Fibonacci series up to a given number, but only if the number is prime.
n = 10 | codefeedback |
What does the "static" keyword do in Java? Explain with examples and provide a detailed explanation of how it works in different scenarios. | codefeedback |
Edit the given code to use dynamic programming to solve the problem. The time complexity should be O(n^2) and the space complexity should be O(n).
def rod_cutting(arr, n):
if n <= 0:
return 0
dp = [0] * (n+1)
for i in range(1, n+1):
max_val = 0
for j in range(i):
max_val... | codefeedback |
Given the following code, find the output.
def f(x):
if x == 0 or x == 1:
return 1
return f(x-1) + f(x-2)
print(f(10)) | codefeedback |
Create a Flask application to display a web page containing the words "Hello, World." However, the web page should also include a button that, when clicked, changes the text to "Goodbye, World." Additionally, implement a feature where the web page keeps track of the number of times the button has been clicked and displ... | codefeedback |
Use Python to reverse the order of a string input, while also ensuring that all vowels in the original string are replaced with the corresponding vowel from a given list of replacements. | codefeedback |
Create a JSON from a given array that contains objects with the following properties: id (a randomly generated 5-digit number), name (a randomly generated 10-character string), and age (a randomly generated number between 18 and 65). The array should have a length of 1000. | codefeedback |
Design a program to count the total number of even numbers in a given array, but now the program should also output the sum of all the even numbers in the array. Additionally, the program should handle arrays with a size of up to 10^6 elements. | codefeedback |
Write the SQL query to select the second last element of a table where the name column is "John" and the age column is greater than 25.
table_name: users | codefeedback |
Create an array with 4 elements, where the first element is the sum of the first and second element of the previous array, the second element is the difference between the first and second element of the previous array, the third element is the product of the first and second element of the previous array, and the four... | codefeedback |
Use Predicate logic for representing the following statement with the additional requirement:
"An elephant only lives in an African safari and has a lifespan of at least 50 years." | codefeedback |
Design an algorithm in JavaScript to check if a given string consists of only unique characters. The string may contain any printable ASCII characters. The algorithm should have a time complexity of O(n) and use constant additional space.
#Solution#
To solve this problem, we can iterate through each character in the s... | codefeedback |
Create a function in Python which checks if an input value is prime or composite. The function should return True if the input value is prime, and False if it is composite.
Note:
- The input value will be a positive integer greater than 1.
- You are not allowed to use any built-in functions or libraries that directly ... | codefeedback |
Convert the given context free grammar to Chomsky Normal Form.
S --> AaBb
A --> aAa | bA | a | b
B --> bBa | aB | a | b | codefeedback |
Develop a Java code which assigns each element of an array of integers to an individual variable. The code should also calculate the sum of all the elements in the array and display it as output. Additionally, the code should check if any of the elements in the array are negative, and if so, throw an exception with an ... | codefeedback |
Write a Java program to read in a list of integers and separate them into three lists: one for even numbers, one for odd numbers, and one for prime numbers. | codefeedback |
Write a query in PostgreSQL for deleting a table, but before deleting the table, check if it exists in the database. If the table exists, prompt the user to confirm the deletion. If the user confirms, delete the table along with any associated constraints and indexes. Additionally, log the deletion activity in a separa... | codefeedback |
Implement a class in Java that represents a shopping cart. The shopping cart should have the following functionalities:
1. Add an item to the cart, specifying the name and cost of the item.
2. Remove an item from the cart, specifying the name of the item.
3. Get the total cost of all the items in the cart.
4. Get the ... | codefeedback |
Create a function called "multiply_dict_values" that takes in a dictionary as input and returns a new dictionary where the keys are multiplied by their respective values in the input dictionary. However, if the input dictionary contains any negative values, the function should raise a ValueError with the message "Negat... | codefeedback |
Write a program that implements Simpson's rule for numerical integration. | codefeedback |
Create HTML code for a table that has 7 columns and 10 rows. Each cell in the table should display the sum of its row and column numbers. | codefeedback |
How would you create a function in Python to add two lists of numbers element-wise, where each list can have varying lengths? | codefeedback |
Write a C++ program to find all pairs of perfect numbers whose sum is also a perfect number, within a given range. | codefeedback |
Create a MySQL query to find the top 5 employees with the highest rating during their last review, ordered by their salary in descending order. | codefeedback |
Write a Python function that takes a list of numbers and returns the mean, median, and standard deviation of that list. Additionally, the function should be able to handle cases where the list contains non-numeric values or is empty. | codefeedback |
Write a Java program to get the day of the month from a given Date object, but do not use any built-in date or time libraries or classes. | codefeedback |
Edit the code to create a class for a profile with the following constraints and requirements:
1. The profile should have a constructor that takes in a username and password as parameters.
2. The username should be a string with a minimum length of 5 characters and a maximum length of 20 characters.
3. The password sho... | codefeedback |
Implement a class hierarchy for a simple banking system. The system should have a base class Account, with subclasses CheckingAccount and SavingsAccount. The Account class should have the following attributes: account_number (string), account_balance (float), and interest_rate (float). The CheckingAccount class should ... | codefeedback |
Create a class in JavaScript to encapsulate user information. The class should have the following additional requirements:
- The user's email address should be stored as a private property and should be validated to ensure it is in the correct format (e.g., "example@example.com").
- The user's password should be stored... | codefeedback |
Create a PHP script to calculate and print out the sum of the first 1000 Fibonacci numbers. | codefeedback |
Design an algorithm to determine if a given string contains a valid email address. | codefeedback |
Compute the average of the following three numbers: 5, 10, and 15. However, you are not allowed to use any arithmetic operators (+, -, *, /) or the built-in average function in your solution. | codefeedback |
Reverse each word in this sentence: "I can do coding." | codefeedback |
Given the object below, debug the problem to make a valid code in JavaScript. The code should include proper error handling for invalid inputs.
let obj = {
name: 'John',
age: 20,
printDetails: () => {
console.log(`The name is ${name} and age is ${age}`);
}
}
Additional requirements: Implement a... | codefeedback |
Write a C++ program to calculate the shortest path between two points in a weighted directed graph using Dijkstra's algorithm. The graph is represented by an adjacency matrix and each edge has a positive weight associated with it. The program should output the shortest path length and the sequence of vertices visited i... | codefeedback |
Create an if statement that prints "Fizz" if a number is divisible by 3 and "Buzz" if a number is divisible by 5. Additionally, the program should print "FizzBuzz" if a number is divisible by both 3 and 5. The program should also handle negative numbers and print "Invalid input" if the input is not a number. | codefeedback |
Using the given array, create a function that takes in two arguments, the array and a number, and returns the position of the number in the array. The function should have a time complexity of O(log n) or better, where n is the length of the array. Additionally, the function should use an iterative binary search algori... | codefeedback |
Write a Bash script to read three numbers and print their sum to the screen. However, the script should only use one variable to store the sum, and should not use any arithmetic operators (such as + or -) to calculate the sum. | codefeedback |
Design a responsive HTML page to display a table of students' grades for multiple subjects. The table should include the following columns: student name, subject name, grade, and date. The page should allow the user to sort the table based on any column in ascending or descending order. Additionally, the page should in... | codefeedback |
Create an algorithm which is able to sort a given array of integers in descending order. The algorithm should have a time complexity of O(n log n). | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.