task_id
stringlengths
2
30
buggy_code
stringlengths
137
2.23k
fixed_code
stringlengths
137
2.23k
unit_tests
stringlengths
549
3.38M
hex_key
package humaneval.buggy; public class HEX_KEY { public static int hex_key(String num) { int result = 0; for (char c : num.toCharArray()) { if (c == '2' || c == '3' || c == '5' || c == '7') result += 1; } return result; } }
package humaneval.buggy; // 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...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_HEX_KEY { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.HEX_KEY.hex_key("AB"); org.junit.A...
rescale_to_unit
package humaneval.buggy; public class RESCALE_TO_UNIT { public static double[] rescale_to_unit(double[] numbers){ double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (int i = 0; i < numbers.length; i += 1) { if (numbers[i] > max) { max = numbers[i]...
package humaneval.buggy; public class RESCALE_TO_UNIT { public static double[] rescale_to_unit(double[] numbers){ double min = Double.MAX_VALUE; double max = Double.MIN_VALUE; for (int i = 0; i < numbers.length; i += 1) { if (numbers[i] > max) { max = numbers[i]...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_RESCALE_TO_UNIT { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { double[] result = humaneval.buggy.RESCALE_TO_UNIT.rescale_to_unit...
exchange
package humaneval.buggy; import java.util.ArrayList; /* * 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 exch...
package humaneval.buggy; import java.util.ArrayList; /* * 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 exch...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_EXCHANGE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> lst1 = new ArrayList<>(Arrays.asList(1,2,3,4)); ...
string_xor
package humaneval.buggy; public class STRING_XOR { public static String string_xor(String a, String b){ String result = ""; for (int i = 0; i < a.length(); i += 1){ if (a.charAt(i) == b.charAt(i)){ result += "0"; } } return result; } }
package humaneval.buggy; public class STRING_XOR { public static String string_xor(String a, String b){ String result = ""; for (int i = 0; i < a.length(); i += 1){ if (a.charAt(i) == b.charAt(i)){ result += "0"; } } return result; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_STRING_XOR { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.STRING_XOR.string_xor("111000", "101...
monotonic
package humaneval.buggy; import java.util.Arrays; // Return True is list elements are monotonically increasing or decreasing. // >>> monotonic([1, 2, 4, 20]) // True // >>> monotonic([1, 20, 4, 10]) // False // >>> monotonic([4, 1, 0, -10]) // True public class MONOTONIC { public static boolean monotonic(int[] l...
package humaneval.buggy; import java.util.Arrays; // Return True is list elements are monotonically increasing or decreasing. // >>> monotonic([1, 2, 4, 20]) // True // >>> monotonic([1, 20, 4, 10]) // False // >>> monotonic([4, 1, 0, -10]) // True public class MONOTONIC { public static boolean monotonic(int[] l...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MONOTONIC { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.MONOTONIC.monotonic( new...
is_multiply_prime
package humaneval.buggy; // 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 public class IS_MULTIPLY_PRIME { public static boolean is_prime(...
package humaneval.buggy; // 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 public class IS_MULTIPLY_PRIME { public static boolean is_prime(...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_IS_MULTIPLY_PRIME { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.IS_MULTIPLY_PRIME.is_multipl...
starts_one_ends
package humaneval.buggy; /* Given a positive integer n, return the count of the numbers of n-digit positive integers that start or end with 1. */ public class STARTS_ONE_ENDS { public static int starts_one_ends(int n) { if (n == 1) return 1; return (int) ((10 + 9) * Math.pow(10, n - 2)...
package humaneval.buggy; /* Given a positive integer n, return the count of the numbers of n-digit positive integers that start or end with 1. */ public class STARTS_ONE_ENDS { public static int starts_one_ends(int n) { if (n == 1) return 1; return (int) ((10 + 9) * Math.pow(10, n - 2)...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_STARTS_ONE_ENDS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.STARTS_ONE_ENDS.starts_one_ends(1); ...
factorial
package humaneval.buggy; import java.util.ArrayList; /* * 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...
package humaneval.buggy; import java.util.ArrayList; /* * 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...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FACTORIAL { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> result = humaneval.buggy.FACTORIAL.factorial(5); ...
multiply
package humaneval.buggy; // 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) should return 16. // multiply(19, 28) should return 72. // multiply(2020, 1851) should return 0. // multiply(14,-15) should...
package humaneval.buggy; // 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) should return 16. // multiply(19, 28) should return 72. // multiply(2020, 1851) should return 0. // multiply(14,-15) should...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MULTIPLY { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.MULTIPLY.multiply(148, 412); org....
pairs_sum_to_zero
package humaneval.buggy; import java.util.List; /* pairs_sum_to_zero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. */ public class PAIRS_SUM_TO_ZERO { public static boolean pairs_sum_to_zero(List<Integer> l) { f...
package humaneval.buggy; import java.util.List; /* pairs_sum_to_zero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. */ public class PAIRS_SUM_TO_ZERO { public static boolean pairs_sum_to_zero(List<Integer> l) { f...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_PAIRS_SUM_TO_ZERO { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.PAIRS_SUM_TO_ZERO.pairs_sum_...
digit_sum
package humaneval.buggy; /* Task Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. Examples: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abcCd") => 67 digitSum("helloE") => 69 digitSum("woArBld") => 131 digitSum("aAaaaXa") => 1...
package humaneval.buggy; /* Task Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. Examples: digitSum("") => 0 digitSum("abAB") => 131 digitSum("abcCd") => 67 digitSum("helloE") => 69 digitSum("woArBld") => 131 digitSum("aAaaaXa") => 1...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DIGIT_SUM { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.DIGIT_SUM.digit_sum(""); org.jun...
triples_sum_to_zero
package humaneval.buggy; /* triples_sum_to_zero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> triples_sum_to_zero([1, 3, 5, 0]) False >>> triples_sum_to_zero([1, 3, -2, 1]) True >>> triples_sum_to_zero([1, 2, 3, 7]) F...
package humaneval.buggy; /* triples_sum_to_zero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. >>> triples_sum_to_zero([1, 3, 5, 0]) False >>> triples_sum_to_zero([1, 3, -2, 1]) True >>> triples_sum_to_zero([1, 2, 3, 7]) F...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_TRIPLES_SUM_TO_ZERO { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.TRIPLES_SUM_TO_ZERO.triple...
prime_length
package humaneval.buggy; /* Write a function that takes a string and returns True if the string length is a prime number or False otherwise Examples prime_length('Hello') == True prime_length('abcdcba') == True prime_length('kittens') == True prime_length('orange') == False */ public class PRIME_LENGTH { public s...
package humaneval.buggy; /* Write a function that takes a string and returns True if the string length is a prime number or False otherwise Examples prime_length('Hello') == True prime_length('abcdcba') == True prime_length('kittens') == True prime_length('orange') == False */ public class PRIME_LENGTH { public s...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_PRIME_LENGTH { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.PRIME_LENGTH.prime_length("Hello"...
incr_list
package humaneval.buggy; import java.util.ArrayList; import java.util.List; /* Return list with elements incremented by 1. >>> incr_list([1, 2, 3]) [2, 3, 4] >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123]) [6, 4, 6, 3, 4, 4, 10, 1, 124] */ public class INCR_LIST { public static List<Integer> incr_list(List<Integer>...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; /* Return list with elements incremented by 1. >>> incr_list([1, 2, 3]) [2, 3, 4] >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123]) [6, 4, 6, 3, 4, 4, 10, 1, 124] */ public class INCR_LIST { public static List<Integer> incr_list(List<Integer>...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_INCR_LIST { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.INCR_LIST.incr_list( ...
maximum_k
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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. Example 1: Input: arr = [-3, -4, 5], k = 3 Output: [-4, -3, 5] Example 2...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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. Example 1: Input: arr = [-3, -4, 5], k = 3 Output: [-4, -3, 5] Example 2...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MAXIMUM_K { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> input = new ArrayList<>(Arrays.asList(-3,-4,5)); ...
is_bored
package humaneval.buggy; /* You'll be given a string of words, and your task is to count the number of boredoms. A boredom is a sentence that starts with the word "I". Sentences are delimited by '.', '?' or '!'. For example: >>> is_bored("Hello world") 0 >>> is_bored("The sky is blue. The sun is shining. I love this ...
package humaneval.buggy; /* You'll be given a string of words, and your task is to count the number of boredoms. A boredom is a sentence that starts with the word "I". Sentences are delimited by '.', '?' or '!'. For example: >>> is_bored("Hello world") 0 >>> is_bored("The sky is blue. The sun is shining. I love this ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_IS_BORED { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.IS_BORED.is_bored("Hello world"); ...
decode_shift
package humaneval.buggy; /* encode_shift(): returns encoded string by shifting every character by 5 in the alphabet. decode_shift(): takes as input string encoded with encode_shift function. Returns decoded string. */ public class DECODE_SHIFT { public static String encode_shift(String string){ StringBuil...
package humaneval.buggy; /* encode_shift(): returns encoded string by shifting every character by 5 in the alphabet. decode_shift(): takes as input string encoded with encode_shift function. Returns decoded string. */ public class DECODE_SHIFT { public static String encode_shift(String string){ StringBuil...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DECODE_SHIFT { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String input = "tantywccpjkimslotpzs"; String result = hum...
sum_to_n
package humaneval.buggy; /* 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 */ public class SUM_TO_N { public static int sum_to_n(int n) { return (n + 1) * (n / 2); } }
package humaneval.buggy; /* 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 */ public class SUM_TO_N { public static int sum_to_n(int n) { return (n + 1) * (n / 2); } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SUM_TO_N { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.SUM_TO_N.sum_to_n(1); org.junit.Ass...
by_length
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.Map; import java.util.HashMap; /* * 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 "On...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.Map; import java.util.HashMap; /* * 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 "On...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_BY_LENGTH { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> input = new ArrayList<>(Arrays.asList(2,1,1,4,5,8,2,3...
has_close_elements
package humaneval.buggy; import java.util.List; public class HAS_CLOSE_ELEMENTS { public static boolean has_close_elements(List<Double> numbers, double threshold){ for (int i = 0; i < numbers.size(); i += 1){ for (int j = i + 1; j < numbers.size(); j += 1){ double distance = nu...
package humaneval.buggy; import java.util.List; public class HAS_CLOSE_ELEMENTS { public static boolean has_close_elements(List<Double> numbers, double threshold){ for (int i = 0; i < numbers.size(); i += 1){ for (int j = i + 1; j < numbers.size(); j += 1){ double distance = nu...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_HAS_CLOSE_ELEMENTS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.HAS_CLOSE_ELEMENTS.has_clos...
unique
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class UNIQUE { public static List<Integer> unique(List<Integer> l) { List<Integer> result = new ArrayList<Integer>(); for (Integer n : l){ result.add(n); } ...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class UNIQUE { public static List<Integer> unique(List<Integer> l) { List<Integer> result = new ArrayList<Integer>(); for (Integer n : l){ result.add(n); } ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_UNIQUE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.UNIQUE.unique( new Ar...
simplify
package humaneval.buggy; /* 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 numera...
package humaneval.buggy; /* 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 numera...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SIMPLIFY { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.SIMPLIFY.simplify("1/5", "5/1"); ...
string_sequence
package humaneval.buggy; public class STRING_SEQUENCE { public static String string_sequence(int n) { String result = ""; for (int i = 0; i <= n; i += 1){ result += i + " "; } return result; } }
package humaneval.buggy; public class STRING_SEQUENCE { public static String string_sequence(int n) { String result = ""; for (int i = 0; i <= n; i += 1){ result += i + " "; } return result; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_STRING_SEQUENCE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.STRING_SEQUENCE.string_sequence...
unique_digits
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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. For example: >>> unique_digits([15, 33, 1422, ...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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. For example: >>> unique_digits([15, 33, 1422, ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_UNIQUE_DIGITS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> input = new ArrayList<Integer>(Arrays.asList(1...
fruit_distribution
package humaneval.buggy; /* 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 repres...
package humaneval.buggy; /* 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 repres...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FRUIT_DISTRIBUTION { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.FRUIT_DISTRIBUTION.fruit_distri...
int_to_mini_roman
package humaneval.buggy; // 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' public class INT...
package humaneval.buggy; // 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' public class INT...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_INT_TO_MINI_ROMAN { @org.junit.Test(timeout = 3000) public void test() throws java.lang.Exception { int[] inputs = new int[] {43, 90, 94, 532, 900, 994, 1000}; ...
triangle_area
package humaneval.buggy; /* Given length of a side and high return area for a triangle. >>> triangle_area(5, 3) 7.5 */ public class TRIANGLE_AREA { public static double triangle_area(double a, double h) { return a * h; } }
package humaneval.buggy; /* Given length of a side and high return area for a triangle. >>> triangle_area(5, 3) 7.5 */ public class TRIANGLE_AREA { public static double triangle_area(double a, double h) { return a * h; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_TRIANGLE_AREA { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { double result = humaneval.buggy.TRIANGLE_AREA.triangle_area(5, 3)...
min_path
package humaneval.buggy; /* * 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 ca...
package humaneval.buggy; /* * 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 ca...
package humaneval; public class TEST_MIN_PATH { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { int[][] input = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int[] result = humaneval.buggy.MIN_PATH.min_path(input, 3); int[] desired = {1, 2, 1}; org.junit.A...
rounded_avg
package humaneval.buggy; /* * 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 (if the number ends in 0.5 round down) and convert that to binary. If n is greater than m, r...
package humaneval.buggy; /* * 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 (if the number ends in 0.5 round down) and convert that to binary. If n is greater than m, r...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_ROUNDED_AVG { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.ROUNDED_AVG.rounded_avg(1, 5); ...
sort_even
package humaneval.buggy; import java.util.Arrays; public class SORT_EVEN { public static int[] sort_even(int[] l) { int[] result = new int[l.length]; int[] evens = new int[1 + (int) (l.length / 2.)]; for (int i = 0; i < l.length; i += 2) { evens[(int) i / 2] = l[i]; } ...
package humaneval.buggy; import java.util.Arrays; public class SORT_EVEN { public static int[] sort_even(int[] l) { int[] result = new int[l.length]; int[] evens = new int[1 + (int) (l.length / 2.)]; for (int i = 0; i < l.length; i += 2) { evens[(int) i / 2] = l[i]; } ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SORT_EVEN { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int[] result = humaneval.buggy.SORT_EVEN.sort_even( new i...
get_row
package humaneval.buggy; import java.util.ArrayList; public class GET_ROW { public class Tuple{ int x; int y; public Tuple(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (o ins...
package humaneval.buggy; import java.util.ArrayList; public class GET_ROW { public class Tuple{ int x; int y; public Tuple(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (o ins...
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_GET_ROW { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { ArrayList<humaneval.buggy.GET_ROW.Tuple> result = humaneval.buggy.GET_ROW.get_row( new ArrayList<ArrayList<I...
iscube
package humaneval.buggy; import java.math.BigDecimal; import java.math.RoundingMode; // Write a function that takes an integer a and returns True // if this ingeger is a cube of some integer number. // Note: you may assume the input is always valid. // Examples: // iscube(1) ==> True // iscube(2) ==> False // iscube...
package humaneval.buggy; import java.math.BigDecimal; import java.math.RoundingMode; // Write a function that takes an integer a and returns True // if this ingeger is a cube of some integer number. // Note: you may assume the input is always valid. // Examples: // iscube(1) ==> True // iscube(2) ==> False // iscube...
package humaneval; public class TEST_ISCUBE { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.ISCUBE.iscude(1); org.junit.Assert.assertEquals( result, true ); } @org.junit.Test(timeout = 3000) pu...
longest
package humaneval.buggy; import java.util.List; public class LONGEST { public static String longest(List<String> strings){ int maxlen = 0; for (String string : strings){ if (strings.size() > string.length()){ maxlen = strings.size(); } } for ...
package humaneval.buggy; import java.util.List; public class LONGEST { public static String longest(List<String> strings){ int maxlen = 0; for (String string : strings){ if (strings.size() > string.length()){ maxlen = strings.size(); } } for ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_LONGEST { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.LONGEST.longest( new ArrayLis...
file_name_check
package humaneval.buggy; /* 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'-'...
package humaneval.buggy; /* 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'-'...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FILE_NAME_CHECK { @org.junit.Test(timeout = 3000) public void test() throws java.lang.Exception { String[] inputs = new String[] { "/this_is_valid.dll"...
check_if_last_char_is_a_letter
package humaneval.buggy; /* * 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. Examples: check_if_last_char_is_a_letter("apple pie") ...
package humaneval.buggy; /* * 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. Examples: check_if_last_char_is_a_letter("apple pie") ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CHECK_IF_LAST_CHAR_IS_A_LETTER { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { org.junit.Assert.assertEquals(false, humaneval.b...
sort_array_binary
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; /* * 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 decima...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; /* * 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 decima...
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_SORT_ARRAY_BINARY { @org.junit.Test(timeout=3000) public void test_0() throws java.lang.Exception { ArrayList<Integer> input = new ArrayList<>(Arrays.asList(1, 5, 2, 3, 4)); ArrayList<Integer> result = hu...
mean_absolute_deviation
package humaneval.buggy; import java.util.List; public class MEAN_ABSOLUTE_DEVIATION { public static double mean_absolute_deviation(List<Double> numbers) { double sum = 0.; for (Double number : numbers){ sum += number; } double mean = sum / numbers.size(); doubl...
package humaneval.buggy; import java.util.List; public class MEAN_ABSOLUTE_DEVIATION { public static double mean_absolute_deviation(List<Double> numbers) { double sum = 0.; for (Double number : numbers){ sum += number; } double mean = sum / numbers.size(); doubl...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MEAN_ABSOLUTE_DEVIATION { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { double result = humaneval.buggy.MEAN_ABSOLUTE_DEVIATION...
decimal_to_binary
package humaneval.buggy; // You will be given a number in decimal form and your task is to convert it to // binary format. The function should return a string, with each character representing a binary // number. Each character in the string will be '0' or '1'. // There will be an extra couple of characters 'db' at t...
package humaneval.buggy; // You will be given a number in decimal form and your task is to convert it to // binary format. The function should return a string, with each character representing a binary // number. Each character in the string will be '0' or '1'. // There will be an extra couple of characters 'db' at t...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DECIMAL_TO_BINARY { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.DECIMAL_TO_BINARY.decimal_to_...
special_factorial
package humaneval.buggy; /* * he Brazilian factorial is defined as: brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! where n > 0 For example: >>> special_factorial(4) 288 The function will receive an integer as input and should return the special factorial of this integer. */ ...
package humaneval.buggy; /* * he Brazilian factorial is defined as: brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! where n > 0 For example: >>> special_factorial(4) 288 The function will receive an integer as input and should return the special factorial of this integer. */ ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SPECIAL_FACTORIAL { @org.junit.Test(timeout = 1000) public void test_3() throws java.lang.Exception { org.junit.Assert.assertEquals(1, humaneval.buggy.SPECIAL_FACTOR...
encrypt
package humaneval.buggy; /* Create a function encrypt that takes a string as an argument and returns a string encrypted with the alphabet being rotated. The alphabet should be rotated in a manner such that the letters shift down by two multiplied to two places. For example: encrypt('hi') returns 'lm' encrypt('asdfgh...
package humaneval.buggy; /* Create a function encrypt that takes a string as an argument and returns a string encrypted with the alphabet being rotated. The alphabet should be rotated in a manner such that the letters shift down by two multiplied to two places. For example: encrypt('hi') returns 'lm' encrypt('asdfgh...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_ENCRYPT { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.ENCRYPT.encrypt("hi"); org.juni...
all_prefixes
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class ALL_PREFIXES { public static List<String> all_prefixes(String string){ List<String> result = new ArrayList<String>(); for (int i = 0; i < string.length(); i += 1){ result.add(string.substring(i + ...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class ALL_PREFIXES { public static List<String> all_prefixes(String string){ List<String> result = new ArrayList<String>(); for (int i = 0; i < string.length(); i += 1){ result.add(string.substring(i + ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_ALL_PREFIXES { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<String> result = humaneval.buggy.ALL_PREFIXES.all_prefixes(""...
generate_integers
package humaneval.buggy; import java.util.ArrayList; // Given two positive integers a and b, return the even digits between a // and b, in ascending order. // For example: // generate_integers(2, 8) => [2, 4, 6, 8] // generate_integers(8, 2) => [2, 4, 6, 8] // generate_integers(10, 14) => [] public class GENERATE_I...
package humaneval.buggy; import java.util.ArrayList; // Given two positive integers a and b, return the even digits between a // and b, in ascending order. // For example: // generate_integers(2, 8) => [2, 4, 6, 8] // generate_integers(8, 2) => [2, 4, 6, 8] // generate_integers(10, 14) => [] public class GENERATE_I...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GENERATE_INTEGERS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> result = humaneval.buggy.GENERATE_INTEGERS...
check_dict_case
package humaneval.buggy; import java.util.HashMap; // Given a dictionary, return True if all keys are strings in lower // case or all keys are strings in upper case, else return False. // The function should return False is the given dictionary is empty. // Examples: // check_dict_case({"a":"apple", "b":"banana"}) s...
package humaneval.buggy; import java.util.HashMap; // Given a dictionary, return True if all keys are strings in lower // case or all keys are strings in upper case, else return False. // The function should return False is the given dictionary is empty. // Examples: // check_dict_case({"a":"apple", "b":"banana"}) s...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CHECK_DICT_CASE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.CHECK_DICT_CASE.check_dict_cas...
solve_string
package humaneval.buggy; // 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. // Examples // solve("1234") = "4321" // solve("...
package humaneval.buggy; // 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. // Examples // solve("1234") = "4321" // solve("...
package humaneval; public class TEST_SOLVE_STRING { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.SOLVE_STRING.solve_string("AsDf"); org.junit.Assert.assertEquals( result, "aSdF" ); } @org.junit.Tes...
right_angle_triangle
package humaneval.buggy; // 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_ang...
package humaneval.buggy; // 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_ang...
package humaneval; public class TEST_RIGHT_ANGLE_TRIANGLE { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.RIGHT_ANGLE_TRIANGLE.right_angle_triangle(3, 4, 5); org.junit.Assert.assertEquals( result, true ); ...
greatest_common_divisor
package humaneval.buggy; public class GREATEST_COMMON_DIVISOR { public static int greatest_common_divisor(int a, int b){ while (b > 0) { a = b; b = a % b; } return a; } }
package humaneval.buggy; public class GREATEST_COMMON_DIVISOR { public static int greatest_common_divisor(int a, int b){ while (b > 0) { a = b; b = a % b; } return a; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GREATEST_COMMON_DIVISOR { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.GREATEST_COMMON_DIVISOR.gr...
largest_smallest_integers
package humaneval.buggy; /* * 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 0. Examples: largest_smallest_integers([2, 4, 1, 3, 5, 7...
package humaneval.buggy; /* * 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 0. Examples: largest_smallest_integers([2, 4, 1, 3, 5, 7...
package humaneval; public class TEST_LARGEST_SMALLEST_INTEGERS { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { int[] input = {2, 4, 1, 3, 5, 7}; int[] result = {0, 1}; org.junit.Assert.assertArrayEquals(result, humaneval.buggy.LARGEST_SMALLEST_INTEGER...
fibfib
package humaneval.buggy; /* The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). Please write a function to efficiently compute the n-th element of the fibfib number sequ...
package humaneval.buggy; /* The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). Please write a function to efficiently compute the n-th element of the fibfib number sequ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FIBFIB { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.FIBFIB.fibfib(2); org.junit.Assert....
fib4
package humaneval.buggy; import java.util.ArrayList; /* The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). Please write a function to efficiently compute the ...
package humaneval.buggy; import java.util.ArrayList; /* The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). Please write a function to efficiently compute the ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FIB4 { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.FIB4.fib4(5); org.junit.Assert.assert...
compare
package humaneval.buggy; /* 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...
package humaneval.buggy; /* 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...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_COMPARE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int[] result = humaneval.buggy.COMPARE.compare( new int[] {1...
count_distinct_characters
package humaneval.buggy; import java.util.HashSet; public class COUNT_DISTINCT_CHARACTERS { public static int count_distinct_characters(String string) { HashSet<Character> distinct = new HashSet<Character>(); for (char c : string.toCharArray()) { if (! distinct.contains(Character.toLo...
package humaneval.buggy; import java.util.HashSet; public class COUNT_DISTINCT_CHARACTERS { public static int count_distinct_characters(String string) { HashSet<Character> distinct = new HashSet<Character>(); for (char c : string.toCharArray()) { if (! distinct.contains(Character.toLo...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_COUNT_DISTINCT_CHARACTERS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.COUNT_DISTINCT_CHARACTER...
search
package humaneval.buggy; /* 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, re...
package humaneval.buggy; /* 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, re...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SEARCH { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.SEARCH.search( new int[] {5,5,5...
anti_shuffle
package humaneval.buggy; import java.util.Arrays; /* Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where all the characters arranged in ascending order based on ascii value. Note: You sh...
package humaneval.buggy; import java.util.Arrays; /* Write a function that takes a string and returns an ordered version of it. Ordered version of string, is a string where all words (separated by space) are replaced by a new word where all the characters arranged in ascending order based on ascii value. Note: You sh...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_ANTI_SHUFFLE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.ANTI_SHUFFLE.anti_shuffle("Hi"); ...
sorted_list_sum
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* 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...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* 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...
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_SORTED_LIST_SUM { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { ArrayList<String> result = humaneval.buggy.SORTED_LIST_SUM.sorted_list_sum( new ArrayList<String>(Ar...
prime_fib
package humaneval.buggy; import java.util.ArrayList; public class PRIME_FIB { public static boolean is_prime(int n) { if (n < 2) return false; for (int i = 2; i < (int)Math.sqrt(n) + 1; i += 1){ if (n % i == 0) return false; } return true; ...
package humaneval.buggy; import java.util.ArrayList; public class PRIME_FIB { public static boolean is_prime(int n) { if (n < 2) return false; for (int i = 2; i < (int)Math.sqrt(n) + 1; i += 1){ if (n % i == 0) return false; } return true; ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_PRIME_FIB { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.PRIME_FIB.prime_fib(1); org.junit....
find_zero
package humaneval.buggy; import java.util.List; public class FIND_ZERO { public static double poly(List<Double> xs, double x) { double sum = 0; for (int i = 0; i < xs.size(); i += 1){ sum += xs.get(i) * Math.pow(x, i); } return sum; } public static double find_...
package humaneval.buggy; import java.util.List; public class FIND_ZERO { public static double poly(List<Double> xs, double x) { double sum = 0; for (int i = 0; i < xs.size(); i += 1){ sum += xs.get(i) * Math.pow(x, i); } return sum; } public static double find_...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FIND_ZERO { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Double> xs = new ArrayList<Double>(Arrays.asList(-10d,-2d)); ...
choose_num
package humaneval.buggy; /* 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 */ publi...
package humaneval.buggy; /* 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 */ publi...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CHOOSE_NUM { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.CHOOSE_NUM.choose_num(12, 15); org...
cycpattern_check
package humaneval.buggy; // 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") =...
package humaneval.buggy; // 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") =...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CYCPATTERN_CHECK { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.CYCPATTERN_CHECK.cycpattern_c...
x_or_y
package humaneval.buggy; /* A simple program which should return the value of x if n is a prime number and should return the value of y otherwise. Examples: for x_or_y(7, 34, 12) == 34 for x_or_y(15, 8, 5) == 5 */ public class X_OR_Y { public static int x_or_y(int n, int x, int y) { if (n == 1) return y...
package humaneval.buggy; /* A simple program which should return the value of x if n is a prime number and should return the value of y otherwise. Examples: for x_or_y(7, 34, 12) == 34 for x_or_y(15, 8, 5) == 5 */ public class X_OR_Y { public static int x_or_y(int n, int x, int y) { if (n == 1) return y...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_X_OR_Y { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.X_OR_Y.x_or_y(7,34,12); org.junit.Ass...
derivative
package humaneval.buggy; import java.util.ArrayList; import java.util.List; /* xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> derivative([3, 1, 2, 4, 5]) [1, 4, 12, 20] >>> derivative([1, 2, 3]) [2, 6] */ public class D...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; /* xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. >>> derivative([3, 1, 2, 4, 5]) [1, 4, 12, 20] >>> derivative([1, 2, 3]) [2, 6] */ public class D...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DERIVATIVE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.DERIVATIVE.derivative( ...
get_closet_vowel
package humaneval.buggy; import java.util.ArrayList; import java.util.Arrays; /* * 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 y...
package humaneval.buggy; import java.util.ArrayList; import java.util.Arrays; /* * 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 y...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GET_CLOSET_VOWEL { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.GET_CLOSET_VOWEL.get_closet_vo...
digits
package humaneval.buggy; /* * Given a positive integer n, return the product of the odd digits. Return 0 if all digits are even. For example: digits(1) == 1 digits(4) == 0 digits(235) == 15 */ public class DIGITS { public static int digits(int n) { int product = 1; int odd_...
package humaneval.buggy; /* * Given a positive integer n, return the product of the odd digits. Return 0 if all digits are even. For example: digits(1) == 1 digits(4) == 0 digits(235) == 15 */ public class DIGITS { public static int digits(int n) { int product = 1; int odd_...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DIGITS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { org.junit.Assert.assertEquals(5, humaneval.buggy.DIGITS.digits(5)); ...
is_equal_to_sum_even
package humaneval.buggy; /* * Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers Example is_equal_to_sum_even(4) == False is_equal_to_sum_even(6) == False is_equal_to_sum_even(8) == True */ public class IS_EQUAL_TO_SUM_EVEN { public static boolean i...
package humaneval.buggy; /* * Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers Example is_equal_to_sum_even(4) == False is_equal_to_sum_even(6) == False is_equal_to_sum_even(8) == True */ public class IS_EQUAL_TO_SUM_EVEN { public static boolean i...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_IS_EQUAL_TO_SUM_EVEN { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { org.junit.Assert.assertEquals(false, humaneval.buggy.IS_EQ...
fix_spaces
package humaneval.buggy; /* 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 - fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Example_1" fix_spaces(" Example 2") == "_Example_2" fix_spaces(" ...
package humaneval.buggy; /* 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 - fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Example_1" fix_spaces(" Example 2") == "_Example_2" fix_spaces(" ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FIX_SPACES { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.FIX_SPACES.fix_spaces( "...
make_a_pile
package humaneval.buggy; import java.util.ArrayList; /* * 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 sto...
package humaneval.buggy; import java.util.ArrayList; /* * 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 sto...
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_MAKE_A_PILE { @org.junit.Test(timeout=3000) public void test_0() throws java.lang.Exception { ArrayList<Integer> result = humaneval.buggy.MAKE_A_PILE.make_a_pile(3); ArrayList<Integer> desired = new ArrayList<Integer>(Arra...
numerical_letter_grade
package humaneval.buggy; // 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 wri...
package humaneval.buggy; // 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 wri...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_NUMERICAL_LETTER_GRADE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String[] result = humaneval.buggy.NUMERICAL_LETTER_GRADE...
fizz_buzz
package humaneval.buggy; public class FIZZ_BUZZ { public static int fizz_buzz(int n) { int result = 0; for (int i = 0; i < n; i += 1){ if (i % 11 == 0 || i % 13 == 0) { for (int j = 0; j < i + "".length(); j += 1){ if (i + "".substring(j, j + 1) == "...
package humaneval.buggy; public class FIZZ_BUZZ { public static int fizz_buzz(int n) { int result = 0; for (int i = 0; i < n; i += 1){ if (i % 11 == 0 || i % 13 == 0) { for (int j = 0; j < i + "".length(); j += 1){ if (i + "".substring(j, j + 1) == "...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FIZZ_BUZZ { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.FIZZ_BUZZ.fizz_buzz(50); org.jun...
common
package humaneval.buggy; import java.util.*; // Return sorted unique common elements for two lists. // >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) // [1, 5, 653] // >>> common([5, 3, 2, 8], [3, 2]) // [2, 3] public class COMMON { public static int[] common(int[] l1, int[] l2) { ArrayL...
package humaneval.buggy; import java.util.*; // Return sorted unique common elements for two lists. // >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) // [1, 5, 653] // >>> common([5, 3, 2, 8], [3, 2]) // [2, 3] public class COMMON { public static int[] common(int[] l1, int[] l2) { ArrayL...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_COMMON { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int[] result = humaneval.buggy.COMMON.common( new int[] {1,4...
filter_by_prefix
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class FILTER_BY_PREFIX { public static List<String> filter_by_prefix(List<String> strings, String prefix) { List<String> result = new ArrayList<String>(); for (String string : strings){ if (string.start...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class FILTER_BY_PREFIX { public static List<String> filter_by_prefix(List<String> strings, String prefix) { List<String> result = new ArrayList<String>(); for (String string : strings){ if (string.start...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FILTER_BY_PREFIX { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<String> result = humaneval.buggy.FILTER_BY_PREFIX.filter_by...
words_in_sentence
package humaneval.buggy; /* 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 orig...
package humaneval.buggy; /* 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 orig...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_WORDS_IN_SENTENCE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.WORDS_IN_SENTENCE.words_in_se...
sum_squares
package humaneval.buggy; /* 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 lis...
package humaneval.buggy; /* 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 lis...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SUM_SQUARES { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.SUM_SQUARES.sum_squares(new int[] {1,2,3...
intersperse
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class INTERSPERSE { public static List<Integer> intersperse(List<Integer> numbers, int delimeter) { List<Integer> result = new ArrayList<Integer>(); if (numbers.size() == 0) return result; ...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class INTERSPERSE { public static List<Integer> intersperse(List<Integer> numbers, int delimeter) { List<Integer> result = new ArrayList<Integer>(); if (numbers.size() == 0) return result; ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_INTERSPERSE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.INTERSPERSE.intersperse( ...
get_positive
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class GET_POSITIVE { public static List<Integer> get_positive(List<Integer> numbers) { List<Integer> result = new ArrayList<Integer>(); for (Integer number : numbers) { result.add(number); } ...
package humaneval.buggy; import java.util.ArrayList; import java.util.List; public class GET_POSITIVE { public static List<Integer> get_positive(List<Integer> numbers) { List<Integer> result = new ArrayList<Integer>(); for (Integer number : numbers) { result.add(number); } ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GET_POSITIVE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.GET_POSITIVE.get_positive( ...
solution
package humaneval.buggy; import java.util.ArrayList; /* * Given a non-empty list of integers, return the sum of all of the odd elements * that are in even positions. Examples solution([5, 8, 7, 1]) ==> 12 solution([3, 3, 3, 3, 3]) ==> 9 solution([30, 13, 24, 321]) ==>0 */ public class SOLUTIO...
package humaneval.buggy; import java.util.ArrayList; /* * Given a non-empty list of integers, return the sum of all of the odd elements * that are in even positions. Examples solution([5, 8, 7, 1]) ==> 12 solution([3, 3, 3, 3, 3]) ==> 9 solution([30, 13, 24, 321]) ==>0 */ public class SOLUTIO...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SOLUTION { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> input = new ArrayList<>(Arrays.asList(5,8,7,1)); ...
modp
package humaneval.buggy; /* Return 2^n modulo p (be aware of numerics). >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1 */ public class MODP { public static int modp(int n, int p) { int result = 1; for (int i = 0; i < n; i += 1){ result ...
package humaneval.buggy; /* Return 2^n modulo p (be aware of numerics). >>> modp(3, 5) 3 >>> modp(1101, 101) 2 >>> modp(0, 101) 1 >>> modp(3, 11) 8 >>> modp(100, 101) 1 */ public class MODP { public static int modp(int n, int p) { int result = 1; for (int i = 0; i < n; i += 1){ result ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MODP { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.MODP.modp(3, 5); org.junit.Assert.asser...
words_strings
package humaneval.buggy; import java.util.ArrayList; /* * 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. * * For example: * words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] * words_string...
package humaneval.buggy; import java.util.ArrayList; /* * 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. * * For example: * words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] * words_string...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_WORDS_STRINGS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<String> result = humaneval.buggy.WORDS_STRINGS.words_strings("Hi, my ...
concatenate
package humaneval.buggy; public class CONCATENATE { public static String concatenate(String[] strings) { String result = null; for (String string : strings) result += string; return result; } }
package humaneval.buggy; public class CONCATENATE { public static String concatenate(String[] strings) { String result = null; for (String string : strings) result += string; return result; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CONCATENATE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.CONCATENATE.concatenate(new String[...
split_words
package humaneval.buggy; /* * 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')...
package humaneval.buggy; /* * 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')...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SPLIT_WORDS { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String[] result = humaneval.buggy.SPLIT_WORDS.split_words("Hello worl...
encode
package humaneval.buggy; // Write a function that takes a message, and encodes in such a // way that it swaps case of all letters, replaces all vowels in // the message with the letter that appears 2 places ahead of that // vowel in the english alphabet. // Assume only letters. // Examples: // >>> encode('test')...
package humaneval.buggy; // Write a function that takes a message, and encodes in such a // way that it swaps case of all letters, replaces all vowels in // the message with the letter that appears 2 places ahead of that // vowel in the english alphabet. // Assume only letters. // Examples: // >>> encode('test')...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_ENCODE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.ENCODE.encode("TEST"); org.junit...
any_int
package humaneval.buggy; /* Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers (double) can be converted integers. Returns false in any other cases. Examples any_int(5, 2, 7) ➞ True any_int(3, 2, 2) ➞ False any_int(3, -2, 1) ➞ True any_i...
package humaneval.buggy; /* Create a function that takes 3 numbers. Returns true if one of the numbers is equal to the sum of the other two, and all numbers (double) can be converted integers. Returns false in any other cases. Examples any_int(5, 2, 7) ➞ True any_int(3, 2, 2) ➞ False any_int(3, -2, 1) ➞ True any_i...
package humaneval; public class TEST_ANY_INT { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.ANY_INT.any_int(2, 3, 1); org.junit.Assert.assertEquals( result, true ); } @org.junit.Test(timeout = 300...
truncate_number
package humaneval.buggy; public class TRUNCATE_NUMBER { public static double truncate_number(double number) { return number / 1.0; } }
package humaneval.buggy; public class TRUNCATE_NUMBER { public static double truncate_number(double number) { return number / 1.0; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_TRUNCATE_NUMBER { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { double result = humaneval.buggy.TRUNCATE_NUMBER.truncate_number...
sum_squared_nums
package humaneval.buggy; /* * You are given a list of numbers. You need to return the sum of squared numbers in the given list, round each element in the list to the upper int(Ceiling) first. Examples: For lst = [1,2,3] the output should be 14 For lst = [1,4,9] the output should be 98 For lst ...
package humaneval.buggy; /* * You are given a list of numbers. You need to return the sum of squared numbers in the given list, round each element in the list to the upper int(Ceiling) first. Examples: For lst = [1,2,3] the output should be 14 For lst = [1,4,9] the output should be 98 For lst ...
package humaneval; public class TEST_SUM_SQUARED_NUMS { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { double[] input = {1,2,3}; org.junit.Assert.assertEquals(14, humaneval.buggy.SUM_SQUARED_NUMS.sum_squared_nums(input)); } @org.junit.Test(timeout = 30...
max_element
package humaneval.buggy; import java.util.List; public class MAX_ELEMENT { public static int max_element(List<Integer> l) { int m = 0; for (Integer e : l) { if (e > m){ m = e; } } return m; } }
package humaneval.buggy; import java.util.List; public class MAX_ELEMENT { public static int max_element(List<Integer> l) { int m = 0; for (Integer e : l) { if (e > m){ m = e; } } return m; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_MAX_ELEMENT { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.MAX_ELEMENT.max_element( n...
is_happy
package humaneval.buggy; // You are given a string s. // Your task is to check if the string is happy or not. // A string is happy if its length is at least 3 and every 3 consecutive letters are distinct // For example: // is_happy(a) => False // is_happy(aa) => False // is_happy(abcd) => True // is_happy(aabb) => Fal...
package humaneval.buggy; // You are given a string s. // Your task is to check if the string is happy or not. // A string is happy if its length is at least 3 and every 3 consecutive letters are distinct // For example: // is_happy(a) => False // is_happy(aa) => False // is_happy(abcd) => True // is_happy(aabb) => Fal...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_IS_HAPPY { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.IS_HAPPY.is_happy("a"); org.j...
sort_third
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SORT_THIRD { public static List<Integer> sort_third(List<Integer> l) { List<Integer> result = new ArrayList<Integer>(); List<Integer> thirds = new ArrayList<Integer>(); f...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SORT_THIRD { public static List<Integer> sort_third(List<Integer> l) { List<Integer> result = new ArrayList<Integer>(); List<Integer> thirds = new ArrayList<Integer>(); f...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SORT_THIRD { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { List<Integer> result = humaneval.buggy.SORT_THIRD.sort_third( ...
sum_product
package humaneval.buggy; import java.util.List; public class SUM_PRODUCT { public static Integer[] sum_product(List<Integer> numbers) { Integer[] result = new Integer[2]; for (Integer n : numbers){ result[0] += n; result[1] *= n; } return result; } }
package humaneval.buggy; import java.util.List; public class SUM_PRODUCT { public static Integer[] sum_product(List<Integer> numbers) { Integer[] result = new Integer[2]; for (Integer n : numbers){ result[0] += n; result[1] *= n; } return result; } }
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_SUM_PRODUCT { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { Integer[] result = humaneval.buggy.SUM_PRODUCT.sum_product( new ArrayList<Integer>() ); ...
sort_array
package humaneval.buggy; import java.util.Arrays; /* Given an array of non-negative integers, return a copy of the given array after sorting, you will sort the given array in ascending order if the sum( first index value, last index value) is odd, or sort it in descending order if the sum( first index value, last ind...
package humaneval.buggy; import java.util.Arrays; /* Given an array of non-negative integers, return a copy of the given array after sorting, you will sort the given array in ascending order if the sum( first index value, last index value) is odd, or sort it in descending order if the sum( first index value, last ind...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SORT_ARRAY { @org.junit.Test(timeout = 1000) public void test_1() throws java.lang.Exception { int[] result = humaneval.buggy.SORT_ARRAY.sort_array( new ...
special_filter
package humaneval.buggy; import java.util.ArrayList; import java.util.Arrays; /* 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). For example: specialFilter([15, -73, ...
package humaneval.buggy; import java.util.ArrayList; import java.util.Arrays; /* 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). For example: specialFilter([15, -73, ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_SPECIAL_FILTER { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.SPECIAL_FILTER.special_filter( ...
get_max_triples
package humaneval.buggy; /* 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. Example : Input: n...
package humaneval.buggy; /* 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. Example : Input: n...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GET_MAX_TRIPLES { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.GET_MAX_TRIPLES.get_max_triples(5); ...
change_base
package humaneval.buggy; /* 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' */ public class CHANGE_BASE { public static String change_base(int x, i...
package humaneval.buggy; /* 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' */ public class CHANGE_BASE { public static String change_base(int x, i...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CHANGE_BASE { @org.junit.Test(timeout = 3000) public void test() throws java.lang.Exception { for (int x = 2; x < 8; x += 1){ String result = humaneval...
car_race_collision
package humaneval.buggy; /* Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars are said to c...
package humaneval.buggy; /* Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars are said to c...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CAR_RACE_COLLISION { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.CAR_RACE_COLLISION.car_race_col...
circular_shift
package humaneval.buggy; /* 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" */ public class CIRCULAR_SHIFT { public static String circul...
package humaneval.buggy; /* 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" */ public class CIRCULAR_SHIFT { public static String circul...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_CIRCULAR_SHIFT { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.CIRCULAR_SHIFT.circular_shift(10...
flip_case
package humaneval.buggy; public class FLIP_CASE { public static String flip_case(String string) { char[] char_list = string.toCharArray(); for (int i = 0; i < char_list.length; i += 1){ char c = char_list[i]; if (Character.isLowerCase(c)) { char_list...
package humaneval.buggy; public class FLIP_CASE { public static String flip_case(String string) { char[] char_list = string.toCharArray(); for (int i = 0; i < char_list.length; i += 1){ char c = char_list[i]; if (Character.isLowerCase(c)) { char_list...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_FLIP_CASE { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.FLIP_CASE.flip_case(""); org.ju...
get_odd_collatz
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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 in...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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 in...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_GET_ODD_COLLATZ { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { ArrayList<Integer> result = humaneval.buggy.GET_ODD_COLLATZ.get_o...
min_subarray_sum
package humaneval.buggy; import java.util.ArrayList; /* * Given an array of integers nums, find the minimum sum of any non-empty sub-array of nums. Example minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 minSubArraySum([-1, -2, -3]) == -6 */ public class MIN_SUBARRAY_SUM { public static long min_subarr...
package humaneval.buggy; import java.util.ArrayList; /* * Given an array of integers nums, find the minimum sum of any non-empty sub-array of nums. Example minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 minSubArraySum([-1, -2, -3]) == -6 */ public class MIN_SUBARRAY_SUM { public static long min_subarr...
package humaneval; import java.util.ArrayList; import java.util.Arrays; public class TEST_MIN_SUBARRAY_SUM { @org.junit.Test(timeout=3000) public void test_0() throws java.lang.Exception { ArrayList<Long> input = new ArrayList<Long>(Arrays.asList(2L, 3L, 4L, 1L, 2L, 4L)); long result = humanev...
how_many_times
package humaneval.buggy; public class HOW_MANY_TIMES { public static int how_many_times(String string, String substring) { int times = 0; for (int i = 0; i < string.length() - substring.length(); i += 1) { if (string.substring(i, i + substring.length()).equals(substring)){ ...
package humaneval.buggy; public class HOW_MANY_TIMES { public static int how_many_times(String string, String substring) { int times = 0; for (int i = 0; i < string.length() - substring.length(); i += 1) { if (string.substring(i, i + substring.length()).equals(substring)){ ...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_HOW_MANY_TIMES { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { int result = humaneval.buggy.HOW_MANY_TIMES.how_many_times("", "...
decode_cyclic
package humaneval.buggy; import java.util.ArrayList; public class DECODE_CYCLIC { public static String decode_cyclic(String str) { class Cyclic { String encode_cyclic(String s) { ArrayList<String> groups = new ArrayList<String>(); for (int i = 0; i < s.length()...
package humaneval.buggy; import java.util.ArrayList; public class DECODE_CYCLIC { public static String decode_cyclic(String str) { class Cyclic { String encode_cyclic(String s) { ArrayList<String> groups = new ArrayList<String>(); for (int i = 0; i < s.length()...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_DECODE_CYCLIC { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { String result = humaneval.buggy.DECODE_CYCLIC.decode_cyclic("uzfp...
below_threshold
package humaneval.buggy; /* Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False */ public class BELOW_THRESHOLD { public static boolean below_threshold(int[] l, int t) { for (int i = 0; i < l.length; i +=...
package humaneval.buggy; /* Return True if all numbers in the list l are below threshold t. >>> below_threshold([1, 2, 4, 10], 100) True >>> below_threshold([1, 20, 4, 10], 5) False */ public class BELOW_THRESHOLD { public static boolean below_threshold(int[] l, int t) { for (int i = 0; i < l.length; i +=...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_BELOW_THRESHOLD { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { boolean result = humaneval.buggy.BELOW_THRESHOLD.below_threshol...
total_match
package humaneval.buggy; import java.util.List; // Write a function that accepts two lists of strings and returns the list that has // total number of chars in the all strings of the list less than the other list. // if the two lists have the same number of chars, return the first list. // Examples // total_match(...
package humaneval.buggy; import java.util.List; // Write a function that accepts two lists of strings and returns the list that has // total number of chars in the all strings of the list less than the other list. // if the two lists have the same number of chars, return the first list. // Examples // total_match(...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TEST_TOTAL_MATCH { @org.junit.Test(timeout = 3000) public void test_0() throws java.lang.Exception { List<String> result = humaneval.buggy.TOTAL_MATCH.total_match( new ArrayList<Stri...
is_nested
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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...
package humaneval.buggy; import java.util.ArrayList; import java.util.Collections; /* * 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...
package humaneval; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.HashMap; public class TEST_IS_NESTED { @org.junit.Test(timeout = 1000) public void test_0() throws java.lang.Exception { org.junit.Assert.assertEquals(true, humaneval.buggy.IS_NESTED.is_nested...