task_id stringlengths 4 14 | prompt stringlengths 112 1.41k | canonical_solution stringlengths 17 2.16k | test stringlengths 148 2.54k | declaration stringlengths 22 1.2k | example_test stringlengths 0 679 | buggy_solution stringlengths 13 2.16k | bug_type stringclasses 6
values | failure_symptoms stringclasses 3
values | entry_point stringlengths 1 30 | signature stringlengths 14 76 | docstring stringlengths 23 1.21k | instruction stringlengths 103 1.32k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Rust/101 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You will be given a string of words separated by commas or spaces. Your task is
to split the string into ... |
return s
.to_string()
.split(|c: char| c == ',' || c.is_whitespace())
.into_iter()
.filter(|x| x != &"")
.map(|x| x.to_string())
.collect();
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_words_string() {
assert!(words_string("Hi, my name is John") == vec!["Hi", "my", "name", "is", "John"]);
assert!(
words_string("One, two, three, four, five, six")
== vec!["One", "two", "three", "four", "five... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn words_string(s:&str) -> Vec<String> {
| None |
return s
.to_string()
.split(|c: char| c == '.' || c.is_whitespace())
.into_iter()
.filter(|x| x != &"")
.map(|x| x.to_string())
.collect();
}
| value misuse | incorrect output | words_string | words_string(s:&str) -> Vec<String> | You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words. | Write a Rust function `words_string(s:&str) -> Vec<String>` to solve the following problem:
You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words. |
Rust/102 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
This function takes two positive numbers x and y and returns the
biggest even integer number that is in the ra... |
if y < x {
return -1;
}
if y == x && y % 2 == 1 {
return -1;
}
if y % 2 == 1 {
return y - 1;
}
return y;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_choose_num() {
assert!(choose_num(12, 15) == 14);
assert!(choose_num(13, 12) == -1);
assert!(choose_num(33, 12354) == 12354);
assert!(choose_num(6, 29) == 28);
assert!(choose_num(27, 10) == -1);
assert!(... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn choose_num(x:i32, y:i32) -> i32{
| None |
if y < x {
return -1;
}
if y == x && y % 2 == 1 {
return -1;
}
if y % 2 == 1 {
return x - 1;
}
return y;
}
| variable misuse | incorrect output | choose_num | choose_num(x:i32, y:i32) -> i32 | This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1. | Write a Rust function `choose_num(x:i32, y:i32) -> i32` to solve the following problem:
This function takes two positive numbers x and y and returns the
biggest even integer number that is in the range [x, y] inclusive. If
there's no such number, then the function should return -1. |
Rust/103 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given two positive integers n and m, and your task is to compute the
average of the integers from n th... |
if n > m {
return "-1".to_string();
};
let mut num: i32 = (m + n) / 2;
let mut out: String = String::from("");
while num > 0 {
out = (num % 2).to_string() + &out;
num = num / 2;
}
return out;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_rounded_avg() {
assert!(rounded_avg(1, 5) == "11");
assert!(rounded_avg(7, 13) == "1010");
assert!(rounded_avg(964, 977) == "1111001010");
assert!(rounded_avg(996, 997) == "1111100100");
assert!(rounded_avg(560,... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn rounded_avg(n:i32, m:i32) -> String{
| None |
if n > m {
return "-1".to_string();
};
let mut num: i32 = (m + n + 1) / 2;
let mut out: String = String::from("");
while num > 0 {
out = (num % 2).to_string() + &out;
num = num / 2;
}
return out;
}
| value misuse | incorrect output | rounded_avg | rounded_avg(n:i32, m:i32) -> String | You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than m, return -1. | Write a Rust function `rounded_avg(n:i32, m:i32) -> String` to solve the following problem:
You are given two positive integers n and m, and your task is to compute the
average of the integers from n through m (including n and m).
Round the answer to the nearest integer and convert that to binary.
If n is greater than ... |
Rust/104 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
No... |
let mut res: Vec<i32> = vec![];
for (_, elem) in x.into_iter().enumerate() {
let mut elem_cp: i32 = elem;
let mut u: bool = true;
if elem == 0 {
u = false;
}
while elem_cp > 0 && u {
if elem_cp % 2 == 0 {
u = false;
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_unique_digits() {
assert!(unique_digits(vec![15, 33, 1422, 1]) == vec![1, 15, 33]);
assert!(unique_digits(vec![152, 323, 1422, 10]) == vec![]);
assert!(unique_digits(vec![12345, 2033, 111, 151]) == vec![111, 151]);
asse... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn unique_digits(x:Vec<i32>) -> Vec<i32>{
| None |
let mut res: Vec<i32> = vec![];
for (i, elem) in x.into_iter().enumerate() {
let mut elem_cp: i32 = elem;
let mut u: bool = true;
if elem == 0 {
u = false;
}
while elem_cp > 0 && u {
if elem_cp % 2 == 0 {
u = false;
}
... | excess logic | incorrect output | unique_digits | unique_digits(x:Vec<i32>) -> Vec<i32> | Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order. | Write a Rust function `unique_digits(x:Vec<i32>) -> Vec<i32>` to solve the following problem:
Given a list of positive integers x. return a sorted list of all
elements that hasn't any even digit.
Note: Returned list should be sorted in increasing order. |
Rust/105 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting a... |
let mut res: Vec<String> = vec![];
let mut arr_cp: Vec<i32> = arr.clone();
arr_cp.sort();
arr_cp.reverse();
let map: HashMap<i32, &str> = HashMap::from([
(0, "Zero"),
(1, "One"),
(2, "Two"),
(3, "Three"),
(4, "Four"),
(5, "Five"),
(6, "Six"),
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_by_length() {
assert!(
by_length(vec![2, 1, 1, 4, 5, 8, 2, 3])
== vec!["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"]
);
let v_empty: Vec<String> = vec![];
assert!(by_length(ve... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn by_length(arr:Vec<i32>) -> Vec<String>{
| None |
let mut res: Vec<String> = vec![];
let mut arr_cp: Vec<i32> = arr.clone();
arr_cp.sort();
let map: HashMap<i32, &str> = HashMap::from([
(0, "Zero"),
(1, "One"),
(2, "Two"),
(3, "Three"),
(4, "Four"),
(5, "Five"),
(6, "Six"),
(7, "Seven"),
... | missing logic | incorrect output | by_length | by_length(arr:Vec<i32>) -> Vec<String> | Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine". | Write a Rust function `by_length(arr:Vec<i32>) -> Vec<String>` to solve the following problem:
Given an array of integers, sort the integers that are between 1 and 9 inclusive,
reverse the resulting array, and then replace each digit by its corresponding name from
"One", "Two", "Three", "Four", "Five", "Six", "Seven", ... |
Rust/106 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of th... |
let mut sum: i32 = 0;
let mut prod: i32 = 1;
let mut out: Vec<i32> = vec![];
for i in 1..n + 1 {
sum += i;
prod *= i;
if i % 2 == 0 {
out.push(prod);
} else {
out.push(sum)
};
}
return out;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_f() {
assert!(f(5) == vec![1, 2, 6, 24, 15]);
assert!(f(7) == vec![1, 2, 6, 24, 15, 720, 28]);
assert!(f(1) == vec![1]);
assert!(f(3) == vec![1, 2, 6]);
}
}
|
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn f(n:i32) -> Vec<i32>{
| None |
let mut sum: i32 = 0;
let mut prod: i32 = 1;
let mut out: Vec<i32> = vec![];
for i in 1..n + 1 {
sum += i;
prod *= sum;
if i % 2 == 0 {
out.push(prod);
} else {
out.push(sum)
};
}
return out;
}
| variable misuse | incorrect output | f | f(n:i32) -> Vec<i32> | Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i). | Write a Rust function `f(n:i32) -> Vec<i32>` to solve the following problem:
Implement the function f that takes n as a parameter,
and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even
or the sum of numbers from 1 to i otherwise.
i starts from 1.
the factorial of... |
Rust/107 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that f... |
let mut even = 0;
let mut odd = 0;
for i in 1..n + 1 {
let mut w: String = i.to_string();
let mut p: String = w.chars().rev().collect();
if w == p && i % 2 == 1 {
odd += 1;
}
if w == p && i % 2 == 0 {
even += 1;
}
}
(even, od... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_even_odd_palindrome() {
assert!(even_odd_palindrome(123) == (8, 13));
assert!(even_odd_palindrome(12) == (4, 6));
assert!(even_odd_palindrome(3) == (1, 2));
assert!(even_odd_palindrome(63) == (6, 8));
assert!(ev... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn even_odd_palindrome(n: i32) -> (i32, i32) {
| None |
let mut even = 0;
let mut odd = 0;
for i in 1..n {
let mut w: String = i.to_string();
let mut p: String = w.chars().rev().collect();
if w == p && i % 2 == 1 {
odd += 1;
}
if w == p && i % 2 == 0 {
even += 1;
}
}
(even, odd)
}... | value misuse | incorrect output | even_odd_palindrome | even_odd_palindrome(n: i32) -> (i32, i32) | Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
Note:
1. 1 <= n <= 10^3
2. returned tuple has the number of even and odd integer palindromes respectively. | Write a Rust function `even_odd_palindrome(n: i32) -> (i32, i32)` to solve the following problem:
Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
Note:
1. 1 <= n <= 10^3
2. returned tuple has the number of even and odd integ... |
Rust/108 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Write a function count_nums which takes an array of integers and returns
the number of elements which has... |
let mut num: i32 = 0;
for nmbr in n {
if nmbr > 0 {
num += 1;
} else {
let mut sum: i32 = 0;
let mut w: i32;
w = i32::abs(nmbr);
while w >= 10 {
sum += w % 10;
w = w / 10;
}
sum... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_count_nums() {
assert!(count_nums(vec![]) == 0);
assert!(count_nums(vec![-1, -2, 0]) == 0);
assert!(count_nums(vec![1, 1, 2, -2, 3, 4, 5]) == 6);
assert!(count_nums(vec![1, 6, 9, -6, 0, 1, 5]) == 5);
assert!(cou... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn count_nums(n:Vec<i32>) -> i32{
| None |
let mut num: i32 = 0;
for nmbr in n {
if nmbr > 0 {
num += 1;
} else {
let mut sum: i32 = 0;
let mut w: i32;
w = i32::abs(nmbr);
while w >= 10 {
sum += (w % 10) * -1;
w = w / 10;
}
... | excess logic | incorrect output | count_nums | count_nums(n:Vec<i32>) -> i32 | Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, and 3. | Write a Rust function `count_nums(n:Vec<i32>) -> i32` to solve the following problem:
Write a function count_nums which takes an array of integers and returns
the number of elements which has a sum of digits > 0.
If a number is negative, then its first signed digit will be negative:
e.g. -123 has signed digits -1, 2, a... |
Rust/109 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ord... |
let mut num = 0;
if arr.len() == 0 {
return true;
}
for i in 1..arr.len() {
if arr[i] < arr[i - 1] {
num += 1;
}
}
if arr[arr.len() - 1] > arr[0] {
num += 1;
}
if num < 2 {
return true;
}
return false;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_move_one_ball() {
assert!(move_one_ball(vec![3, 4, 5, 1, 2]) == true);
assert!(move_one_ball(vec![3, 5, 10, 1, 2]) == true);
assert!(move_one_ball(vec![4, 3, 1, 2]) == false);
assert!(move_one_ball(vec![3, 5, 4, 1, 2]) ... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn move_one_ball(arr:Vec<i32>) -> bool{
| None |
let mut num = 0;
if arr.len() == 0 {
return true;
}
for i in 1..arr.len() {
if arr[i] < arr[num - 1] {
num += 1;
}
}
if arr[num - 1] > arr[0] {
num += 1;
}
if num < 2 {
return true;
}
return false;
}
| variable misuse | incorrect output | move_one_ball | move_one_ball(arr:Vec<i32>) -> bool | We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the following operation on the given array:
You are allowed to perform right shift operation any nu... | Write a Rust function `move_one_ball(arr:Vec<i32>) -> bool` to solve the following problem:
We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The
numbers in the array will be randomly ordered. Your task is to determine if
it is possible to get an array sorted in non-decreasing order by performing
the fol... |
Rust/110 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is p... |
let mut num = 0;
for i in 0..lst1.len() {
if lst1[i] % 2 == 0 {
num += 1;
}
}
for i in 0..lst2.len() {
if lst2[i] % 2 == 0 {
num += 1;
}
}
if num >= lst1.len() {
return "YES".to_string();
}
return "NO".to_string();
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_exchange() {
assert!(exchange(vec![1, 2, 3, 4], vec![1, 2, 3, 4]) == "YES");
assert!(exchange(vec![1, 2, 3, 4], vec![1, 5, 3, 4]) == "NO");
assert!(exchange(vec![1, 2, 3, 4], vec![2, 1, 4, 3]) == "YES");
assert!(exchang... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn exchange(lst1:Vec<i32>, lst2:Vec<i32>) -> String{
| None |
let mut num = 0;
for i in 0..lst1.len() {
if lst1[i] % 2 == 0 {
num += 1;
}
}
for i in 0..lst2.len() {
if lst2[i] % 2 == 0 {
num -= 1;
}
}
if num >= lst1.len() {
return "YES".to_string();
}
return "NO".to_string();
}
| variable misuse | incorrect output | exchange | exchange(lst1:Vec<i32>, lst2:Vec<i32>) -> String | In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There is no limit on the number of exchanged elements between lst1 and lst2.
If it is possible to exchange eleme... | Write a Rust function `exchange(lst1:Vec<i32>, lst2:Vec<i32>) -> String` to solve the following problem:
In this problem, you will implement a function that takes two lists of numbers,
and determines whether it is possible to perform an exchange of elements
between them to make lst1 a list of only even numbers.
There i... |
Rust/111 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the mo... |
let mut res: HashMap<char, i32> = HashMap::new();
if test == "" {
return res;
}
for c in test.split_ascii_whitespace() {
if res.contains_key(&c.chars().next().unwrap()) {
res.entry(c.chars().next().unwrap()).and_modify(|n| {
*n += 1;
});
}... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_histogram() {
assert!(histogram("a b b a") == HashMap::from([('a', 2), ('b', 2)]));
assert!(histogram("a b c a b") == HashMap::from([('a', 2), ('b', 2)]));
assert!(
histogram("a b c d g")
== HashMap:... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn histogram(test:&str) -> HashMap<char, i32>{
| None |
let mut res: HashMap<char, i32> = HashMap::new();
if test == "" {
return res;
}
for c in test.split_ascii_whitespace() {
if res.contains_key(&c.chars().next().unwrap()) {
res.entry(c.chars().next().unwrap()).and_modify(|n| {
*n += 2;
});
}... | value misuse | incorrect output | histogram | histogram(test:&str) -> HashMap<char, i32> | Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them. | Write a Rust function `histogram(test:&str) -> HashMap<char, i32>` to solve the following problem:
Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all o... |
Rust/112 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any chara... |
let mut n = String::new();
for i in 0..s.len() {
if !c.contains(s.chars().nth(i).unwrap()) {
n.push(s.chars().nth(i).unwrap());
}
}
if n.len() == 0 {
return vec![n, "True".to_string()];
}
let w: String = n.chars().rev().collect();
if w == n {
retu... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_reverse_delete() {
assert!(reverse_delete("abcde", "ae") == ["bcd", "False"]);
assert!(reverse_delete("abcdef", "b") == ["acdef", "False"]);
assert!(reverse_delete("abcdedcba", "ab") == ["cdedc", "True"]);
assert!(rever... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn reverse_delete(s:&str, c:&str) -> Vec<String> {
| None |
let mut n = String::new();
for i in 0..s.len() {
if !c.contains(s.chars().nth(i).unwrap()) {
n.push(s.chars().nth(i).unwrap());
}
}
if n.len() != 0 {
return vec![n, "True".to_string()];
}
let w: String = n.chars().rev().collect();
if w == n {
retu... | operator misuse | incorrect output | reverse_delete | reverse_delete(s:&str, c:&str) -> Vec<String> | Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same backward as forward.
You should return a tuple containing the result string and True/False for the che... | Write a Rust function `reverse_delete(s:&str, c:&str) -> Vec<String>` to solve the following problem:
Task
We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
then check if the result string is palindrome.
A string is called palindrome if it reads the same ... |
Rust/113 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a list of strings, where each string consists of only digits, return a list.
Each element i of the outpu... |
let mut out: Vec<String> = Vec::new();
for i in 0..lst.len() {
let mut sum = 0;
for j in 0..lst[i].len() {
if lst[i].chars().nth(j).unwrap() >= '0'
&& lst[i].chars().nth(j).unwrap() <= '9'
&& lst[i].chars().nth(j).unwrap().to_digit(10).unwrap() % 2 ==... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_odd_count() {
assert!(
odd_count(vec!["1234567"])
== ["the number of odd elements 4n the str4ng 4 of the 4nput."]
);
assert!(
odd_count(vec!["3", "11111111"])
== [
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn odd_count(lst:Vec<&str>) -> Vec<String>{
| None |
let mut out: Vec<String> = Vec::new();
for i in 0..lst.len() {
let mut sum = 0;
for j in 0..lst[i].len() {
if lst[i].chars().nth(j).unwrap() >= '0'
&& lst[i].chars().nth(j).unwrap() <= '9'
&& lst[i].chars().nth(j).unwrap().to_digit(10).unwrap() % 2 ==... | excess logic | incorrect output | odd_count | odd_count(lst:Vec<&str>) -> Vec<String> | Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the number
of odd digits in the i'th string of the input. | Write a Rust function `odd_count(lst:Vec<&str>) -> Vec<String>` to solve the following problem:
Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the... |
Rust/114 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums.
*/
fn min_... |
let mut current = nums[0];
let mut min = nums[0];
for i in 1..nums.len() {
if current < 0 {
current = current + nums[i];
} else {
current = nums[i];
}
if current < min {
min = current;
}
}
min
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_min_sub_array_sum() {
assert!(min_sub_array_sum(vec![2, 3, 4, 1, 2, 4]) == 1);
assert!(min_sub_array_sum(vec![-1, -2, -3]) == -6);
assert!(min_sub_array_sum(vec![-1, -2, -3, 2, -10]) == -14);
assert!(min_sub_array_sum(v... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn min_sub_array_sum(nums: Vec<i64>) -> i64 {
| None |
let mut current = nums[0];
let mut min = *nums.iter().max().unwrap();
for i in 1..nums.len() {
if current < 0 {
current = current + nums[i];
} else {
current = nums[i];
}
if current < min {
min = current;
}
}
min
}
| function misuse | incorrect output | min_sub_array_sum | min_sub_array_sum(nums: Vec<i64>) -> i64 | Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums. | Write a Rust function `min_sub_array_sum(nums: Vec<i64>) -> i64` to solve the following problem:
Given an array of integers nums, find the minimum sum of any non-empty sub-array
of nums. |
Rust/115 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represen... |
let mut out: i32 = 0;
for i in 0..grid.len() {
let mut sum: i32 = 0;
for j in 0..grid[i].len() {
sum += grid[i][j];
}
if sum > 0 {
out += (sum - 1) / capacity + 1;
}
}
return out;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_max_fill() {
assert!(
max_fill(
vec![vec![0, 0, 1, 0], vec![0, 1, 0, 0], vec![1, 1, 1, 1]],
1
) == 6
);
assert!(
max_fill(
vec![
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn max_fill(grid:Vec<Vec<i32>>, capacity:i32) -> i32{
| None |
let mut out: i32 = 0;
for i in 0..grid.len() {
let mut sum: i32 = 0;
for j in 0..grid[i].len() {
sum += grid[i][j];
}
if sum > 0 {
out += (sum - 1) / capacity;
}
}
return out;
}
| function misuse | incorrect output | max_fill | max_fill(grid:Vec<Vec<i32>>, capacity:i32) -> i32 | You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
and all buckets have the same capacity.
Your task is to use the buckets to empty the wells.
Output the numb... | Write a Rust function `max_fill(grid:Vec<Vec<i32>>, capacity:i32) -> i32` to solve the following problem:
You are given a rectangular grid of wells. Each row represents a single well,
and each 1 in a row represents a single unit of water.
Each well has a corresponding bucket that can be used to extract water from it,
a... |
Rust/116 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
In this Kata, you have to sort an array of non-negative integers according to
number of ones in their bin... |
let mut arr_cp = arr.clone();
let mut bin = vec![];
let mut m;
for i in 0..arr_cp.len() {
let mut b = 0;
let mut n = arr_cp[i].abs();
while n > 0 {
b += n % 2;
n = n / 2;
}
bin.push(b);
}
for i in 0..arr_cp.len() {
for j i... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sort_array_1() {
assert!(sort_array_1(vec![1, 5, 2, 3, 4]) == vec![1, 2, 4, 3, 5]);
assert!(sort_array_1(vec![-2, -3, -4, -5, -6]) == vec![-4, -2, -6, -5, -3]);
assert!(sort_array_1(vec![1, 0, 2, 3, 4]) == vec![0, 1, 2, 4, 3]);... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn sort_array_1(arr:Vec<i32>) -> Vec<i32>{
| None |
let mut arr_cp = arr.clone();
let mut bin = vec![];
let mut m;
for i in 0..arr_cp.len() {
let mut b = 0;
let mut n = arr_cp[i].abs();
while n > 0 {
b += n % 2;
n = n / 2;
}
bin.push(b);
}
for i in 0..arr_cp.len() {
for j i... | variable misuse | incorrect output | sort_array | sort_array_1(arr:Vec<i32>) -> Vec<i32> | In this Kata, you have to sort an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value. | Write a Rust function `sort_array_1(arr:Vec<i32>) -> Vec<i32>` to solve the following problem:
In this Kata, you have to sort an array of non-negative integers according to
number of ones in their binary representation in ascending order.
For similar number of ones, sort based on decimal value. |
Rust/117 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of ... |
let vowels = "aeiouAEIOU";
let mut current = String::new();
let mut out = Vec::new();
let mut numc = 0;
let mut s = s.to_string();
s.push(' ');
for i in 0..s.len() {
if s.chars().nth(i).unwrap() == ' ' {
if numc == n {
out.push(current);
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_select_words() {
assert_eq!(select_words("Mary had a little lamb", 4), vec!["little"]);
assert_eq!(
select_words("Mary had a little lamb", 3),
vec!["Mary", "lamb"]
);
let v_empty: Vec<&str> = vec... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn select_words(s:&str, n:i32) -> Vec<String>{
| None |
let vowels = "aeiouAEIOU";
let mut current = String::new();
let mut out = Vec::new();
let mut numc = 0;
let mut s = s.to_string();
s.push(' ');
for i in 0..s.len() {
if s.chars().nth(i).unwrap() == ' ' {
if numc == n {
out.push(current);
}
... | operator misuse | incorrect output | select_words | select_words(s:&str, n:i32) -> Vec<String> | Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the string s is empty then the function should return an empty list.
Note: you may assume the input stri... | Write a Rust function `select_words(s:&str, n:i32) -> Vec<String>` to solve the following problem:
Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words appear in the string s.
If the s... |
Rust/118 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a word. Your task is to find the closest vowel that stands between
two consonants from the righ... |
let vowels = "AEIOUaeiou";
let mut out = "".to_string();
for i in (1..word.len() - 1).rev() {
if vowels.contains(word.chars().nth(i).unwrap()) {
if !vowels.contains(word.chars().nth(i + 1).unwrap()) {
if !vowels.contains(word.chars().nth(i - 1).unwrap()) {
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_closest_vowel() {
assert_eq!(get_closest_vowel("yogurt"), "u");
assert_eq!(get_closest_vowel("full"), "u");
assert_eq!(get_closest_vowel("easy"), "");
assert_eq!(get_closest_vowel("eAsy"), "");
assert_eq!(ge... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn get_closest_vowel(word: &str) -> String {
| None |
let vowels = "AEIOUaeiou";
let mut out = " ".to_string();
for i in (1..word.len() - 1).rev() {
if vowels.contains(word.chars().nth(i).unwrap()) {
if !vowels.contains(word.chars().nth(i + 1).unwrap()) {
if !vowels.contains(word.chars().nth(i - 1).unwrap()) {
... | excess logic | incorrect output | get_closest_vowel | get_closest_vowel(word: &str) -> String | You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you didn't
find any vowel met the above condition.
You may assume that the given string contains Engl... | Write a Rust function `get_closest_vowel(word: &str) -> String` to solve the following problem:
You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you d... |
Rust/119 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')... |
let l1 = lst[0].to_string() + lst[1];
let mut count = 0;
let mut can = true;
for i in 0..l1.len() {
if l1.chars().nth(i).unwrap() == '(' {
count += 1;
}
if l1.chars().nth(i).unwrap() == ')' {
count -= 1;
}
if count < 0 {
can = ... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_match_parens() {
assert_eq!(match_parens(vec!["()(", ")"]), "Yes");
assert_eq!(match_parens(vec![")", ")"]), "No");
assert_eq!(match_parens(vec!["(()(())", "())())"],), "No");
assert_eq!(match_parens(vec![")())", "(()()... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn match_parens(lst: Vec<&str>) -> &str {
| None |
let l1 = lst[0].to_string() + lst[1];
let mut count = 0;
let mut can = true;
for i in 0..l1.len() {
if l1.chars().nth(i).unwrap() == '(' {
count += 1;
}
if l1.chars().nth(i).unwrap() == ')' {
count -= 1;
}
if count < 0 {
can = ... | value misuse | incorrect output | match_parens | match_parens(lst: Vec<&str>) -> &str | You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string will be good.
A string S is considered to be good if and only if all parentheses in S
are balanc... | Write a Rust function `match_parens(lst: Vec<&str>) -> &str` to solve the following problem:
You are given a list of two strings, both strings consist of open
parentheses '(' or close parentheses ')' only.
Your job is to check if it is possible to concatenate the two strings in
some order, that the resulting string wil... |
Rust/120 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maxim... |
let mut arr = arr;
arr.sort();
let mut arr_res: Vec<i32> = arr.iter().rev().take(k as usize).cloned().collect();
arr_res.sort();
return arr_res;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_maximum_120() {
assert_eq!(maximum_120(vec![-3, -4, 5], 3), vec![-4, -3, 5]);
assert_eq!(maximum_120(vec![4, -4, 4], 2), vec![4, 4]);
assert_eq!(maximum_120(vec![-3, 2, 1, 2, -1, -2, 1], 1), vec![2]);
assert_eq!(
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn maximum_120(arr: Vec<i32>, k: i32) -> Vec<i32> {
| None |
let mut arr = arr;
arr.sort();
let mut arr_res: Vec<i32> = arr.iter().rev().take(k as usize).cloned().collect();
arr_res.sort();
arr_res.reverse();
return arr_res;
}
| excess logic | incorrect output | maximum | maximum_120(arr: Vec<i32>, k: i32) -> Vec<i32> | Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the array will be in the range of [-1000, 1000].
3. 0 <= k <= len(arr) | Write a Rust function `maximum_120(arr: Vec<i32>, k: i32) -> Vec<i32>` to solve the following problem:
Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maximum k numbers in arr.
Note:
1. The length of the array will be in the range of [1, 1000].
2. The elements in the a... |
Rust/121 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions.
*/
... |
let mut sum = 0;
for (indx, elem) in lst.iter().enumerate() {
if indx % 2 == 0 {
if elem % 2 == 1 {
sum += elem;
}
}
}
return sum;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_solutions() {
assert_eq!(solutions(vec![5, 8, 7, 1]), 12);
assert_eq!(solutions(vec![3, 3, 3, 3, 3]), 9);
assert_eq!(solutions(vec![30, 13, 24, 321]), 0);
assert_eq!(solutions(vec![5, 9]), 5);
assert_eq!(solutio... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn solutions(lst: Vec<i32>) -> i32 {
| None |
let mut sum = 0;
for (indx, elem) in lst.iter().enumerate() {
if indx % 2 == 1 {
if elem % 2 == 1 {
sum += elem;
}
}
}
return sum;
}
| value misuse | incorrect output | solution | solutions(lst: Vec<i32>) -> i32 | Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. | Write a Rust function `solutions(lst: Vec<i32>) -> i32` to solve the following problem:
Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. |
Rust/122 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two... |
let mut sum = 0;
for i in 0..k {
if arr[i as usize] >= -99 && arr[i as usize] <= 99 {
sum += arr[i as usize];
}
}
sum
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add_elements() {
assert_eq!(add_elements(vec![1, -2, -3, 41, 57, 76, 87, 88, 99], 3), -4);
assert_eq!(add_elements(vec![111, 121, 3, 4000, 5, 6], 2), 0);
assert_eq!(add_elements(vec![11, 21, 3, 90, 5, 6, 7, 8, 9], 4), 125);
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn add_elements(arr: Vec<i32>, k: i32) -> i32 {
| None |
let mut sum = 0;
for i in 0..arr.len() {
if arr[i as usize] >= -99 && arr[i as usize] <= 99 {
sum += arr[i as usize];
}
}
sum
}
| missing logic | incorrect output | add_elements | add_elements(arr: Vec<i32>, k: i32) -> i32 | Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr) | Write a Rust function `add_elements(arr: Vec<i32>, k: i32) -> i32` to solve the following problem:
Given a non-empty array of integers arr and an integer k, return
the sum of the elements with at most two digits from the first k elements of arr.
Constraints:
1. 1 <= len(arr) <= 100
2. 1 <= k <= len(arr) |
Rust/123 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Colla... |
let mut out = vec![1];
let mut n = n;
while n != 1 {
if n % 2 == 1 {
out.push(n);
n = n * 3 + 1;
} else {
n = n / 2;
}
}
out.sort();
out
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_odd_collatz() {
assert_eq!(get_odd_collatz(14), vec![1, 5, 7, 11, 13, 17]);
assert_eq!(get_odd_collatz(5), vec![1, 5]);
assert_eq!(get_odd_collatz(12), vec![1, 3, 5]);
assert_eq!(get_odd_collatz(1), vec![1]);
}
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn get_odd_collatz(n: i32) -> Vec<i32> {
| None |
let mut out = vec![1];
let mut n = n;
while n != 1 {
if n % 2 == 1 {
out.push(n);
n = n * 2 + 1;
} else {
n = n / 2;
}
}
out.sort();
out
}
| value misuse | incorrect output | get_odd_collatz | get_odd_collatz(n: i32) -> Vec<i32> | Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n. Then each term is obtained from the
previous term as follows: if the previous term is even,... | Write a Rust function `get_odd_collatz(n: i32) -> Vec<i32>` to solve the following problem:
Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence.
The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined
as follows: start with any positive integer n.... |
Rust/124 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You have to write a function which validates a given date string and
returns True if the date is valid otherwi... |
let mut mm = 0;
let mut dd = 0;
let mut yy = 0;
let mut i = 0;
if date.len() != 10 {
return false;
}
for i in 0..10 {
if i == 2 || i == 5 {
if date.chars().nth(i).unwrap() != '-' {
return false;
}
} else if date.chars().nth(i).... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_valid_date() {
assert_eq!(valid_date("03-11-2000"), true);
assert_eq!(valid_date("15-01-2012"), false);
assert_eq!(valid_date("04-0-2040"), false);
assert_eq!(valid_date("06-04-2020"), true);
assert_eq!(valid_da... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn valid_date(date: &str) -> bool {
| None |
let mut dd = 0;
let mut mm = 0;
let mut yy = 0;
let mut i = 0;
if date.len() != 10 {
return false;
}
for i in 0..10 {
if i == 2 || i == 5 {
if date.chars().nth(i).unwrap() != '-' {
return false;
}
} else if date.chars().nth(i).... | variable misuse | incorrect output | valid_date | valid_date(date: &str) -> bool | You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the numb... | Write a Rust function `valid_date(date: &str) -> bool` to solve the following problem:
You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date string is not empty.
2. The number of ... |
Rust/125 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you... |
let mut out: Vec<String> = Vec::new();
let alphabet: HashMap<char, i32> = HashMap::from([
('a', 0),
('b', 1),
('c', 2),
('d', 3),
('e', 4),
('f', 5),
('g', 6),
('h', 7),
('i', 8),
('j', 9),
('k', 10),
('l', 11),
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_split_words() {
assert_eq!(split_words("Hello world!"), vec!["Hello", "world!"]);
assert_eq!(split_words("Hello,world!"), vec!["Hello", "world!"]);
assert_eq!(split_words("Hello world,!"), vec!["Hello", "world,!"]);
ass... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn split_words(txt: &str) -> Vec<String> {
| None |
let mut out: Vec<String> = Vec::new();
let alphabet: HashMap<char, i32> = HashMap::from([
('a', 0),
('b', 1),
('c', 2),
('d', 3),
('e', 4),
('f', 5),
('g', 6),
('h', 7),
('i', 8),
('j', 9),
('k', 10),
('l', 11),
... | value misuse | incorrect output | split_words | split_words(txt: &str) -> Vec<String> | Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the
alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 | Write a Rust function `split_words(txt: &str) -> Vec<String>` to solve the following problem:
Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in ... |
Rust/126 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than ... |
for i in 1..lst.len() {
if lst[i] < lst[i - 1] {
return false;
}
if i >= 2 && lst[i] == lst[i - 1] && lst[i] == lst[i - 2] {
return false;
}
}
true
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_sorted() {
assert_eq!(is_sorted(vec![5]), true);
assert_eq!(is_sorted(vec![1, 2, 3, 4, 5]), true);
assert_eq!(is_sorted(vec![1, 3, 2, 4, 5]), false);
assert_eq!(is_sorted(vec![1, 2, 3, 4, 5, 6]), true);
asser... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn is_sorted(lst: Vec<i32>) -> bool {
| None |
for i in 1..lst.len() {
if i >= 2 && lst[i] == lst[i - 1] && lst[i] == lst[i - 2] {
return false;
}
}
true
}
| missing logic | incorrect output | is_sorted | is_sorted(lst: Vec<i32>) -> bool | Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers. | Write a Rust function `is_sorted(lst: Vec<i32>) -> bool` to solve the following problem:
Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers. |
Rust/127 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) =... |
let inter1 = std::cmp::max(interval1[0], interval2[0]);
let inter2 = std::cmp::min(interval1[1], interval2[1]);
let l = inter2 - inter1;
if l < 2 {
return "NO".to_string();
}
for i in 2..l {
if l % i == 0 {
return "NO".to_string();
}
}
return "YES".to... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_intersection() {
assert_eq!(intersection(vec![1, 2], vec![2, 3]), "NO");
assert_eq!(intersection(vec![-1, 1], vec![0, 4]), "NO");
assert_eq!(intersection(vec![-3, -1], vec![-5, 5]), "YES");
assert_eq!(intersection(vec![... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn intersection(interval1: Vec<i32>, interval2: Vec<i32>) -> String {
| None |
let inter1 = std::cmp::max(interval1[0], interval2[0]);
let inter2 = std::cmp::min(interval1[1], interval2[1]);
let l = inter2 - inter1;
for i in 2..l {
if l % i == 0 {
return "NO".to_string();
}
}
return "YES".to_string();
}
| missing logic | incorrect output | intersection | intersection(interval1: Vec<i32>, interval2: Vec<i32>) -> String | You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.
For each given interval, it is assumed that its start is less or equal its end.
Your task is to de... | Write a Rust function `intersection(interval1: Vec<i32>, interval2: Vec<i32>) -> String` to solve the following problem:
You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includ... |
Rust/128 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by... |
if arr.is_empty() {
return -32768;
}
let mut sum = 0;
let mut prods = 1;
for i in arr {
sum += i.abs();
if i == 0 {
prods = 0;
}
if i < 0 {
prods = -prods;
}
}
sum * prods
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_prod_signs() {
assert_eq!(prod_signs(vec![1, 2, 2, -4]), -9);
assert_eq!(prod_signs(vec![0, 1]), 0);
assert_eq!(prod_signs(vec![1, 1, 1, 2, 3, -1, 1]), -10);
assert_eq!(prod_signs(vec![]), -32768);
assert_eq!(pr... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn prod_signs(arr: Vec<i32>) -> i32 {
| None |
if arr.is_empty() {
return -32768;
}
let mut sum = 0;
let mut prods = 1;
for i in arr {
sum += i.abs();
if i == 0 {
prods = 0;
}
if i < 0 {
prods = -prods;
}
}
2 * sum * prods
}
| excess logic | incorrect output | prod_signs | prod_signs(arr: Vec<i32>) -> i32 | You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr. | Write a Rust function `prod_signs(arr: Vec<i32>) -> i32` to solve the following problem:
You are given an array arr of integers and you need to return
sum of magnitudes of integers multiplied by product of all signs
of each number in the array, represented by 1, -1 or 0.
Note: return None for empty arr. |
Rust/129 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains... |
let mut out: Vec<i32> = vec![];
let mut x = 0;
let mut y = 0;
let mut min: i32 = (grid.len() * grid.len()) as i32;
for i in 0..grid.len() {
for j in 0..grid[i].len() {
if grid[i][j] == 1 {
x = i;
y = j;
}
}
}
if x > 0 &... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_min_path() {
assert_eq!(
min_path(vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]], 3),
vec![1, 2, 1]
);
assert_eq!(
min_path(vec![vec![5, 9, 3], vec![4, 1, 6], vec![7, 8, 2]], 1),
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn min_path(grid: Vec<Vec<i32>>, k: i32) -> Vec<i32> {
| None |
let mut out: Vec<i32> = vec![];
let mut x = 0;
let mut y = 0;
let mut min: i32 = (grid.len() * grid.len()) as i32;
for i in 0..grid.len() {
for j in 0..grid[i].len() {
if grid[i][j] == 1 {
x = i;
y = j;
}
}
}
if x > 0 &... | value misuse | incorrect output | min_path | min_path(grid: Vec<Vec<i32>>, k: i32) -> Vec<i32> | Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You have to find the minimum path of length k in the grid. You can start
from any cell, and in each step you ca... | Write a Rust function `min_path(grid: Vec<Vec<i32>>, k: i32) -> Vec<i32>` to solve the following problem:
Given a grid with N rows and N columns (N >= 2) and a positive integer k,
each cell of the grid contains a value. Every integer in the range [1, N * N]
inclusive appears exactly once on the cells of the grid.
You h... |
Rust/130 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. Howe... |
let mut out = vec![1, 3];
if n == 0 {
return vec![1];
}
for i in 2..=n {
if i % 2 == 0 {
out.push(1 + i / 2);
} else {
out.push(out[(i - 1) as usize] + out[(i - 2) as usize] + 1 + (i + 1) / 2);
}
}
out
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_tri() {
assert!(tri(3) == vec![1, 3, 2, 8]);
assert!(tri(4) == vec![1, 3, 2, 8, 3]);
assert!(tri(5) == vec![1, 3, 2, 8, 3, 15]);
assert!(tri(6) == vec![1, 3, 2, 8, 3, 15, 4]);
assert!(tri(7) == vec![1, 3, 2, 8, ... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn tri(n: i32) -> Vec<i32> {
| None |
let mut out = vec![1, 3];
if n == 0 {
return vec![1];
}
for i in 2..=n {
if i % 2 == 0 {
out.push(1 + i / 2);
} else {
out.push(out[(i - 1) as usize] + out[(i - 2) as usize] + 1 + i * (i + 1) / 2);
}
}
out
}
| excess logic | incorrect output | tri | tri(n: i32) -> Vec<i32> | Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2, if n is even.
tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
For... | Write a Rust function `tri(n: i32) -> Vec<i32>` to solve the following problem:
Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in
the last couple centuries. However, what people don't know is Tribonacci sequence.
Tribonacci sequence is defined by the recurrence:
tri(1) = 3
tri(n) = 1 + n / 2... |
Rust/131 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even.
*/
fn ... |
let mut prod: i32 = 1;
let mut has = 0;
let s = n.to_string();
for i in 0..s.len() {
if s.chars().nth(i).unwrap().to_digit(10).unwrap() % 2 == 1 {
has = 1;
prod = prod * (s.chars().nth(i).unwrap().to_digit(10).unwrap()) as i32;
}
}
if has == 0 {
r... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_digits() {
assert_eq!(digits(5), 5);
assert_eq!(digits(54), 5);
assert_eq!(digits(120), 1);
assert_eq!(digits(5014), 5);
assert_eq!(digits(98765), 315);
assert_eq!(digits(5576543), 2625);
assert_... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn digits(n: i32) -> i32 {
| None |
let mut prod: i32 = 1;
let mut has = 0;
let s = n.to_string();
for i in 0..s.len() {
if s.chars().nth(i).unwrap().to_digit(10).unwrap() % 2 == 1 {
has = 1;
prod *= prod * (s.chars().nth(i).unwrap().to_digit(10).unwrap()) as i32;
}
}
if has == 0 {
... | excess logic | incorrect output | digits | digits(n: i32) -> i32 | Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even. | Write a Rust function `digits(n: i32) -> i32` to solve the following problem:
Given a positive integer n, return the product of the odd digits.
Return 0 if all digits are even. |
Rust/132 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function that takes a string as input which contains only square brackets.
The function should r... |
let mut count = 0;
let mut maxcount = 0;
for i in 0..str.len() {
if str.chars().nth(i).unwrap() == '[' {
count += 1;
}
if str.chars().nth(i).unwrap() == ']' {
count -= 1;
}
if count < 0 {
count = 0;
}
if count > max... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_nested() {
assert_eq!(is_nested("[[]]"), true);
assert_eq!(is_nested("[]]]]]]][[[[[]"), false);
assert_eq!(is_nested("[][]"), false);
assert_eq!(is_nested("[]"), false);
assert_eq!(is_nested("[[[[]]]]"), true... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn is_nested(str: &str) -> bool {
| None |
let mut count = 0;
let mut maxcount = 0;
for i in 0..str.len() {
if str.chars().nth(i).unwrap() == '(' {
count += 1;
}
if str.chars().nth(i).unwrap() == ')' {
count -= 1;
}
if count < 0 {
count = 0;
}
if count > max... | value misuse | incorrect output | is_nested | is_nested(str: &str) -> bool | Create a function that takes a string as input which contains only square brackets.
The function should return True if and only if there is a valid subsequence of brackets
where at least one bracket in the subsequence is nested. | Write a Rust function `is_nested(str: &str) -> bool` to solve the following problem:
Create a function that takes a string as input which contains only square brackets.
The function should return True if and only if there is a valid subsequence of brackets
where at least one bracket in the subsequence is nested. |
Rust/133 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
"
This function will take a list of integers. For all entries in the list, the function shall square the integ... |
let mut sum: f32 = 0.0;
for i in 0..lst.len() {
sum = sum + (lst[i].ceil() * lst[i].ceil());
}
sum as i32
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sum_squares() {
assert_eq!(sum_squares(vec![1.0, 2.0, 3.0]), 14);
assert_eq!(sum_squares(vec![1.0, 2.0, 3.0]), 14);
assert_eq!(sum_squares(vec![1.0, 3.0, 5.0, 7.0]), 84);
assert_eq!(sum_squares(vec![1.4, 4.2, 0.0]), 29)... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn sum_squares(lst: Vec<f32>) -> i32 {
| None |
let mut sum: f32 = 0.0;
for i in 0..lst.len() {
sum = sum + (lst[i].ceil() * 2.0);
}
sum as i32
}
| operator misuse | incorrect output | sum_squares | sum_squares(lst: Vec<f32>) -> i32 | This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries in the list whose indexes are not a multi... | Write a Rust function `sum_squares(lst: Vec<f32>) -> i32` to solve the following problem:
This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multipl... |
Rust/134 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function that returns True if the last character
of a given string is an alphabetical character ... |
if txt.len() == 0 {
return false;
}
let chr = txt.chars().last().unwrap();
if chr < 'A' || (chr > 'Z' && chr < 'a') || chr > 'z' {
return false;
}
if txt.len() == 1 {
return true;
}
let chr = txt.chars().nth(txt.len() - 2).unwrap();
if (chr >= 'A' && chr <= '... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_check_if_last_char_is_a_letter() {
assert_eq!(check_if_last_char_is_a_letter("apple"), false);
assert_eq!(check_if_last_char_is_a_letter("apple pi e"), true);
assert_eq!(check_if_last_char_is_a_letter("eeeee"), false);
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn check_if_last_char_is_a_letter(txt: &str) -> bool {
| None |
if txt.len() == 0 {
return false;
}
let chr = txt.chars().last().unwrap();
if chr < 'a' || (chr > 'z' && chr < 'A') || chr > 'Z' {
return false;
}
if txt.len() == 1 {
return true;
}
let chr = txt.chars().nth(txt.len() - 2).unwrap();
if (chr >= 'a' && chr <= '... | function misuse | incorrect output | check_if_last_char_is_a_letter | check_if_last_char_is_a_letter(txt: &str) -> bool | Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: "word" is a group of characters separated by space. | Write a Rust function `check_if_last_char_is_a_letter(txt: &str) -> bool` to solve the following problem:
Create a function that returns True if the last character
of a given string is an alphabetical character and is not
a part of a word, and False otherwise.
Note: "word" is a group of characters separated by space. |
Rust/135 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function which returns the largest index of an element which
is not greater than or equal to the elem... |
let mut max: i32 = -1;
for i in 0..arr.len() {
if arr[i] <= i as i32 {
max = i as i32;
}
}
max
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_can_arrange() {
assert_eq!(can_arrange(vec![1, 2, 4, 3, 5]), 3);
assert_eq!(can_arrange(vec![1, 2, 4, 5]), -1);
assert_eq!(can_arrange(vec![1, 4, 2, 5, 6, 7, 8, 9, 10]), 2);
assert_eq!(can_arrange(vec![4, 8, 5, 7, 3]),... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn can_arrange(arr: Vec<i32>) -> i32 {
| None |
let mut max: i32 = -1;
for i in 0..arr.len() {
if arr[i] <= i as i32 {
max = i as i32;
}
}
max -= 1;
return max;
}
| excess logic | incorrect output | can_arrange | can_arrange(arr: Vec<i32>) -> i32 | Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate values. | Write a Rust function `can_arrange(arr: Vec<i32>) -> i32` to solve the following problem:
Create a function which returns the largest index of an element which
is not greater than or equal to the element immediately preceding it. If
no such element exists then return -1. The given array will not contain
duplicate value... |
Rust/136 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is ... |
let mut maxneg = 0;
let mut minpos = 0;
for i in 0..lst.len() {
if lst[i] < 0 && (maxneg == 0 || lst[i] > maxneg) {
maxneg = lst[i];
}
if lst[i] > 0 && (minpos == 0 || lst[i] < minpos) {
minpos = lst[i];
}
}
vec![maxneg, minpos]
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_largest_smallest_integers() {
assert_eq!(
largest_smallest_integers(vec![2, 4, 1, 3, 5, 7]),
vec![0, 1]
);
assert_eq!(
largest_smallest_integers(vec![2, 4, 1, 3, 5, 7, 0]),
vec![0... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn largest_smallest_integers(lst: Vec<i32>) -> Vec<i32> {
| None |
let mut maxneg = 0;
let mut minpos = 0;
for i in 0..lst.len() {
if lst[i] < 0 && (maxneg == 0 || lst[i] > maxneg) {
maxneg = lst[i];
}
if lst[i] > 0 && (minpos == 0 || lst[i] < minpos) {
minpos = lst[i];
maxneg = lst[i] * -1;
}
}
v... | excess logic | incorrect output | largest_smallest_integers | largest_smallest_integers(lst: Vec<i32>) -> Vec<i32> | Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as None. | Write a Rust function `largest_smallest_integers(lst: Vec<i32>) -> Vec<i32>` to solve the following problem:
Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them as ... |
Rust/137 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larg... |
let a_f64 = Any_to_f64(a);
let b_f64 = Any_to_f64(b);
if a_f64 > b_f64 {
return original_type(a);
}
if a_f64 < b_f64 {
return original_type(b);
} else {
return RtnType::String("None".to_string());
}
}
#[derive(Debug, PartialEq)]
pub enum RtnType<S, F, I> {
Emp... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compare_one() {
assert_eq!(compare_one(&1, &2), RtnType::Int(2));
assert_eq!(compare_one(&1, &2.5), RtnType::Float(2.5));
assert_eq!(compare_one(&2, &3), RtnType::Int(3));
assert_eq!(compare_one(&5, &6), RtnType::Int(6)... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn compare_one<'a>(a:&'a dyn Any, b:&'a dyn Any) -> RtnType<String,f64,i32>{
| None |
let a_f64 = Any_to_f64(a);
let b_f64 = Any_to_f64(b);
if a_f64 > b_f64 {
return original_type(a);
}
if a_f64 < b_f64 {
return original_type(b);
} else {
return RtnType::String("None".to_string());
}
}
#[derive(Debug, PartialEq)]
pub enum RtnType<S, F, I> {
Emp... | excess logic | incorrect output | compare_one | compare_one<'a>(a:&'a dyn Any, b:&'a dyn Any) -> RtnType<String,f64,i32> | Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, the floating point might be . or , | Write a Rust function `compare_one<'a>(a:&'a dyn Any, b:&'a dyn Any) -> RtnType<String,f64,i32>` to solve the following problem:
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If ... |
Rust/138 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
*/
fn is_equ... |
if n % 2 == 0 && n >= 8 {
return true;
}
return false;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_equal_to_sum_even() {
assert_eq!(is_equal_to_sum_even(4), false);
assert_eq!(is_equal_to_sum_even(6), false);
assert_eq!(is_equal_to_sum_even(8), true);
assert_eq!(is_equal_to_sum_even(10), true);
assert_eq!(... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn is_equal_to_sum_even(n: i32) -> bool {
| None |
if n % 2 == 0 && n >= 8 && n <= 8 {
return true;
}
return false;
}
| excess logic | incorrect output | is_equal_to_sum_even | is_equal_to_sum_even(n: i32) -> bool | Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers | Write a Rust function `is_equal_to_sum_even(n: i32) -> bool` to solve the following problem:
Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers |
Rust/139 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > ... |
let mut fact = 1;
let mut bfact: i64 = 1;
for i in 1..=n {
fact = fact * i;
bfact = bfact * fact as i64;
}
bfact
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_special_factorial() {
assert_eq!(special_factorial(4), 288);
assert_eq!(special_factorial(5), 34560);
assert_eq!(special_factorial(7), 125411328000);
assert_eq!(special_factorial(1), 1);
}
}
|
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn special_factorial(n: i32) -> i64 {
| None |
let mut fact = 1;
let mut bfact: i64 = 1;
for i in 1..=n {
fact = fact * i;
bfact = bfact * fact as i64 * i as i64;
}
bfact
}
| excess logic | incorrect output | special_factorial | special_factorial(n: i32) -> i64 | The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
The function will receive an integer as input and should return the special
factorial of this integer. | Write a Rust function `special_factorial(n: i32) -> i64` to solve the following problem:
The Brazilian factorial is defined as:
brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
where n > 0
The function will receive an integer as input and should return the special
factorial of this integer. |
Rust/140 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecut... |
let mut out = String::new();
let mut spacelen = 0;
for c in text.chars() {
if c == ' ' {
spacelen += 1;
} else {
if spacelen == 1 {
out.push('_');
}
if spacelen == 2 {
out.push_str("__");
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fix_spaces() {
assert_eq!(fix_spaces("Example"), "Example");
assert_eq!(fix_spaces("Mudasir Hanif "), "Mudasir_Hanif_");
assert_eq!(
fix_spaces("Yellow Yellow Dirty Fellow"),
"Yellow_Yellow__Dirty__Fel... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn fix_spaces(text: &str) -> String {
| None |
let mut out = String::new();
let mut spacelen = 0;
for c in text.chars() {
if c == ' ' {
spacelen += 1;
} else {
if spacelen == 1 {
out.push('_');
}
if spacelen == 2 {
out.push_str("__");
}
... | excess logic | incorrect output | fix_spaces | fix_spaces(text: &str) -> String | Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with - | Write a Rust function `fix_spaces(text: &str) -> String` to solve the following problem:
Given a string text, replace all spaces in it with underscores,
and if a string has more than 2 consecutive spaces,
then replace all consecutive spaces with - |
Rust/141 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is... |
let mut numdigit = 0;
let mut numdot = 0;
if file_name.len() < 5 {
return "No";
}
let w = file_name.chars().nth(0).unwrap();
if w < 'A' || (w > 'Z' && w < 'a') || w > 'z' {
return "No";
}
let last = &file_name[file_name.len() - 4..];
if last != ".txt" && last != ".ex... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_file_name_check() {
assert_eq!(file_name_check("example.txt"), "Yes");
assert_eq!(file_name_check("1example.dll"), "No");
assert_eq!(file_name_check("s1sdf3.asd"), "No");
assert_eq!(file_name_check("K.dll"), "Yes");
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn file_name_check(file_name: &str) -> &str {
| None |
let mut numdigit = 0;
let mut numdot = 0;
if file_name.len() < 5 {
return "No";
}
let w = file_name.chars().nth(0).unwrap();
let last = &file_name[file_name.len() - 4..];
if last != ".txt" && last != ".exe" && last != ".dll" {
return "No";
}
for c in file_name.chars(... | missing logic | incorrect output | file_name_check | file_name_check(file_name: &str) -> &str | Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions
are met:
- There should not be more than three digits ('0'-'9') in the file's name.
- The ... | Write a Rust function `file_name_check(file_name: &str) -> &str` to solve the following problem:
Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following cond... |
Rust/142 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
"
This function will take a list of integers. For all entries in the list, the function shall square the integ... |
let mut sum = 0;
for i in 0..lst.len() {
if i % 3 == 0 {
sum += lst[i] * lst[i];
} else if i % 4 == 0 {
sum += lst[i] * lst[i] * lst[i];
} else {
sum += lst[i];
}
}
return sum;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sum_squares_142() {
assert_eq!(sum_squares_142(vec![1, 2, 3]), 6);
assert_eq!(sum_squares_142(vec![1, 4, 9]), 14);
assert_eq!(sum_squares_142(vec![]), 0);
assert_eq!(sum_squares_142(vec![1, 1, 1, 1, 1, 1, 1, 1, 1]), 9);... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn sum_squares_142(lst: Vec<i32>) -> i32 {
| None |
let mut sum = 0;
for i in 0..lst.len() {
if i % 3 == 0 {
sum += lst[i] * lst[i];
} else {
sum += lst[i];
}
}
return sum;
}
| missing logic | incorrect output | sum_squares | sum_squares_142(lst: Vec<i32>) -> i32 | This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not
change the entries in the list whose indexes are not a multi... | Write a Rust function `sum_squares_142(lst: Vec<i32>) -> i32` to solve the following problem:
This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a
multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a mul... |
Rust/143 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a string representing a sentence,
the sentence contains some words separated by a space,
... |
let mut out = String::new();
let mut current = String::new();
let mut sentence = sentence.to_string();
sentence.push(' ');
for i in 0..sentence.len() {
if sentence.chars().nth(i).unwrap() != ' ' {
current.push(sentence.chars().nth(i).unwrap());
} else {
let ... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_words_in_sentence() {
assert_eq!(words_in_sentence("This is a test"), "is");
assert_eq!(words_in_sentence("lets go for swimming"), "go for");
assert_eq!(
words_in_sentence("there is no place available here"),
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn words_in_sentence(sentence: &str) -> String {
| None |
let mut out = String::new();
let mut current = String::new();
let mut sentence = sentence.to_string();
sentence.push(' ');
for i in 0..sentence.len() {
if sentence.chars().nth(i).unwrap() != ' ' {
current.push(sentence.chars().nth(i).unwrap());
} else {
let ... | missing logic | incorrect output | words_in_sentence | words_in_sentence(sentence: &str) -> String | You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
the order of the words in the new string should be the same as the original one.
Constraints:
* 1 <=... | Write a Rust function `words_in_sentence(sentence: &str) -> String` to solve the following problem:
You are given a string representing a sentence,
the sentence contains some words separated by a space,
and you have to return a string that contains the words from the original sentence,
whose lengths are prime numbers,
... |
Rust/144 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Your task is to implement a function that will simplify the expression
x * n. The function returns True if x *... |
let mut a = 0;
let mut b = 0;
let mut c = 0;
let mut d = 0;
let mut i = 0;
for i in 0..x.len() {
if x.chars().nth(i).unwrap() == '/' {
a = x
.chars()
.take(i)
.collect::<String>()
.parse::<i32>()
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_simplify() {
assert_eq!(simplify("1/5", "5/1"), true);
assert_eq!(simplify("1/6", "2/1"), false);
assert_eq!(simplify("5/1", "3/1"), true);
assert_eq!(simplify("7/10", "10/2"), false);
assert_eq!(simplify("2/10"... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn simplify(x: &str, n: &str) -> bool {
| None |
let mut a = 0;
let mut b = 0;
let mut c = 0;
let mut d = 0;
let mut i = 0;
for i in 0..x.len() {
if x.chars().nth(i).unwrap() == '/' {
a = x
.chars()
.take(i)
.collect::<String>()
.parse::<i32>()
... | excess logic | incorrect output | simplify | simplify(x: &str, n: &str) -> bool | Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
<numerator>/<denominator> where both numerator and denominator are posit... | Write a Rust function `simplify(x: &str, n: &str) -> bool` to solve the following problem:
Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the... |
Rust/145 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Write a function which sorts the given list of integers
in ascending order according to the sum of their ... |
let mut result = arr.clone();
result.sort_by_key(|&x| (sum_of_digits(x)));
result
}
pub fn sum_of_digits(n: i32) -> i32 {
let mut sum = 0;
let mut n = n;
if n < 0 {
let right = n / 10;
let mut left;
if right != 0 {
left = n % 10;
left = -1 * lef... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_order_by_points() {
assert_eq!(
order_by_points(vec![1, 11, -1, -11, -12]),
vec![-1, -11, 1, -12, 11]
);
assert_eq!(
order_by_points(vec![
1234, 423, 463, 145, 2, 423, 423, 53... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn order_by_points(arr: Vec<i32>) -> Vec<i32> {
| None |
let mut result = arr.clone();
result.sort_by_key(|&x| (sum_of_digits(x)));
result
}
pub fn sum_of_digits(n: i32) -> i32 {
let mut sum = 0;
let mut n = n;
if n < 0 {
let right = n / 10;
let mut left;
if right != 0 {
left = n % 10;
left = -1 * lef... | excess logic | incorrect output | order_by_points | order_by_points(arr: Vec<i32>) -> Vec<i32> | Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original list. | Write a Rust function `order_by_points(arr: Vec<i32>) -> Vec<i32>` to solve the following problem:
Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in origin... |
Rust/146 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Write a function that takes an array of numbers as input and returns
the number of elements in the array that... |
let mut num = 0;
for i in 0..nums.len() {
if nums[i] > 10 {
let w = nums[i].to_string();
if w.chars().nth(0).unwrap().to_digit(10).unwrap() % 2 == 1
&& w.chars().last().unwrap().to_digit(10).unwrap() % 2 == 1
{
num += 1;
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_special_filter() {
assert_eq!(special_filter(vec![5, -2, 1, -5]), 0);
assert_eq!(special_filter(vec![15, -73, 14, -15]), 1);
assert_eq!(special_filter(vec![33, -2, -3, 45, 21, 109]), 2);
assert_eq!(special_filter(vec![4... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn special_filter(nums: Vec<i32>) -> i32 {
| None |
let mut num = 0;
for i in 0..nums.len() {
if nums[i] > 10 {
let w = nums[i].to_string();
if w.chars().nth(0).unwrap().to_digit(10).unwrap() + 1 % 2 == 1
&& w.chars().last().unwrap().to_digit(10).unwrap() % 2 == 1
{
num += 1;
... | excess logic | incorrect output | special_filter | special_filter(nums: Vec<i32>) -> i32 | Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9). | Write a Rust function `special_filter(nums: Vec<i32>) -> i32` to solve the following problem:
Write a function that takes an array of numbers as input and returns
the number of elements in the array that are greater than 10 and both
first and last digits of a number are odd (1, 3, 5, 7, 9). |
Rust/147 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ... |
let mut a = vec![];
let mut sum = vec![vec![0, 0, 0]];
let mut sum2 = vec![vec![0, 0, 0]];
for i in 1..=n {
a.push((i * i - i + 1) % 3);
sum.push(sum[sum.len() - 1].clone());
sum[i as usize][a[i as usize - 1] as usize] += 1;
}
for times in 1..3 {
for i in 1..=n... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_matrix_triples() {
assert_eq!(get_matrix_triples(5), 1);
assert_eq!(get_matrix_triples(6), 4);
assert_eq!(get_matrix_triples(10), 36);
assert_eq!(get_matrix_triples(100), 53361);
}
}
|
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn get_matrix_triples(n: i32) -> i32 {
| None |
let mut a = vec![];
let mut sum = vec![vec![0, 0, 0]];
let mut sum2 = vec![vec![0, 0, 0]];
for i in 1..=n {
a.push((i * i) % 3);
sum.push(sum[sum.len() - 1].clone());
sum[i as usize][a[i as usize - 1] as usize] += 1;
}
for times in 1..3 {
for i in 1..=n {
... | missing logic | incorrect output | get_matrix_triples | get_matrix_triples(n: i32) -> i32 | You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j] + a[k] is a multiple of 3. | Write a Rust function `get_matrix_triples(n: i32) -> i32` to solve the following problem:
You are given a positive integer n. You have to create an integer array a of length n.
For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
and a[i] + a[j... |
Rust/148 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
There are eight planets in our solar system: the closerst to the Sun
is Mercury, the next one is Venus, ... |
let planets = vec![
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune",
];
let mut pos1: i32 = -1;
let mut pos2: i32 = -1;
let mut m;
for m in 0..planets.len() {
if planets[m] == planet1 {
pos1 = m as i32;
}
if planets[m] ==... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_bf() {
assert_eq!(bf("Jupiter", "Neptune"), vec!["Saturn", "Uranus"]);
assert_eq!(bf("Earth", "Mercury"), vec!["Venus"]);
assert_eq!(
bf("Mercury", "Uranus"),
vec!["Venus", "Earth", "Mars", "Jupiter", "S... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn bf(planet1: &str, planet2: &str) -> Vec<String> {
| None |
let planets = vec![
"Mercury", "Venus", "Earth", "Mars", "Jupyter", "Saturn", "Uranus", "Neptune",
];
let mut pos1: i32 = -1;
let mut pos2: i32 = -1;
let mut m;
for m in 0..planets.len() {
if planets[m] == planet1 {
pos1 = m as i32;
}
if planets[m] ==... | value misuse | incorrect output | bf | bf(planet1: &str, planet2: &str) -> Vec<String> | There are eight planets in our solar system: the closerst to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings planet1 and planet2.
The function should return a tuple containing all planets whose orbits are
located betw... | Write a Rust function `bf(planet1: &str, planet2: &str) -> Vec<String>` to solve the following problem:
There are eight planets in our solar system: the closerst to the Sun
is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
Uranus, Neptune.
Write a function that takes two planet names as strings plan... |
Rust/149 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from... |
let mut out: Vec<&str> = Vec::new();
for i in 0..lst.len() {
if lst[i].len() % 2 == 0 {
out.push(lst[i]);
}
}
out.sort();
for i in 0..out.len() {
for j in 1..out.len() {
if out[j].len() < out[j - 1].len() {
let mid = out[j];
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sorted_list_sum() {
assert_eq!(sorted_list_sum(vec!["aa", "a", "aaa"]), vec!["aa"]);
assert_eq!(
sorted_list_sum(vec!["school", "AI", "asdf", "b"]),
vec!["AI", "asdf", "school"]
);
let v_empty: Ve... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn sorted_list_sum(lst: Vec<&str>) -> Vec<&str> {
| None |
let mut out: Vec<&str> = Vec::new();
for i in 0..lst.len() {
if lst[i].len() % 2 == 0 {
out.push(lst[i]);
}
}
for i in 0..out.len() {
for j in 1..out.len() {
if out[j].len() < out[j - 1].len() {
let mid = out[j];
out[j] = o... | missing logic | incorrect output | sorted_list_sum | sorted_list_sum(lst: Vec<&str>) -> Vec<&str> | Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an array of numbers,
and it may contain duplicates.
The order of the list should be ascending by length of ... | Write a Rust function `sorted_list_sum(lst: Vec<&str>) -> Vec<&str>` to solve the following problem:
Write a function that accepts a list of strings as a parameter,
deletes the strings that have odd lengths from it,
and returns the resulted list with a sorted order,
The list is always a list of strings and never an arr... |
Rust/150 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
A simple program which should return the value of x if n is
a prime number and should return the value of y o... |
let mut isp = true;
if n < 2 {
isp = false;
}
for i in 2..=n / 2 {
if n % i == 0 {
isp = false;
}
}
if isp {
return x;
}
return y;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_x_or_y() {
assert_eq!(x_or_y(7, 34, 12), 34);
assert_eq!(x_or_y(15, 8, 5), 5);
assert_eq!(x_or_y(3, 33, 5212), 33);
assert_eq!(x_or_y(1259, 3, 52), 3);
assert_eq!(x_or_y(7919, -1, 12), -1);
assert_eq!(x_... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn x_or_y(n: i32, x: i32, y: i32) -> i32 {
| None |
let mut isp = true;
if n < 2 {
isp = false;
}
for i in 2..=n / 2 {
if n % i - 1 == 0 {
isp = false;
}
}
if isp {
return x;
}
return y;
}
| excess logic | incorrect output | x_or_y | x_or_y(n: i32, x: i32, y: i32) -> i32 | A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise. | Write a Rust function `x_or_y(n: i32, x: i32, y: i32) -> i32` to solve the following problem:
A simple program which should return the value of x if n is
a prime number and should return the value of y otherwise. |
Rust/151 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore number... |
let mut sum: i64 = 0;
for i in 0..lst.len() {
if (lst[i] - lst[i].round()).abs() < 1e-4 {
if lst[i] > 0.0 && (lst[i].round() as i64) % 2 == 1 {
sum += (lst[i].round() as i64) * (lst[i].round() as i64);
}
}
}
return sum;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_double_the_difference() {
assert_eq!(double_the_difference(vec![]), 0);
assert_eq!(double_the_difference(vec![5.0, 4.0]), 25);
assert_eq!(double_the_difference(vec![0.1, 0.2, 0.3]), 0);
assert_eq!(double_the_difference(... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn double_the_difference(lst: Vec<f32>) -> i64 {
| None |
let mut sum: i64 = 0;
for i in 0..lst.len() {
if (lst[i] - lst[i].round()).abs() < 1e-4 {
if lst[i] > 0.0 {
sum += (lst[i].round() as i64) * (lst[i].round() as i64);
}
}
}
return sum;
}
| missing logic | incorrect output | double_the_difference | double_the_difference(lst: Vec<f32>) -> i64 | Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
If the input list is empty, return 0. | Write a Rust function `double_the_difference(lst: Vec<f32>) -> i64` to solve the following problem:
Given a list of numbers, return the sum of squares of the numbers
in the list that are odd. Ignore numbers that are negative or not integers.
If the input list is empty, return 0. |
Rust/152 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings... |
let mut out: Vec<i32> = Vec::new();
for i in 0..game.len() {
out.push(i32::abs(game[i] - guess[i]));
}
return out;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compare() {
assert_eq!(
compare(vec![1, 2, 3, 4, 5, 1], vec![1, 2, 3, 4, 2, -2]),
vec![0, 0, 0, 0, 3, 3]
);
assert_eq!(
compare(vec![0, 5, 0, 0, 0, 4], vec![4, 1, 1, 0, 0, -2]),
v... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn compare(game: Vec<i32>, guess: Vec<i32>) -> Vec<i32> {
| None |
let mut out: Vec<i32> = Vec::new();
for i in 0..game.len() {
out.push(i32::abs(game[i] - guess[i]) + i32::abs(guess[i] - game[i]));
}
return out;
}
| excess logic | incorrect output | compare | compare(game: Vec<i32>, guess: Vec<i32>) -> Vec<i32> | I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to determine if a person correctly guessed the results of a number of matches.
You are given two arrays of scor... | Write a Rust function `compare(game: Vec<i32>, guess: Vec<i32>) -> Vec<i32>` to solve the following problem:
I think we all remember that feeling when the result of some long-awaited
event is finally known. The feelings and thoughts you have at that moment are
definitely worth noting down and comparing.
Your task is to... |
Rust/153 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to lo... |
let mut strongest = "";
let mut max = -1000;
for i in 0..extensions.len() {
let mut strength = 0;
for j in 0..extensions[i].len() {
let chr = extensions[i].chars().nth(j).unwrap();
if chr >= 'A' && chr <= 'Z' {
strength += 1;
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_strongest_extension() {
assert_eq!(
strongest_extension("Watashi", vec!["tEN", "niNE", "eIGHt8OKe"]),
"Watashi.eIGHt8OKe"
);
assert_eq!(
strongest_extension("Boku123", vec!["nani", "NazeDa", ... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn strongest_extension(class_name: &str, extensions: Vec<&str>) -> String {
| None |
let mut strongest = "";
let mut max = -1000;
for i in 0..extensions.len() {
let mut strength = 0;
for j in 0..extensions[i].len() {
let chr = extensions[i].chars().nth(j).unwrap();
if chr >= 'A' && chr <= 'Z' {
strength += 1;
}
... | missing logic | incorrect output | strongest_extension | strongest_extension(class_name: &str, extensions: Vec<&str>) -> String | You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the number of the uppercase
letters in the extension's name, and let SM be the number of lowercase letters
in the exte... | Write a Rust function `strongest_extension(class_name: &str, extensions: Vec<&str>) -> String` to solve the following problem:
You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Le... |
Rust/154 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the fi... |
for i in 0..b.len() {
let rotate = format!("{}{}", &b[i..], &b[..i]);
if a.contains(&rotate) {
return true;
}
}
false
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cycpattern_check() {
assert_eq!(cycpattern_check("xyzw", "xyw"), false);
assert_eq!(cycpattern_check("yello", "ell"), true);
assert_eq!(cycpattern_check("whattup", "ptut"), false);
assert_eq!(cycpattern_check("efef", "f... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn cycpattern_check(a: &str, b: &str) -> bool {
| None |
for i in 1..b.len() {
let rotate = format!("{}{}", &b[i..], &b[..i]);
if a.contains(&rotate) {
return true;
}
}
false
}
| value misuse | incorrect output | cycpattern_check | cycpattern_check(a: &str, b: &str) -> bool | You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word | Write a Rust function `cycpattern_check(a: &str, b: &str) -> bool` to solve the following problem:
You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word |
Rust/155 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given an integer. return a tuple that has the number of even and odd digits respectively.
*/
fn even_odd_coun... |
let w = num.abs().to_string();
let mut n1 = 0;
let mut n2 = 0;
for i in 0..w.len() {
if w.chars().nth(i).unwrap().to_digit(10).unwrap() % 2 == 1 {
n1 += 1;
} else {
n2 += 1;
}
}
vec![n2, n1]
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_even_odd() {
assert_eq!(even_odd_count(7), vec![0, 1]);
assert_eq!(even_odd_count(-78), vec![1, 1]);
assert_eq!(even_odd_count(3452), vec![2, 2]);
assert_eq!(even_odd_count(346211), vec![3, 3]);
assert_eq!(even_... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn even_odd_count(num: i32) -> Vec<i32> {
| None |
let w = num.abs().to_string();
let mut n1 = 0;
let mut n2 = 0;
for i in 0..w.len() {
if w.chars().nth(i).unwrap().to_digit(10).unwrap() % 2 == 1 {
n1 += 1;
}
}
vec![n2, n1]
}
| missing logic | incorrect output | even_odd_count | even_odd_count(num: i32) -> Vec<i32> | Given an integer. return a tuple that has the number of even and odd digits respectively. | Write a Rust function `even_odd_count(num: i32) -> Vec<i32>` to solve the following problem:
Given an integer. return a tuple that has the number of even and odd digits respectively. |
Rust/156 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
... |
let mut current = String::new();
let mut number = number;
let rep = vec![
"m", "cm", "d", "cd", "c", "xc", "l", "xl", "x", "ix", "v", "iv", "i",
];
let num = vec![1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
let mut pos = 0;
while number > 0 {
while number >= num[p... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_int_to_mini_romank() {
assert_eq!(int_to_mini_romank(19), "xix");
assert_eq!(int_to_mini_romank(152), "clii");
assert_eq!(int_to_mini_romank(251), "ccli");
assert_eq!(int_to_mini_romank(426), "cdxxvi");
assert_e... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn int_to_mini_romank(number: i32) -> String {
| None |
let mut current = String::new();
let mut number = number;
let rep = vec![
"m", "cm", "d", "cd", "c", "xc", "l", "xl", "x", "ix", "v", "iv", "i",
];
let num = vec![1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
let mut pos = 0;
while number > 0 {
while number >= num[p... | missing logic | infinite loop | int_to_mini_roman | int_to_mini_romank(number: i32) -> String | Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000 | Write a Rust function `int_to_mini_romank(number: i32) -> String` to solve the following problem:
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000 |
Rust/157 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled tr... |
if (a * a + b * b - c * c).abs() < 1e-4
|| (a * a + c * c - b * b).abs() < 1e-4
|| (b * b + c * c - a * a).abs() < 1e-4
{
return true;
}
return false;
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_right_angle_triangle() {
assert_eq!(right_angle_triangle(3.0, 4.0, 5.0), true);
assert_eq!(right_angle_triangle(1.0, 2.0, 3.0), false);
assert_eq!(right_angle_triangle(10.0, 6.0, 8.0), true);
assert_eq!(right_angle_tria... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn right_angle_triangle(a: f32, b: f32, c: f32) -> bool {
| None |
if (a * a + b * b - c * c).abs() < 1e-4
{
return true;
}
return false;
}
| missing logic | incorrect output | right_angle_triangle | right_angle_triangle(a: f32, b: f32, c: f32) -> bool | Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 degree. | Write a Rust function `right_angle_triangle(a: f32, b: f32, c: f32) -> bool` to solve the following problem:
Given the lengths of the three sides of a triangle. Return True if the three
sides form a right-angled triangle, False otherwise.
A right-angled triangle is a triangle in which one angle is right angle or
90 deg... |
Rust/158 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Write a function that accepts a list of strings.
The list contains different words. Return the word with maxim... |
let mut max = "";
let mut maxu = 0;
for i in 0..words.len() {
let mut unique = String::from("");
for j in 0..words[i].len() {
if !unique.contains(words[i].chars().nth(j).unwrap()) {
unique.push(words[i].chars().nth(j).unwrap());
}
}
if... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_find_max() {
assert_eq!(find_max(vec!["name", "of", "string"]), "string");
assert_eq!(find_max(vec!["name", "enam", "game"]), "enam");
assert_eq!(find_max(vec!["aaaaaaa", "bb", "cc"]), "aaaaaaa");
assert_eq!(find_max(ve... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn find_max(words: Vec<&str>) -> &str {
| None |
let mut max = "";
let mut maxu = 0;
for i in 0..words.len() {
let mut unique = String::from("");
for j in 0..words[i].len() {
if !unique.contains(words[i].chars().nth(j).unwrap()) {
unique.push(words[i].chars().nth(j).unwrap());
}
}
if... | missing logic | incorrect output | find_max | find_max(words: Vec<&str>) -> &str | Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexicographical order. | Write a Rust function `find_max(words: Vec<&str>) -> &str` to solve the following problem:
Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which come... |
Rust/159 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat m... |
if need > remaining {
return vec![number + remaining, 0];
}
return vec![number + need, remaining - need];
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_eat() {
assert_eq!(eat(5, 6, 10), vec![11, 4]);
assert_eq!(eat(4, 8, 9), vec![12, 1]);
assert_eq!(eat(1, 10, 10), vec![11, 0]);
assert_eq!(eat(2, 11, 5), vec![7, 0]);
assert_eq!(eat(4, 5, 7), vec![9, 2]);
... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn eat(number: i32, need: i32, remaining: i32) -> Vec<i32> {
| None |
if need > remaining {
return vec![number + remaining, 0];
}
return vec![number + need, number + remaining - need];
}
| excess logic | incorrect output | eat | eat(number: i32, need: i32, remaining: i32) -> Vec<i32> | You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots after your meals,
the number of carrots left after your meals ]
if there are not enough remaining carrots, you w... | Write a Rust function `eat(number: i32, need: i32, remaining: i32) -> Vec<i32>` to solve the following problem:
You're a hungry rabbit, and you already have eaten a certain number of carrots,
but now you need to eat more carrots to complete the day's meals.
you should return an array of [ total number of eaten carrots ... |
Rust/160 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given two lists operator, and operand. The first list has basic algebra operations, and
the second list ... |
let mut operand: Vec<i32> = operand;
let mut num: Vec<i32> = vec![];
let mut posto: Vec<i32> = vec![];
for i in 0..operand.len() {
posto.push(i as i32);
}
for i in 0..operato.len() {
if operato[i] == "**" {
while posto[posto[i] as usize] != posto[i] {
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_do_algebra() {
assert_eq!(do_algebra(vec!["**", "*", "+"], vec![2, 3, 4, 5]), 37);
assert_eq!(do_algebra(vec!["+", "*", "-"], vec![2, 3, 4, 5]), 9);
assert_eq!(do_algebra(vec!["//", "*"], vec![7, 3, 4]), 8);
}
}
|
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn do_algebra(operato: Vec<&str>, operand: Vec<i32>) -> i32 {
| None |
let mut operand: Vec<i32> = operand;
let mut num: Vec<i32> = vec![];
let mut posto: Vec<i32> = vec![];
for i in 0..operand.len() {
posto.push(i as i32);
}
for i in 0..operato.len() {
if operato[i] == "**" {
while posto[posto[i] as usize] != posto[i] {
... | excess logic | incorrect output | do_algebra | do_algebra(operato: Vec<&str>, operand: Vec<i32>) -> i32 | Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this expression.
The basic algebra operations:
Addition ( + )
Subtraction ( - )
Multiplication ( * )
Floor ... | Write a Rust function `do_algebra(operato: Vec<&str>, operand: Vec<i32>) -> i32` to solve the following problem:
Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluati... |
Rust/161 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherw... |
let mut nletter = 0;
let mut out = String::new();
for c in s.chars() {
let mut w = c;
if w >= 'A' && w <= 'Z' {
w = w.to_ascii_lowercase();
} else if w >= 'a' && w <= 'z' {
w = w.to_ascii_uppercase();
} else {
nletter += 1;
}
... |
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_solve_161() {
assert_eq!(solve_161("AsDf"), "aSdF");
assert_eq!(solve_161("1234"), "4321");
assert_eq!(solve_161("ab"), "AB");
assert_eq!(solve_161("#a@C"), "#A@c");
assert_eq!(solve_161("#AsdfW^45"), "#aSDFw^45... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn solve_161(s: &str) -> String {
| None |
let mut nletter = 0;
let mut out = String::new();
for c in s.chars() {
let mut w = c;
if w >= 'A' && w <= 'Z' {
w = w.to_ascii_lowercase();
} else {
nletter += 1;
}
out.push(w);
}
if nletter == s.len() {
out.chars().rev().colle... | missing logic | incorrect output | solve | solve_161(s: &str) -> String | You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string. | Write a Rust function `solve_161(s: &str) -> String` to solve the following problem:
You are given a string s.
if s[i] is a letter, reverse its case from lower to upper or vise versa,
otherwise keep it as it is.
If the string contains no letters, reverse the string.
The function should return the resulted string. |
Rust/162 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None.
... |
if text.is_empty() {
return "None".to_string();
}
let digest = md5::compute(text.as_bytes());
return format!("{:x}", digest);
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_string_to_md5() {
assert_eq!(
string_to_md5("Hello world"),
"3e25960a79dbc69b674cd4ec67a72c62"
);
assert_eq!(string_to_md5(""), "None");
assert_eq!(string_to_md5("A B C"), "0ef78513b0cb8cef12743f... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn string_to_md5(text: &str) -> String {
| None |
if text.is_empty() {
return "None".to_string();
}
let digest = md5::compute("text");
return format!("{:x}", digest);
}
| function misuse | incorrect output | string_to_md5 | string_to_md5(text: &str) -> String | Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None. | Write a Rust function `string_to_md5(text: &str) -> String` to solve the following problem:
Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None. |
Rust/163 | fn main(){}
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
/*
Given two positive integers a and b, return the even digits between a
and b, in ascending order.
*/
... |
let mut a = a;
let mut b = b;
let mut m;
if b < a {
m = a;
a = b;
b = m;
}
let mut out = vec![];
for i in a..=b {
if i < 10 && i % 2 == 0 {
out.push(i);
}
}
out
}
|
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_integers() {
assert_eq!(generate_integers(2, 10), vec![2, 4, 6, 8]);
assert_eq!(generate_integers(10, 2), vec![2, 4, 6, 8]);
assert_eq!(generate_integers(132, 2), vec![2, 4, 6, 8]);
assert_eq!(generate_integers... |
use std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};
use rand::Rng;
use regex::Regex;
use md5;
use std::any::{Any, TypeId};
fn generate_integers(a: i32, b: i32) -> Vec<i32> {
| None |
let mut a = a;
let mut b = b;
let mut m;
if b < a {
m = a;
a = b;
b = m;
}
let mut out = vec![];
for i in a..=b {
if i < 10 && i % 2 == 1 {
out.push(i);
}
}
out
}
| value misuse | incorrect output | generate_integers | generate_integers(a: i32, b: i32) -> Vec<i32> | Given two positive integers a and b, return the even digits between a
and b, in ascending order. | Write a Rust function `generate_integers(a: i32, b: i32) -> Vec<i32>` to solve the following problem:
Given two positive integers a and b, return the even digits between a
and b, in ascending order. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.