task_id
cargo_test_passed_eval_smol.parquet
comparing changes between versions
rust_prompt
rust_code
rust_test_list
prediction
task_id
rust_prompt
task_19933
Given a vector of strings where each string represents a sequence of opening and closing parentheses, your task is to determine the total score based on the legality of each sequence. Each legal sequence scores 1 point, while each illegal sequence scores 0 points. A sequence is considered legal if every opening parenthesis has a corresponding closing parenthesis in the correct order. Implement a function `calculate_score(data: Vec<String>) -> i32` that takes a vector of strings and returns the total score for all sequences. The function should return the sum of points for all legal sequences in the input vector.
task_19936
You are given a function that takes an iterator producing tuples consisting of user IDs and item IDs. Your task is to implement a function that takes this iterator and returns a vector of user IDs where the second half of the vector is a copy of the first half. This means the output should be a vector of user IDs with the last half being identical to the first half. The input iterator provides the user IDs in a sequence, and you can assume that the iterator will yield a finite number of user IDs. Implement the function `collate_with_neg_fn(iterator)` that returns the modified vector of user IDs.
task_19937
Implement a function `sqrt(x)` that calculates the square root of a given non-negative number. If the input is negative or not a number, the function should return 'Invalid input'. The function should handle float inputs and rounding errors, returning a float result for non-negative inputs. Example inputs include integers and floats. Write the function such that it adheres to the following specifications:
- For input `-1`, the output should be 'Invalid input'.
- For input `4`, the output should be `2.0`.
- For input `14.6`, the output should be approximately `3.8196858509568554`.
- For input `25.0`, the output should be `5.0`.
- For input `1.12`, the output should be approximately `1.0583005244258363`.
- For input `0`, the output should be `0.0`.
- For input `0.3333333333333333`, the output should be approximately `0.5773502691896257`.
task_19938
Implement a function that takes a vector of integers as input and returns a new vector containing the same integers sorted in ascending order using the merge sort algorithm.
task_19939
You are given a string that represents a sequence of characters. Your task is to implement a function that counts the number of vowels (a, e, i, o, u) in the string. The function should ignore case, meaning both uppercase and lowercase vowels should be counted. The input string may contain spaces and punctuation marks, but they should not be counted as vowels. Write a function `count_vowels(s: String) -> i32` that returns the total count of vowels in the given string.
task_19940
You are tasked with implementing a Rust function that processes a list of model configurations and generates a list of results for each model. The function should take in an initial batch size, a list of model configurations, and a set of arguments. Your implementation should iterate through the model configurations, updating the arguments with the model name and checkpoint, and then generate a list of structs, where each struct contains the model name and an empty result. The function signature should be: `fn process_model_configurations(start_batch_size: i32, model_cfgs: Vec<(String, String)>, args: std::collections::HashMap<String, String>) -> Vec<ModelResult>`. The input parameters are as follows: - `start_batch_size` (i32): the initial batch size for processing the models. - `model_cfgs` (Vec<(String, String)>): a vector of tuples, where each tuple contains a model name and its corresponding checkpoint. - `args` (std::collections::HashMap<String, String>): a hash map containing additional arguments for processing the models. The output should be a vector of structs, each containing the model name and an empty result. For example, given `start_batch_size = 32`, `model_cfgs = vec![("resnet".to_string(), "resnet_checkpoint.pth".to_string()), ("vgg".to_string(), "vgg_checkpoint.pth".to_string())]` and `args = [("arg1".to_string(), "value1".to_string()), ("arg2".to_string(), "value2".to_string())].iter().cloned().collect()`, the output should be `vec![ModelResult { model: "resnet".to_string(), result: std::collections::HashMap::new() }, ModelResult { model: "vgg".to_string(), result: std::collections::HashMap::new() }]`.
task_19941
Given a vector of group names and a HashMap that maps group names to their corresponding GIDs, implement a function `get_gid(group_dict: HashMap<String, i32>, groupname: String) -> Result<i32, bool>` that returns the GID of the specified group name. If the group name does not exist in the HashMap, return `Err(false)`. The function should handle case sensitivity when looking up group names.
Example:
- Input: group_dict = vec![("admin", 1), ("user", 2), ("guest", 3)].into_iter().collect(), groupname = "User".to_string()
- Output: Err(false)
- Input: group_dict = vec![("admin", 1), ("user", 2), ("guest", 3)].into_iter().collect(), groupname = "user".to_string()
- Output: Ok(2)
task_19942
You are given a vector of file names and their corresponding URLs. Write a function that takes in this vector and checks if each file can be downloaded successfully. You should simulate the download process. For each file, return a vector of boolean values where `true` indicates the file was 'successfully downloaded' (simulated) and `false` indicates the download failed. The download is considered successful if the URL ends with '.txt', and failed otherwise. The function should have the following signature: `fn check_downloads(files: Vec<(String, String)>) -> Vec<bool>:`.
task_19944
You are given a vector of integers, where each integer represents the number of rows returned by different database queries. Your task is to implement a function `get_total_rowcount(rows: Vec<i32>) -> i32` that returns the total number of rows returned by all the queries. The function should take a vector of integers as input and output a single integer representing the total row count. The input vector may contain zero or more integers. If the vector is empty, return 0. Please note that the integers in the vector can be positive, negative, or zero.
task_19945
Implement a function `fibonacci(n: i32) -> i32` that calculates the Fibonacci number at the Nth term, where N is a non-negative integer. The Fibonacci sequence is defined as follows: Fibonacci(0) = 0, Fibonacci(1) = 1, and Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2) for n >= 2. The function should efficiently compute the Nth Fibonacci number, where N can be as large as 10,000.
task_19946
Given a string with unique characters, write a function that generates all possible permutations of the string. The function should disregard capitalization, meaning that 'A' and 'a' are considered the same character. Return a vector of all distinct permutations in lexicographical order. For example, the input 'Abc' should return vec!["abc", "acb", "bac", "bca", "cab", "cba"].
task_19948
Implement a function `validate_ipv6(ipv6: String) -> bool` that checks if a given string is a valid IPv6 address. The function should correctly handle the full notation as well as shorthand notations for IPv6 addresses. A valid IPv6 address consists of eight groups of four hexadecimal digits, separated by colons. Shorthand notation allows for omitting leading zeros and using '::' to represent one or more groups of zeros. Return true if the input string is a valid IPv6 address; otherwise, return false.
task_19949
You are tasked with creating a function that simulates receiving messages in a chat application. The function should take a vector of messages, each formatted as 'username: message', and return a single string that contains all messages concatenated with a newline character. Your function should ensure that the messages are displayed in the order they were received. Implement the function `receive_messages(messages: Vec<String>) -> String`, where `messages` is a vector of strings representing received chat messages. The function should return a single string with all the messages, each on a new line.
task_19950
You are tasked with implementing a function that verifies if a given command string is a valid list rulesets command. The valid commands are 'lr' and 'listrulesets'. Your function should take a single string input and return true if the command is valid, otherwise return false.
Function Signature: `fn is_valid_ruleset_command(command: String) -> bool:`
### Input
- A single string `command` (1 <= command.len() <= 20) that represents the command to be checked.
### Output
- Return a boolean value: true if the command is valid ('lr' or 'listrulesets'), false otherwise.
task_19952
You are given two strings: `gt_dir` and `result_dir` which represent two directory paths in a filesystem. Your task is to write a function that evaluates whether the `result_dir` contains at least 3 more files than the `gt_dir`. Return `true` if it does, otherwise return `false`. Assume that the number of files in each directory can be determined by counting the number of characters in the string representation of the directory, where each character represents a file. If either directory is empty, consider it to have 0 files. Note that you do not need to access the actual filesystem, just perform the evaluation based on the string lengths.
task_19953
Implement a function `binary_search` that takes a vector of sorted numbers (which may include integers and floating point numbers with up to ten decimal places) and a target number. The function should return the index of the first occurrence of the target in the vector. If the target is not found, return -1. The vector can contain up to 1 million numbers and may include duplicates. Handle edge cases such as an empty vector or a vector with only one element.
task_19954
You are given a vector of integers representing the number of hours worked over a weekend (Saturday and Sunday) by employees. Your task is to implement a function that checks if the total hours worked on the weekend by an employee does not exceed a given threshold. The function should take the following parameters: a vector of integers `hours`, an integer `threshold`, and return `true` if the total hours worked on Saturday and Sunday is less than or equal to the threshold, otherwise return `false`. Assume the input vector will always contain exactly two elements representing hours worked on Saturday and Sunday respectively.
task_19955
Implement a function `is_valid_hex_color(code: String) -> bool` that determines if a given string is a valid hexadecimal color code. A valid hexadecimal color code starts with a '#' followed by exactly six characters, which can be digits (0-9) or letters (A-F or a-f).
task_19956
You are given a vector of strings where each string represents a categorical label. Your task is to implement a function that encodes these categorical labels into numerical values. Each unique label should be assigned a unique integer starting from 0. The function should return a vector of integers corresponding to the encoded labels. For example, if the input vector is vec!["apple", "banana", "apple", "orange"], the output should be vec![0, 1, 0, 2], assuming 'apple' is encoded as 0, 'banana' as 1, and 'orange' as 2. Implement the function `encode_labels(data: Vec<String>) -> Vec<i32>`.
task_19957
Given a vector of integers, write a function `nearest_value_index` that finds the index of the nearest neighbor for a given target value in the vector. If there are multiple nearest neighbors, return the index of the first one found. If the vector is empty, return -1. The function should take a vector of integers and a target integer as input and return an integer representing the index of the nearest neighbor.
Function Signature: `fn nearest_value_index(arr: Vec<i32>, target: i32) -> i32:`
task_19958
Implement a function that swaps the positions of two specified elements in a vector and returns the number of elements that were swapped during the process. The function should be able to handle vectors containing duplicates and should maintain the original order of elements that are not being swapped. The function should have a time complexity of O(n) and space complexity of O(1).
task_19959
You are tasked with creating a function that checks if a given vector of strings contains invalid path names. A valid path name must not be empty, must not consist only of whitespace, and must not contain control characters (ASCII values 0-31 and 127). Implement a function `is_valid_path(paths: Vec<String>) -> Vec<bool>` that takes a vector of strings `paths` and returns a vector of boolean values where each boolean indicates whether the corresponding path in the input vector is valid (`true`) or invalid (`false`).
task_19960
You are tasked with creating a function that formats server information based on the given parameters. The function should take three strings as input: `hostname`, `name`, and `region`. It should return a formatted string in the following format: 'Server <name> with hostname <hostname> is located in region <region>'. Implement a single function `format_server_info(hostname: String, name: String, region: String) -> String` that achieves this.
task_19961
You are given a vector of integers representing the temperatures recorded over a period of time. Your task is to write a function `calculate_average_temperature` that computes the average temperature from the vector. The average should be rounded to two decimal places. If the vector is empty, the function should return 0.0. Implement the function as follows:
```rust
fn calculate_average_temperature(temperatures: Vec<i32>) -> f32 {
pass
}
```
### Input
- A vector of integers, `temperatures`, where 0 <= temperatures.len() <= 1000 and -100 <= temperatures[i] <= 100.
### Output
- A float representing the average temperature rounded to two decimal places or 0.0 if the vector is empty.
task_19962
Write a function `find_perfect_squares(n: i32) -> Vec<i32>` that returns a vector of all perfect squares between 1 and a given integer `n`, inclusive. A perfect square is an integer that is the square of an integer. If `n` is less than 1, the function should return an empty vector.
task_19963
Implement a function `is_happy(s)` that determines if a given string `s` composed exclusively of lowercase alphabets can be classified as 'happy'. A string is defined as 'happy' if it meets the following criteria: it has a minimum length of three characters, every series of three successive characters is unique, each unique character occurs at least twice, there are no consecutive repetitions of the same character, and if the occurrences of any unique character are three or less, then the counts of those occurrences cannot exceed two. For example, `is_happy(String::from("a"))` should return `false`, and `is_happy(String::from("adbbd"))` should return `true`.
task_19964
You are given a vector of integers representing the lengths of various reads. Implement a function `filter_lengths(reads: Vec<i32>, min_length: i32, max_length: i32) -> Vec<i32>` that filters out the lengths of reads that fall within a specified minimum and maximum range (inclusive). The function should return a new vector containing only the lengths that meet the criteria. If no lengths meet the criteria, return an empty vector. Your function should handle the case where the input vector is empty.
task_19965
Write a function that accepts a string of continuous characters containing words, punctuation, and numerical characters. Your task is to generate a HashMap where each distinct word corresponds to a key, and the value is the frequency of its appearance in the string. The function should be case-sensitive, meaning 'Word' and 'word' are treated as different words. Additionally, common punctuation marks should not affect the recognition of a word. Implement this function with optimal performance.
task_19966
Given a vector of strings, write a function `nth_lengthiest_string(strings: Vec<String>, n: i32) -> Option<String>` that returns the nth lengthiest string from the vector. If there are multiple strings of the same length, return the first one that appears in the vector. If the vector contains fewer than n strings, return None.
task_19967
You are given a vector of integers representing the ages of individuals in a group. Your task is to implement a function that determines the average age of the group. The average age should be calculated as the sum of all ages divided by the number of individuals. If the vector is empty, the function should return 0. Write a function `calculate_average_age(ages: Vec<i32>) -> f32` that takes a vector of integers as input and returns the average age as a float.
task_19968
Given two sorted integer vectors, vec1 and vec2, write a function that merges these two vectors into a single sorted vector without using any built-in functions. The merged vector should maintain the sorted order of the elements from both input vectors. The function should be defined as merge_arrays(vec1, vec2).
task_19970
You are given a string representing a module path and a boolean flag indicating whether to perform a dry run. Your task is to implement a function `load_and_run(module: String, dry_run: bool) -> String` that simulates loading a module by returning a message. If `dry_run` is `true`, the function should return 'Dry run: Ready to load module {module}'. If `dry_run` is `false`, the function should return 'Module {module} loaded successfully.'.
Make sure to use `String` for string manipulation in Rust.
task_19971
You are given a vector of tuples, where each tuple consists of a name (a string), an integer value, and a function that returns a HashMap when called. Your task is to create a function `get_configuration` that takes this vector of tuples as input and returns a HashMap. The HashMap should have names as keys and the values should be the result of calling their corresponding functions. Implement the function `get_configuration(triples: Vec<(String, i32, fn() -> HashMap<String, String>)>) -> HashMap<String, HashMap<String, String>>`.
task_19972
You are given a vector of hash maps representing records of entries in a database. Each hash map contains three keys: "pdbid", "cdr", and "entry". Write a function `get_total_entries(entries: Vec<HashMap<String, String>>, pdbid: String, cdr: String) -> i32` that returns the total number of entries that match the provided `pdbid` and `cdr`. The input vector `entries` can contain multiple hash maps, and your function should count how many of these hash maps have the specified `pdbid` and `cdr`.
task_19974
You are tasked with creating a Rust function that simulates a cooldown mechanism for a given function. The function should take two parameters: the cooldown duration (in seconds) and the bucket type (a string). If the function is called before the cooldown period has elapsed, it should return a `CooldownError` with the remaining time until the cooldown expires. If the cooldown period has elapsed, the function should execute and update the cooldown timestamp. Implement the `cooldown_function` which simulates this behavior, along with the `CooldownError` struct. The `cooldown_function` should not be an async function and should not use any attributes. Example usage: `cooldown_function(5, "user".to_string())` should enforce a 5-second cooldown for the respective bucket type.
task_19975
You are tasked with implementing a function that manages a collection of camera serial numbers. Your function should take a vector of serial numbers and a specific serial number to remove from the collection. If the serial number exists in the collection, it should be removed; if it does not exist, the collection remains unchanged. The function should return the updated vector of serial numbers. Implement the function `remove_camera_serials(serials: Vec<String>, serial_to_remove: String) -> Vec<String>` where `serials` is a vector of unique camera serial numbers and `serial_to_remove` is the serial number to be removed.
task_19976
Implement a function `shell_sort` that takes an unsorted vector of integers as input and returns the vector sorted in ascending order using the shell sort algorithm. Shell sort is a highly efficient sorting algorithm that is a variation of insertion sort. The algorithm starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared and swapped. The process is repeated until the gap becomes 1, at which point the algorithm behaves like insertion sort.
Example:
Given the input vector:
`vec![3, 2, 1, 0, 7, 11, 56, 23]`
The function should return:
`vec![0, 1, 2, 3, 7, 11, 23, 56]`
task_19977
You are tasked with implementing a function that processes a vector of hash maps and returns a new vector containing modified hash maps. Each hash map in the input vector represents an entry in a database, with keys representing column names and values representing the corresponding data. The function should add a new key-value pair to each hash map, where the key is "processed" and the value is set to true. If the "status" key in the hash map has a value of "active", the function should also add a key-value pair where the key is "priority" and the value is set to "high". If the "status" key has a value of "inactive", the function should add a key-value pair where the key is "priority" and the value is set to "low". Your task is to implement the function `process_entries(entries)` which takes a vector of hash maps as input and returns a new vector containing the modified hash maps according to the rules specified above.
task_19978
Create a Rust function that accepts a vector of strings and returns a HashMap containing the frequency of each distinct character from each string. Additionally, for each string, the HashMap should include the character with the highest frequency. In case of a tie for the highest frequency character, resolve it by choosing the character that comes first alphabetically. Your HashMap should return results in descending order based on the frequency of characters. Implement the function `frequency_counter(strings)` where `strings` is the input vector of strings.
task_19979
You are tasked with implementing a custom text formatter function in Rust. Your text formatter should be able to format text by replacing specific placeholders with corresponding values. The placeholders will be enclosed in curly braces and will consist of alphanumeric characters and underscores only. For example, `{name}` could be a placeholder that needs to be replaced with the actual name. Your task is to implement a function `format_text(mappings, text)` which takes in a hash map `mappings` that maps placeholder keys to their corresponding values, and a string `text` as input. The function should replace all occurrences of placeholders in the text with their corresponding values. If a placeholder does not have a mapping, it should remain unchanged in the formatted text. The function should return an `Err` if the text contains a placeholder that does not have a mapping. Additionally, your function should handle nested placeholders, meaning if the text is `Hello {title_{gender}} {name}` and the mappings are `{title_Mr: 'Mr.', title_Ms: 'Ms.', name: 'Smith', gender: 'Ms'}`, the formatted text should be `Hello Ms. Smith`. You can assume that the input text and the mappings will only contain ASCII characters.
task_19980
You are given a vector of transaction names and a hashmap containing various data, including the 'strand' key, which is a vector of strings representing the strands of these transactions. Your task is to implement a function that checks if all the strands in the given data are the same. If they are the same, return true; otherwise, return false. If there are no strands present in the data, return false. Implement the function `verify_same_strand(tx_names: Vec<String>, data: HashMap<String, Vec<String>>) -> bool` where `tx_names` is a vector of transaction names and `data` is a hashmap containing a key 'strand' mapping to a vector of strings representing the strands.
task_19982
You are given a 2D vector representing a grayscale image, where each element is an integer between 0 and 255, representing the pixel intensity. Your task is to convert this 2D vector into a 1D vector (flatten the image) while preserving the order of pixels from left to right and top to bottom. Implement a function `flatten_image(image: Vec<Vec<i32>>) -> Vec<i32>` that takes the 2D vector as input and returns the flattened 1D vector. The input image will always be non-empty and will contain only integers in the specified range.
task_19983
Given a multi-layered map, implement a function `extract_super_nested_values(d: std::collections::HashMap<String, Box<dyn std::any::Any>>) -> Vec<i32>` that extracts all values associated with the key 'super_nested_key'. The function should return a vector of all values found for this key, including duplicates. If no such key exists, return an empty vector.
task_19984
You are tasked with implementing a message processing function for a BitTorrent protocol handler. Your function will take in three parameters: `message`, `t`, and `noisy`. The function should handle different types of messages based on the value of `t`. The specific behavior of the function is as follows:
1. If `t` equals `UTORRENT_MSG`, and `noisy` is `true`, log the message and return a string indicating that a uTorrent message was processed along with the decoded message.
2. If `t` equals `AZUREUS_MSG`, and the handler supports Azureus extension (assume this is indicated by a global variable `USES_AZUREUS_EXTENSION`), log the message if `noisy` is `true`, and return a string indicating that an Azureus message was processed along with the decoded message.
3. If `t` equals `HOLE_PUNCH`, and the handler supports NAT traversal (assume this is indicated by a global variable `USES_NAT_TRAVERSAL`), log the message if `noisy` is `true`, and return a string indicating that a NAT traversal message was processed along with the decoded message.
The function should decode messages as needed, and if `noisy` is `false`, it should not log any messages. You can assume the existence of helper functions `bdecode` and `ebdecode` for decoding the messages appropriately. Your implementation should return a string describing the processed message for each case.
Implement the function with the following signature:
```rust
fn process_bittorrent_message(message: String, t: i32, noisy: bool) -> String {
```
task_19986
Define a struct `CombinedClass` that implements two traits: `BaseTrait1` and `BaseTrait2`. The `CombinedClass` should have a method `get_messages` that returns a vector containing messages from both traits. The `BaseTrait1` should have a method `message1` that returns "Hello from BaseTrait1" and `BaseTrait2` should have a method `message2` that returns "Hello from BaseTrait2". Implement the `CombinedClass` and the method `get_messages` accordingly.
task_19987
You are tasked with creating a function that takes a string representation of a model definition and checks whether the definition is valid. The model definition consists of a line containing the class name followed by a series of parameters. You need to implement a function `is_valid_model_definition(model_str: String) -> bool` that returns `true` if the model definition is valid and `false` otherwise. A valid model definition should start with a class name followed by at least three integer parameters, and the rest can be any string or integer. For example, the string 'First 34 45 65 "sdf" 45' is valid because it has a class name 'First', followed by three integers (34, 45, 65) and two additional parameters of different types. If the string does not follow this pattern, the function should return `false`.
task_19988
You are tasked with calculating the average loss for a vector of loss values that are grouped into multiple parts. Write a function `calculate_average_loss(loss_list: Vec<Vec<f32>>) -> Vec<f32>` that takes a vector of vectors, where each inner vector represents a part of losses. The function should return a vector of average losses corresponding to each part. If a part has no values, its average loss should be considered as 0.0. For example, given `[[1.0, 2.0], [3.0], []]`, the output should be `[1.5, 3.0, 0.0]`.
task_19989
You are tasked with validating authentication details for an appliance configuration. You will implement a function named `validate_auth` that takes four parameters: `profile`, `endpoint`, `access_token`, and `serial_id`. The function should validate the authentication details based on the following criteria:
1. The `profile` must be a non-empty string.
2. The `endpoint` must be a non-empty string that starts with 'http://' or 'https://'.
3. The `access_token` must be a non-empty string.
4. The `serial_id` must be a non-empty string consisting of digits only.
The function should return `true` if all the criteria are met, otherwise it should return `false`.
task_19990
You are tasked with validating a list of URL paths to determine whether each path is valid or not. A valid URL path is defined as a string that matches a specific format: it must start with a forward slash ('/') and can contain alphanumeric characters, hyphens ('-'), underscores ('_'), and forward slashes. Write a function `is_valid_path(path: String) -> bool` that takes a single string input representing a URL path and returns `true` if the path is valid according to the aforementioned criteria, and `false` otherwise.
task_19991
Implement a function `check_key_value(map: std::collections::HashMap<String, Vec<i32>>, key: Option<String>) -> bool` that checks if a given key exists in a map and if its corresponding value is a non-empty vector. The function should return `true` if the key exists and its value is a non-empty vector; otherwise, it should return `false`. The function should also handle edge cases, such as if the key is `None` or if the value is `None`.
Select a cell to see row details