instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
Create a C++ function to compute the area of a triangle with three given edges. The function should also check if the given edges form a valid triangle, and if not, it should return an appropriate error message.
codefeedback
Implement a stack to store and retrieve items in last-in first-out order. Additionally, implement the following operations: - getMin(): Retrieve the minimum element in the stack in constant time complexity. - getMax(): Retrieve the maximum element in the stack in constant time complexity. - popAll(): Remove all element...
codefeedback
Modify the given Swift code to compute the product of two numbers and print the result. However, you are not allowed to use the '*' operator for multiplication. a = 5 b = 8
codefeedback
Create a C program that sorts an array in either ascending or descending order, depending on the user’s selection. The program should implement the QuickSort algorithm for sorting. Requirements: 1. The program should allow the user to input the size of the array. 2. The program should allow the user to input the eleme...
codefeedback
Write a HTML/CSS code to implement a responsive design that adapts to different screen sizes and devices, while also incorporating a sticky header that remains fixed at the top of the page as the user scrolls.
codefeedback
Create an SQL query to get the second highest salary from a table named 'employee' where the salary must be greater than 50000 and the employee must have been hired within the last 3 years.
codefeedback
Generate a correct assembly language code to execution the following: Add two numbers and store the result in memory address 2000. However, the program must only use bitwise operations (AND, OR, XOR, SHIFT, etc.) to perform the addition and store the result.
codefeedback
Write a Ruby function to find the most frequently occurring elements in an array, but exclude any elements that are divisible by 3.
codefeedback
Extract all characters from the following text and store them in a new string. However, you are not allowed to use any built-in string manipulation functions or methods. Your solution should have a time complexity of O(n) and a space complexity of O(n), where n is the length of the input string. Input: "Hello world!" ...
codefeedback
Identify all person names in the given text using python. The program should be able to handle text that includes additional punctuation marks such as commas, periods, and exclamation marks. Only consider names that are at least two characters long.
codefeedback
Write a function in Ruby that takes in two parameters, a string and a list of words, and returns true if the string is an anagram of a word in the list. The list may or may not be alphabetically sorted. Example: Input: string = "listen" word_list = ["silent", "enlist", "list", "tin"] Output: true Input: string = "re...
codefeedback
Sort the elements in an integer array in non-decreasing order, using only constant space complexity and without using any built-in sorting functions or libraries. arr = [4, 23, 1, 7, 10]
codefeedback
Create a function in HTML that checks to make sure the provided input is a prime number.
codefeedback
Write a MySQL query to calculate the average temperature for each user, given a table of log data. However, the average temperature should only be calculated for users who have logged in at least 10 times in the past month and have a temperature sensor with a precision of at least 0.01 degrees.
codefeedback
Write a method in C that prints out all the permutations of a given string. String: ABCD Erroneous Code: ```c #include<stdio.h> #include<string.h> void swap(char *x, char *y) { char temp; temp = *x; *x = *y; *y = temp; } void permute(char *str, int l, int r) { int i; if (l == r) pri...
codefeedback
Write an SQL query to find the top 10 users with the highest temperature reading in the past 24 hours.
codefeedback
Given a JSON string, write a function in JavaScript to extract the value for the key "name". If the value is an object or an array, return a string representation of it. Example: jsonString = {"name":"John", "age":30, "city":"New York"} Output: "John" jsonString = {"name":"John", "hobbies":["reading", "painting"], ...
codefeedback
Replace the placeholder in the given HTML document with the corresponding table, where the table data is fetched from an external API. <html> <body> <!-- replace placeholder with table --> </body> </html> Fetch the data from the API endpoint: `https://example.com/api/users` which returns an array of user obje...
codefeedback
Search for the string "tutorials" in the given text and replace it with the word "lessons". text = "This site provides many Python tutorials and tutorials for other programming languages. These tutorials cover a wide range of topics including data structures, algorithms, and machine learning tutorials." #Erroneous Cod...
codefeedback
Write C++ code to implement a basic doubly linked list with the following additional requirements: - The list should support adding elements at the front and back, as well as removing elements from the front and back. - The list should have a method to check if it contains a specific element. - The list should have a m...
codefeedback
Given two integers, implement a function in C to swap their values without using a temporary variable. int a = 3; int b = 5; You may not use a temporary variable or any other data structure to store the values. Your function should directly swap the values of the given integers.
codefeedback
Create a SQL query to get the total count of the employees in the team "Development" that have the job title of "software engineer" and have been employed for at least 2 years. Table: Employees Columns: id (int), name (string), job_title (string), team (string), years_employed (int)
codefeedback
Write a C# class which implements two-dimensional array searching using binary search algorithms. The two-dimensional array contains sorted rows and columns in ascending order. The class should have the following methods: 1. `SearchValue(int[,] arr, int target)`: This method takes in the two-dimensional array `arr` an...
codefeedback
Code a function in JavaScript to find the area of a triangle given the lengths of its three sides. The function should have a time complexity of O(1).
codefeedback
Implement a program in Java that reverses a string input given by the user. The program should not use any built-in string manipulation functions or libraries. The input string can have a maximum length of 100 characters.
codefeedback
Parse a given HTML page to extract all <h1> tags and their corresponding text content. <html> <head> <title>Page Title</title> </head> <body> <h1>This is a heading 1</h1> <h2>This is a heading 2</h2> <p>This is a paragraph.</p> <h1>This is another heading 1</h1> </body> </html> Note: The given HTML...
codefeedback
Create a JavaScript function called `customArrayMethods` that mimics the functionality of the `.push()`, `.pop()`, `.shift()`, and `.unshift()` methods in JavaScript arrays. The function should take two parameters: an array and a value. The function should modify the array based on the following rules: - `.push()` sho...
codefeedback
Design an algorithm to detect whether two given strings are permutations of each other. Additionally, the algorithm should handle strings containing spaces and punctuation marks. #Revised Test# Design an algorithm to detect whether two given strings are permutations of each other. The algorithm should also account for...
codefeedback
Modify the given code so it prints a prime number table up to a given limit. table_limit = 1000
codefeedback
Determine how many alphanumeric characters are in a given string, excluding any punctuation marks or special characters. my_string = "Hello, world! 123"
codefeedback
Generate Python code to find the compound interest for a given principal amount, rate, and time period, while also considering any additional contributions made to the principal amount at regular intervals. The code should take as input the principal amount, the annual interest rate (as a decimal), the time period in ...
codefeedback
Convert the elements of a given array of strings to integers, but exclude any elements that are not numeric strings. The converted elements should then be sorted in descending order and stored in a new array. Additional constraint: You are not allowed to use any built-in sorting functions or libraries. arr = ["1", "2"...
codefeedback
Calculate the difference between two given dates in terms of weeks. date1 = "2020-5-15" date2 = "2020-6-20"
codefeedback
Generate a Flask route that handles both GET and POST requests. The route should return the sum of two numbers passed as query parameters in the URL for a GET request, and return the product of two numbers passed as JSON in the body for a POST request.
codefeedback
Clone a given repository and create a pull request with the following additional requirements: 1. Ensure that the pull request includes a detailed description of the changes made. 2. Implement a unit test for at least one function in the repository. 3. Add a new feature or improvement to the existing codebase before su...
codefeedback
Construct an SQL query to get the names, job titles, and total compensation (salary + bonus) of the employees who earn more than a given salary and have a job title of "Manager". The total compensation should be calculated by summing the salary and bonus columns from the "employees" table. salary: 50000
codefeedback
Construct an SQL query to find the average temperature for each month in the year, considering only the days when the temperature was above a certain threshold (e.g. 30 degrees Celsius).
codefeedback
Generate a JavaScript array containing the first twenty Fibonacci numbers, starting with 0 and 1.
codefeedback
Create a class in Python with one method called talk that prints a string when invoked. The method should only print the string if it is called within a specific time window of 9 AM to 5 PM. Additionally, the talk method should only print the string if it is called by a user with administrative privileges.
codefeedback
Construct a query to find all movies released since a given year, and filter the results to only include movies with a runtime of at least 120 minutes. year: 2000
codefeedback
Construct an SQL query to select all the unique values of one column from a table that appear more than twice and are not NULL. Include the count of each unique value in the result set. column_name: 'gender'
codefeedback
Create an array of objects in JavaScript, each object should have four properties: "name", "age", "gender", and "occupation". The "name" property should be a string representing the name of the person, the "age" property should be a number representing the person's age, the "gender" property should be a string represen...
codefeedback
Construct an SQL query to find the number of records where the value in a certain column is greater than a specified value, but the query should not use the ">" operator.
codefeedback
Write a SQL query to update all the records in the table with new values from another table, but also add a condition that only updates records where a specific column in the original table matches a value in the new table.
codefeedback
Design a suitable data structure to hold a series of student records, considering the following requirements: 1. Each student record should contain the following information: - Student ID (unique identifier) - Name - Age - Grade - Address 2. The data structure should support the following operations: ...
codefeedback
Write a PHP code to validate a date in the format MM/DD/YYYY, considering leap years and the number of days in each month.
codefeedback
Suggest a PHP code snippet which calculates the sum of two numbers, without using any built-in arithmetic operators or mathematical functions.
codefeedback
Using recursion, write a Python program to find the sum of all odd numbers in a given range. Range: 1 to 10
codefeedback
Create a program to calculate the mean of the following list. However, you must only use a single line of code to achieve this. Additionally, you should handle any potential errors that may arise, such as empty lists or invalid input.
codefeedback
Compare the two strings using the given regular expression and return the number of matching characters. Regular Expression: /^[a-z]+$/ Strings: string1 and string2 Constraint: The length of string1 and string2 should be equal.
codefeedback
Given the data, find the correlation coefficient between the two variables, x and y, using the least squares method. The program should handle large datasets efficiently, with a time complexity of O(n). The input data may contain missing values, which should be handled appropriately.
codefeedback
Return the number of elements in a dictionary, but exclude any elements whose keys are numbers. The dictionary may contain nested dictionaries as values. Additionally, you should handle cases where the dictionary is empty or where the dictionary values are themselves dictionaries. Example: myDict = {'a':1, 'b':2, 'c...
codefeedback
Rewrite the test to be more difficult: Write a program that validates whether a given string is a valid JSON object or not.
codefeedback
Given two strings, s1 and s2, write a program to return the longest common substring between them. The strings may contain uppercase and lowercase letters, numbers, and special characters. s1 = 'abcdefGHIJK123!@#' s2 = 'fghijkGHIJK456!@#'
codefeedback
Explain the concept of closures and how they are used in functional programming.
codefeedback
Modify the following JavaScript code to alert "Thanks for visiting!" when the page is loaded. Additionally, make sure that the alert is only triggered if the page has been visited for more than 5 seconds.
codefeedback
Implement a JavaScript function that takes two strings as parameters and replaces all occurrences of the first string with the second, but only if the first string is surrounded by a pair of square brackets [] and the second string is surrounded by a pair of curly braces {}.
codefeedback
Extract the last four characters from a text string and display them in reverse order. text = "This is a sample text" #Solution# 1. Initialize a variable 'last_four' as an empty string. 2. Check if the length of 'text' is greater than or equal to 4. 3. If the condition is true, extract the last four characters from 't...
codefeedback
Assign a value to each of the variables, x = ? and y = ?, such that x + y = 7. Additionally, the value of x must be a prime number and the value of y must be a multiple of 3.
codefeedback
Write a code to count the occurrences of a particular element in a given list, while ignoring any occurrences within nested sublists. Additionally, the code should only consider elements that are of a specific data type. The list may contain elements of various data types such as integers, strings, and dictionaries. li...
codefeedback
You have been given a list containing both words and numbers. You need to write a code to generate a new list containing only words in the original list and to calculate the average length of the words. If the average length is an integer, you need to round it up to the nearest integer. mixed_list = ['cat', 1, 'dog', ...
codefeedback
You have been given a list of numbers. Write a code to generate a new list of numbers containing only the even numbers from the original list, without using any built-in functions or operators for checking if a number is even. Your code should only use bitwise operations to determine if a number is even. numbers = [2, ...
codefeedback
Write a code to generate the fibonacci series for the first n numbers, but the code should be written in a functional programming style using recursion.
codefeedback
You have been given a list of user details (Names, Addresses etc). Write a code to filter out the users whose age is more than 21. Additionally, you need to sort the filtered users by their addresses in ascending order. The filtered list should only include users whose names start with the letter 'J'. Finally, you shou...
codefeedback
Create a PHP function that trims a string and removes all leading and trailing whitespace, as well as any whitespace between words. $string = " Hello World "; The function should return the string "Hello World" after removing all leading and trailing whitespace and collapsing any consecutive whitespace between w...
codefeedback
Create a JavaScript object which contains a key-value pair representing "name" and "lucy", but the value should be encrypted using a custom encryption algorithm that you have to implement. The algorithm should use a combination of bitwise operations and mathematical calculations to encrypt the value. The encrypted valu...
codefeedback
Write a Python program to identify all prime numbers within a given range. The program should accept two integers as input, representing the lower and upper bounds of the range, and output a list of all prime numbers within that range. The program should have a time complexity of O(n√m), where n is the size of the rang...
codefeedback
Write a code to detect all possible anagrams of a given word, where each letter in the anagram must be a vowel, in Python. word = "cat"
codefeedback
Explain the difference between the INNER JOIN and LEFT JOIN operations in SQL and provide an example of when each would be used.
codefeedback
Create a code to find the largest prime number from a list of given numbers in HTML. The code should have a time complexity of O(n^2) and should not use any built-in functions or libraries for finding prime numbers.
codefeedback
Create a function in C to edit a string. The function should correct all occurrences of two or more consecutive spaces with a single space. However, the function should also handle cases where there are multiple consecutive tabs or a combination of spaces and tabs. For example, the function should correctly convert "Hi...
codefeedback
Given a 2-dimensional array, print the elements across each row in reverse order.
codefeedback
Output the string "Programming is Fun" when you run the code. The code should be written in Python and should utilize a recursive function. The input string should be reversed before outputting the result.
codefeedback
Debug the following for loop for computing the sum of all prime numbers between 0 and 100. Initialize a variable called "sum" to 0. For each number "num" in the range from 0 to 100: If the number is equal to 2, add it to the "sum" variable. If the number is greater than 2, iterate from 2 to the square root of ...
codefeedback
Print a multiplication table of a given number, but only display the odd multiples. num = 7
codefeedback
Write a piece of code that implements a 3-way merge sort in Java, but with the following additional requirements: 1. The code should be able to handle both ascending and descending sorting orders, based on a parameter passed to the sorting function. 2. The code should be able to handle sorting of objects of any class ...
codefeedback
Read an array of numbers, where the length of the array is between 1 and 10^5 (inclusive), and output an array with all the even numbers in ascending order. The array can contain positive and negative integers ranging from -10^9 to 10^9.
codefeedback
Using a given array of numbers, create a function to display the frequency of each number and also identify the numbers with the highest and lowest frequencies.
codefeedback
How would you create a function in JavaScript that takes a string as an argument, counts the number of occurrences of a given character, and returns the count as well as the indices of each occurrence in an array?
codefeedback
Write a function in Java that takes a string as an argument and returns the length of the longest word in the string. The function should also exclude any punctuation marks or special characters from consideration when determining the longest word. Additionally, the function should handle cases where the string may con...
codefeedback
Write a Python program to find the longest substring in a given string which has no repeating characters and starts with a vowel.
codefeedback
Create a function in JavaScript that takes an array and returns a new array containing the elements in reverse order. Additionally, the function should not use any built-in JavaScript array methods (such as `reverse()`, `map()`, or `slice()`) to achieve this.
codefeedback
Perform the following calculation without using the multiplication operator: Multiply two given numbers, a and b, where a and b are positive integers.
codefeedback
Write a program that simulates a bot that can play tic-tac-toe against a human player. The bot should be able to make intelligent moves and attempt to win the game. The program should include a graphical user interface for the players to interact with.
codefeedback
Find all local maxima in the given list. A local maximum is defined as an element in the list that is greater than its immediate neighbors. list_vals = [1, 2, 3, 4, 5, 2, 1] Write a function called "find_local_maxima" that takes in a list of integers and returns a list of the indices of all the local maxima in the li...
codefeedback
Write an algorithm in JavaScript for finding the maximum number in a given array, while also keeping track of the index of the maximum number.
codefeedback
Create an HTML form with two text inputs, one for email and one for a password. Add client-side validation to check if the email input is a valid email address format (e.g. contains an "@" symbol and a valid domain name). Also, implement password strength validation to ensure that the password contains at least one upp...
codefeedback
Create a script to find the longest palindrome in a given sentence, considering only alphanumeric characters and ignoring any punctuation or whitespace. The script should return the longest palindrome, its length, and its starting and ending indices within the sentence.
codefeedback
Compare and contrast Java and Python for developing applications, focusing on the following aspects: 1. Performance: Discuss the differences in terms of runtime efficiency, memory management, and handling large datasets. 2. Language features: Analyze the syntax, object-oriented programming capabilities, and built-in li...
codefeedback
Design a code to arrange an array of numbers such that all odd numbers come before even numbers, without using any extra space. The code should have a time complexity of O(n) and should not modify the relative order of the numbers within each category. [2, 8, 3, 4, 9]
codefeedback
Write a C++ program to take two numbers from the user and display the sum, but the input numbers must be in Roman numeral format and the output must be displayed in binary format.
codefeedback
Given an array of integers, return the sum of the elements that are divisible by 3 and greater than 5. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
codefeedback
Write a loop in SQL for selecting all customer names that are not 'Bob' and have made more than 5 purchases.
codefeedback
Summarize the text into a few sentences. The United Nations (UN) is a global organization that seeks to uphold global peace, promote friendly relations among nations, foster international cooperation, and serve as a hub for coordinating the actions of countries. It is the largest, most recognized, most globally diverse...
codefeedback
Write an algorithm to find the longest sub string without repeating characters in a given string. However, the algorithm should also consider whitespace characters as potential repeating characters. Example: string = 'abc abcbb' #Erroneous Code Reference# string = 'a bcd efg' Note: The provided erroneous code is inc...
codefeedback
Provide an example of a query to find all users whose age is between 16 and 18, and their first name starts with the letter "J".
codefeedback
Generate a random probability distribution with mean 0 and standard deviation 1, such that the values are limited to a specified range, in Python.
codefeedback
Store this JSON data into a database of your choice. You are given a JSON array containing information about multiple people. Each person has the following attributes: "name" (string), "age" (integer), and "city" (string). Your task is to store this data into a database table. To accomplish this, you need to perform ...
codefeedback
Filter a given list of numbers in Python to find all the prime numbers. list1 = [3, 4, 5, 6, 7, 8, 9] Reference erroneous code: ``` def is_prime(num): if num < 2: return False for i in range(2, num): if num % i == 0: return True return True prime_numbers = filter(is_prime, l...
codefeedback
Fill in the blank to generate a SHA-256 hash in JavaScript, using a library or algorithm other than the built-in crypto module or SHA-2 family.
codefeedback