instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Build a finite-state machine in Python to process incoming keyboard events for a text-based adventure game. The state machine should have at least three states: "Exploring", "Battle", and "Menu". In the "Exploring" state, the player can move around a virtual world and interact with objects. In the "Battle" state, the p...
codefeedback
Generate a program to calculate the combination of n elements taken k at a time, where n and k are non-negative integers. Ensure that the program handles cases where n is smaller than k, and outputs an appropriate error message. Example: Input: n = 5, k = 3 Output: 10 Input: n = 2, k = 4 Output: "Invalid input: n sho...
codefeedback
Create a program that finds the second largest element in a list of integers. arr = [1, 10, 4, 5, 6, 7, 9]
codefeedback
Generate a function that takes an array of integers and rearranges the elements in a cyclical fashion, such that the element at index 0 comes last, the element at index 1 goes to the front, the element at index 2 is inserted after the element at the last index and so on. Additionally, if the element at the current inde...
codefeedback
You need to create a web form with 3 input fields: Name, Age, and Email. Additionally, you need to add validation to the form. The Name field should not be empty and should only contain alphabetic characters. The Age field should not be empty and should only contain numeric characters. The Email field should not be e...
codefeedback
Given a string, write an algorithm to remove all occurrences of a given letter that are followed by a digit. my_string = "Python is a popular programming language, version 3.9.2" letter = 'o'
codefeedback
Create a Python function called split_string that takes a string and a delimiter as arguments and returns a list containing the string split by the delimiter. The function should also remove any leading or trailing whitespace from each split element in the resulting list. For example, given the string "hello, world" ...
codefeedback
How to retrieve the data of the third element in a nested JSON array within a nested JSON object?
codefeedback
Write a code to calculate the age in years, months, and days given the date of birth. Date of Birth: 4 June 1998
codefeedback
Given an array of integers, determine the maximum and minimum value of the array. The array can have duplicate values and can be of any length between 1 and 10^6.
codefeedback
Create a function that evaluates a mathematical expression stored as a string. The expression can contain the following operators: +, -, *, /, and ^. The expression may also include parentheses. The function should handle operator precedence correctly. For example, the expression "1+2*3/4" should evaluate to 2.5, and t...
codefeedback
Create a function that filters a list of strings based on their length and returns a new list with the filtered strings sorted in descending order. List = ["Carrot", "Apple", "Orange", "Banana", "Pear"] #Additional Instructions# 1. The function should accept two parameters: the list of strings and a minimum length thr...
codefeedback
Augment an integer list with zeros after every 4 elements. However, if a zero is encountered in the original list, skip the next 3 elements and then add the zeros. Original List: [1, 2, 0, 4, 5, 6, 7, 8] Augmented List: [1, 2, 0, 0, 0, 0, 5, 6, 0, 0, 0, 0, 7, 8] Note: The number of elements in the original list may ...
codefeedback
Implement a SQL query to find the top 5 highest paid employees, excluding any employees whose job title is "Manager". Additionally, consider the possibility that multiple employees may have the same salary, and modify the query to also include their names in the result.
codefeedback
Determine if a given word is a valid word of English language. If the word is valid, return the number of vowels in the word; otherwise, return -1. Word: lycanthropy
codefeedback
Create a SQL statement to select a list of customer names, the number of orders each customer has made, and the total price of all their orders. Additionally, sort the results in descending order of the total price.
codefeedback
Develop an algorithm to reverse an integer and return the sum of its digits. 123 Time complexity requirement: O(logN) Space complexity requirement: O(1)
codefeedback
Develop a C# function to check if a given number is a narcissistic number or not. A narcissistic number is one which is equal to the sum of its digits raised to the power of the number of digits, but the number of digits must be prime.
codefeedback
Develop an algorithm to find the depth of a specific node in a binary tree.
codefeedback
Write a C# function to generate all combinations of length n of a given array, where n is a positive integer less than or equal to the length of the array. The function should handle arrays containing duplicate elements and should return the combinations in lexicographical order.
codefeedback
Write a function in Python to check if two lists have the same elements regardless of their order. The elements in the lists will be strings consisting of lowercase letters only, and each element will have a length between 1 and 10 characters inclusive. The lists can have a maximum of 100 elements. If the lists have th...
codefeedback
Find the sum of the products of the odd digits of a given number with its reverse. If there are no odd digits in the number, return -1. Number = 1234
codefeedback
Calculate the maximum sum of a subarray of length k that consists only of prime numbers. Array: [2, 7, 9, 3, 13, 11, 5] K: 4
codefeedback
Train a Naive Bayes model in Python to classify emails into spam and non-spam classes. Additionally, implement a feature selection technique such as chi-square or information gain to select the most relevant features for classification.
codefeedback
Choose a non-comparison based sorting algorithm and write a function in C++ to sort a list of positive integers in descending order.
codefeedback
Create a SQL query to count the total number of movies for every genre that have a rating higher than 8 in the database.
codefeedback
Given an array of strings and the task is to find the longest string from the given string array, but only considering strings that contain at least one uppercase letter.
codefeedback
Write a Python function to generate a random password with length 8 containing any combination of upper and lowercase letters, numbers, and symbols. The password should also meet the following requirements: 1. At least one uppercase letter. 2. At least one lowercase letter. 3. At least one number. 4. At least one symb...
codefeedback
Suggest a way to scale the following function for n values, while also ensuring that the scaling process has a time complexity of O(n) or less. def scale(x): result = [] for num in x: result.append(num * 2) return result
codefeedback
Create a responsive website layout with three columns and a fixed size main section. The main section should have a minimum width of 800 pixels and the columns should have a minimum width of 200 pixels. Additionally, the layout should be fluid and adjust its size automatically when the window is resized.
codefeedback
Create a cloud-based web application in Java to store financial details. The application should have user authentication and authorization functionality, where users can register, login, and have different levels of access based on their roles (e.g., admin, manager, employee). The application should allow users to sec...
codefeedback
Write a function to find the path from a source point to a destination point in a given 2D array. Array: [[0, 1, 0, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 1, 0], [0, 0, 0, 1, 0]] Source Point: [0, 0] Destination Point: [3, 4] However, the given array may contain obstacles represented by a value of 1. The function should fi...
codefeedback
Create a code to get the difference between two timestamps in seconds, but also consider time zones and daylight saving time. timestamp1 = "2020-07-02 14:13:37 UTC" timestamp2 = "2020-07-03 13:21:46 PDT" Note: In this rewritten test, the timestamps include time zone information (UTC and PDT). The code should accurate...
codefeedback
Given an array of integers, create a code to return the second-largest number that is also a prime number. If there is no second-largest prime number in the array, return -1. [12, 45, 2, 41, 31, 10, 8, 6, 4]
codefeedback
Write a code to generate all possible binary strings of length N, where N is an input parameter.
codefeedback
Create an HTML view with a button that changes its text when clicked. The button text should also change its color to red when clicked. Additionally, the view should have a counter that keeps track of the number of times the button has been clicked, and this counter should be displayed below the button.
codefeedback
Create a code to create a unique alphanumeric userid from the given firstname and lastname, with the following constraints: the userid must be at least 8 characters long, must contain at least one uppercase letter, one lowercase letter, and one digit, and must not contain any special characters or spaces. If multiple u...
codefeedback
Create a database to store customer data and products. Additionally, implement a feature that allows customers to place orders for multiple products at once, and track the inventory levels of each product.
codefeedback
Given a list of positive and negative numbers, create a code to find the maximum product of three numbers, where the product must include at least one positive number and one negative number. Additionally, the code should be optimized to have a time complexity of O(n), where n is the length of the list. [-1, -2, 4, 5, ...
codefeedback
Construct an SQL query to find the total number of female employees who have a salary above a certain threshold in a certain department in a company. Department: HR Salary Threshold: $5000
codefeedback
Create a JavaScript program to generate Fibonacci series up to a given number, but each number in the series must be divisible by 3.
codefeedback
Create a KMP algorithm in Python to find the number of times a pattern appears in a given text, without using any string methods or libraries. Text: abcabdababd Pattern: abd
codefeedback
Create a C++ function to determine the number of inversions in an array. An inversion occurs when two elements in the array are out of order, i.e., if i < j but arr[i] > arr[j].
codefeedback
Given the following code, write a function to validate the input dates are in increasing order. The input dates should be in the format "yyyy-mm-dd" and should strictly adhere to the Gregorian calendar system. Additionally, the function should check for leap years and consider the number of days in each month accuratel...
codefeedback
Write a Scala function that takes in two integers, `start` and `end`, and generates a range of numbers from `start` to `end`. The function should also take in an optional integer `step` parameter, which specifies the increment between each number in the range. If `step` is not provided, the default value should be 1. ...
codefeedback
Write a function in Python to remove all 'null' values from a nested dictionary. The function should also remove any empty dictionaries or lists that are left behind after removing the 'null' values. The function should have a time complexity of O(n), where n is the total number of elements in the nested dictionary.
codefeedback
Write a function to compare two strings and return the number of different characters in each string. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the longer string.
codefeedback
Generate a code snippet to calculate the sum of an array, but you are not allowed to use any built-in array methods or loops. The array will always contain positive integers. You may only use recursion to solve this problem. arr = [1, 23, 4, 3, 5]
codefeedback
Change the following code to convert the temperature from Fahrenheit to Celsius, ensuring that the result is rounded to the nearest whole number. The input temperature should be between -100 and 100, inclusive. The converted temperature should be within the range of -50 and 50, inclusive. If the input temperature is ou...
codefeedback
Write a JavaScript function to create a new object from the given object, while also ensuring that all keys in the new object are in uppercase and sorted alphabetically, and the values are converted to lowercase and have a maximum length of 10 characters. The original object should remain unchanged. obj = { "name"...
codefeedback
Write a function to generate all possible permutations of a given string. The input string will contain only lowercase alphabets and may contain duplicate characters. Example: Input: "aba" Output: ["aba", "aab", "baa"] Constraints: - The length of the input string will not exceed 8. - The output list should be sorted...
codefeedback
Design a function to create a secure password that meets the following requirements: - Contains at least one uppercase letter, one lowercase letter, and one digit - Does not contain any repeating characters - Must be at least 12 characters long - Must include at least one special character (e.g. !@#$%^&*) - Cannot cont...
codefeedback
Arrange the following characters in a valid Python expression. <, 1, %, (, *, [] (Note: The addition of the characters *, [] in the test increases the complexity by introducing additional symbols and requiring the understanding of operator precedence.)
codefeedback
Submit an optimized solution to the following leetcode problem. Problem: Given two binary trees, write a function to check if they are the same or not. The trees should have at most 1000 nodes each and the values of the nodes should be integers within the range of -1000 to 1000. Two binary trees are considered the same...
codefeedback
Define a class in Python that represents a currency. The currency should have attributes for the name, symbol, and exchange rate to USD. The class should also have methods to convert an amount in the currency to USD and vice versa.
codefeedback
Write a Python function to convert a given Unix timestamp to a readable format like "day, month, date, hours:minutes:seconds, year". The function should also include the option to convert the timestamp to different time zones, taking into account daylight saving time if applicable.
codefeedback
Generate code which returns a random character from a given list of strings, but with the added condition that the character must be an uppercase letter. ['apple','orange','pineapple','grape']
codefeedback
Given a first person narrative created by a GPT model, develop a program that not only makes the narrative more coherent, but also adds descriptive elements to each sentence, such as the protagonist's emotions, the surrounding environment, and the dragon's behavior. The program should also generate a concluding sentenc...
codefeedback
Write a Python function to implement the game of Tic-Tac-Toe, but with the additional requirement that the game must be played on a 4x4 grid instead of the standard 3x3 grid.
codefeedback
Train a deep learning algorithm to classify objects into one of three classes. Additionally, ensure that the algorithm is able to handle imbalanced datasets by applying appropriate sampling techniques.
codefeedback
Analyze an object-oriented program written in Python and suggest changes to improve its technical quality. ## Problem Description You are given a program that prints each element of a given list. Your task is to analyze the program and suggest changes to improve its technical quality. ## Program Details The given p...
codefeedback
Write a function in JavaScript to flatten a nested array. The input array can contain arrays at any level of nesting, and the output should be a single flattened array with no nested arrays. Example: Input: [1, [[2, 3], 4], 5, [6]] Output: [1, 2, 3, 4, 5, 6] Note: - The input array can contain any valid JavaScript da...
codefeedback
Write a Java program to implement a web scraping application that extracts data from a given website. Requirements: 1. The program should send an HTTP GET request to the specified URL. 2. The program should parse the HTML content of the website using a library of your choice. 3. The program should extract specific inf...
codefeedback
Create a serverless application with AWS Lambda that performs real-time sentiment analysis on a stream of Twitter data. Requirements: 1. The application should use the Twitter Streaming API to fetch a continuous stream of tweets. 2. The application should perform sentiment analysis on each incoming tweet using a natur...
codefeedback
Build a script to print the words that have the most occurrences in a given string, excluding all common English stop words such as "the", "and", "but", "or", etc.
codefeedback
Build a PHP function to check if two strings are anagrams. $s1 = 'abcd'; $s2 = 'dcba'; #Updated Test# Build a PHP function to check if two strings are anagrams. $s1 = 'abcd'; $s2 = 'dcba'; $s3 = 'abdc'; $s4 = 'abcd'; #Erroneous Code# ``` function areAnagrams($s1, $s2) { if (strlen($s1) !== strlen($s2)) { re...
codefeedback
Given a string in Python, generate a new string with the same set of characters but in the reverse order. The input string will have at most 1000 characters and will only consist of lowercase letters. You are not allowed to use any built-in reverse functions or methods.
codefeedback
Create a dynamic HTML page that displays a table holding information about the 10 most populous countries in the world. The table should include the following columns: Country, Population, Area, and Density. To achieve this, you should: 1. Retrieve the necessary data about the 10 most populous countries from a reliabl...
codefeedback
Given the following Python code, identify if it is syntactically correct or not. The code should also return the sum of the elements in a given list, with the additional requirement that the code must use recursion to calculate the sum. def sum_list_recursive(lst): if len(lst) == 0: return 0 elif len(l...
codefeedback
Implement an algorithm to subtract two strings, represented as a linked list, in the order they appear in and return the result as a linked list. The linked lists may contain digits from 0 to 9. You can assume that the input strings are well-formed and do not contain leading zeros, except for the number zero itself. ...
codefeedback
Create a Java program that takes a list of integers as an argument and computes the longest increasing subsequence. The longest increasing subsequence is a sequence of integers in the original list that are in increasing order, and no other sequence in the list is longer. Example input: [8, 10, 1, 4, 15, 6, 7] Expect...
codefeedback
Use PHP to create a web page redirect script that includes the following requirements: - The script should only redirect users who are accessing the web page from a specific IP address range. - The script should log the IP address, timestamp, and redirect destination for each redirected user in a database. - The redire...
codefeedback
Given an array of integers, remove any duplicate numbers and sort the remaining elements in descending order. The final array should also include the count of each unique element. Example: Input: arr = [3, 9, 8, 4, 6, 7, 5, 4] Output: sortedArr = [9, 8, 7, 6, 5, 4, 3], countArr = [1, 1, 1, 1, 1, 2]
codefeedback
Generate a concise summary of an article containing more than 500 words, while ensuring that the summary is at least 90% accurate in terms of capturing the key information and ideas. Additionally, the summary should be generated within a time limit of 5 seconds for every 100 words in the article.
codefeedback
Design a function to find the Fibonacci sequence numbers given n. The function should only use a single loop and no recursion. The function should also handle the edge case when n is negative or zero by returning an empty list. n = 5
codefeedback
Create a program that outputs a spiral array from the given input of a 2D array. The program should take into consideration that the input array can have any number of rows and columns. For example: Input: [[ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9]] Output: [1, 2, 3, 6, 9, 8, 7, 4, 5]
codefeedback
Compute the sum of all even integers from 1 to the given number n.
codefeedback
Create a Python script to print out all prime numbers up to and including a given number n, with the additional requirement that the script must be able to handle inputs up to 10^9 efficiently.
codefeedback
Design an algorithm that computes the minimum number of moves required to sort an array of integers, where a move is defined as swapping two adjacent elements. The algorithm should have a time complexity of O(n^2) and a space complexity of O(1). #Explanation# The original test asks for an algorithm that computes the m...
codefeedback
Compute the sum of all the prime numbers and Fibonacci numbers in an array of numbers. [2, 3, 5, 7, 8, 13]
codefeedback
Design a function to parse the given URL and return its components. The function should handle URL encoding and decoding. The URL may contain special characters and non-ASCII characters. The function should also validate the URL format and throw an error if it is not a valid URL. Additionally, the function should suppo...
codefeedback
Write a script that prints out the current value of environment variables, but only for variables that contain the word "secret" in their name.
codefeedback
Name a specific package that can be used to implement a REST API in Node.js, while ensuring that the API supports authentication and authorization for different user roles.
codefeedback
Develop a C++ function to update the contents of an integer array. The int array contains {1, 2, 3, 4, 5}. Update the array so that it contains {1, 4, 9, 16, 25}. Note: The array should be updated by squaring each element.
codefeedback
Modify the following code segment to add multiple values in an array while ensuring that each value is unique and the array does not exceed a length of 10. Use a loop to prompt the user to enter a value, check if it already exists in the array, and only add it if it is unique. Additionally, display an error message if ...
codefeedback
Generate a query to find the name, age, and grade of all students whose age is greater than 18, and who are in grade 12 or higher.
codefeedback
Write a code to delete white space from this sentence, while also keeping track of the number of words in the sentence. This is a sentence with extra white space.
codefeedback
Design a JavaScript class to instantiate objects for student records. The student records should store the student name, age, and score of the last test. In addition to the above requirements, the class should also include the following functionalities: 1. A method to calculate the average score of all the tests ta...
codefeedback
Write a PHP script to get the length of a string, but you are not allowed to use the built-in function `strlen()`. The string to be evaluated is "Hello World!".
codefeedback
Write code to create an SQLite table called "Students" with 5 columns: student_id, name, age, class, and grade. The student_id column should be a primary key with auto-increment functionality, ensuring each student has a unique identifier. The name column should be limited to a maximum of 50 characters. The age c...
codefeedback
Implement a recursive function that finds the nth number in the Fibonacci sequence. The Fibonacci sequence is defined as follows: each number in the sequence is the sum of the two preceding ones, starting from 0 and 1. For example, the sequence begins as follows: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... In addition to fin...
codefeedback
Discover and remove redundant code from this C++ program, while also ensuring that the code uses a maximum of three variables and does not use any loops or conditional statements.
codefeedback
Create a function in JavaScript which prints out squares of all numbers from 1 to a given number, where the given number can be up to 10^6. The function should have a time complexity of O(n), where n is the given number.
codefeedback
Write a SQL query to get the names of all customers who have placed orders that have a total cost greater than $100 and were placed within the last 7 days. Table names: customers, orders Table columns: customers(customer_id, customer_name), orders(order_id, customer_id, order_cost, order_date).
codefeedback
Use HTML and CSS to create a responsive webpage which features a table with at least 5 columns and 10 rows. The table should have alternating row colors and a header that remains fixed when scrolling. Additionally, implement a search functionality where the table dynamically filters based on user input.
codefeedback
Balance the following reaction equation: 2 NaOH + H2SO4 → Na2SO4 + 2 H2O
codefeedback
Given a 2D array in Python, find the maximum value in each column and return a new 2D array where each element is replaced by its corresponding column's maximum value. The input array can have any number of rows and columns. For example, given the input array: array = [[1, 2, 3], [4, 5, 6], [7, 8, ...
codefeedback
Create a C++ class called "HelloPrinter" that has a private member variable called "name" and a public member function called "printHello" that prints the "Hello World!" string followed by the value of the "name" variable. The "printHello" function should also have a parameter called "numTimes" that specifies the numbe...
codefeedback
Proposition some ideas for a C++ program to calculate the average price of a product given its list of purchased items, while also implementing error handling for invalid inputs such as non-numeric values or negative prices.
codefeedback
Write a script in PHP for generating a random alphanumeric string of length 10. The generated string should not contain any repeated characters.
codefeedback