instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with implementing a simple factory design pattern for creating different types of smartphones. The code snippet provided is a starting point for the problem. You are given the following class definitions: ```cpp class Nokia { public: virtual void Call(const std::string& number) = 0; }; class Lumia...
codefeedback
You are tasked with implementing the A* search algorithm to find the shortest path between two points on a grid. The grid is represented as a 2D array where each cell can be either empty or blocked. The A* search algorithm uses a heuristic to guide its search and is commonly used in pathfinding and graph traversal. Yo...
codefeedback
You are given an array A of integers. Your task is to find the maximum possible length of a contiguous subarray within A, such that the subarray is non-decreasing. For example, given the array A = [3, 1, 6, 2, 7, 4], the contiguous subarray [2, 7, 4] is the longest non-decreasing subarray, with a length of 3. Write ...
codefeedback
You are tasked with implementing a parser for a custom language that uses a specific syntax for defining key-value pairs. The language allows for defining multiple key-value pairs within a single string, with each pair separated by commas. The keys can have optional values, which are enclosed in square brackets and sep...
codefeedback
You are given a hexadecimal-encoded image file in the form of a long string. Your task is to decode the image and convert it into a human-readable format. Write a function `decode_image(hex_string: str) -> str` that takes a hexadecimal-encoded image string as input and returns the decoded image in a human-readable for...
codefeedback
You are tasked with implementing a custom YAML deserialization feature for a C# application. The application uses the YamlDotNet library for YAML processing. Your goal is to create a custom deserializer that can handle a specific attribute, `ScalarStyle`, for the `InputDefinition` class. The `InputDefinition` class is...
codefeedback
You are tasked with creating a program to manage a hierarchical structure of body parts in a 3D model. Each body part has a unique identifier and a descriptive name. The identifiers follow a specific naming convention, where the prefix "mixamorig:" is followed by the body part name and a number indicating the level of ...
codefeedback
You are tasked with creating a script to automate the comparison of benchmark results for different sets of parameters. The script should take benchmark data, parameter values, and display names as input, and then calculate differences between original and modified benchmarks. Finally, the script should copy the result...
codefeedback
You are tasked with creating a program that decrypts a message encoded using a simple substitution cipher. In a substitution cipher, each letter in the plaintext is replaced by a letter some fixed number of positions down or up the alphabet. For this problem, you are given a string `encrypted_text` containing the encry...
codefeedback
You are tasked with designing a vehicle detection and tracking system for an autonomous driving application. The system will consist of several components, each responsible for a specific operation. The components include LaneFinder, PerspectiveFinder, StatsWriter, VehicleFinder, VehicleClusterer, and VehicleTracker. E...
codefeedback
You are working on a data processing application that involves handling SQL scripts, source data, and destination tables. Your task is to implement a class method that processes input arguments and performs necessary operations based on the provided inputs. The method should handle various scenarios such as specifying ...
codefeedback
You are tasked with implementing a custom JSON serialization method for a Swift array. The method should take an array of elements and convert it into a JSON string. Additionally, the method should support an optional parameter for pretty-printing the JSON output. You are provided with a partial implementation of the ...
codefeedback
You are tasked with implementing a compression and decompression utility in C#. Your goal is to create a class that provides methods for compressing and decompressing data using the Deflate algorithm. The class should offer both synchronous and asynchronous decompression methods, and should allow the option to leave th...
codefeedback
You are tasked with implementing a function to determine the number of days in a given month of a given year. The function should account for leap years, where February has 29 days. You are provided with a code snippet that contains a function to return 29 for February in a leap year and an array `daysinmonth` that hol...
codefeedback
You are tasked with creating a Discord bot that can perform various tasks based on user commands. The bot will need to read settings from a JSON file and utilize Discord's intents feature for specific functionalities. You are provided with a Python code snippet that initializes the necessary components for the bot, in...
codefeedback
You are tasked with developing a module for a web-based report generation system. The module should allow users to customize the header and footer of the reports, as well as specify various formatting options such as margins and orientation. The provided code snippet is a part of the module's configuration, defining th...
codefeedback
You are tasked with creating a Python program to fetch a list of free proxy servers from a website and test their connectivity to a specific URL. You will need to parse the proxy server details from the website, establish a connection to each proxy server, and then test the connectivity to a testing URL. Your program...
codefeedback
You are tasked with implementing a Python class for managing book information, specifically related to ISBN (International Standard Book Number) codes. The class should provide functionality for validating and formatting ISBN codes. Your task is to complete the implementation of the `ISBNManager` class by adding the f...
codefeedback
You are tasked with creating a Python program to optimize a DEA (Data Envelopment Analysis) problem using the Korali library. DEA is a non-parametric method for measuring the efficiency of decision-making units (DMUs) such as firms, organizations, and schools. In this problem, you will need to set up an experiment usin...
codefeedback
You are tasked with implementing a function that processes a series of input pairs and constructs a specific data structure based on the input. Each pair consists of a numeric identifier and a corresponding action. The actions are as follows: - If the identifier is 93, it signifies the count of generation settings to b...
codefeedback
You are tasked with implementing a poker hand ranking system in Java. Your goal is to extend the existing codebase to include the functionality for identifying a "One Pair" hand in a poker game. The provided code snippet is a part of the existing codebase and represents the beginning of the implementation for the "One ...
codefeedback
You are tasked with implementing a Python class that represents a machine learning model. The class should have a method to fit the model and a property to retrieve the accuracy of the model on a test set. You need to implement the `fit` method and the `accuracy` property according to the given specifications. Your ta...
codefeedback
You are tasked with creating a program that analyzes the frequency of words in a given text. Your program should take a string of text as input and output a list of unique words along with their frequencies, sorted in descending order based on frequency. For this problem, a word is defined as a sequence of alphanumeric...
codefeedback
You are tasked with implementing a function to control the movement of a robot with two wheels. The provided code snippet is a part of a larger program that controls the robot's movement. The `rotate` function is responsible for rotating the robot by a specified angle at a given speed. The robot's movement is achieved ...
codefeedback
You are tasked with implementing a function that processes a dictionary of functions and their associated metadata. The function should filter and organize the functions based on certain criteria and return the result in a specific format. You are given the following code snippet as a starting point: ```python funcs ...
codefeedback
You are tasked with implementing a class that manages an indexed collection of objects. The class should support adding new objects, removing existing ones, and iterating through the collection. You are given a code snippet that partially implements the functionality. Your task is to complete the implementation of the...
codefeedback
You are tasked with implementing a network data transfer monitoring system. Your goal is to create a program that tracks the amount of data sent over a network connection and provides real-time feedback on the data being transferred. You will need to simulate a network connection and implement a data transfer monitorin...
codefeedback
You are tasked with creating a Python program that converts a PDF file into an audiobook. The program should utilize the `PyPDF2` and `pyttsx3` libraries to extract text from each page of the PDF and convert it into speech. The program should be able to handle any PDF file and convert its content into an audiobook. Yo...
codefeedback
You are tasked with creating a file upload helper function in PHP. The function should take a file and an upload directory as input and handle the file upload process. Your task is to complete the `uploadHelper` function by implementing the file upload logic using PHP's built-in functions. The `uploadHelper` function ...
codefeedback
You are tasked with creating a Python program that simulates a simple server-client interaction using the `caravan` library. The server will be responsible for processing tasks sent by clients, and the clients will send tasks to the server for processing. Your task is to complete the Python program by implementing the...
codefeedback
You are tasked with creating a Python program that analyzes a given directory and its subdirectories to retrieve information about the directory structure. Your program should list all the directories and files within the specified path and its subdirectories. Additionally, it should calculate the total size of all the...
codefeedback
You are working on a project that involves storing and retrieving large arrays of numerical data efficiently. You have decided to use Python's `pickle` module for serialization and deserialization, and the `numpy` library for handling numerical arrays. However, you want to ensure that the data is stored in a compressed...
codefeedback
You are tasked with implementing a Python function that parses a bpython-formatted colored string and returns a list of tuples representing the colored segments of the string. The bpython-formatted colored string consists of color codes enclosed in square brackets followed by the text to be colored. The color codes ar...
codefeedback
You are tasked with implementing a custom data structure called `UniqueStack` that combines the functionality of a stack and a set. The `UniqueStack` should store unique elements and support standard stack operations such as push, pop, and peek. Additionally, it should provide a method to retrieve the minimum element i...
codefeedback
You are working on a project that involves a TypeScript Angular client generated from an API. The project structure includes a file named `api.ts` located at `<filename>front02/src/typescript-angular-client-generated/typescript-angular-client/api/api.ts`. This file is used to export functionality from a service named `...
codefeedback
You are tasked with implementing a context manager for a database session in Python. The context manager should handle adding a status to the database, committing the changes, rolling back the changes in case of an exception, and removing the database session. Your task is to complete the implementation of the `Databas...
codefeedback
You are tasked with implementing a Python function that extracts information about the arguments and annotations of another function. Your goal is to create a function that takes a function `f` as input and returns specific details about its arguments and annotations. Write a Python function `extract_function_info(f)`...
codefeedback
You are tasked with implementing a version control system for a software project. The version control system will manage three types of version numbers: release version, database version, and build version. Each type of version number has specific rules for when and how it should be updated. The release version (rr) s...
codefeedback
You are given a code snippet that manipulates arrays using various operations. Your task is to implement a function that performs a specific rotation operation on an array. You are given the following information: - The code snippet uses the functions `reset`, `cp`, and `rot` to manipulate arrays. - The `reset` functi...
codefeedback
You are working on a medical imaging software project and need to implement a function to print a bucket map to a volume. The provided code snippet includes a function `printbucket` that takes three parameters: `bck` (bucket map), `vol` (volume), and `value`. Additionally, there are two variables `seed` and `voxel_size...
codefeedback
You are tasked with implementing a Python class method that retrieves a record from a database by its UUID (Universally Unique Identifier). The method should handle potential exceptions and errors, and ensure that the database transaction is rolled back in case of failure. Below is the skeleton of the method: ```pytho...
codefeedback
You are tasked with creating a Python class to manage outbound rules for a security group. The class should allow for adding, removing, and listing outbound rules. Each outbound rule consists of the following attributes: - `action` (a string representing the action of the rule, e.g., "ALLOW" or "DENY") - `ip` (a string...
codefeedback
You are tasked with creating a Django model for a document repository system. The model should include fields for the repository name, document URL, user who uploaded the document, and the date and time of the upload. Below is a partial code snippet for the Django model: ```python class Document(models.Model): rep...
codefeedback
You are tasked with creating a Python class that handles running tests and generating test files. Your class should handle potential errors that may occur during the test running process. The provided code snippet is a part of the class method that initializes the test runner and handles specific exceptions. Your task ...
codefeedback
You are working on an image processing project and need to implement a function to create multiple ellipses on a given image. The function should take an input image and return the image with applied shadow mask, blur effect, and multiple ellipses. You are given a code snippet that initializes a shadow mask and calls ...
codefeedback
You are tasked with implementing a program to manage a pharmacy's inventory using object-oriented programming in Python. The pharmacy sells various types of medications, each with different properties such as name, price, quantity, and expiration date. Your program should allow the user to perform operations such as ad...
codefeedback
You are tasked with creating a Python program to manage different types of projects and their content using object-oriented programming and inheritance. Your program should include the following classes and their relationships: 1. `ProjectGrouperAdmin`: A base class for managing project groups. 2. `ProjectContent`: A ...
codefeedback
You are tasked with creating a Swift function that efficiently organizes files into a directory structure based on their file extensions. The function should take a source directory path as input and organize the files within it into subdirectories based on their file extensions. If the source directory does not exist,...
codefeedback
You are tasked with implementing a configuration struct for a genetic algorithm in Rust. The struct, named `GeneticAlgorithmConfig`, contains several fields representing various parameters and settings for the genetic algorithm. Your goal is to define the struct and its associated default implementation method. The `G...
codefeedback
You are tasked with implementing a function to rotate a 2D pixel buffer 270 degrees clockwise. The pixel buffer is represented as a 1D array, and the rotation should be performed in-place. You are given the following code snippet as a starting point: ```rust /// Rotate buffer 270 degrees clockwise pub fn rotate270<C>...
codefeedback
You are given a string representing a simple HTML tag. The tag can be an opening tag, a closing tag, or a self-closing tag. Your task is to write a function that determines whether the tag is valid or not. A valid tag must adhere to the following rules: 1. Opening tags must start with `<` followed by a valid tag name a...
codefeedback
You are tasked with creating a Python function that simulates a memory management system. The function should calculate the amount of physical memory available on a system, given certain constraints and constants. You are provided with a code snippet that imports modules and defines constants and a function. The const...
codefeedback
You are tasked with implementing a custom class in Java that extends the `Single` class and implements the `Callable` interface. The class, `TraceContextCallableSingle`, is designed to handle asynchronous computation and tracing within a distributed system. It takes a generic type `T` and has three member variables: `s...
codefeedback
You are tasked with implementing a function to calculate the intersection point of two line segments in a 2D plane. The line segments are defined by their start and end points. The function should return the coordinates of the intersection point if it exists, or indicate if the line segments are parallel or overlapping...
codefeedback
You are tasked with creating a notification management system for a web application. The system should allow users to push notifications and clear all notifications. Additionally, there should be a theme toggle feature to switch between light and dark themes. You are provided with a code snippet that includes a navigat...
codefeedback
You are tasked with implementing a Binary Search Tree (BST) class in Python. Your task is to create a method to remove a specific element from the BST and then calculate the height (or maximum depth) of the resulting tree. You are given a code snippet that demonstrates the usage of the BST class. The snippet first rem...
codefeedback
You are tasked with creating a Python function that processes a given dataframe to generate two distinct subsets based on certain conditions. The function should take in a dataframe `df` and a boolean variable `validate`, indicating whether to create a validation dataframe. If `validate` is `False`, the second datafram...
codefeedback
You are given an array of non-negative integers representing the heights of a series of vertical lines. The distance between any two vertical lines is the difference in their indices. Your task is to write a function `maxArea` to find the maximum area formed between two vertical lines by using the shorter line as the h...
codefeedback
You are tasked with implementing a custom iterator in Java that iterates over a collection of elements and filters out any elements that do not meet a specific condition. Your custom iterator should be able to iterate over a collection of integers and yield only the elements that are greater than a given threshold. Yo...
codefeedback
You are given a 3x3 Tic-Tac-Toe board represented as an array of strings. Each string represents a row of the board, and each character in the string represents a square on the board. The characters can be either "X", "O", or " " (empty). Your task is to write a function that determines whether the current board state...
codefeedback
You are tasked with developing a Python script to automate the process of uploading image files to an AWS S3 bucket. The script should accept command-line arguments for the image size, the name of the S3 bucket, and the prefix under which the images should be stored. Your task is to implement the script to handle these...
codefeedback
You are tasked with creating a Python program that processes a given text file and generates a report of word frequencies. The program should read a text file named "input.txt" and count the occurrences of each word in the file. The output should display each word along with the number of times it appears in the file. ...
codefeedback
You are tasked with implementing a class hierarchy for managing different types of storage disks in a virtualization environment. The base class `Disk` represents a generic storage disk, and it has two subclasses: `DiskImage` and `DiskVolume`. The `DiskImage` class represents a storage disk that stores data in the form...
codefeedback
You are tasked with creating a Python function that validates a list of IP addresses against a given IP network. The function should raise specific exceptions for different scenarios, and handle both IPv4 and IPv6 addresses. Write a function `validate_ip_addresses(ip_list, network_str)` that takes in a list of IP addr...
codefeedback
You are working on a Python project that involves handling search responses using different classes. The code snippet provided includes the definition of two classes, `CartQueryResponseWithFacets` and `CartMatrixResponseWithFacets`, which inherit from other classes. Your task is to understand the inheritance and initia...
codefeedback
You are tasked with implementing a lazy property in Swift that represents a user interface element in an iOS app testing framework. The lazy property should be initialized with a closure that returns an `XCUIElement` representing a chip element in a user interface. The `XCUIElement` class is part of the XCTest framewor...
codefeedback
You are tasked with implementing a Python function to calculate the posterior probability distribution for a given set of data points. The posterior probability distribution is based on a Gaussian likelihood function and a Gaussian prior distribution. The likelihood function is defined as $p(X|\mu, \sigma)$, where $X$ ...
codefeedback
You are given two non-negative integers represented as strings, `numberN` and `numberM`. Your task is to implement a function to add these two numbers and return the result as a string. Function Signature: `char* addStrings(char* numberN, char* numberM)` Input: - Two non-negative integers `numberN` and `numberM`, whe...
codefeedback
You are tasked with implementing a token management system for a security service. The system provides three operations: issue, cancel, and renew. Each operation is associated with a specific method that interacts with the underlying token management service. The code snippet provided shows a part of the token manageme...
codefeedback
You are tasked with implementing a custom lazy initialization mechanism for a data structure in Rust. The provided code snippet includes a partial implementation of a `Default` trait for a struct `Data`, where the `status` field is initialized using the `Lazy` type. Your goal is to complete the implementation of the la...
codefeedback
You are tasked with implementing a function that simulates a simple text-based game. The game involves a player navigating through a grid-based world, collecting treasures, and avoiding obstacles. The player's position and the layout of the world are represented by a 2D grid. The player can move up, down, left, or righ...
codefeedback
You are tasked with implementing a unit test for a presenter in a mobile application. The presenter is responsible for setting up and coordinating the display of reward information to the user. The presenter interacts with a stubbed view and a reward service. The code snippet provided is a part of the unit test for the...
codefeedback
You are tasked with creating a Python function that simulates the removal of files and directories based on a given file path. The function should handle both verbose and non-verbose modes, printing appropriate messages and performing the removal operations accordingly. You are provided with a code snippet that demons...
codefeedback
You are tasked with implementing a multi-block component system in Java. The `IMultiBlockUnit` interface represents a unit within a multi-block structure and provides methods for interacting with the multi-block system. Your goal is to create a concrete implementation of the `IMultiBlockUnit` interface and a correspond...
codefeedback
You are working on a project that involves training and evaluating a machine learning model using PyTorch. The given code snippet is part of a larger script that loads a trained model, prints a message indicating the successful loading of the model, and then proceeds to evaluate the model's performance on a dataset. Y...
codefeedback
You are tasked with implementing a binary search tree (BST) in Python. A binary search tree is a binary tree in which for each node, the left child is less than the parent and the right child is greater than the parent. You need to implement the deletion operation for the BST. You are given a code snippet that handles...
codefeedback
You are tasked with creating a custom exception hierarchy for a Python library called "Arequests" that handles various errors related to making HTTP requests. The provided code snippet shows the initial definition of a base exception class `ArequestsError` with a docstring. Your task is to extend this exception hierar...
codefeedback
You are given an array of integers `nums`, which is sorted in non-decreasing order. Your task is to find all unique triplets in the array that sum up to zero and return them as a list of lists. Each triplet should be in non-decreasing order. For example, given the input `nums = [-1, 0, 1, 2, -1, -4]`, the output shoul...
codefeedback
You are tasked with implementing a PositionController class for a drone simulator. The PositionController is responsible for controlling the drone's position based on a given set of commands. The mission_setup method is used to set up the mission planner with a flight plan, and the controller is initialized with the dr...
codefeedback
You are tasked with creating a Python program to analyze and visualize polynomial functions. The program should take user input for the coefficients of a polynomial function, evaluate the function at various points, and then plot the resulting curve using matplotlib. Your program should perform the following steps: 1....
codefeedback
You are tasked with creating a script to automate the transfer of configuration files from a local machine to a remote server using the `scp` command. The script should be able to handle multiple configuration files and transfer them to the specified remote server. You are given a code snippet from a shell script that...
codefeedback
You are tasked with creating a PHP class that establishes a connection to a message broker using the STOMP protocol. The provided code snippet is a partial configuration array for the STOMP connection. Your task is to complete the PHP class by implementing the connection logic and error handling. Your PHP class should...
codefeedback
You are tasked with creating a program to process geographical coordinates and calculate the distance between two points on the Earth's surface. The program should take latitude and longitude coordinates as input and output the distance between the two points in kilometers. You are provided with the Haversine formula t...
codefeedback
You are tasked with creating a function that processes a listing of resources and returns a specific subset of data in a JSON format. The given code snippet is a part of a Laravel controller, and it contains two methods: `index()` and `index22()`. Your task is to complete the `index22()` method to achieve the same func...
codefeedback
You are tasked with implementing a function that processes a list of URLs and extracts the domain names from each URL. The domain name is defined as the substring between the protocol (e.g., "http://", "https://") and the first subsequent slash ("/"). If the URL does not contain a protocol or a subsequent slash, the en...
codefeedback
You are tasked with implementing a class that manages spatial and temporal processing for a video analysis system. The class should handle the initialization of spatial and temporal components based on certain conditions and parameters. Your task is to complete the implementation of the `VideoProcessor` class by fillin...
codefeedback
You are tasked with implementing a resource management system that provides methods for using, destroying, draining, and clearing resources. The system should support asynchronous operations using promises. You are given a TypeScript-like code snippet that outlines the interface for the resource management system: ```...
codefeedback
You are tasked with creating a Python program that captures screenshots when the user clicks the mouse button. Your program should utilize the `pyautogui` and `pynput` libraries to achieve this functionality. The `pyautogui` library provides the ability to take screenshots, while the `pynput` library allows for monitor...
codefeedback
You are tasked with creating a PHP function that securely retrieves the username from a session variable and performs a specific action based on the presence of the username. Your function should handle potential security vulnerabilities and ensure that the username is properly validated before further processing. Wri...
codefeedback
You are tasked with implementing a method to add a discussion post to a forum. The method should take a `DiscussPost` object as a parameter and perform certain operations on the post before adding it to the forum. The `DiscussPost` class has a `title` attribute, which needs to be processed to escape HTML tags before be...
codefeedback
You are tasked with implementing a Python class that manages a production system for a factory. The class, named `ProductionManager`, is responsible for handling the production of various items and managing the entry limit attributes. The class has a method `produces` that returns a list of items produced and a method ...
codefeedback
You are tasked with creating a script to merge multiple PDF files into a single PDF document. The script should take input from a file containing a list of file paths and a folder name, and then use the `wkhtmltopdf` and `pdftk` commands to merge the PDF files. Your script should perform the following steps: 1. Read e...
codefeedback
You are tasked with implementing a web scraping and crawling module in Python. The module should provide three functions: `scrape_by_url`, `crawl_by_url`, and `crawl_by_keyword`. The `scrape_by_url` function should retrieve the content of a web page given its URL, the `crawl_by_url` function should traverse a website s...
codefeedback
You are tasked with creating a function that processes a report for taxi services based on a given request. The function should take the request data as input and perform specific operations to generate the report. The request data will contain information related to taxi services, and the function needs to process thi...
codefeedback
You are tasked with implementing a data transfer object (DTO) for binary data. The DTO should support writing the binary content to a provided buffer asynchronously. Your task is to create a class that fulfills the requirements of the IDataTransferObject interface and passes the provided unit tests. The IDataTransferO...
codefeedback
You are tasked with implementing a function to calculate the gradient penalty for a Wasserstein GAN (Generative Adversarial Network). In a Wasserstein GAN, the gradient penalty is used to enforce the Lipschitz constraint on the discriminator network. The provided code snippet is a part of the gradient penalty calculati...
codefeedback
You are tasked with implementing a service for a superhero simulator application. The service will be responsible for handling various functionalities related to superheroes, such as retrieving hero data, displaying messages, managing application state, handling routing, shortening URLs, managing the clipboard, and dis...
codefeedback
You are tasked with creating a Python script that automates the release process for a software project. The release process involves the following steps: 1. Clean up the existing build and distribution directories by removing them if they exist. 2. Use the `python -m build` command to create a new distribution of the ...
codefeedback
You are tasked with implementing a function that processes and modifies labels based on specific rules. The function takes a label and a Y-axis option as input and applies the corresponding transformation to the label based on the Y-axis option. The Y-axis options are represented by an enumeration called `YAxisOptions`...
codefeedback
You are working on a Python application that interacts with a database using the `cursor` object. The `cursor.execute()` method is used to execute SQL queries. However, you want to ensure that the application handles potential errors that may arise during the execution of the query. Write a function `execute_query_saf...
codefeedback