Prompt:
# 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 positive whole numbers.
# You can assume that x, and n are valid fractions, and do not have zero as denominator.
# >>> simplify('1/5', '5/1')
# TRUE
# >>> simplify('1/6', '2/1')
# FALSE
# >>> simplify('7/10', '10/2')
# FALSE
simplify <- function(x, n) {

test_humaneval <- function() {
    candidate <- simplify
    stopifnot(isTRUE(all.equal(candidate('1/5', '5/1'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('1/6', '2/1'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('5/1', '3/1'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('7/10', '10/2'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('2/10', '50/10'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('7/2', '4/2'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('11/6', '6/1'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('2/3', '5/2'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('5/2', '3/5'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('2/4', '8/4'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('2/4', '4/2'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('1/5', '5/1'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('1/5', '1/5'), FALSE)))
}
test_humaneval()


Prompt:
# You have been tasked to write a function that receives
# a hexadecimal number as a string and counts the number of hexadecimal
# digits that are primes (prime number, or a prime, is a natural number
# greater than 1 that is not a product of two smaller natural numbers).
# Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
# Prime numbers are 2, 3, 5, 7, 11, 13, 17,...
# So you have to determine a number of the following digits: 2, 3, 5, 7,
# B (=decimal 11), D (=decimal 13).
# Note: you may assume the input is always correct or empty string,
# and symbols A,B,C,D,E,F are always uppercase.
# Examples:
# >>> hex_key('AB')
# 1
# >>> hex_key('1077E')
# 2
# >>> hex_key('ABED1A33')
# 4
# >>> hex_key('123456789ABCDEF0')
# 6
# >>> hex_key('2020')
# 2
hex_key <- function(num) {

test_humaneval <- function() {
    candidate <- hex_key
    stopifnot(isTRUE(all.equal(candidate('AB'), 1)))
    stopifnot(isTRUE(all.equal(candidate('1077E'), 2)))
    stopifnot(isTRUE(all.equal(candidate('ABED1A33'), 4)))
    stopifnot(isTRUE(all.equal(candidate('2020'), 2)))
    stopifnot(isTRUE(all.equal(candidate('123456789ABCDEF0'), 6)))
    stopifnot(isTRUE(all.equal(candidate('112233445566778899AABBCCDDEEFF00'), 12)))
}
test_humaneval()


Prompt:
# 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.
# Example 1:
# >>> words_in_sentence('This is a test')
# 'is'
# Example 2:
# >>> words_in_sentence('lets go for swimming')
# 'go for'
# Constraints:
# * 1 <= len(sentence) <= 100
# * sentence contains only letters
words_in_sentence <- function(sentence) {

test_humaneval <- function() {
    candidate <- words_in_sentence
    stopifnot(isTRUE(all.equal(candidate('This is a test'), 'is')))
    stopifnot(isTRUE(all.equal(candidate('lets go for swimming'), 'go for')))
    stopifnot(isTRUE(all.equal(candidate('there is no place available here'), 'there is no place')))
    stopifnot(isTRUE(all.equal(candidate('Hi I am Hussein'), 'Hi am Hussein')))
    stopifnot(isTRUE(all.equal(candidate('go for it'), 'go for it')))
    stopifnot(isTRUE(all.equal(candidate('here'), '')))
    stopifnot(isTRUE(all.equal(candidate('here is'), 'is')))
}
test_humaneval()


Prompt:
# Given a string representing a space separated lowercase letters, return a named list
# of the letter with the most repetition and containing the corresponding count.
# If several letters have the same occurrence, return all of them.
# Example:
# >>> histogram('a b c')
# list('a' = 1, 'b' = 1, 'c' = 1)
# >>> histogram('a b b a')
# list('a' = 2, 'b' = 2)
# >>> histogram('a b c a b')
# list('a' = 2, 'b' = 2)
# >>> histogram('b b b b a')
# list('b' = 4)
# >>> histogram('')
# list()
histogram <- function(test) {

test_humaneval <- function() {
    candidate <- histogram
    stopifnot(isTRUE(all.equal(candidate('a b b a'), list('a' = 2, 'b' = 2))))
    stopifnot(isTRUE(all.equal(candidate('a b c a b'), list('a' = 2, 'b' = 2))))
    stopifnot(isTRUE(all.equal(candidate('a b c d g'), list('a' = 1, 'b' = 1, 'c' = 1, 'd' = 1, 'g' = 1))))
    stopifnot(isTRUE(all.equal(candidate('r t g'), list('r' = 1, 't' = 1, 'g' = 1))))
    stopifnot(isTRUE(all.equal(candidate('b b b b a'), list('b' = 4))))
    stopifnot(isTRUE(all.equal(candidate('r t g'), list('r' = 1, 't' = 1, 'g' = 1))))
    stopifnot(isTRUE(all.equal(candidate(''), list())))
    stopifnot(isTRUE(all.equal(candidate('a'), list('a' = 1))))
}
test_humaneval()


Prompt:
# You are given a 2 dimensional data, as a nested lists,
# which is similar to matrix, however, unlike matrices,
# each row may contain a different number of columns.
# Given lst, and integer x, find integers x in the list,
# and return list of lists, [(x1, y1), (x2, y2) ...] such that
# each list is a coordinate - (row, columns), starting with 0.
# Sort coordinates initially by rows in ascending order.
# Also, sort coordinates of the row by columns in descending order.
# Examples:
# >>> get_row(list(c(1, 2, 3, 4, 5, 6), c(1, 2, 3, 4, 1, 6), c(1, 2, 3, 4, 5, 1)), 1)
# list(c(0, 0), c(1, 4), c(1, 0), c(2, 5), c(2, 0))
# >>> get_row(c(), 1)
# c()
# >>> get_row(list(c(), c(1), c(1, 2, 3)), 3)
# list(c(2, 2))
get_row <- function(lst, x) {


Prompt:
# 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, the next term is one half of
# the previous term. If the previous term is odd, the next term is 3 times the previous
# term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.
# Note:
# 1. Collatz(1) is [1].
# 2. returned list sorted in increasing order.
# For example:
# get_odd_collatz(5) returns [1, 5] # The collatz sequence for 5 is [5, 16, 8, 4, 2, 1], so the odd numbers are only 1, and 5.
# >>> get_odd_collatz(5)
# c(1, 5)
get_odd_collatz <- function(n) {

test_humaneval <- function() {
    candidate <- get_odd_collatz
    stopifnot(isTRUE(all.equal(candidate(14), c(1, 5, 7, 11, 13, 17))))
    stopifnot(isTRUE(all.equal(candidate(5), c(1, 5))))
    stopifnot(isTRUE(all.equal(candidate(12), c(1, 3, 5))))
    stopifnot(isTRUE(all.equal(candidate(1), c(1))))
}
test_humaneval()


Prompt:
# 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 vector will not contain
# duplicate values.
# Examples:
# >>> can_arrange(c(1, 2, 4, 3, 5))
# 3
# >>> can_arrange(c(1, 2, 3))
# -1
can_arrange <- function(arr) {

test_humaneval <- function() {
    candidate <- can_arrange
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 4, 3, 5)), 3)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 4, 5)), -1)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 4, 2, 5, 6, 7, 8, 9, 10)), 2)))
    stopifnot(isTRUE(all.equal(candidate(c(4, 8, 5, 7, 3)), 4)))
    stopifnot(isTRUE(all.equal(candidate(c()), -1)))
}
test_humaneval()


Prompt:
# Input is a space-delimited string of numberals from 'zero' to 'nine'.
# Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
# Return the string with numbers sorted from smallest to largest
# >>> sort_numbers('three one five')
# 'one three five'
sort_numbers <- function(numbers) {

test_humaneval <- function() {
    candidate <- sort_numbers
    stopifnot(isTRUE(all.equal(candidate(''), '')))
    stopifnot(isTRUE(all.equal(candidate('three'), 'three')))
    stopifnot(isTRUE(all.equal(candidate('three five nine'), 'three five nine')))
    stopifnot(isTRUE(all.equal(candidate('five zero four seven nine eight'), 'zero four five seven eight nine')))
    stopifnot(isTRUE(all.equal(candidate('six five four three two one zero'), 'zero one two three four five six')))
}
test_humaneval()


Prompt:
# Circular shift the digits of the integer x, shift the digits right by shift
# and return the result as a string.
# If shift > number of digits, return digits reversed.
# >>> circular_shift(12, 1)
# '21'
# >>> circular_shift(12, 2)
# '12'
circular_shift <- function(x, shift) {

test_humaneval <- function() {
    candidate <- circular_shift
    stopifnot(isTRUE(all.equal(candidate(100, 2), '001')))
    stopifnot(isTRUE(all.equal(candidate(12, 2), '12')))
    stopifnot(isTRUE(all.equal(candidate(97, 8), '79')))
    stopifnot(isTRUE(all.equal(candidate(12, 1), '21')))
    stopifnot(isTRUE(all.equal(candidate(11, 101), '11')))
}
test_humaneval()


Prompt:
# "
# 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 multiple of 3 or 4. The function shall then return the sum of all entries.
# Examples:
# >>> lst
# c(1, 2, 3)
# >>> lst
# c()
# >>> lst
# c(-1, -5, 2, -1, -5)
sum_squares <- function(lst) {

test_humaneval <- function() {
    candidate <- sum_squares
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3)), 6)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 4, 9)), 14)))
    stopifnot(isTRUE(all.equal(candidate(c()), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 1, 1, 1, 1, 1, 1, 1, 1)), 9)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -1, -1, -1, -1, -1, -1, -1, -1)), -3)))
    stopifnot(isTRUE(all.equal(candidate(c(0)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -5, 2, -1, -5)), -126)))
    stopifnot(isTRUE(all.equal(candidate(c(-56, -99, 1, 0, -2)), 3030)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, 0, 0, 0, 0, 0, 0, 0, -1)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37)), -14196)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10)), -1448)))
}
test_humaneval()


Prompt:
# You are given a list of integers.
# You need to find the largest prime value and return the sum of its digits.
# Examples:
# >>> skjkasdkd(c(0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3))
# 10
# >>> skjkasdkd(c(1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1))
# 25
# >>> skjkasdkd(c(1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3))
# 13
# >>> skjkasdkd(c(0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6))
# 11
# >>> skjkasdkd(c(0, 81, 12, 3, 1, 21))
# 3
# >>> skjkasdkd(c(0, 8, 1, 2, 1, 7))
# 7
skjkasdkd <- function(lst) {


Prompt:
# For a given list of integers, return a list consisting of a sum and a product of all the integers in a list.
# Empty sum should be equal to 0 and empty product should be equal to 1.
# >>> sum_product(c())
# c(0, 1)
# >>> sum_product(c(1, 2, 3, 4))
# c(10, 24)
sum_product <- function(numbers) {

test_humaneval <- function() {
    candidate <- sum_product
    stopifnot(isTRUE(all.equal(candidate(c()), c(0, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(1, 1, 1)), c(3, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(100, 0)), c(100, 0))))
    stopifnot(isTRUE(all.equal(candidate(c(3, 5, 7)), c(15, 105))))
    stopifnot(isTRUE(all.equal(candidate(c(10)), c(10, 10))))
}
test_humaneval()


Prompt:
# 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.
# For example:
# >>> choose_num(12, 15)
# 14
# >>> choose_num(13, 12)
# -1
choose_num <- function(x, y) {

test_humaneval <- function() {
    candidate <- choose_num
    stopifnot(isTRUE(all.equal(candidate(12, 15), 14)))
    stopifnot(isTRUE(all.equal(candidate(13, 12), -1)))
    stopifnot(isTRUE(all.equal(candidate(33, 12354), 12354)))
    stopifnot(isTRUE(all.equal(candidate(5234, 5233), -1)))
    stopifnot(isTRUE(all.equal(candidate(6, 29), 28)))
    stopifnot(isTRUE(all.equal(candidate(27, 10), -1)))
    stopifnot(isTRUE(all.equal(candidate(7, 7), -1)))
    stopifnot(isTRUE(all.equal(candidate(546, 546), 546)))
}
test_humaneval()


Prompt:
# Create a function that returns a list (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 NULL.
# Examples:
# >>> largest_smallest_integers(c(2, 4, 1, 3, 5, 7))
# list(NULL, 1)
# >>> largest_smallest_integers(c())
# list(NULL, NULL)
# >>> largest_smallest_integers(c(0))
# list(NULL, NULL)
largest_smallest_integers <- function(lst) {

test_humaneval <- function() {
    candidate <- largest_smallest_integers
    stopifnot(isTRUE(all.equal(candidate(c(2, 4, 1, 3, 5, 7)), list(NULL, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(2, 4, 1, 3, 5, 7, 0)), list(NULL, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(1, 3, 2, 4, 5, 6, -2)), c(-2, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(4, 5, 3, 6, 2, 7, -7)), c(-7, 2))))
    stopifnot(isTRUE(all.equal(candidate(c(7, 3, 8, 4, 9, 2, 5, -9)), c(-9, 2))))
    stopifnot(isTRUE(all.equal(candidate(c()), list(NULL, NULL))))
    stopifnot(isTRUE(all.equal(candidate(c(0)), list(NULL, NULL))))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -3, -5, -6)), list(-1, NULL))))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -3, -5, -6, 0)), list(-1, NULL))))
    stopifnot(isTRUE(all.equal(candidate(c(-6, -4, -4, -3, 1)), c(-3, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(-6, -4, -4, -3, -100, 1)), c(-3, 1))))
}
test_humaneval()


Prompt:
# Given a string, find out how many distinct characters (regardless of case) does it consist of
# >>> count_distinct_characters('xyzXYZ')
# 3
# >>> count_distinct_characters('Jerry')
# 4
count_distinct_characters <- function(string) {

test_humaneval <- function() {
    candidate <- count_distinct_characters
    stopifnot(isTRUE(all.equal(candidate(''), 0)))
    stopifnot(isTRUE(all.equal(candidate('abcde'), 5)))
    stopifnot(isTRUE(all.equal(candidate('abcdecadeCADE'), 5)))
    stopifnot(isTRUE(all.equal(candidate('aaaaAAAAaaaa'), 1)))
    stopifnot(isTRUE(all.equal(candidate('Jerry jERRY JeRRRY'), 5)))
}
test_humaneval()


Prompt:
# Given a positive integer n, you have to make a pile of n levels of stones.
# The first level has n stones.
# The number of stones in the next level is:
# - the next odd number if n is odd.
# - the next even number if n is even.
# Return the number of stones in each level in a list, where element at index
# i represents the number of stones in the level (i+1).
# Examples:
# >>> make_a_pile(3)
# c(3, 5, 7)
make_a_pile <- function(n) {

test_humaneval <- function() {
    candidate <- make_a_pile
    stopifnot(isTRUE(all.equal(candidate(3), c(3, 5, 7))))
    stopifnot(isTRUE(all.equal(candidate(4), c(4, 6, 8, 10))))
    stopifnot(isTRUE(all.equal(candidate(5), c(5, 7, 9, 11, 13))))
    stopifnot(isTRUE(all.equal(candidate(6), c(6, 8, 10, 12, 14, 16))))
    stopifnot(isTRUE(all.equal(candidate(8), c(8, 10, 12, 14, 16, 18, 20, 22))))
}
test_humaneval()


Prompt:
# You are given a vector arr of integers and you need to return
# sum of magnitudes of integers multiplied by product of all signs
# of each number in the vector, represented by 1, -1 or 0.
# Note: return NULL for empty arr.
# Example:
# >>> prod_signs(c(1, 2, 2, -4))
# 9
# >>> prod_signs(c(0, 1))
# 0
# >>> prod_signs(c())
# NULL
prod_signs <- function(arr) {

test_humaneval <- function() {
    candidate <- prod_signs
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 2, -4)), -9)))
    stopifnot(isTRUE(all.equal(candidate(c(0, 1)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 1, 1, 2, 3, -1, 1)), -10)))
    stopifnot(isTRUE(all.equal(candidate(c()), NULL)))
    stopifnot(isTRUE(all.equal(candidate(c(2, 4, 1, 2, -1, -1, 9)), 20)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, 1, -1, 1)), 4)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, 1, 1, 1)), -4)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, 1, 1, 0)), 0)))
}
test_humaneval()


Prompt:
# Given a vector of integers nums, find the minimum sum of any non-empty sub-vector
# of nums.
# Example
# >>> minSubArraySum(c(2, 3, 4, 1, 2, 4))
# 1
# >>> minSubArraySum(c(-1, -2, -3))
# -6
minSubArraySum <- function(nums) {

test_humaneval <- function() {
    candidate <- minSubArraySum
    stopifnot(isTRUE(all.equal(candidate(c(2, 3, 4, 1, 2, 4)), 1)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -2, -3)), -6)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -2, -3, 2, -10)), -14)))
    stopifnot(isTRUE(all.equal(candidate(c(-9999999999999999)), -9999999999999999)))
    stopifnot(isTRUE(all.equal(candidate(c(0, 10, 20, 1000000)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -2, -3, 10, -5)), -6)))
    stopifnot(isTRUE(all.equal(candidate(c(100, -1, -2, -3, 10, -5)), -6)))
    stopifnot(isTRUE(all.equal(candidate(c(10, 11, 13, 8, 3, 4)), 3)))
    stopifnot(isTRUE(all.equal(candidate(c(100, -33, 32, -1, 0, -2)), -33)))
    stopifnot(isTRUE(all.equal(candidate(c(-10)), -10)))
    stopifnot(isTRUE(all.equal(candidate(c(7)), 7)))
    stopifnot(isTRUE(all.equal(candidate(c(1, -1)), -1)))
}
test_humaneval()


Prompt:
# Return a string containing space-delimited numbers starting from 0 upto n inclusive.
# >>> string_sequence(0)
# '0'
# >>> string_sequence(5)
# '0 1 2 3 4 5'
string_sequence <- function(n) {

test_humaneval <- function() {
    candidate <- string_sequence
    stopifnot(isTRUE(all.equal(candidate(0), '0')))
    stopifnot(isTRUE(all.equal(candidate(3), '0 1 2 3')))
    stopifnot(isTRUE(all.equal(candidate(10), '0 1 2 3 4 5 6 7 8 9 10')))
}
test_humaneval()


Prompt:
# 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
# >>> cycpattern_check('abcd', 'abd')
# FALSE
# >>> cycpattern_check('hello', 'ell')
# TRUE
# >>> cycpattern_check('whassup', 'psus')
# FALSE
# >>> cycpattern_check('abab', 'baa')
# TRUE
# >>> cycpattern_check('efef', 'eeff')
# FALSE
# >>> cycpattern_check('himenss', 'simen')
# TRUE
cycpattern_check <- function(a, b) {

test_humaneval <- function() {
    candidate <- cycpattern_check
    stopifnot(isTRUE(all.equal(candidate('xyzw', 'xyw'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('yello', 'ell'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('whattup', 'ptut'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('efef', 'fee'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('abab', 'aabb'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('winemtt', 'tinem'), TRUE)))
}
test_humaneval()


Prompt:
# Return TRUE is list elements are monotonically increasing or decreasing.
# >>> monotonic(c(1, 2, 4, 20))
# TRUE
# >>> monotonic(c(1, 20, 4, 10))
# FALSE
# >>> monotonic(c(4, 1, 0, -10))
# TRUE
monotonic <- function(l) {

test_humaneval <- function() {
    candidate <- monotonic
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 4, 10)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 4, 20)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 20, 4, 10)), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(4, 1, 0, -10)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(4, 1, 1, 0)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3, 2, 5, 60)), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3, 4, 5, 60)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(9, 9, 9, 9)), TRUE)))
}
test_humaneval()


Prompt:
# Out of list of strings, return the longest one. Return the first one in case of multiple
# strings of the same length. Return NULL in case the input list is empty.
# >>> longest(c())
# NULL
# >>> longest(c('a', 'b', 'c'))
# 'a'
# >>> longest(c('a', 'bb', 'ccc'))
# 'ccc'
longest <- function(strings) {

test_humaneval <- function() {
    candidate <- longest
    stopifnot(isTRUE(all.equal(candidate(c()), NULL)))
    stopifnot(isTRUE(all.equal(candidate(c('x', 'y', 'z')), 'x')))
    stopifnot(isTRUE(all.equal(candidate(c('x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc')), 'zzzz')))
}
test_humaneval()


Prompt:
# Return TRUE if all numbers in the list l are below threshold t.
# >>> below_threshold(c(1, 2, 4, 10), 100)
# TRUE
# >>> below_threshold(c(1, 20, 4, 10), 5)
# FALSE
below_threshold <- function(l, t) {

test_humaneval <- function() {
    candidate <- below_threshold
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 4, 10), 100), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 20, 4, 10), 5), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 20, 4, 10), 21), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 20, 4, 10), 22), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 8, 4, 10), 11), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 8, 4, 10), 10), FALSE)))
}
test_humaneval()


Prompt:
# Write a function that returns true if the given number is the multiplication of 3 prime numbers
# and false otherwise.
# Knowing that (a) is less then 100.
# Example:
# >>> is_multiply_prime(30)
# TRUE
# 30 = 2 * 3 * 5
is_multiply_prime <- function(a) {

test_humaneval <- function() {
    candidate <- is_multiply_prime
    stopifnot(isTRUE(all.equal(candidate(5), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(30), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(8), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(10), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(125), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(105), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(126), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(729), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(891), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(1001), TRUE)))
}
test_humaneval()


Prompt:
# Return only positive numbers in the list.
# >>> get_positive(c(-1, 2, -4, 5, 6))
# c(2, 5, 6)
# >>> get_positive(c(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))
# c(5, 3, 2, 3, 9, 123, 1)
get_positive <- function(l) {

test_humaneval <- function() {
    candidate <- get_positive
    stopifnot(isTRUE(all.equal(candidate(c(-1, -2, 4, 5, 6)), c(4, 5, 6))))
    stopifnot(isTRUE(all.equal(candidate(c(5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10)), c(5, 3, 2, 3, 3, 9, 123, 1))))
    stopifnot(isTRUE(all.equal(candidate(c(-1, -2)), c())))
    stopifnot(isTRUE(all.equal(candidate(c()), c())))
}
test_humaneval()


Prompt:
# This function takes a list l and returns a list l' such that
# l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
# to the values of the corresponding indicies of l, but sorted.
# >>> sort_third(c(1, 2, 3))
# c(1, 2, 3)
# >>> sort_third(c(5, 6, 3, 4, 8, 9, 2))
# c(2, 6, 3, 4, 8, 9, 5)
sort_third <- function(l) {

test_humaneval <- function() {
    candidate <- sort_third
    stopifnot(isTRUE(all.equal(candidate(c(5, 6, 3, 4, 8, 9, 2)), c(2, 6, 3, 4, 8, 9, 5))))
    stopifnot(isTRUE(all.equal(candidate(c(5, 8, 3, 4, 6, 9, 2)), c(2, 8, 3, 4, 6, 9, 5))))
    stopifnot(isTRUE(all.equal(candidate(c(5, 6, 9, 4, 8, 3, 2)), c(2, 6, 9, 4, 8, 3, 5))))
    stopifnot(isTRUE(all.equal(candidate(c(5, 6, 3, 4, 8, 9, 2, 1)), c(2, 6, 3, 4, 8, 9, 5, 1))))
}
test_humaneval()


Prompt:
# Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
# For each of the group, output the deepest level of nesting of parentheses.
# E.g. (()()) has maximum two levels of nesting while ((())) has three.
# >>> parse_nested_parens('(()()) ((())) () ((())()())')
# c(2, 3, 1, 3)
parse_nested_parens <- function(paren_string) {

test_humaneval <- function() {
    candidate <- parse_nested_parens
    stopifnot(isTRUE(all.equal(candidate('(()()) ((())) () ((())()())'), c(2, 3, 1, 3))))
    stopifnot(isTRUE(all.equal(candidate('() (()) ((())) (((())))'), c(1, 2, 3, 4))))
    stopifnot(isTRUE(all.equal(candidate('(()(())((())))'), c(4))))
}
test_humaneval()


Prompt:
# Given length of a side and high return area for a triangle.
# >>> triangle_area(5, 3)
# 7.5
triangle_area <- function(a, h) {

test_humaneval <- function() {
    candidate <- triangle_area
    stopifnot(isTRUE(all.equal(candidate(5, 3), 7.5)))
    stopifnot(isTRUE(all.equal(candidate(2, 2), 2.0)))
    stopifnot(isTRUE(all.equal(candidate(10, 8), 40.0)))
}
test_humaneval()


Prompt:
# Complete the function that takes two integers and returns
# the product of their unit digits.
# Assume the input is always valid.
# Examples:
# >>> multiply(148, 412)
# 16
# >>> multiply(19, 28)
# 72
# >>> multiply(2020, 1851)
# 0
# >>> multiply(14, -15)
# 20
multiply <- function(a, b) {

test_humaneval <- function() {
    candidate <- multiply
    stopifnot(isTRUE(all.equal(candidate(148, 412), 16)))
    stopifnot(isTRUE(all.equal(candidate(19, 28), 72)))
    stopifnot(isTRUE(all.equal(candidate(2020, 1851), 0)))
    stopifnot(isTRUE(all.equal(candidate(14, -15), 20)))
    stopifnot(isTRUE(all.equal(candidate(76, 67), 42)))
    stopifnot(isTRUE(all.equal(candidate(17, 27), 49)))
    stopifnot(isTRUE(all.equal(candidate(0, 1), 0)))
    stopifnot(isTRUE(all.equal(candidate(0, 0), 0)))
}
test_humaneval()


Prompt:
# For a given list of input numbers, calculate Mean Absolute Deviation
# around the mean of this dataset.
# Mean Absolute Deviation is the average absolute difference between each
# element and a centerpoint (mean in this case):
# MAD = average | x - x_mean |
# >>> mean_absolute_deviation(c(1.0, 2.0, 3.0, 4.0))
# 1.0
mean_absolute_deviation <- function(numbers) {

test_humaneval <- function() {
    candidate <- mean_absolute_deviation
    stopifnot(isTRUE(all.equal(candidate(c(1.0, 2.0)), 0.5)))
    stopifnot(isTRUE(all.equal(candidate(c(1.0, 2.0, 3.0, 4.0)), 1.0)))
    stopifnot(isTRUE(all.equal(candidate(c(1.0, 2.0, 3.0, 4.0, 5.0)), 1.2)))
}
test_humaneval()


Prompt:
# Return sorted unique common elements for two lists.
# >>> common(c(1, 4, 3, 34, 653, 2, 5), c(5, 7, 1, 5, 9, 653, 121))
# c(1, 5, 653)
# >>> common(c(5, 3, 2, 8), c(3, 2))
# c(2, 3)
common <- function(l1, l2) {

test_humaneval <- function() {
    candidate <- common
    stopifnot(isTRUE(all.equal(candidate(c(1, 4, 3, 34, 653, 2, 5), c(5, 7, 1, 5, 9, 653, 121)), c(1, 5, 653))))
    stopifnot(isTRUE(all.equal(candidate(c(5, 3, 2, 8), c(3, 2)), c(2, 3))))
    stopifnot(isTRUE(all.equal(candidate(c(4, 3, 2, 8), c(3, 2, 4)), c(2, 3, 4))))
    stopifnot(isTRUE(all.equal(candidate(c(4, 3, 2, 8), c()), c())))
}
test_humaneval()


Prompt:
# Given a positive integer, obtain its roman numeral equivalent as a string,
# and return it in lowercase.
# Restrictions: 1 <= num <= 1000
# Examples:
# >>> int_to_mini_roman(19)
# 'xix'
# >>> int_to_mini_roman(152)
# 'clii'
# >>> int_to_mini_roman(426)
# 'cdxxvi'
int_to_mini_roman <- function(number) {

test_humaneval <- function() {
    candidate <- int_to_mini_roman
    stopifnot(isTRUE(all.equal(candidate(19), 'xix')))
    stopifnot(isTRUE(all.equal(candidate(152), 'clii')))
    stopifnot(isTRUE(all.equal(candidate(251), 'ccli')))
    stopifnot(isTRUE(all.equal(candidate(426), 'cdxxvi')))
    stopifnot(isTRUE(all.equal(candidate(500), 'd')))
    stopifnot(isTRUE(all.equal(candidate(1), 'i')))
    stopifnot(isTRUE(all.equal(candidate(4), 'iv')))
    stopifnot(isTRUE(all.equal(candidate(43), 'xliii')))
    stopifnot(isTRUE(all.equal(candidate(90), 'xc')))
    stopifnot(isTRUE(all.equal(candidate(94), 'xciv')))
    stopifnot(isTRUE(all.equal(candidate(532), 'dxxxii')))
    stopifnot(isTRUE(all.equal(candidate(900), 'cm')))
    stopifnot(isTRUE(all.equal(candidate(994), 'cmxciv')))
    stopifnot(isTRUE(all.equal(candidate(1000), 'm')))
}
test_humaneval()


Prompt:
# In this task, you will be given a string that represents a number of apples and oranges
# that are distributed in a basket of fruit this basket contains
# apples, oranges, and mango fruits. Given the string that represents the total number of
# the oranges and apples and an integer that represent the total number of the fruits
# in the basket return the number of the mango fruits in the basket.
# for examble:
# >>> fruit_distribution('5 apples and 6 oranges', 19)
# 8
# >>> fruit_distribution('0 apples and 1 oranges', 3)
# 2
# >>> fruit_distribution('2 apples and 3 oranges', 100)
# 95
# >>> fruit_distribution('100 apples and 1 oranges', 120)
# 19
fruit_distribution <- function(s, n) {

test_humaneval <- function() {
    candidate <- fruit_distribution
    stopifnot(isTRUE(all.equal(candidate('5 apples and 6 oranges', 19), 8)))
    stopifnot(isTRUE(all.equal(candidate('5 apples and 6 oranges', 21), 10)))
    stopifnot(isTRUE(all.equal(candidate('0 apples and 1 oranges', 3), 2)))
    stopifnot(isTRUE(all.equal(candidate('1 apples and 0 oranges', 3), 2)))
    stopifnot(isTRUE(all.equal(candidate('2 apples and 3 oranges', 100), 95)))
    stopifnot(isTRUE(all.equal(candidate('2 apples and 3 oranges', 5), 0)))
    stopifnot(isTRUE(all.equal(candidate('1 apples and 100 oranges', 120), 19)))
}
test_humaneval()


Prompt:
# 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 list containing the result string and TRUE/FALSE for the check.
# Example
# >>> reverse_delete('abcde', 'ae')
# list('bcd', FALSE)
# >>> reverse_delete('abcdef', 'b')
# list('acdef', FALSE)
# >>> reverse_delete('abcdedcba', 'ab')
# list('cdedc', TRUE)
reverse_delete <- function(s, c) {

test_humaneval <- function() {
    candidate <- reverse_delete
    stopifnot(isTRUE(all.equal(candidate('abcde', 'ae'), list('bcd', FALSE))))
    stopifnot(isTRUE(all.equal(candidate('abcdef', 'b'), list('acdef', FALSE))))
    stopifnot(isTRUE(all.equal(candidate('abcdedcba', 'ab'), list('cdedc', TRUE))))
    stopifnot(isTRUE(all.equal(candidate('dwik', 'w'), list('dik', FALSE))))
    stopifnot(isTRUE(all.equal(candidate('a', 'a'), list('', TRUE))))
    stopifnot(isTRUE(all.equal(candidate('abcdedcba', ''), list('abcdedcba', TRUE))))
    stopifnot(isTRUE(all.equal(candidate('abcdedcba', 'v'), list('abcdedcba', TRUE))))
    stopifnot(isTRUE(all.equal(candidate('vabba', 'v'), list('abba', TRUE))))
    stopifnot(isTRUE(all.equal(candidate('mamma', 'mia'), list('', TRUE))))
}
test_humaneval()


Prompt:
# Return a greatest common divisor of two integers a and b
# >>> greatest_common_divisor(3, 5)
# 1
# >>> greatest_common_divisor(25, 15)
# 5
greatest_common_divisor <- function(a, b) {

test_humaneval <- function() {
    candidate <- greatest_common_divisor
    stopifnot(isTRUE(all.equal(candidate(3, 7), 1)))
    stopifnot(isTRUE(all.equal(candidate(10, 15), 5)))
    stopifnot(isTRUE(all.equal(candidate(49, 14), 7)))
    stopifnot(isTRUE(all.equal(candidate(144, 60), 12)))
}
test_humaneval()


Prompt:
# 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
# Examples
# >>> split_words('Hello world!')
# c('Hello', 'world!')
# >>> split_words('Hello,world!')
# c('Hello', 'world!')
# >>> split_words('abcdef')
# 3
split_words <- function(txt) {

test_humaneval <- function() {
    candidate <- split_words
    stopifnot(isTRUE(all.equal(candidate('Hello world!'), c('Hello', 'world!'))))
    stopifnot(isTRUE(all.equal(candidate('Hello,world!'), c('Hello', 'world!'))))
    stopifnot(isTRUE(all.equal(candidate('Hello world,!'), c('Hello', 'world,!'))))
    stopifnot(isTRUE(all.equal(candidate('Hello,Hello,world !'), c('Hello,Hello,world', '!'))))
    stopifnot(isTRUE(all.equal(candidate('abcdef'), 3)))
    stopifnot(isTRUE(all.equal(candidate('aaabb'), 2)))
    stopifnot(isTRUE(all.equal(candidate('aaaBb'), 1)))
    stopifnot(isTRUE(all.equal(candidate(''), 0)))
}
test_humaneval()


Prompt:
# In this Kata, you have to sort a vector 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.
# It must be implemented like this:
# >>> sort_array(c(1, 5, 2, 3, 4))
# c(1, 2, 3, 4, 5)
# >>> sort_array(c(-2, -3, -4, -5, -6))
# c(-6, -5, -4, -3, -2)
# >>> sort_array(c(1, 0, 2, 3, 4))
# c(0, 1, 2, 3, 4)
sort_array <- function(arr) {

test_humaneval <- function() {
    candidate <- sort_array
    stopifnot(isTRUE(all.equal(candidate(c(1, 5, 2, 3, 4)), c(1, 2, 4, 3, 5))))
    stopifnot(isTRUE(all.equal(candidate(c(-2, -3, -4, -5, -6)), c(-4, -2, -6, -5, -3))))
    stopifnot(isTRUE(all.equal(candidate(c(1, 0, 2, 3, 4)), c(0, 1, 2, 4, 3))))
    stopifnot(isTRUE(all.equal(candidate(c()), c())))
    stopifnot(isTRUE(all.equal(candidate(c(2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4)), c(2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77))))
    stopifnot(isTRUE(all.equal(candidate(c(3, 6, 44, 12, 32, 5)), c(32, 3, 5, 6, 12, 44))))
    stopifnot(isTRUE(all.equal(candidate(c(2, 4, 8, 16, 32)), c(2, 4, 8, 16, 32))))
    stopifnot(isTRUE(all.equal(candidate(c(2, 4, 8, 16, 32)), c(2, 4, 8, 16, 32))))
}
test_humaneval()


Prompt:
# Concatenate list of strings into a single string
# >>> concatenate(c())
# ''
# >>> concatenate(c('a', 'b', 'c'))
# 'abc'
concatenate <- function(strings) {

test_humaneval <- function() {
    candidate <- concatenate
    stopifnot(isTRUE(all.equal(candidate(c()), '')))
    stopifnot(isTRUE(all.equal(candidate(c('x', 'y', 'z')), 'xyz')))
    stopifnot(isTRUE(all.equal(candidate(c('x', 'y', 'z', 'w', 'k')), 'xyzwk')))
}
test_humaneval()


Prompt:
# 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 a vector of numbers,
# and it may contain duplicates.
# The order of the list should be ascending by length of each word, and you
# should return the list sorted by that rule.
# If two words have the same length, sort the list alphabetically.
# The function should return a list of strings in sorted order.
# You may assume that all words will have the same length.
# For example:
# >>> list_sort(c('aa', 'a', 'aaa'))
# c('aa')
# >>> list_sort(c('ab', 'a', 'aaa', 'cd'))
# c('ab', 'cd')
sorted_list_sum <- function(lst) {

test_humaneval <- function() {
    candidate <- sorted_list_sum
    stopifnot(isTRUE(all.equal(candidate(c('aa', 'a', 'aaa')), c('aa'))))
    stopifnot(isTRUE(all.equal(candidate(c('school', 'AI', 'asdf', 'b')), c('AI', 'asdf', 'school'))))
    stopifnot(isTRUE(all.equal(candidate(c('d', 'b', 'c', 'a')), c())))
    stopifnot(isTRUE(all.equal(candidate(c('d', 'dcba', 'abcd', 'a')), c('abcd', 'dcba'))))
    stopifnot(isTRUE(all.equal(candidate(c('AI', 'ai', 'au')), c('AI', 'ai', 'au'))))
    stopifnot(isTRUE(all.equal(candidate(c('a', 'b', 'b', 'c', 'c', 'a')), c())))
    stopifnot(isTRUE(all.equal(candidate(c('aaaa', 'bbbb', 'dd', 'cc')), c('cc', 'dd', 'aaaa', 'bbbb'))))
}
test_humaneval()


Prompt:
# Filter an input list of strings only for ones that contain given substring
# >>> filter_by_substring(c(), 'a')
# c()
# >>> filter_by_substring(c('abc', 'bacd', 'cde', 'array'), 'a')
# c('abc', 'bacd', 'array')
filter_by_substring <- function(strings, substring) {

test_humaneval <- function() {
    candidate <- filter_by_substring
    stopifnot(isTRUE(all.equal(candidate(c(), 'john'), c())))
    stopifnot(isTRUE(all.equal(candidate(c('xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'), 'xxx'), c('xxx', 'xxxAAA', 'xxx'))))
    stopifnot(isTRUE(all.equal(candidate(c('xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'), 'xx'), c('xxx', 'aaaxxy', 'xxxAAA', 'xxx'))))
    stopifnot(isTRUE(all.equal(candidate(c('grunt', 'trumpet', 'prune', 'gruesome'), 'run'), c('grunt', 'prune'))))
}
test_humaneval()


Prompt:
# Create a function that takes a value (string) representing a number
# and returns the closest integer to it. If the number is equidistant
# from two integers, round it away from zero.
# Examples
# >>> closest_integer('10')
# 10
# >>> closest_integer('15.3')
# 15
# Note:
# Rounding away from zero means that if the given number is equidistant
# from two integers, the one you should return is the one that is the
# farthest from zero. For example closest_integer("14.5") should
# return 15 and closest_integer("-14.5") should return -15.
closest_integer <- function(value) {

test_humaneval <- function() {
    candidate <- closest_integer
    stopifnot(isTRUE(all.equal(candidate('10'), 10)))
    stopifnot(isTRUE(all.equal(candidate('14.5'), 15)))
    stopifnot(isTRUE(all.equal(candidate('-15.5'), -16)))
    stopifnot(isTRUE(all.equal(candidate('15.3'), 15)))
    stopifnot(isTRUE(all.equal(candidate('0'), 0)))
}
test_humaneval()


Prompt:
# Write a function vowels_count which takes a string representing
# a word as input and returns the number of vowels in the string.
# Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
# vowel, but only when it is at the end of the given word.
# Example:
# >>> vowels_count('abcde')
# 2
# >>> vowels_count('ACEDY')
# 3
vowels_count <- function(s) {

test_humaneval <- function() {
    candidate <- vowels_count
    stopifnot(isTRUE(all.equal(candidate('abcde'), 2)))
    stopifnot(isTRUE(all.equal(candidate('Alone'), 3)))
    stopifnot(isTRUE(all.equal(candidate('key'), 2)))
    stopifnot(isTRUE(all.equal(candidate('bye'), 1)))
    stopifnot(isTRUE(all.equal(candidate('keY'), 2)))
    stopifnot(isTRUE(all.equal(candidate('bYe'), 1)))
    stopifnot(isTRUE(all.equal(candidate('ACEDY'), 3)))
}
test_humaneval()


Prompt:
# 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.
# >>> find_max(c('name', 'of', 'string'))
# 'string'
# >>> find_max(c('name', 'enam', 'game'))
# 'enam'
# >>> find_max(c('aaaaaaa', 'bb', 'cc'))
# 'aaaaaaa'
find_max <- function(words) {

test_humaneval <- function() {
    candidate <- find_max
    stopifnot(isTRUE(all.equal(candidate(c('name', 'of', 'string')), 'string')))
    stopifnot(isTRUE(all.equal(candidate(c('name', 'enam', 'game')), 'enam')))
    stopifnot(isTRUE(all.equal(candidate(c('aaaaaaa', 'bb', 'cc')), 'aaaaaaa')))
    stopifnot(isTRUE(all.equal(candidate(c('abc', 'cba')), 'abc')))
    stopifnot(isTRUE(all.equal(candidate(c('play', 'this', 'game', 'of', 'footbott')), 'footbott')))
    stopifnot(isTRUE(all.equal(candidate(c('we', 'are', 'gonna', 'rock')), 'gonna')))
    stopifnot(isTRUE(all.equal(candidate(c('we', 'are', 'a', 'mad', 'nation')), 'nation')))
    stopifnot(isTRUE(all.equal(candidate(c('this', 'is', 'a', 'prrk')), 'this')))
    stopifnot(isTRUE(all.equal(candidate(c('b')), 'b')))
    stopifnot(isTRUE(all.equal(candidate(c('play', 'play', 'play')), 'play')))
}
test_humaneval()


Prompt:
# Given a string 'text', return its md5 hash equivalent string.
# If 'text' is an empty string, return NULL.
# >>> string_to_md5('Hello world')
# '3e25960a79dbc69b674cd4ec67a72c62'
string_to_md5 <- function(text) {

test_humaneval <- function() {
    candidate <- string_to_md5
    stopifnot(isTRUE(all.equal(candidate('Hello world'), '3e25960a79dbc69b674cd4ec67a72c62')))
    stopifnot(isTRUE(all.equal(candidate(''), NULL)))
    stopifnot(isTRUE(all.equal(candidate('A B C'), '0ef78513b0cb8cef12743f5aeb35f888')))
    stopifnot(isTRUE(all.equal(candidate('password'), '5f4dcc3b5aa765d61d8327deb882cf99')))
}
test_humaneval()


Prompt:
# Change numerical base of input number x to base.
# return string representation after the conversion.
# base numbers are less than 10.
# >>> change_base(8, 3)
# '22'
# >>> change_base(8, 2)
# '1000'
# >>> change_base(7, 2)
# '111'
change_base <- function(x, base) {

test_humaneval <- function() {
    candidate <- change_base
    stopifnot(isTRUE(all.equal(candidate(8, 3), '22')))
    stopifnot(isTRUE(all.equal(candidate(9, 3), '100')))
    stopifnot(isTRUE(all.equal(candidate(234, 2), '11101010')))
    stopifnot(isTRUE(all.equal(candidate(16, 2), '10000')))
    stopifnot(isTRUE(all.equal(candidate(8, 2), '1000')))
    stopifnot(isTRUE(all.equal(candidate(7, 2), '111')))
    stopifnot(isTRUE(all.equal(candidate(2, 3), '2')))
    stopifnot(isTRUE(all.equal(candidate(3, 4), '3')))
    stopifnot(isTRUE(all.equal(candidate(4, 5), '4')))
    stopifnot(isTRUE(all.equal(candidate(5, 6), '5')))
    stopifnot(isTRUE(all.equal(candidate(6, 7), '6')))
    stopifnot(isTRUE(all.equal(candidate(7, 8), '7')))
}
test_humaneval()


Prompt:
# 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.
# Example:
# >>> right_angle_triangle(3, 4, 5)
# TRUE
# >>> right_angle_triangle(1, 2, 3)
# FALSE
right_angle_triangle <- function(a, b, c) {

test_humaneval <- function() {
    candidate <- right_angle_triangle
    stopifnot(isTRUE(all.equal(candidate(3, 4, 5), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(1, 2, 3), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(10, 6, 8), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(2, 2, 2), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(7, 24, 25), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(10, 5, 7), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(5, 12, 13), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(15, 8, 17), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(48, 55, 73), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(1, 1, 1), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(2, 2, 10), FALSE)))
}
test_humaneval()


Prompt:
# It is the last week of the semester and the teacher has to give the grades
# to students. The teacher has been making her own algorithm for grading.
# The only problem is, she has lost the code she used for grading.
# She has given you a list of GPAs for some students and you have to write
# a function that can output a list of letter grades using the following table:
# GPA       |    Letter grade
# 4.0                A+
# > 3.7                A
# > 3.3                A-
# > 3.0                B+
# > 2.7                B
# > 2.3                B-
# > 2.0                C+
# > 1.7                C
# > 1.3                C-
# > 1.0                D+
# > 0.7                D
# > 0.0                D-
# 0.0                E
# Example:
# >>> grade_equation(c(4.0, 3, 1.7, 2, 3.5))
# c('A+', 'B', 'C-', 'C', 'A-')
numerical_letter_grade <- function(grades) {

test_humaneval <- function() {
    candidate <- numerical_letter_grade
    stopifnot(isTRUE(all.equal(candidate(c(4.0, 3, 1.7, 2, 3.5)), c('A+', 'B', 'C-', 'C', 'A-'))))
    stopifnot(isTRUE(all.equal(candidate(c(1.2)), c('D+'))))
    stopifnot(isTRUE(all.equal(candidate(c(0.5)), c('D-'))))
    stopifnot(isTRUE(all.equal(candidate(c(0.0)), c('E'))))
    stopifnot(isTRUE(all.equal(candidate(c(1.0, 0.3, 1.5, 2.8, 3.3)), c('D', 'D-', 'C-', 'B', 'B+'))))
    stopifnot(isTRUE(all.equal(candidate(c(0.0, 0.7)), c('E', 'D-'))))
}
test_humaneval()


Prompt:
# Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
# >>> intersperse(c(), 4)
# c()
# >>> intersperse(c(1, 2, 3), 4)
# c(1, 4, 2, 4, 3)
intersperse <- function(numbers, delimeter) {

test_humaneval <- function() {
    candidate <- intersperse
    stopifnot(isTRUE(all.equal(candidate(c(), 7), c())))
    stopifnot(isTRUE(all.equal(candidate(c(5, 6, 3, 2), 8), c(5, 8, 6, 8, 3, 8, 2))))
    stopifnot(isTRUE(all.equal(candidate(c(2, 2, 2), 2), c(2, 2, 2, 2, 2))))
}
test_humaneval()


Prompt:
# Write a function that takes a vector of numbers as input and returns
# the number of elements in the vector that are greater than 10 and both
# first and last digits of a number are odd (1, 3, 5, 7, 9).
# For example:
# >>> specialFilter(c(15, -73, 14, -15))
# 1
# >>> specialFilter(c(33, -2, -3, 45, 21, 109))
# 2
specialFilter <- function(nums) {

test_humaneval <- function() {
    candidate <- specialFilter
    stopifnot(isTRUE(all.equal(candidate(c(5, -2, 1, -5)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c(15, -73, 14, -15)), 1)))
    stopifnot(isTRUE(all.equal(candidate(c(33, -2, -3, 45, 21, 109)), 2)))
    stopifnot(isTRUE(all.equal(candidate(c(43, -12, 93, 125, 121, 109)), 4)))
    stopifnot(isTRUE(all.equal(candidate(c(71, -2, -33, 75, 21, 19)), 3)))
    stopifnot(isTRUE(all.equal(candidate(c(1)), 0)))
    stopifnot(isTRUE(all.equal(candidate(c()), 0)))
}
test_humaneval()


Prompt:
# sum_to_n is a function that sums numbers from 1 to n.
# >>> sum_to_n(30)
# 465
# >>> sum_to_n(100)
# 5050
# >>> sum_to_n(5)
# 15
# >>> sum_to_n(10)
# 55
# >>> sum_to_n(1)
# 1
sum_to_n <- function(n) {

test_humaneval <- function() {
    candidate <- sum_to_n
    stopifnot(isTRUE(all.equal(candidate(1), 1)))
    stopifnot(isTRUE(all.equal(candidate(6), 21)))
    stopifnot(isTRUE(all.equal(candidate(11), 66)))
    stopifnot(isTRUE(all.equal(candidate(30), 465)))
    stopifnot(isTRUE(all.equal(candidate(100), 5050)))
}
test_humaneval()


Prompt:
# From a list of integers, remove all elements that occur more than once.
# Keep order of elements left the same as in the input.
# >>> remove_duplicates(c(1, 2, 3, 2, 4))
# c(1, 3, 4)
remove_duplicates <- function(numbers) {

test_humaneval <- function() {
    candidate <- remove_duplicates
    stopifnot(isTRUE(all.equal(candidate(c()), c())))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3, 4)), c(1, 2, 3, 4))))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3, 2, 4, 3, 5)), c(1, 4, 5))))
}
test_humaneval()


Prompt:
# Given two positive integers a and b, return the even digits between a
# and b, in ascending order.
# For example:
# >>> generate_integers(2, 8)
# c(2, 4, 6, 8)
# >>> generate_integers(8, 2)
# c(2, 4, 6, 8)
# >>> generate_integers(10, 14)
# c()
generate_integers <- function(a, b) {

test_humaneval <- function() {
    candidate <- generate_integers
    stopifnot(isTRUE(all.equal(candidate(2, 10), c(2, 4, 6, 8))))
    stopifnot(isTRUE(all.equal(candidate(10, 2), c(2, 4, 6, 8))))
    stopifnot(isTRUE(all.equal(candidate(132, 2), c(2, 4, 6, 8))))
    stopifnot(isTRUE(all.equal(candidate(17, 89), c())))
}
test_humaneval()


Prompt:
# From a given list of integers, generate a list of rolling maximum element found until given moment
# in the sequence.
# >>> rolling_max(c(1, 2, 3, 2, 3, 4, 2))
# c(1, 2, 3, 3, 3, 4, 4)
rolling_max <- function(numbers) {

test_humaneval <- function() {
    candidate <- rolling_max
    stopifnot(isTRUE(all.equal(candidate(c()), c())))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, 3, 4)), c(1, 2, 3, 4))))
    stopifnot(isTRUE(all.equal(candidate(c(4, 3, 2, 1)), c(4, 4, 4, 4))))
    stopifnot(isTRUE(all.equal(candidate(c(3, 2, 3, 100, 3)), c(3, 3, 3, 100, 100))))
}
test_humaneval()


Prompt:
# You're given a list of deposit and withdrawal operations on a bank account that starts with
# zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
# at that point function should return TRUE. Otherwise it should return FALSE.
# >>> below_zero(c(1, 2, 3))
# FALSE
# >>> below_zero(c(1, 2, -4, 5))
# TRUE
below_zero <- function(operations) {

test_humaneval <- function() {
    candidate <- below_zero
    stopifnot(isTRUE(all.equal(candidate(c()), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, -3, 1, 2, -3)), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, 2, -4, 5, 6)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, -1, 2, -2, 5, -5, 4, -4)), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, -1, 2, -2, 5, -5, 4, -5)), TRUE)))
    stopifnot(isTRUE(all.equal(candidate(c(1, -2, 2, -2, 5, -5, 4, -4)), TRUE)))
}
test_humaneval()


Prompt:
# You are given a non-empty list of positive integers. Return the greatest integer that is greater than
# zero, and has a frequency greater than or equal to the value of the integer itself.
# The frequency of an integer is the number of times it appears in the list.
# If no such a value exist, return -1.
# Examples:
# >>> search(c(4, 1, 2, 2, 3, 1))
# 2
# >>> search(c(1, 2, 2, 3, 3, 3, 4, 4, 4))
# 3
# >>> search(c(5, 5, 4, 4, 4))
# -1
search <- function(lst) {


Prompt:
# brackets is a string of "(" and ")".
# return TRUE if every opening bracket has a corresponding closing bracket.
# >>> correct_bracketing('(')
# FALSE
# >>> correct_bracketing('()')
# TRUE
# >>> correct_bracketing('(()())')
# TRUE
# >>> correct_bracketing(')(()')
# FALSE
correct_bracketing <- function(brackets) {

test_humaneval <- function() {
    candidate <- correct_bracketing
    stopifnot(isTRUE(all.equal(candidate('()'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('(()())'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('()()(()())()'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('()()((()()())())(()()(()))'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('((()())))'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(')(()'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('('), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('(((('), FALSE)))
    stopifnot(isTRUE(all.equal(candidate(')'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('(()'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('()()(()())())(()'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('()()(()())()))()'), FALSE)))
}
test_humaneval()


Prompt:
# This function takes a list l and returns a list l' such that
# l' is identical to l in the odd indicies, while its values at the even indicies are equal
# to the values of the even indicies of l, but sorted.
# >>> sort_even(c(1, 2, 3))
# c(1, 2, 3)
# >>> sort_even(c(5, 6, 3, 4))
# c(3, 6, 5, 4)
sort_even <- function(l) {


Prompt:
# Check if two words have the same characters.
# >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc')
# TRUE
# >>> same_chars('abcd', 'dddddddabc')
# TRUE
# >>> same_chars('dddddddabc', 'abcd')
# TRUE
# >>> same_chars('eabcd', 'dddddddabc')
# FALSE
# >>> same_chars('abcd', 'dddddddabce')
# FALSE
# >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc')
# FALSE
same_chars <- function(s0, s1) {

test_humaneval <- function() {
    candidate <- same_chars
    stopifnot(isTRUE(all.equal(candidate('eabcdzzzz', 'dddzzzzzzzddeddabc'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('abcd', 'dddddddabc'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('dddddddabc', 'abcd'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('eabcd', 'dddddddabc'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('abcd', 'dddddddabcf'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('eabcdzzzz', 'dddzzzzzzzddddabc'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('aabb', 'aaccc'), FALSE)))
}
test_humaneval()


Prompt:
# brackets is a string of "<" and ">".
# return TRUE if every opening bracket has a corresponding closing bracket.
# >>> correct_bracketing('<')
# FALSE
# >>> correct_bracketing('<>')
# TRUE
# >>> correct_bracketing('<<><>>')
# TRUE
# >>> correct_bracketing('><<>')
# FALSE
correct_bracketing <- function(brackets) {

test_humaneval <- function() {
    candidate <- correct_bracketing
    stopifnot(isTRUE(all.equal(candidate('<>'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('<<><>>'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('<><><<><>><>'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('<><><<<><><>><>><<><><<>>>'), TRUE)))
    stopifnot(isTRUE(all.equal(candidate('<<<><>>>>'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('><<>'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('<'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('<<<<'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('>'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('<<>'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('<><><<><>><>><<>'), FALSE)))
    stopifnot(isTRUE(all.equal(candidate('<><><<><>><>>><>'), FALSE)))
}
test_humaneval()