instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write your own version of the Fisher-Yates algorithm for shuffling an array. Your implementation must handle arrays of any size, including very large arrays with millions of elements, efficiently and without causing memory issues. Additionally, your solution should be able to handle arrays containing duplicate elements... | codefeedback |
Generate a random password with the following criteria:
1. The password should be a minimum of 12 characters long.
2. The password must contain at least one uppercase letter, one lowercase letter, one number, and one special character.
3. The password should not contain any repeated characters.
4. The password should ... | codefeedback |
Create a dictionary comprehension to create a dictionary with the values from the given list.
list = ["a","b","c"]
Additional Instructions:
1. Each key in the dictionary should be the corresponding index of the value in the list.
2. The values in the dictionary should be the corresponding value from the list, converte... | codefeedback |
Write a class that simulates a die with 6 sides. The class should include a method that allows the user to roll the die and return the result. The die should not be biased and should have an equal chance of landing on each side. The class should also keep track of the number of times the die has been rolled, and provid... | codefeedback |
Create a class called Ball which has three dimensional coordinates x, y and z. The coordinates should be limited to the range of -1000 to 1000. Additionally, the class should have methods to calculate the distance between two balls, find the closest ball to a given ball, and check if two balls intersect each other. | codefeedback |
Recreate the same result from the given sample output.
You are given a sequence of numbers as follows:
1, 11, 21, 1211, 111221
Write a function or program that takes an integer n as input and returns the nth number in the sequence.
## Example
Input:
n = 5
Output:
111221
### Constraints
- 1 ≤ n ≤ 30
### Note
In... | codefeedback |
Write an R command to calculate the standard deviation of the given array, considering that the array may contain both positive and negative numbers. Additionally, the command should handle arrays with a length of at least 100 elements and output the result with a precision of at least 4 decimal places. | codefeedback |
Create a shortcut command in Bash to run a program called "MyApp" that only accepts a maximum of three command line arguments, where the third argument must be a positive integer greater than 10. | codefeedback |
Suppose you have a 4x3 matrix, A. Find the transpose of A.
A = [1 9 7; 8 0 6; 4 2 3; 5 1 0];
Write a function that takes the matrix A as input and returns its transpose.
The transpose of a matrix is obtained by swapping its rows with its columns. In other words, the element in the ith row and jth column of the origi... | codefeedback |
Compare two strings to check if they are identical using the JavaScript language. However, you are not allowed to use any built-in string comparison methods or operators such as '===', '==', or 'String.prototype.localeCompare()'. You should implement your own algorithm to compare the strings character by character and ... | codefeedback |
Create a class in Java that comprises of a date, a location and temperature reading associated with that location on that particular date. Implement a method within the class that calculates the average temperature for a specific month and year given a list of temperature readings. | codefeedback |
Write an application that keeps track of tasks and provides status updates for the tasks. The application should allow users to create tasks with a specific deadline and priority level. The tasks should be sorted based on their priority level, with higher priority tasks appearing at the top of the list. Additionally, t... | codefeedback |
Define a class named "Day" in Python to represent a day of the week. The class should include the following methods:
1. `get_day_name()`: This method should return the name of the day.
2. `is_weekend()`: This method should return True if the day is a weekend (Saturday or Sunday), and False otherwise.
3. `is_weekday()`... | codefeedback |
Generate a piece of code that defines and calls a function in Python. The function must have at least one input parameter and return a value. Additionally, the code should include a try-except block to handle potential errors and print an appropriate error message. | codefeedback |
Create an array of fruits and vegetables with 10 items, where each item must have at least 5 characters and start with a consonant. | codefeedback |
Write a Java program that takes an input integer n and generates a tabular format of n rows and n columns on the console. Each cell in the table should contain the product of its row number and column number. The program should handle input values up to 10^6. The time complexity of the program should be less than O(n^2... | codefeedback |
Given an input string, reverse the string without using any built-in string reversal functions or methods. The reversed string should be stored in a new variable called "reversed_string". The input string can contain any printable ASCII characters.
For example:
input_string = "Hello, World!"
reversed_string = "!dlroW... | codefeedback |
Create an array with 10 random numbers in the range of -100 to 100, with the condition that each number must be unique. | codefeedback |
Increase the difficulty by requiring the code to handle multiple addresses in a given string and convert them into a list of dictionaries. The addresses should be separated by a comma. Each address should be split into its respective components: street, city, state, and zip code.
Example input:
addresses = "901 Grand ... | codefeedback |
Using the comment as a guide, create a function to calculate the area of a triangle given the lengths of all three sides. The function should handle cases where the triangle is not valid (i.e., the sum of any two sides is less than or equal to the third side). The function should return the area rounded to the nearest ... | codefeedback |
Implement a recursive function that takes in a string and checks if it is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization. The function should return true if the string is a palindrome and fa... | codefeedback |
Create a SQL query to delete all customers with a last name of "Smith" who have made at least one purchase in the last 30 days and have a total purchase amount greater than $1000. | codefeedback |
Create a Swift closure to calculate the power of a number. The closure should take two arguments: a base number and an exponent. The closure should return the result of raising the base number to the power of the exponent.
Additionally, modify the closure to handle the case when the base number is negative and the exp... | codefeedback |
Write a Python function that calculates the natural logarithm of a given number n using the Taylor series expansion method. The function should return an approximate value of the natural logarithm accurate to at least 10 decimal places.
The Taylor series expansion method for calculating the natural logarithm is as fol... | codefeedback |
Construct a pandas dataframe from 4 dictionaries, with the following additional constraints:
- The 'name' column should not contain duplicate values.
- The 'age' column should only contain positive integers.
- The 'weight' column should only contain values between 50 and 100.
- The 'height' column should only contain v... | codefeedback |
Calculate the maximum height reached by a ball thrown upward with an initial velocity of 20m/s and taking into account air resistance. | codefeedback |
Write a function that accepts an integer value n and creates an n by n matrix, with all elements initialised to a random integer between 1 and 10.
#Difficulty increased:#
To increase the difficulty, the matrix should be created using a nested list comprehension. | codefeedback |
Design a JavaScript program to validate a complex form with multiple fields, including text inputs, dropdowns, checkboxes, and radio buttons. The form should have validation rules such as:
- All fields are required
- Text inputs should have a minimum and maximum length
- Dropdowns should have a selected option
- Checkb... | codefeedback |
Come up with some creative and innovative ideas to design a visually appealing and user-friendly user interface for an online database, taking into consideration the need for responsive design and accessibility features. Additionally, ensure that the interface can efficiently handle a large volume of data and implement... | codefeedback |
Scramble a given array so that it appears in a random order. Additionally, you should ensure that no two adjacent elements in the scrambled array are the same.
Example:
Input: [3, 7, 8, 2, 5]
Output: [5, 2, 7, 3, 8] | codefeedback |
Create a computer algorithm to determine the validity of a sudoku puzzle with a time complexity of O(1) and a space complexity of O(1). | codefeedback |
Use a nested for loop to print all numbers from 1 to 100 in separate lines, but only print the odd numbers. | codefeedback |
Create a Java program that prints out a word 5 times, but each time it should print the word in a different language. The languages should be randomly selected from a list of at least 10 languages, and the program should ensure that no language is repeated until all the languages have been used. | codefeedback |
Design a SQL table to store user information such as username, password, email, and date of birth. Include appropriate data types and constraints for each column. Additionally, create a stored procedure that allows users to update their password by providing their username and old password. The stored procedure should ... | codefeedback |
Create a class named "Vector" with two attributes "x" and "y" and define a "length" method that returns the length of the vector. Additionally, implement a method named "normalize" that scales the vector so that its length becomes 1.
Reference Erroneous Code:
Include a reference to a method named "calculateLength" in ... | codefeedback |
Create an array of length 10 and fill each element randomly from 0 to 9. Then, iterate through the array and count the frequency of each number. Finally, print the number that appears the most and its frequency. | codefeedback |
Rewrite the given test by requiring the use of nested for loops and imposing a time complexity requirement of O(n^2), where n is the number of times the inner loop iterates. | codefeedback |
Create a class "Addition" with a method called "add" which takes two integers as inputs and returns the sum of the two numbers. However, you are not allowed to use the "+" operator or any other arithmetic operators (+, -, *, /) in your solution. You can only use bitwise operations and logical operations. | codefeedback |
Sort the list of numbers [3,2,7,9,1] in ascending order. The algorithm must have a time complexity of O(nlogn) and use a stable sorting algorithm. Additionally, you must implement the sorting algorithm from scratch without using any built-in sorting functions or libraries. You are allowed to use basic data structures s... | codefeedback |
Write a function which takes a list of positive integers and returns an integer which is the product of all the prime numbers in the list. | codefeedback |
Design a function to get the length of the longest increasing subsequence in a given list of integers, ensuring that the time complexity of your solution is O(n log n), where n is the length of the list. | codefeedback |
Create a function in TypeScript that takes two strings of equal length and returns the number of characters which match at the same position in the strings. The function should have a time complexity of O(n) and should not use any built-in string manipulation methods or regular expressions. | codefeedback |
Create a bash script that takes a path argument and recursively searches for all files with the extension `.gitconfig` in the specified directory and its subdirectories. The script should then print the absolute path of each found `.gitconfig` file. | codefeedback |
Write a Java program to convert a hexadecimal character to an int. | codefeedback |
Implement a decision tree as a class in Python.
You are given a dataset containing information about customers and whether they will purchase a product or not. The dataset consists of the following columns: age, income, gender, and purchase.
Your task is to implement a decision tree classifier that can predict wheth... | codefeedback |
How would you delete every third element of a given linked list while also ensuring that the remaining elements are in ascending order? | codefeedback |
Write a C code to compare two strings letter-wise and print out the number of times they differ. The strings may contain uppercase and lowercase letters.
Example:
Input:
String 1: "aBCd"
String 2: "BcdE"
Output:
The strings differ at 3 positions.
Note:
- The comparison should be case-sensitive, meaning that uppercas... | codefeedback |
Write a function in Javascript that takes an array of numbers and combines them in order to calculate their sum. The function should also handle cases where the array may contain nested arrays of numbers and calculate the sum accordingly. | codefeedback |
Create an HTML page with a table containing the following data in four rows. The table should have the ability to dynamically add or remove rows. Each row should have a unique identifier and contain the following columns: Id, First Name, Last Name, Age. The table should also include sorting functionality for each colum... | codefeedback |
Write a JavaScript function to convert an array of objects to a string separated by a key-value pair separator such as "|". Each object in the array should have at least two key-value pairs. The resulting string should include all key-value pairs for each object in the array.
const array1 = [
{ name: 'John', age: 25... | codefeedback |
Separate the numbers from the non-numeric characters in the given string variable. Return the sum of all the separated numbers.
String: 1a2b34c
Note: You should not use any built-in functions or libraries that directly solve the problem. | codefeedback |
Write a Java class named "Shape" which has an abstract method named "surfaceArea". Additionally, the "Shape" class should have a constructor that takes in a parameter representing the dimensions of the shape. The dimensions can be of any type, such as integers or floating-point numbers. The "Shape" class should also ha... | codefeedback |
Update a MongoDB document such that it replaces a specific field with a new value. However, you need to ensure that the update is performed only if the document meets a certain condition. If the condition is not met, the update should not be executed and a specific error message should be returned.
db_name: "users"
co... | codefeedback |
Combine two sorted arrays into one sorted array. The two input arrays are arr1 and arr2. Your task is to create a new array that contains all the elements from arr1 and arr2, in sorted order.
arr1 = [1, 5, 8, 9, 10];
arr2 = [2, 3, 4, 6, 7];
Write a function mergeArrays(arr1, arr2) that takes in two sorted arrays as i... | codefeedback |
Write an HTML code snippet to create an interactive dropdown menu with a maximum of 5 options that cannot be hard-coded in the HTML file. | codefeedback |
Develop a code snippet in Java to create a thread that runs a simple print statement every 5 seconds. Additionally, the thread should print the current time along with the statement. | codefeedback |
Develop a machine learning model in Python to classify emails as either important, urgent, or not important. The model should be able to accurately predict the urgency level of each email based on its content and other relevant features. | codefeedback |
Write a CSS code to create a responsive navigation menu with drop down sub menus that collapses into a hamburger menu on smaller screens, and must be implemented using flexbox and media queries. | codefeedback |
Write a code that takes a given list and sorts them using heapsort. The list will contain positive integers only and will have at least 10 elements. The code should handle cases where the list has duplicate elements and sort them in ascending order. The code should also handle cases where the list is already sorted and... | codefeedback |
Create a ReactJS component to display a modal window with a form. The form should have the following fields:
- Name (required, maximum length of 50 characters)
- Email (required, valid email address)
- Password (required, minimum length of 8 characters, at least one uppercase letter, one lowercase letter, and one speci... | codefeedback |
Create a function to print out a multiplication table of two given multidimensional arrays. The function should also check if the arrays have the same number of rows and columns, and throw an error if they don't. Additionally, the function should only accept arrays with positive integers as elements, and throw an error... | codefeedback |
Write an SQL query that returns the third highest salary from a table with a salary column. | codefeedback |
Parse the following HTML string and get a list of all the <p> tags that have a class attribute equal to "highlight". If a <p> tag does not have a class attribute or if its value is not "highlight", it should not be included in the list.
<html>
<p class="highlight">This is a highlighted paragraph</p>
<div>
<spa... | codefeedback |
Create a Python function that takes an object as an input and returns its names and values. The function should also handle nested objects and lists within the input object. Additionally, the function should only return the names and values of the top-level attributes of the object, excluding any attributes within nest... | codefeedback |
Given a two-dimensional array, write a Python code to sum each row in the array and store it in a new array. Print the sum of each row in reverse order.
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
#Erroneous Code#
```python
def sum_rows(arr):
row_sum = []
for row in arr:
row_sum.append(sum(row))
row_sum.reve... | codefeedback |
Write a SQL query to get the name, age, address, and average salary of the people whose age is greater than 25 and whose average salary is greater than $50,000. | codefeedback |
Retrieve the name of the third author from a given list of authors and return it in reverse order.
Authors: John Doe, Jane Smith, Tom Johnson | codefeedback |
Construct a C++ program that checks whether a number is prime or not.
Allow the user to input the number.
Validate the user input to ensure it is a positive integer greater than 1.
Implement a function that uses the trial division method to determine if the number is prime.
Display an appropriate message indicating... | codefeedback |
Generate a Fibonacci number sequence with n numbers where each number is the sum of the previous three numbers.
10 | codefeedback |
Find the output of the following array after sorting it in ascending order.
array = [6, 2, 9, 4, 1]
Additional requirement: Do not use any built-in sorting functions or algorithms. You must implement your own sorting algorithm. | codefeedback |
Write a Python program to check if a substring is present in a set of strings, but the substring must be a palindrome.
substring: "abcba"
strings: ["hoabcll", "aaabcbc", "abcbal"] | codefeedback |
Use PHP to replace all occurrences of the word 'apple' with the word 'orange' in a given string, but also capitalize the first letter of each replaced word. Additionally, count the number of replacements made and display it at the end of the string.
string = 'This apple is red and this apple is green' | codefeedback |
Generate all possible strings of length n using A, B and C. Each string must have at least one occurrence of each character. | codefeedback |
Use Python to filter out all the prime numbers from a given list of integers. | codefeedback |
Find all the string literals in a given C++ program, and count the occurrences of each unique string literal. Additionally, the program should ignore string literals that are enclosed in comments or are part of a larger string literal. The program should output the unique string literals and their respective counts in ... | codefeedback |
You need to delete all occurrences of a given pattern of characters from a string.
Write a function that takes in two strings, `string` and `pattern`, and returns a new string with all occurrences of `pattern` removed.
The function should have a time complexity of O(n), where n is the length of the string, and a spac... | codefeedback |
Create an algorithm that sorts an array of words in alphabetical order, without using any built-in sorting functions. The algorithm should be able to handle words containing both uppercase and lowercase letters. Additionally, the algorithm should remove any duplicate words from the sorted array.
words = [ 'Hello', 'thi... | codefeedback |
Generate a random string of length 8 with characters from a-zA-Z0-9, ensuring that the string contains at least one uppercase letter, one lowercase letter, one digit, and one special character (such as !@#$%^&*()). | codefeedback |
Create a JavaScript function for finding the two largest prime numbers among a given array of numbers.
Array of numbers: [3, 6, 8, 5, 9, 1] | codefeedback |
Implement a function to remove all occurrences of string t from string s, but the removal should be case-sensitive.
s = 'The quick brown fox jumps over the lazy dog.'
t = 'the' | codefeedback |
Given a string s and a list of words words, write a program to find all occurrences of words in the string s, while ignoring any occurrences that are part of a larger word. Additionally, the program should return the frequency of each word in the string s. s = 'The quick brown fox jumps over the lazy dog.' words = ['qu... | codefeedback |
Retrieve the third item from a doubly linked list and delete it from the list. | codefeedback |
Create an HTML form that can process the user's email address and password. Implement client-side validation to ensure that the email address is in a valid format and the password meets the following requirements:
1. Must be at least 8 characters long.
2. Must contain at least one uppercase letter.
3. Must contain at ... | codefeedback |
Given a string s, write a program to classify it as a palindrome or not. The program should handle strings with uppercase and lowercase letters, and should ignore any non-alphabet characters. Additionally, the program should consider the string as a palindrome if it is a palindrome when read forwards and backwards, inc... | codefeedback |
Retrieve the word with the second highest frequency from a given text while also considering word case sensitivity. Text: This is a sample text with a lot of words. | codefeedback |
Write a PHP code snippet to display "Hello, World!" in console. However, the code must use recursion to print each character of the string individually, with a delay of 1 second between each character. | codefeedback |
Write a different style of a given JavaScript code snippet, but you are not allowed to use the addition operator (+) to perform the sum. | codefeedback |
Implement a class to represent a vector, with an initial vector and a scaler. Include methods to add, subtract, and multiply two vectors.
The vector should support the following operations:
1. Addition: Given two vectors A and B, return a new vector that is the sum of A and B. The time complexity of this operation sh... | codefeedback |
Write a SQL query to find the values that have occurred more than three times consecutively. | codefeedback |
Write an HTML page with two headings "Home" and "About". Implement a toggle functionality where clicking on the "Home" heading should hide the "About" heading and vice versa. | codefeedback |
Given two strings s1 and s2, write a program to edit s1 to s2 by removing, inserting or replacing one character in s1. The program should find the minimum number of operations required to convert s1 to s2 and return all possible shortest sequences of operations. The operations allowed are:
1. Removing a character from ... | codefeedback |
How would you write a function in C++ to check if a given number is a prime number? | codefeedback |
Create a SQL query to update all rows of the table "product" if their stock is below 10. However, you are not allowed to use the UPDATE statement. | codefeedback |
Write code in Java to find the maximum value of the array, while also ensuring that the maximum value is greater than or equal to 10. Additionally, you must handle cases where the array contains negative numbers, and return a meaningful error message if the array is empty. The array can contain up to 1000 elements. | codefeedback |
Write a JavaScript code to reverse the words in the following string and also capitalize the first letter of each word.
"hello world!" | codefeedback |
Write a piece of code in Java to check if the following string contains at least two numeric characters and one special character.
"Hello123%World!" | codefeedback |
In Python, construct a function to fit a curve to a given set of data points, using a polynomial of degree N. The degree N must be specified as an additional input parameter to the function. The function should return the coefficients of the polynomial that best fits the data points. Additionally, the function should i... | codefeedback |
Create a React component in JavaScript which displays the given string as a status update. The component should also include a timestamp that shows the date and time when the status was posted. The timestamp should be formatted as "DD/MM/YYYY HH:mm". Additionally, the component should only show the status update if it ... | codefeedback |
Create a class in Python that implements the __len__ method to return the length of a given string. However, you should also add an additional method called count_vowels that returns the number of vowels in the given string. The vowels that should be considered are 'a', 'e', 'i', 'o', and 'u' in both uppercase and lowe... | codefeedback |
Create a function in Python that performs a web scrape of a specific website and returns the most frequent words from the resulting text, excluding stop words and punctuation marks. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.