instruction_seed
stringlengths
0
26.4k
source
stringclasses
4 values
You are tasked with creating a Python function that simulates a simple game of rock-paper-scissors. The function should take a player's choice as input and then randomly generate the computer's choice. After that, it should determine the winner based on the standard rules of rock-paper-scissors. Additionally, the funct...
codefeedback
You are tasked with implementing a function that processes a given path and returns the concatenated subpaths in the correct order. The input path is represented as a list of tuples, where each tuple contains a move and a position. The moves can be either `Path.LINETO` or another move type, and the positions are repres...
codefeedback
You are given an array of integers `nums` and an integer `target`. Your task is to write a function `twoSum` that finds the indices of the two numbers such that they add up to the `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice. The function signatur...
codefeedback
You are tasked with creating a Python function to backup files from a specified directory to a backup directory based on certain criteria. The function should take in the following parameters: - `data_dir`: The directory containing the data files to be backed up. - `backup_dir`: The directory where the backup files sho...
codefeedback
You are tasked with implementing a binary tree data structure in Python. The binary tree should support the following operations: 1. Accessing a node's attribute using square brackets notation (`[]`). 2. Setting a node's attribute using square brackets notation (`[]`). 3. Generating a string representation of the bina...
codefeedback
You are tasked with implementing a function to calculate the precision and recall of a multi-class classification model. The function takes two parameters: `predictions`, a list of predicted class labels, and `truth`, a 2D numpy array containing the true class labels for each sample. Each row in `truth` represents the ...
codefeedback
You are tasked with creating a function to generate an augmented trajectory for a robotic arm to pick up an object from a pick position, move it to a drop position, and then drop it. The function takes in the robot, pick position, drop position, pick orientation, drop orientation, and a specified move height. The pick ...
codefeedback
You are tasked with creating a user registration form validation system for a web application. The system should enforce various rules and constraints on the user input to ensure data integrity and security. The provided code snippet is a part of the validation rules for the user registration form in a Laravel applicat...
codefeedback
You are tasked with creating a SwiftUI view that displays a feature card for a given scene. The feature card should include the feature image if available, along with the scene's title and description. Your goal is to implement the `FeatureCard` view with the following requirements: - The `FeatureCard` view should tak...
codefeedback
You are given a class `LineSearch` with a method `advance_and_retreat` that takes five parameters: `a0`, `h0`, `t`, `a`, and `b`. The method updates the values of `a` and `b` based on the input parameters. Additionally, there are two assertions that follow the method call: 1. `ASSERT_LE(a, 3.0)`: This assertion checks...
codefeedback
You are tasked with creating a TypeScript class that represents a simplified version of an educational course. The class should have properties for the course title and grade, and it should also include a method to enroll students in the course. Additionally, the class should have a method to calculate the average grad...
codefeedback
You are tasked with implementing a function that performs a specific type of text transformation. The transformation is based on the concept of graphemes and the Fano encoding method. Graphemes are the smallest units of writing in a language that distinguish meaning, while Fano encoding is a technique for data compress...
codefeedback
You are tasked with creating a Python function that utilizes the `PIL` library to perform a specific image processing task. The function should take in an input image and apply a series of transformations to align and crop a face within the image. The alignment and cropping process involves detecting facial points and ...
codefeedback
You are tasked with creating a PHP function that generates an email verification link for a user and embeds it in an email template. The function should take the user's verification token and email address as input and return the complete HTML email template with the verification link. The email template should includ...
codefeedback
You are tasked with implementing a retry mechanism for a client in a distributed system. The `get_client` method is responsible for creating and returning a client object, and the `RetryableClient` class is used to wrap the client with retry functionality. The `get_client` method takes in the following parameters: - `...
codefeedback
You are tasked with designing a performance testing tool for a key-value store. The tool will measure the throughput and latency of a set of operations on the key-value store. The operations include getting and setting key-value pairs. The code snippet provided is a part of the performance testing tool and includes a l...
codefeedback
You are tasked with creating a simple command-line tool that simulates a basic file management system. Your program should support the following commands: 1. `create <filename>`: Create a new file with the given name. 2. `delete <filename>`: Delete the file with the given name. 3. `list`: List all the files in the cur...
codefeedback
You are working on a web application that uses JavaServer Pages (JSP) for generating dynamic web pages. The code snippet provided is a part of a JSP file that is responsible for rendering a user's billing information. The snippet shows a JSP custom tag usage to output the value of the `billToFirstName` property from an...
codefeedback
You are tasked with implementing a class to represent a hierarchical structure of tags. Each tag has a name, a list of children tags, a span, and an index. The `__init__` method initializes the tag with the given name, children (defaulting to an empty list if not provided), and span. The `__str__` method returns a stri...
codefeedback
You are tasked with creating a Python script that generates a secret key for a Django application if the key is not already provided. The script should check for the existence of a file named `secret.py` containing the `SECRET_KEY` variable. If the file exists and the variable is defined, the script should use the exis...
codefeedback
You are tasked with implementing a function that creates a new process in a hypothetical operating system environment. The function `do_new_process` takes three parameters: `path` (the path to the executable file), `args` (the arguments to be passed to the new process), and `host_stdio_fds` (file descriptors for standa...
codefeedback
You are tasked with implementing a custom hook for managing form state in a React application. The hook should retrieve a specific property from the form state and return it to the component using the hook. You are given the following code snippet as a starting point: ```javascript useFormStore(formId, (state) => stat...
codefeedback
You are tasked with implementing a program that processes a list of employee records and generates a summary report. Each employee record is represented as a dictionary with the following fields: "name" (string), "department" (string), "salary" (integer), and "joining_year" (integer). The program should calculate and d...
codefeedback
You are tasked with creating a Python class that interacts with a Heroku client to manage and deploy applications. The `HerokuClient` class provides methods for deploying, scaling, and managing applications on the Heroku platform. Your task is to implement the `HerokuClient` class with the following methods: 1. `deplo...
codefeedback
You are given a code snippet that represents a SHA-256 hash and its size. Your task is to write a program that can generate a SHA-256 hash for a given input string and verify if it matches the provided hash. Additionally, you need to calculate the size of the generated hash and compare it with the given size. Write a ...
codefeedback
You are tasked with creating a Bash script that will recursively search for files with a specific extension within a given directory and its subdirectories. Your script should take two arguments: the directory to search in and the file extension to look for. The script should then output the absolute paths of all files...
codefeedback
You are tasked with implementing a simplified version of the `fetch` function in JavaScript. The `fetch` function is used to make network requests and handle the response asynchronously. Your task is to create a function that mimics the behavior of `fetch` by accepting a `Request` object and options, and then allowing ...
codefeedback
You are given a string `input_str` containing a sentence with words and numbers. Your task is to write a Python function `extract_numbers(input_str)` that extracts all the numbers from the input string and returns them as a list of floats. For example, if `input_str = "The price is $25.50 and the quantity is 10"`, th...
codefeedback
You are tasked with implementing a function to validate and convert a string containing parentheses, brackets, and braces into a valid format. The function should take a string `input_str` as input and return a new string with the parentheses, brackets, and braces in a valid order. If the input string contains any unex...
codefeedback
You are tasked with implementing a file archiving and concatenation system. The system should read scriptlet files associated with a given package, filter them based on a predefined set of suffixes, and then concatenate the filtered scriptlets into a single output file. Your task is to write a function that performs th...
codefeedback
You are tasked with implementing a function to classify IP addresses as either IPv4, IPv6, or invalid. An IP address is considered valid if it conforms to the IPv4 or IPv6 address format. The IPv4 address format consists of four decimal numbers separated by periods (e.g., 192.168.1.1), while the IPv6 address format con...
codefeedback
You are tasked with creating a resource service class that interacts with a database to retrieve a list of resources. The class has a method `GetResourcesAsync` that takes a `resourceGroup` as a parameter and returns a list of strings representing the resources in that group. The database connection is established usin...
codefeedback
You are tasked with implementing a simplified version of a customer management system using Java. Your task is to create a class that implements the `CustomerService` interface provided below. The `CustomerService` interface defines two methods: `createCustomer` for adding a new customer to the system and `getCustomerO...
codefeedback
You are tasked with implementing a function to generate a Digital Signature Algorithm (DSA) for a given message using a private key and a specified algorithm. The function should handle the encoding and decoding of the message and signature using base64. Your task is to complete the implementation of the `genDSA` funct...
codefeedback
You are tasked with designing a generic interface for a distributed system that manages nodes of different types. The interface provides methods to retrieve collections of nodes based on their types. Your goal is to implement a class that adheres to this interface and provides the necessary functionality to manage and ...
codefeedback
You are tasked with implementing a function that processes validation annotations for a given object. The function should take in an object, custom validations, and an instance container as input and return an array of validation annotations for each property of the object. The function should follow these rules: - If...
codefeedback
You are given an array of integers `nums` and an integer `target`. Your task is to write a function `two_sum` that finds the indices of the two numbers such that they add up to the `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice. The function signatu...
codefeedback
You are working for a financial services company that needs to implement a secure system for signing and posting XML data related to tax ID subscriptions. Your task is to create a Python program that utilizes cryptographic operations to sign an XML example and then consult a tax ID subscription using a provided service...
codefeedback
You are tasked with implementing a function to manage project teams and their progress. The function `findTeams` takes in two parameters: `contributors` and `projects`. Each project has a `working` attribute indicating whether it is currently being worked on, and a `days` attribute representing the number of days requi...
codefeedback
You are tasked with creating a script to manage the installation and uninstallation of a Tendermint node. The provided code snippet is a part of a larger script that handles the uninstallation process. Your task is to implement the installation process, which involves setting up the necessary directories and services f...
codefeedback
You are tasked with creating a Python program that processes a given long description and extracts specific information from it. The long description is a multi-line string containing information about a Python module. Your program needs to extract the following details from the long description: 1. The purpose of the ...
codefeedback
You are tasked with implementing a URL management system for a web application. The system should be able to construct and compare URLs, as well as preserve filters for a specific URL. You are given a code snippet from a Python class method that is responsible for constructing and comparing URLs, as well as preserving...
codefeedback
You are given a list of integers representing the scores of a game. Your task is to write a function that calculates the average score of the game, excluding the highest and lowest scores. Write a function `calculate_average_score(scores)` that takes in a list of integers `scores` (2 <= len(scores) <= 100) and returns...
codefeedback
You are tasked with implementing a Python class that parses and processes data from a web application. The class should have methods for running the parser and retrieving the results. Additionally, the class should be capable of writing the parsed data to a JSON file. Your task is to complete the implementation of the...
codefeedback
You are tasked with creating a Discord bot feature that sends health and fitness reminders to a specific channel at different times on Mondays. The provided code snippet includes a partial implementation of the health reminder feature. The `health_reminder` function is responsible for sending different messages based o...
codefeedback
You are tasked with implementing a command-line utility that processes user input to perform specific actions. The utility accepts command-line options and their corresponding arguments to carry out various operations. Your task is to implement the functionality for processing the command-line options and their argumen...
codefeedback
You are tasked with creating a Java enum class to represent different chemical elements and compounds. Each enum constant should have a corresponding string value associated with it. Your task is to implement the enum class and write a method to retrieve the string value for a given chemical element or compound. Creat...
codefeedback
You are tasked with creating a program that simulates a simple game of "Guess the Number". The program should generate a random number between 1 and 100, and then prompt the user to guess the number. After each guess, the program should provide feedback on whether the guess was too high, too low, or correct. The user s...
codefeedback
You are tasked with implementing a class for managing the hunger level of virtual pets. The Pet class should have a constructor that takes an initial hunger level as an argument. However, the constructor should enforce that the hunger level is an integer and handle cases where the input is of an inappropriate type. Yo...
codefeedback
You are tasked with implementing a custom Rope data structure in Python. A Rope is a data structure used for efficiently storing and manipulating large strings. It represents the string as a tree of smaller strings, allowing for efficient concatenation, insertion, and deletion operations. Your task is to implement the ...
codefeedback
You are tasked with implementing a multi-process communication system using named pipes in Python. Named pipes, also known as FIFOs, are a method for inter-process communication that allows processes to communicate with each other by writing to and reading from a named pipe in the file system. Your task is to create a...
codefeedback
You are tasked with implementing a simple neural network using PyTorch to classify handwritten digits from the MNIST dataset. The MNIST dataset consists of 28x28 grayscale images of handwritten digits (0-9). Your goal is to create a neural network model using PyTorch's nn module and train it to achieve high accuracy on...
codefeedback
You are tasked with implementing a rendering system for a hierarchical structure of elements. Each element can have child elements, and the rendering process involves recursively rendering all children of an element. You are given a partial implementation of the `add_render` method for the element class, which sets a f...
codefeedback
You are tasked with implementing a command-line interface for managing FAQs and presentations in a group chat application. The interface allows users to add, list, answer, and delete FAQs, as well as add presentations with notifications. The commands are formatted with specific parameters and actions, and the interface...
codefeedback
You are working on a software system that involves mutating molecular records. The code snippet provided is a part of a function that performs a mutation on a molecular record and then asserts the equivalence of the mutated record with a given mutation record. The `mutator` object is used to perform the mutation, and t...
codefeedback
You are tasked with implementing a GPX (GPS Exchange Format) parser in Swift. The GPX format is used for exchanging GPS data between different software applications. Your task is to create a class that can parse a GPX file and extract relevant information from it. You are provided with a Swift code snippet that includ...
codefeedback
You are tasked with implementing a simple caching mechanism using Swift. Your goal is to create a generic cache class that can store and retrieve objects of any type. The cache should have a fixed capacity and should evict the least recently used item when the capacity is exceeded. You should implement the `LRUCache` ...
codefeedback
You are tasked with creating a script that sets the appropriate library name suffix based on the operating system. The script should check the operating system type and assign the correct suffix to the variable `LIBRARY_NAME_SUFFIX`. If the operating system is "Darwin" (macOS), the suffix should be set to "dylib"; othe...
codefeedback
You are tasked with implementing a reinforcement learning algorithm using PyTorch. Your goal is to create a custom implementation of the Proximal Policy Optimization (PPO) algorithm for training an actor-critic model. The actor-critic model consists of two neural networks: an actor network that outputs a probability di...
codefeedback
You are tasked with implementing a class to handle incident attributes for a create request. The class should have methods to set and get the attributes of the incident. The attributes include incident ID, description, category, and priority. Additionally, the class should have a method to validate the incident attribu...
codefeedback
You are tasked with implementing a function that calculates the sum of all prime numbers within a given range. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Your function should take two integers, `start` and `end`, as input and return the sum of all prime numb...
codefeedback
You are tasked with creating a Python program that processes the WordNet lexical database to extract and store the definitions of all synsets in a specific format. WordNet is a large lexical database of English, developed at Princeton University, which groups English words into sets of synonyms called synsets, provides...
codefeedback
You are tasked with implementing a retry mechanism for executing a given action until it succeeds. The provided code snippet is a macro definition for `retry_until_ok!` that is used to retry an action until it returns a successful result. Your task is to implement the missing part of the `retry_until_ok!` macro, which...
codefeedback
You are tasked with implementing a robot selection algorithm for a multi-arm environment. The algorithm should choose the appropriate robot configuration based on certain criteria and exclude bimanual robots. Additionally, the algorithm should select a task for the chosen robot configuration. Your task is to implement ...
codefeedback
You are working on a project that involves manipulating data using a custom programming language. In this language, you are provided with a set of operations to perform various tasks. One of the operations is the "load" operation, which loads a value from a specific memory address and assigns it to a variable. The synt...
codefeedback
You are tasked with implementing a cache eviction algorithm for a key-value store. The cache has a maximum capacity, and when it reaches this capacity, the least recently used item needs to be evicted to make room for new entries. You are given a code snippet that represents part of the eviction logic. Your task is to ...
codefeedback
You are tasked with creating a script to automate the setup of a service on a Linux system. The script should perform several tasks, including creating a system user, obtaining the current directory, and executing a command with backticks. Your goal is to write a Bash script that accomplishes these tasks. Your script ...
codefeedback
You are tasked with implementing a function to find the second smallest element in an array of integers. The function should take an array of integers as input and return the second smallest element. If the array has less than two elements, the function should return None. For example, given the input array [5, 2, 8, ...
codefeedback
You are tasked with creating a script to manage the installation and version checking of a software library. The script should check if the library is already installed, and if so, verify its version. If the library is not installed or is an outdated version, the script should proceed with the installation process. Yo...
codefeedback
You are tasked with implementing a simple event handling system in Python. The system should allow registering event handlers and triggering those handlers when specific events occur. You are provided with a basic EventManager class that manages events and their associated handlers. The class has the following methods...
codefeedback
You are tasked with implementing a program that processes JSON data and performs specific operations on the provided input. Your task is to write a function that takes a JSON string as input and returns the sum of all the integers in the "args" array within the JSON object. You are given the following code snippet as ...
codefeedback
You are tasked with creating a script to automate the build process for a web application using the LittlevGL library. LittlevGL is a graphics library for embedded systems and it provides support for creating graphical user interfaces. The build process involves cloning the LittlevGL repository from GitHub, checking ou...
codefeedback
You are tasked with creating a Python script to clear the Elasticsearch index using the `elasticsearch` library. Your script should connect to the Elasticsearch server, clear the index, and handle any potential errors that may occur during the process. Write a Python function `clear_elasticsearch_index` that takes the...
codefeedback
You are tasked with implementing a neural network architecture using TensorFlow. The network consists of a series of operations including convolution, batch normalization, and activation functions. Your goal is to complete the implementation of the `network` function, which takes input data `X` and target labels `Y`, a...
codefeedback
You are tasked with creating a Python function that interacts with the DeansList API to retrieve specific information. The DeansList API requires a base URL and a dictionary of endpoints to hit. Additionally, the function should utilize base64 encoding and datetime manipulation to handle the authentication and date-rel...
codefeedback
You are tasked with implementing a data filtering algorithm for a specific experiment evaluation system. The system uses a class called `IPETEvaluation` to perform evaluations on experimental data. The `IPETEvaluation` class takes two parameters: `index` and `indexsplit`. Additionally, the code snippet provided instant...
codefeedback
You are tasked with creating a program that compares two files and generates an edit script to transform one file into the other. An edit script is a sequence of edit operations (insert, delete, and replace) that, when applied to the first file, results in the second file. Your program should take three command-line ar...
codefeedback
You are tasked with implementing a custom data validation feature for a PHP web application. The application uses the Laravel framework, and you need to extend the functionality of the existing `UserV2` model. The `UserV2` model represents user data and includes a property `$type` that defines the data types for specif...
codefeedback
You are tasked with implementing a data structure and associated methods for managing batch choices in a game. The game allows players to select characters and boosters in batches. The provided code snippet includes a partial implementation of the `BatchChoices` enum and its associated methods for retrieving characters...
codefeedback
You are working on a medical management system that uses Frappe framework for database operations. Your task is to create a Python function that updates the database based on certain conditions. The database contains two tables: `tabActual` and `tabTreatment Plan`. The function needs to perform the following updates: ...
codefeedback
You are tasked with creating a bash script that will analyze a given GitHub repository's information and output a summary report. The script should take the repository name as a command-line argument and fetch the repository's details using the GitHub API. The summary report should include the repository name, the numb...
codefeedback
You are tasked with creating a Python program to process a file containing lines of comma-separated values representing names and ages. Each line in the file follows the format "name, age". Your program should read the file, extract the name and age from each line, and then print them in the following format: "Nome: [n...
codefeedback
You are tasked with implementing a mobile phone contact management system. The system should allow users to add, delete, and search for contacts, as well as display all contacts in the phonebook. Each contact will have a name and a phone number. Your task is to implement the `Contact` class and the `Phonebook` class to...
codefeedback
You are working on a materials science project and need to process some data from a repository. The repository contains a directory named `dmftmodel` under the organization `correlatedmaterialslaboratory`. Within this directory, there is a script that copies files from another location to a subdirectory named `sigs`. ...
codefeedback
You are tasked with implementing a custom event loop for a GUI application. The event loop should continuously update the GUI and handle the application's termination. You are provided with a code snippet from the event loop implementation, which includes a method call to `custom_update(self)` and a check for the appli...
codefeedback
You are tasked with implementing a Python class that manages the synchronization of files between a local directory and a remote server using the MEGA cloud storage service. The class contains a method `start_sync` that initiates the synchronization process for both the "in" and "out" directions. The method first start...
codefeedback
You are tasked with implementing a service locator using reflection in PHP. The service locator should be able to resolve and instantiate classes based on their dependencies using reflection. You need to create a class `ReflectionServiceLocator` that provides the following functionality: 1. A method `addService` that ...
codefeedback
You are tasked with creating a program to parse and analyze network configuration commands. The configuration commands are provided in the form of a text file, with each line representing a single command. Each command follows a specific format and is used to configure various network interfaces and instances. The con...
codefeedback
You are tasked with creating a Python script that reads a given file and extracts the author's name and contact email from the file's header comments. The header comments are structured as follows: ``` <filename>utils/tools.py #!/usr/bin/env python # -*- coding: utf-8 -*- #---------------------------------------------...
codefeedback
You are tasked with implementing a multi-threaded program to simulate a simple producer-consumer scenario using Java's `Lock` and `Condition` classes. The producer will generate products, and the consumer will purchase them. The producer should not produce more products than a specified limit, and the consumer should n...
codefeedback
You are tasked with implementing a data structure to efficiently store and retrieve key-value pairs. The data structure should support operations such as inserting a key-value pair, retrieving the value associated with a given key, and deleting a key-value pair. Additionally, the data structure should provide an operat...
codefeedback
You are tasked with implementing a K-means clustering algorithm to group a set of data points into K clusters. The algorithm works by iteratively assigning each data point to the nearest cluster and then recalculating the cluster centroids based on the assigned points. The process continues until the cluster assignment...
codefeedback
You are working on a code editor application that needs to handle different programming language syntax highlighting and configuration. The code snippet provided is a part of the backend logic for this application. The `__init__` method initializes the code with a given programming language, and the `get_class_configur...
codefeedback
You are tasked with creating a Python script that generates a visualization of a directed graph using the Graphviz library. The script should take a graph description in the DOT language as input and produce a PNG image as output. The DOT language is a plain text graph description language. The input graph will be prov...
codefeedback
You are working on a project that involves processing and analyzing various image files. You have been tasked with writing a Java program to extract specific information from an image file using the Apache Commons Imaging library. The library provides classes and methods for working with various image formats and extra...
codefeedback
You are tasked with creating a Java program that simulates a data generator for a fictional company. The data generator should produce a set of random data points based on specific criteria and store the generated data in a file. The data points should include information such as customer names, ages, email addresses, ...
codefeedback
You are tasked with implementing a Python class that calculates the surface area of a 3D object. The class should be named `Surface` and should have a method `calculate_area()` that returns the surface area of the given 3D object. The 3D object is represented by the parameter `M`, which is a list of lists representing ...
codefeedback
You are tasked with implementing a function to generate a random key pair for encryption and decryption. The function should utilize a cryptographic library to create a random key pair and a corresponding certificate. Additionally, the function should import the generated key pair into a PFX (Personal Information Excha...
codefeedback
You are tasked with creating a program to monitor the battery capacity of a laptop. The program should read the battery capacity from a file and display a warning message if the battery is not detected. If the battery is detected, the program should calculate the remaining capacity and display it as a percentage. Your...
codefeedback
You are tasked with implementing a function `orderedsandwich` that takes a list of ingredients as input and returns a string representing the ordered sandwich. The function should follow the following rules: - If the list contains only one ingredient, the sandwich should be made with that ingredient and the string "san...
codefeedback