suffix
stringclasses 1
value | compare_func
listlengths 0
0
| doc_string
stringclasses 1
value | demos
listlengths 0
0
| tgt_lang
stringclasses 1
value | src_lang
stringclasses 1
value | task_name
stringclasses 1
value | solution
stringlengths 42
900
| test_cases
listlengths 1
100
| entry_func
stringlengths 1
30
| data_id
stringlengths 23
25
| dataset_name
stringclasses 1
value | prefix
stringlengths 122
1.47k
| import_str
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
distance = abs(elem - elem2)
if distance < threshold:
return True
return False
|
[
[
"[1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3",
"True"
],
[
"[1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05",
"False"
],
[
"[1.0, 2.0, 5.9, 4.0, 5.0], 0.95",
"True"
],
[
"[1.0, 2.0, 5.9, 4.0, 5.0], 0.8",
"False"
],
[
"[1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1",
"True"
],
[
"[1.1, 2.2, 3.1, 4.1, 5.1], 1.0",
"True"
],
[
"[1.1, 2.2, 3.1, 4.1, 5.1], 0.5",
"False"
]
] |
has_close_elements
|
humaneval_java_python_0
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean has_close_elements(List<Double> numbers, double threshold) {
for (int i = 0; i < numbers.size(); i++) {
for (int j = i + 1; j < numbers.size(); j++) {
double distance = Math.abs(numbers.get(i) - numbers.get(j));
if (distance < threshold) return true;
}
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
result = []
current_string = []
current_depth = 0
for c in paren_string:
if c == '(':
current_depth += 1
current_string.append(c)
elif c == ')':
current_depth -= 1
current_string.append(c)
if current_depth == 0:
result.append(''.join(current_string))
current_string.clear()
return result
|
[
[
"'(()()) ((())) () ((())()())'",
"[\n '(()())', '((()))', '()', '((())()())'\n ]"
],
[
"'() (()) ((())) (((())))'",
"[\n '()', '(())', '((()))', '(((())))'\n ]"
],
[
"'(()(())((())))'",
"[\n '(()(())((())))'\n ]"
],
[
"'( ) (( )) (( )( ))'",
"['()', '(())', '(()())']"
]
] |
separate_paren_groups
|
humaneval_java_python_1
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<String> separate_paren_groups(String paren_string) {
List<String> result = new ArrayList<>();
StringBuilder current_string = new StringBuilder();
int current_depth = 0;
for (char c : paren_string.toCharArray()) {
if (c == '(') {
current_depth += 1;
current_string.append(c);
} else if (c == ')') {
current_depth -= 1;
current_string.append(c);
if (current_depth == 0) {
result.add(current_string.toString());
current_string.setLength(0);
}
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def truncate_number(number: float) -> float:
return number % 1.0
|
[
[
"3.5",
"0.5"
],
[
"1.33",
"0.33"
],
[
"123.456",
"0.456"
]
] |
truncate_number
|
humaneval_java_python_2
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public double truncate_number(double number) {
return number % 1.0;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def below_zero(operations: List[int]) -> bool:
balance = 0
for op in operations:
balance += op
if balance < 0:
return True
return False
|
[
[
"[]",
"False"
],
[
"[1, 2, -3, 1, 2, -3]",
"False"
],
[
"[1, 2, -4, 5, 6]",
"True"
],
[
"[1, -1, 2, -2, 5, -5, 4, -4]",
"False"
],
[
"[1, -1, 2, -2, 5, -5, 4, -5]",
"True"
],
[
"[1, -2, 2, -2, 5, -5, 4, -4]",
"True"
]
] |
below_zero
|
humaneval_java_python_3
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean below_zero(List<Integer> operations) {
int balance = 0;
for (int op : operations) {
balance += op;
if (balance < 0) {
return true;
}
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def mean_absolute_deviation(numbers: List[float]) -> float:
mean = sum(numbers) / len(numbers)
return sum(abs(x - mean) for x in numbers) / len(numbers)
|
[
[
"[1.0, 2.0, 3.0]",
"2.0/3.0"
],
[
"[1.0, 2.0, 3.0, 4.0]",
"1.0"
],
[
"[1.0, 2.0, 3.0, 4.0, 5.0]",
"6.0/5.0"
]
] |
mean_absolute_deviation
|
humaneval_java_python_4
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public double mean_absolute_deviation(List<Double> numbers) {
double sum = 0.0;
for (double num : numbers) {
sum += num;
}
double mean = sum / numbers.size();
double sum_abs_diff = 0.0;
for (double num : numbers) {
sum_abs_diff += Math.abs(num - mean);
}
return sum_abs_diff / numbers.size();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
if not numbers:
return []
result = []
for n in numbers[:-1]:
result.append(n)
result.append(delimeter)
result.append(numbers[-1])
return result
|
[
[
"[], 7",
"[]"
],
[
"[5, 6, 3, 2], 8",
"[5, 8, 6, 8, 3, 8, 2]"
],
[
"[2, 2, 2], 2",
"[2, 2, 2, 2, 2]"
]
] |
intersperse
|
humaneval_java_python_5
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> intersperse(List<Integer> numbers, int delimiter) {
if (numbers.size() == 0) {
return List.of();
}
List<Integer> result = new ArrayList<>(List.of());
for (int i = 0; i < numbers.size() - 1; i++) {
result.add(numbers.get(i));
result.add(delimiter);
}
result.add(numbers.get(numbers.size() - 1));
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def parse_nested_parens(paren_string: str) -> List[int]:
def parse_paren_group(s):
depth = 0
max_depth = 0
for c in s:
if c == '(':
depth += 1
max_depth = max(depth, max_depth)
else:
depth -= 1
return max_depth
return [parse_paren_group(x) for x in paren_string.split(' ') if x]
|
[
[
"'(()()) ((())) () ((())()())'",
"[2, 3, 1, 3]"
],
[
"'() (()) ((())) (((())))'",
"[1, 2, 3, 4]"
],
[
"'(()(())((())))'",
"[4]"
]
] |
parse_nested_parens
|
humaneval_java_python_6
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> parse_nested_parens(String paren_string) {
String[] groups = paren_string.split(" ");
List<Integer> result = new ArrayList<>(List.of());
for (String group : groups) {
if (group.length() > 0) {
int depth = 0;
int max_depth = 0;
for (char c : group.toCharArray()) {
if (c == '(') {
depth += 1;
max_depth = Math.max(depth, max_depth);
} else {
depth -= 1;
}
}
result.add(max_depth);
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def filter_by_substring(strings: List[str], substring: str) -> List[str]:
return [x for x in strings if substring in x]
|
[
[
"[], 'john'",
"[]"
],
[
"['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx'",
"['xxx', 'xxxAAA', 'xxx']"
],
[
"['xxx', 'asd', 'aaaxxy', 'john doe', 'xxxAAA', 'xxx'], 'xx'",
"['xxx', 'aaaxxy', 'xxxAAA', 'xxx']"
],
[
"['grunt', 'trumpet', 'prune', 'gruesome'], 'run'",
"['grunt', 'prune']"
]
] |
filter_by_substring
|
humaneval_java_python_7
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<String> filter_by_substring(List<String> strings, String substring) {
List<String> result = new ArrayList<>();
for (String x : strings) {
if (x.contains(substring)) {
result.add(x);
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
sum_value = 0
prod_value = 1
for n in numbers:
sum_value += n
prod_value *= n
return sum_value, prod_value
|
[
[
"[]",
"(0, 1)"
],
[
"[1, 1, 1]",
"(3, 1)"
],
[
"[100, 0]",
"(100, 0)"
],
[
"[3, 5, 7]",
"(3 + 5 + 7, 3 * 5 * 7)"
],
[
"[10]",
"(10, 10)"
]
] |
sum_product
|
humaneval_java_python_8
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> sum_product(List<Integer> numbers) {
int sum = 0;
int product = 1;
for (int n : numbers) {
sum += n;
product *= n;
}
return Arrays.asList(sum, product);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List, Tuple
def rolling_max(numbers: List[int]) -> List[int]:
running_max = None
result = []
for n in numbers:
if running_max is None:
running_max = n
else:
running_max = max(running_max, n)
result.append(running_max)
return result
|
[
[
"[]",
"[]"
],
[
"[1, 2, 3, 4]",
"[1, 2, 3, 4]"
],
[
"[4, 3, 2, 1]",
"[4, 4, 4, 4]"
],
[
"[3, 2, 3, 100, 3]",
"[3, 3, 3, 100, 100]"
]
] |
rolling_max
|
humaneval_java_python_9
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> rolling_max(List<Integer> numbers) {
List<Integer> result = new ArrayList<>();
if (numbers.size() == 0) {
return result;
}
int rolling_max = numbers.get(0);
result.add(rolling_max);
for (int i = 1; i < numbers.size(); i++) {
if (numbers.get(i) > rolling_max) {
rolling_max = numbers.get(i);
}
result.add(rolling_max);
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_palindrome(string: str) -> bool:
""" Test if given string is a palindrome """
return string == string[::-1]
def make_palindrome(string: str) -> str:
if not string:
return ''
beginning_of_suffix = 0
while not is_palindrome(string[beginning_of_suffix:]):
beginning_of_suffix += 1
return string + string[:beginning_of_suffix][::-1]
|
[
[
"''",
"''"
],
[
"'x'",
"'x'"
],
[
"'xyz'",
"'xyzyx'"
],
[
"'xyx'",
"'xyx'"
],
[
"'jerry'",
"'jerryrrej'"
]
] |
make_palindrome
|
humaneval_java_python_10
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
/**
Test if given string is a palindrome
*/
public boolean make_palindrome(String string) {
int i = 0;
int j = string.length() - 1;
while (i < j) {
if (string.charAt(i)!= string.charAt(j)) {
return false;
}
i++;
j--;
}
return true;
}
public String makePalindrome(String string) {
if (string.length() == 0) {
return "";
}
int beginning_of_suffix = 0;
while (!make_palindrome(string.substring(beginning_of_suffix))) {
beginning_of_suffix++;
}
return string + new StringBuffer(string.substring(0, beginning_of_suffix)).reverse().toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def string_xor(a: str, b: str) -> str:
def xor(i, j):
if i == j:
return '0'
else:
return '1'
return ''.join(xor(x, y) for x, y in zip(a, b))
|
[
[
"'111000', '101010'",
"'010010'"
],
[
"'1', '1'",
"'0'"
],
[
"'0101', '0000'",
"'0101'"
]
] |
string_xor
|
humaneval_java_python_11
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String string_xor(String a, String b) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) == b.charAt(i)) {
result.append("0");
} else {
result.append("1");
}
}
return result.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
if not strings:
return None
maxlen = max(len(x) for x in strings)
for s in strings:
if len(s) == maxlen:
return s
|
[
[
"[]",
"None"
],
[
"['x', 'y', 'z']",
"'x'"
],
[
"['x', 'yyy', 'zzzz', 'www', 'kkkk', 'abc']",
"'zzzz'"
]
] |
longest
|
humaneval_java_python_12
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public Optional<String> longest(List<String> strings) {
if (strings.isEmpty()) {
return Optional.empty();
}
String longest = strings.get(0);
for (String s : strings) {
if (s.length() > longest.length()) {
longest = s;
}
}
return Optional.of(longest);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def greatest_common_divisor(a: int, b: int) -> int:
while b:
a, b = b, a % b
return a
|
[
[
"3, 7",
"1"
],
[
"10, 15",
"5"
],
[
"49, 14",
"7"
],
[
"144, 60",
"12"
]
] |
greatest_common_divisor
|
humaneval_java_python_13
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int greatest_common_divisor(int a, int b) {
if (a == 0 || b == 0) {
return a + b;
}
if (a == b) {
return a;
}
if (a > b) {
return greatest_common_divisor(a % b, b);
} else {
return greatest_common_divisor(a, b % a);
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def all_prefixes(string: str) -> List[str]:
result = []
for i in range(len(string)):
result.append(string[:i+1])
return result
|
[
[
"''",
"[]"
],
[
"'asdfgh'",
"['a', 'as', 'asd', 'asdf', 'asdfg', 'asdfgh']"
],
[
"'WWW'",
"['W', 'WW', 'WWW']"
]
] |
all_prefixes
|
humaneval_java_python_14
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<String> all_prefixes(String string) {
List<String> result = new ArrayList<>();
for (int i = 1; i <= string.length(); i++) {
result.add(string.substring(0, i));
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def string_sequence(n: int) -> str:
return ' '.join([str(x) for x in range(n + 1)])
|
[
[
"0",
"'0'"
],
[
"3",
"'0 1 2 3'"
],
[
"10",
"'0 1 2 3 4 5 6 7 8 9 10'"
]
] |
string_sequence
|
humaneval_java_python_15
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String string_sequence(int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(i);
sb.append(" ");
}
sb.append(n);
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def count_distinct_characters(string: str) -> int:
return len(set(string.lower()))
|
[
[
"''",
"0"
],
[
"'abcde'",
"5"
],
[
"'abcde' + 'cade' + 'CADE'",
"5"
],
[
"'aaaaAAAAaaaa'",
"1"
],
[
"'Jerry jERRY JeRRRY'",
"5"
]
] |
count_distinct_characters
|
humaneval_java_python_16
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int count_distinct_characters(String string) {
Set<Character> set = new HashSet<>();
for (char c : string.toLowerCase().toCharArray()) {
set.add(c);
}
return set.size();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def parse_music(music_string: str) -> List[int]:
note_map = {'o': 4, 'o|': 2, '.|': 1}
return [note_map[x] for x in music_string.split(' ') if x]
|
[
[
"''",
"[]"
],
[
"'o o o o'",
"[4, 4, 4, 4]"
],
[
"'.| .| .| .|'",
"[1, 1, 1, 1]"
],
[
"'o| o| .| .| o o o o'",
"[2, 2, 1, 1, 4, 4, 4, 4]"
],
[
"'o| .| o| .| o o| o o|'",
"[2, 1, 2, 1, 4, 2, 4, 2]"
]
] |
parse_music
|
humaneval_java_python_17
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> parse_music(String string) {
String[] notes = string.split(" ");
List<Integer> result = new ArrayList<>();
for (String s : notes) {
switch (s) {
case "o" -> result.add(4);
case "o|" -> result.add(2);
case ".|" -> result.add(1);
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def how_many_times(string: str, substring: str) -> int:
times = 0
for i in range(len(string) - len(substring) + 1):
if string[i:i+len(substring)] == substring:
times += 1
return times
|
[
[
"'', 'x'",
"0"
],
[
"'xyxyxyx', 'x'",
"4"
],
[
"'cacacacac', 'cac'",
"4"
],
[
"'john doe', 'john'",
"1"
]
] |
how_many_times
|
humaneval_java_python_18
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int how_many_times(String string, String substring) {
int times = 0;
for (int i = 0; i < string.length() - substring.length() + 1; i++) {
if (string.substring(i, i + substring.length()).equals(substring)) {
times += 1;
}
}
return times;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def sort_numbers(numbers: str) -> str:
value_map = {
'zero': 0,
'one': 1,
'two': 2,
'three': 3,
'four': 4,
'five': 5,
'six': 6,
'seven': 7,
'eight': 8,
'nine': 9
}
return ' '.join(sorted([x for x in numbers.split(' ') if x], key=lambda x: value_map[x]))
|
[
[
"''",
"''"
],
[
"'three'",
"'three'"
],
[
"'three five nine'",
"'three five nine'"
],
[
"'five zero four seven nine eight'",
"'zero four five seven eight nine'"
],
[
"'six five four three two one zero'",
"'zero one two three four five six'"
]
] |
sort_numbers
|
humaneval_java_python_19
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String sort_numbers(String numbers) {
String[] nums = numbers.split(" ");
List<Integer> num = new ArrayList<>();
for (String string : nums) {
switch (string) {
case "zero" -> num.add(0);
case "one" -> num.add(1);
case "two" -> num.add(2);
case "three" -> num.add(3);
case "four" -> num.add(4);
case "five" -> num.add(5);
case "six" -> num.add(6);
case "seven" -> num.add(7);
case "eight" -> num.add(8);
case "nine" -> num.add(9);
}
}
Collections.sort(num);
List<String> result = new ArrayList<>();
for (int m : num) {
switch (m) {
case 0 -> result.add("zero");
case 1 -> result.add("one");
case 2 -> result.add("two");
case 3 -> result.add("three");
case 4 -> result.add("four");
case 5 -> result.add("five");
case 6 -> result.add("six");
case 7 -> result.add("seven");
case 8 -> result.add("eight");
case 9 -> result.add("nine");
}
}
return String.join(" ", result);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
closest_pair = None
distance = None
for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
if distance is None:
distance = abs(elem - elem2)
closest_pair = tuple(sorted([elem, elem2]))
else:
new_distance = abs(elem - elem2)
if new_distance < distance:
distance = new_distance
closest_pair = tuple(sorted([elem, elem2]))
return closest_pair
|
[
[
"[1.0, 2.0, 3.9, 4.0, 5.0, 2.2]",
"(3.9, 4.0)"
],
[
"[1.0, 2.0, 5.9, 4.0, 5.0]",
"(5.0, 5.9)"
],
[
"[1.0, 2.0, 3.0, 4.0, 5.0, 2.2]",
"(2.0, 2.2)"
],
[
"[1.0, 2.0, 3.0, 4.0, 5.0, 2.0]",
"(2.0, 2.0)"
],
[
"[1.1, 2.2, 3.1, 4.1, 5.1]",
"(2.2, 3.1)"
]
] |
find_closest_elements
|
humaneval_java_python_20
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Double> find_closest_elements(List<Double> numbers) {
List<Double> closest_pair = new ArrayList<>();
closest_pair.add(numbers.get(0));
closest_pair.add(numbers.get(1));
double distance = Math.abs(numbers.get(1) - numbers.get(0));
for (int i = 0; i < numbers.size(); i++) {
for (int j = i + 1; j < numbers.size(); j++) {
if (Math.abs(numbers.get(i) - numbers.get(j)) < distance) {
closest_pair.clear();
closest_pair.add(numbers.get(i));
closest_pair.add(numbers.get(j));
distance = Math.abs(numbers.get(i) - numbers.get(j));
}
}
}
Collections.sort(closest_pair);
return closest_pair;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
min_number = min(numbers)
max_number = max(numbers)
return [(x - min_number) / (max_number - min_number) for x in numbers]
|
[
[
"[2.0, 49.9]",
"[0.0, 1.0]"
],
[
"[100.0, 49.9]",
"[1.0, 0.0]"
],
[
"[1.0, 2.0, 3.0, 4.0, 5.0]",
"[0.0, 0.25, 0.5, 0.75, 1.0]"
],
[
"[2.0, 1.0, 5.0, 3.0, 4.0]",
"[0.25, 0.0, 1.0, 0.5, 0.75]"
],
[
"[12.0, 11.0, 15.0, 13.0, 14.0]",
"[0.25, 0.0, 1.0, 0.5, 0.75]"
]
] |
rescale_to_unit
|
humaneval_java_python_21
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Double> rescale_to_unit(List<Double> numbers) {
double min_number = Collections.min(numbers);
double max_number = Collections.max(numbers);
List<Double> result = new ArrayList<>();
for (double x : numbers) {
result.add((x - min_number) / (max_number - min_number));
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List, Any
def filter_integers(values: List[Any]) -> List[int]:
return [x for x in values if isinstance(x, int)]
|
[
[
"[]",
"[]"
],
[
"[4, {}, [], 23.2, 9, 'adasd']",
"[4, 9]"
],
[
"[3, 'c', 3, 3, 'a', 'b']",
"[3, 3, 3]"
]
] |
filter_integers
|
humaneval_java_python_22
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> filter_integers(List<Object> values) {
List<Integer> result = new ArrayList<>();
for (Object x : values) {
if (x instanceof Integer) {
result.add((Integer) x);
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def strlen(string: str) -> int:
return len(string)
|
[
[
"''",
"0"
],
[
"'x'",
"1"
],
[
"'asdasnakj'",
"9"
]
] |
strlen
|
humaneval_java_python_23
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int strlen(String string) {
return string.length();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def largest_divisor(n: int) -> int:
for i in reversed(range(n)):
if n % i == 0:
return i
|
[
[
"3",
"1"
],
[
"7",
"1"
],
[
"10",
"5"
],
[
"100",
"50"
],
[
"49",
"7"
]
] |
largest_divisor
|
humaneval_java_python_24
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int largest_divisor(int n) {
for (int i = n - 1; i > 0; i--) {
if (n % i == 0) {
return i;
}
}
return 1;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def factorize(n: int) -> List[int]:
import math
fact = []
i = 2
while i <= int(math.sqrt(n) + 1):
if n % i == 0:
fact.append(i)
n //= i
else:
i += 1
if n > 1:
fact.append(n)
return fact
|
[
[
"2",
"[2]"
],
[
"4",
"[2, 2]"
],
[
"8",
"[2, 2, 2]"
],
[
"3 * 19",
"[3, 19]"
],
[
"3 * 19 * 3 * 19",
"[3, 3, 19, 19]"
],
[
"3 * 19 * 3 * 19 * 3 * 19",
"[3, 3, 3, 19, 19, 19]"
],
[
"3 * 19 * 19 * 19",
"[3, 19, 19, 19]"
],
[
"3 * 2 * 3",
"[2, 3, 3]"
]
] |
factorize
|
humaneval_java_python_25
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> factorize(int n) {
List<Integer> fact = new ArrayList<>();
int i = 2;
while (n > 1) {
if (n % i == 0) {
fact.add(i);
n /= i;
} else {
i++;
}
}
return fact;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
import collections
c = collections.Counter(numbers)
return [n for n in numbers if c[n] <= 1]
|
[
[
"[]",
"[]"
],
[
"[1, 2, 3, 4]",
"[1, 2, 3, 4]"
],
[
"[1, 2, 3, 2, 4, 3, 5]",
"[1, 4, 5]"
]
] |
remove_duplicates
|
humaneval_java_python_26
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
import java.util.stream.Collectors;
class Solution {
public List<Integer> remove_duplicates(List<Integer> numbers) {
Map<Integer, Integer> c = new HashMap<>();
for (int i : numbers) {
c.put(i, c.getOrDefault(i, 0) + 1);
}
return numbers.stream().filter(i -> c.get(i) == 1).collect(Collectors.toList());
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def flip_case(string: str) -> str:
return string.swapcase()
|
[
[
"''",
"''"
],
[
"'Hello!'",
"'hELLO!'"
],
[
"'These violent delights have violent ends'",
"'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'"
]
] |
flip_case
|
humaneval_java_python_27
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String flip_case(String string) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < string.length(); i++) {
if (Character.isLowerCase(string.charAt(i))) {
sb.append(Character.toUpperCase(string.charAt(i)));
} else {
sb.append(Character.toLowerCase(string.charAt(i)));
}
}
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def concatenate(strings: List[str]) -> str:
return ''.join(strings)
|
[
[
"[]",
"''"
],
[
"['x', 'y', 'z']",
"'xyz'"
],
[
"['x', 'y', 'z', 'w', 'k']",
"'xyzwk'"
]
] |
concatenate
|
humaneval_java_python_28
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String concatenate(List<String> strings) {
return String.join("", strings);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
from typing import List
def filter_by_prefix(strings: List[str], prefix: str) -> List[str]:
return [x for x in strings if x.startswith(prefix)]
|
[
[
"[], 'john'",
"[]"
],
[
"['xxx', 'asd', 'xxy', 'john doe', 'xxxAAA', 'xxx'], 'xxx'",
"['xxx', 'xxxAAA', 'xxx']"
]
] |
filter_by_prefix
|
humaneval_java_python_29
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
import java.util.stream.Collectors;
class Solution {
public List<String> filter_by_prefix(List<String> strings, String prefix) {
return strings.stream().filter(p -> p.startsWith(prefix)).collect(Collectors.toList());
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def get_positive(l: list):
return [e for e in l if e > 0]
|
[
[
"[-1, -2, 4, 5, 6]",
"[4, 5, 6]"
],
[
"[5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]",
"[5, 3, 2, 3, 3, 9, 123, 1]"
],
[
"[-1, -2]",
"[]"
],
[
"[]",
"[]"
]
] |
get_positive
|
humaneval_java_python_30
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
import java.util.stream.Collectors;
class Solution {
public List<Integer> get_positive(List<Integer> l) {
return l.stream().filter(p -> p > 0).collect(Collectors.toList());
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_prime(n):
if n < 2:
return False
for k in range(2, n - 1):
if n % k == 0:
return False
return True
|
[
[
"6",
"False"
],
[
"101",
"True"
],
[
"11",
"True"
],
[
"13441",
"True"
],
[
"61",
"True"
],
[
"4",
"False"
],
[
"1",
"False"
],
[
"5",
"True"
],
[
"11",
"True"
],
[
"17",
"True"
],
[
"5 * 17",
"False"
],
[
"11 * 7",
"False"
],
[
"13441 * 19",
"False"
]
] |
is_prime
|
humaneval_java_python_31
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean is_prime(int n) {
if (n < 2) {
return false;
}
for (int k = 2; k < n; k++) {
if (n % k == 0) {
return false;
}
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
import math
def poly(xs: list, x: float):
"""
Evaluates polynomial with coefficients xs at point x.
return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n
"""
return sum([coeff * math.pow(x, i) for i, coeff in enumerate(xs)])
def find_zero(xs: list):
begin, end = -1., 1.
while poly(xs, begin) * poly(xs, end) > 0:
begin *= 2.0
end *= 2.0
while end - begin > 1e-10:
center = (begin + end) / 2.0
if poly(xs, center) * poly(xs, begin) > 0:
begin = center
else:
end = center
return begin
|
[
[
"[1, 2]",
"[1, 2]"
],
[
"[-6, 11, -6, 1]",
"[-6, 11, -6, 1]"
],
[
"[3, -4]",
"[3, -4]"
],
[
"[5, 0, -20]",
"[5, 0, -20]"
],
[
"[-1, 0, 0, 1]",
"[-1, 0, 0, 1]"
]
] |
find_zero
|
humaneval_java_python_32
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
/**
Evaluates find_zeronomial with coefficients xs at point x.
return xs[0] + xs[1] * x + xs[1] * x^2 + .... xs[n] * x^n
*/
public double find_zero(List<Double> xs, double x) {
double result = 0;
for (int i = 0; i < xs.size(); i++) {
result += xs.get(i) * Math.pow(x, i);
}
return result;
}
public double findZero(List<Double> xs) {
double begin = -1, end = 1;
while (find_zero(xs, begin) * find_zero(xs, end) > 0) {
begin *= 2;
end *= 2;
}
while (end - begin > 1e-10) {
double center = (begin + end) / 2;
if (find_zero(xs, begin) * find_zero(xs, center) > 0) {
begin = center;
} else {
end = center;
}
}
return begin;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def sort_third(l: list):
l = list(l)
l[::3] = sorted(l[::3])
return l
|
[
[
"[1, 2, 3]",
"[1, 2, 3]"
],
[
"[5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]",
"[1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10]"
],
[
"[5, 8, -12, 4, 23, 2, 3, 11, 12, -10]",
"[-10, 8, -12, 3, 23, 2, 4, 11, 12, 5]"
],
[
"[5, 6, 3, 4, 8, 9, 2, 1]",
"[2, 6, 3, 4, 8, 9, 5, 1]"
],
[
"[5, 8, 3, 4, 6, 9, 2]",
"[2, 8, 3, 4, 6, 9, 5]"
],
[
"[5, 6, 9, 4, 8, 3, 2]",
"[2, 6, 9, 4, 8, 3, 5]"
]
] |
sort_third
|
humaneval_java_python_33
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> sort_third(List<Integer> l) {
List<Integer> thirds = new ArrayList<>();
for (int i = 0; i < l.size(); i += 3) {
thirds.add(l.get(i));
}
Collections.sort(thirds);
List<Integer> result = l;
for (int i = 0; i < l.size(); i += 3) {
result.set(i, thirds.get(i / 3));
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def unique(l: list):
return sorted(list(set(l)))
|
[
[
"[5, 3, 5, 2, 3, 3, 9, 0, 123]",
"[0, 2, 3, 5, 9, 123]"
]
] |
unique
|
humaneval_java_python_34
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> unique(List<Integer> l) {
List<Integer> result = new ArrayList<>(new HashSet<>(l));
Collections.sort(result);
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def max_element(l: list):
m = l[0]
for e in l:
if e > m:
m = e
return m
|
[
[
"[1, 2, 3]",
"3"
],
[
"[5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]",
"124"
]
] |
max_element
|
humaneval_java_python_35
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int max_element(List<Integer> l) {
return Collections.max(l);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def fizz_buzz(n: int):
ns = []
for i in range(n):
if i % 11 == 0 or i % 13 == 0:
ns.append(i)
s = ''.join(list(map(str, ns)))
ans = 0
for c in s:
ans += (c == '7')
return ans
|
[
[
"50",
"0"
],
[
"78",
"2"
],
[
"79",
"3"
],
[
"100",
"3"
],
[
"200",
"6"
],
[
"4000",
"192"
],
[
"10000",
"639"
],
[
"100000",
"8026"
]
] |
fizz_buzz
|
humaneval_java_python_36
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int fizz_buzz(int n) {
int result = 0;
for (int i = 1; i < n; i++) {
if (i % 11 == 0 || i % 13 == 0) {
char[] digits = String.valueOf(i).toCharArray();
for (char c : digits) {
if (c == '7') {
result += 1;
}
}
}
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def sort_even(l: list):
evens = l[::2]
odds = l[1::2]
evens.sort()
ans = []
for e, o in zip(evens, odds):
ans.extend([e, o])
if len(evens) > len(odds):
ans.append(evens[-1])
return ans
|
[
[
"[1, 2, 3]",
"[1, 2, 3]"
],
[
"[5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]",
"[-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123]"
],
[
"[5, 8, -12, 4, 23, 2, 3, 11, 12, -10]",
"[-12, 8, 3, 4, 5, 2, 12, 11, 23, -10]"
]
] |
sort_even
|
humaneval_java_python_37
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> sort_even(List<Integer> l) {
List<Integer> even = new ArrayList<>();
for (int i = 0; i < l.size(); i += 2) {
even.add(l.get(i));
}
Collections.sort(even);
List<Integer> result = l;
for (int i = 0; i < l.size(); i += 2) {
result.set(i, even.get(i / 2));
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def encode_cyclic(s: str):
"""
returns encoded string by cycling groups of three characters.
"""
# split string to groups. Each of length 3.
groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]
# cycle elements in each group. Unless group has fewer elements than 3.
groups = [(group[1:] + group[0]) if len(group) == 3 else group for group in groups]
return "".join(groups)
def decode_cyclic(s: str):
return encode_cyclic(encode_cyclic(s))
|
[
[
"'eaztdrcpoojjs'",
"'zeartdocpjojs'"
],
[
"'fcsasgmhiqc'",
"'sfcgasimhqc'"
],
[
"'avmirjdeqbylxuau'",
"'mavjirqdelbyaxuu'"
],
[
"'azhacmsfsnfsg'",
"'hazmacssfsnfg'"
],
[
"'zbvkvwoatdccvw'",
"'vzbwkvtoacdcvw'"
],
[
"'mqzfshjknuz'",
"'zmqhfsnjkuz'"
],
[
"'bgpjjqmghur'",
"'pbgqjjhmgur'"
],
[
"'skuuqfixmobqarshlnfv'",
"'uskfuqmixqobsarnhlfv'"
],
[
"'bwcoqbjzilceuidscgn'",
"'cbwboqijzelcduigscn'"
],
[
"'lpoyfvzavtysssduxn'",
"'olpvyfvzastydssnux'"
],
[
"'rguzukgsizsrmvrnt'",
"'urgkzuigsrzsrmvnt'"
],
[
"'orjrnmyozyhwc'",
"'jormrnzyowyhc'"
],
[
"'egkdzdeufufsupt'",
"'kegddzfeusuftup'"
],
[
"'kuqnvecsetyvdfero'",
"'qkuenvecsvtyedfro'"
],
[
"'rglvlgjtgesicfkcmkm'",
"'lrggvlgjtieskcfkcmm'"
],
[
"'jpdxznnaqylzmmh'",
"'djpnxzqnazylhmm'"
],
[
"'zwmgzcntpbawwlfbex'",
"'mzwcgzpntwbafwlxbe'"
],
[
"'unjdpwbxpxkpqdopaalb'",
"'junwdppbxpxkoqdapalb'"
],
[
"'zeukiguxndy'",
"'uzegkinuxdy'"
],
[
"'sjnaktdnbnokqjg'",
"'nsjtakbdnknogqj'"
],
[
"'vrmtirlygzhf'",
"'mvrrtiglyfzh'"
],
[
"'mhtgmpslldrhjl'",
"'tmhpgmlslhdrjl'"
],
[
"'mpvjpdatrmhtdx'",
"'vmpdjprattmhdx'"
],
[
"'jimzixallctnnsg'",
"'mjixzilalnctgns'"
],
[
"'gahjootuomivad'",
"'hgaojootuvmiad'"
],
[
"'ulilcmoplpsqqoyrppbh'",
"'iulmlclopqpsyqoprpbh'"
],
[
"'oznykgwonynglp'",
"'nozgyknwogynlp'"
],
[
"'fzvyarmdbmeogatu'",
"'vfzryabmdometgau'"
],
[
"'mfnngxdggewb'",
"'nmfxnggdgbew'"
],
[
"'qvacnekscjxe'",
"'aqvecncksejx'"
],
[
"'nmcapqndnkuh'",
"'cnmqapnndhku'"
],
[
"'nnennffezagabnfa'",
"'ennfnnzfeaagfbna'"
],
[
"'ifgknbekvs'",
"'gifbknveks'"
],
[
"'drtekkfffj'",
"'tdrkekfffj'"
],
[
"'tswtymazbcejja'",
"'wtsmtybazjceja'"
],
[
"'vlcyvzwvjbrc'",
"'cvlzyvjwvcbr'"
],
[
"'jvlybcuhdjhoixz'",
"'ljvcybduhojhzix'"
],
[
"'gtpwuynlrwoimpersbri'",
"'pgtywurnliwoempbrsri'"
],
[
"'gxkyyxeiltkdiuq'",
"'kgxxyyleidtkqiu'"
],
[
"'lsxrlnsbrxispzf'",
"'xlsnrlrsbsxifpz'"
],
[
"'hkwqbehapilpgesmj'",
"'whkeqbphapilsgemj'"
],
[
"'qgxkrqvsvsrwesnwot'",
"'xqgqkrvvswsrnestwo'"
],
[
"'tkjskkxoqalpnajqidr'",
"'jtkkskqxopaljnadqir'"
],
[
"'djekkirzcafg'",
"'edjikkcrzgaf'"
],
[
"'srfgcpgexwdbajohros'",
"'fsrpgcxgebwdoajohrs'"
],
[
"'sfckdzevjqezdxmcso'",
"'csfzkdjevzqemdxocs'"
],
[
"'aaikokcghtbyunigyq'",
"'iaakkohcgytbiunqgy'"
],
[
"'jaldcwbuxzqvlsff'",
"'ljawdcxbuvzqflsf'"
],
[
"'hyjfibztlplww'",
"'jhybfilztwplw'"
],
[
"'irsuppaksqoxgkyak'",
"'sirpupsakxqoygkak'"
],
[
"'rvhlirxndd'",
"'hrvrlidxnd'"
],
[
"'fwofairkckdyffng'",
"'ofwifacrkykdnffg'"
],
[
"'idmgovtowjfmf'",
"'midvgowtomjff'"
],
[
"'ovfdtilllkla'",
"'fovidtlllakl'"
],
[
"'kmmlbgisttsjhpgeo'",
"'mkmglbtisjtsghpeo'"
],
[
"'wvnqidnuhafydcdqqbzv'",
"'nwvdqihnuyafddcbqqzv'"
],
[
"'suhgzhdxuwp'",
"'hsuhgzudxwp'"
],
[
"'wovjwmvixtut'",
"'vwomjwxvittu'"
],
[
"'cghripgisjeihgsbkme'",
"'hcgprisgiijeshgmbke'"
],
[
"'vpnnwihekt'",
"'nvpinwkhet'"
],
[
"'oakdzvyxwcubs'",
"'koavdzwyxbcus'"
],
[
"'yiizrtxhhmazu'",
"'iyitzrhxhzmau'"
],
[
"'ykzsucdlyah'",
"'zykcsuydlah'"
],
[
"'wikxqjfoudburqasd'",
"'kwijxqufoudbarqsd'"
],
[
"'cssoeuoaspnhxaeipsc'",
"'scsuoesoahpnexasipc'"
],
[
"'yiztlakgbpfqpnvrwxl'",
"'zyiatlbkgqpfvpnxrwl'"
],
[
"'faljwqdqsyeghhccnrvz'",
"'lfaqjwsdqgyechhrcnvz'"
],
[
"'okdezkfuvnml'",
"'dokkezvfulnm'"
],
[
"'klkbfzkqofdmtcg'",
"'kklzbfokqmfdgtc'"
],
[
"'uqzurwhizdjvr'",
"'zuqwurzhivdjr'"
],
[
"'jrgrscrapvjpfqj'",
"'gjrcrsprapvjjfq'"
],
[
"'nwenxrwcrfaeb'",
"'enwrnxrwcefab'"
],
[
"'pldrrczxefqs'",
"'dplcrrezxsfq'"
],
[
"'ksvouegvkjyfecan'",
"'vkseoukgvfjyaecn'"
],
[
"'ijqaxfmbwjkevttzbxk'",
"'qijfaxwmbejktvtxzbk'"
],
[
"'irewkmbwkh'",
"'eirmwkkbwh'"
],
[
"'mhqhodamvtgiev'",
"'qmhdhovamitgev'"
],
[
"'ryjpgtgwucmyeulwhydh'",
"'jrytpgugwycmleuywhdh'"
],
[
"'ttkwvupppyakk'",
"'kttuwvpppkyak'"
],
[
"'dsgidvchdrln'",
"'gdsviddchnrl'"
],
[
"'nklhmphxejdcwx'",
"'lnkphmehxcjdwx'"
],
[
"'plwenneudaqxtwheh'",
"'wplnendeuxaqhtweh'"
],
[
"'pasolfzaalcs'",
"'spafolazaslc'"
],
[
"'mvohmjdjtvggijdbxbnh'",
"'omvjhmtdjgvgdijbbxnh'"
],
[
"'olbcwcvbnhh'",
"'bolccwnvbhh'"
],
[
"'nttkuqayrlcuxioymcl'",
"'tntqkurayulcoxicyml'"
],
[
"'jxhrreunodmezni'",
"'hjxerrounedmizn'"
],
[
"'wsrxjpqyzkxhbxc'",
"'rwspxjzqyhkxcbx'"
],
[
"'kxkqlaosighdfirrgd'",
"'kkxaqliosdghrfidrg'"
],
[
"'jwlphbvzsosmfdq'",
"'ljwbphsvzmosqfd'"
],
[
"'osdfiyiitm'",
"'dosyfitiim'"
],
[
"'yndqfrdeuthbcwhhvizq'",
"'dynrqfudebthhcwihvzq'"
],
[
"'cmqnxmwxnrv'",
"'qcmmnxnwxrv'"
],
[
"'qvfdfgsgqkwa'",
"'fqvgdfqsgakw'"
],
[
"'zzuimcybadfunvwd'",
"'uzzcimaybudfwnvd'"
],
[
"'bsrzyntvnvsppnz'",
"'rbsnzyntvpvszpn'"
],
[
"'mjrvpbrpqemkws'",
"'rmjbvpqrpkemws'"
],
[
"'ekwvxxlganvrot'",
"'wekxvxalgrnvot'"
],
[
"'onlzsrfkdqfuvl'",
"'lonrzsdfkuqfvl'"
],
[
"'rcwvivhovywyfnqsefv'",
"'wrcvvivhoyywqfnfsev'"
]
] |
decode_cyclic
|
humaneval_java_python_38
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
/**
returns encoded string by cycling groups of three characters.
*/
public String decode_cyclic(String s) {
// split string to groups. Each of length 3.
List<String> groups = new ArrayList<>();
for (int i = 0; i < s.length(); i += 3) {
groups.add(s.substring(i, Math.min(i + 3, s.length())));
}
// cycle elements in each group. Unless group has fewer elements than 3.
for (int i = 0; i < groups.size(); i++) {
if (groups.get(i).length() == 3) {
groups.set(i, groups.get(i).substring(1) + groups.get(i).charAt(0));
}
}
return String.join("", groups);
}
public String decodeCyclic(String s) {
return decode_cyclic(decode_cyclic(s));
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def prime_fib(n: int):
import math
def is_prime(p):
if p < 2:
return False
for k in range(2, min(int(math.sqrt(p)) + 1, p - 1)):
if p % k == 0:
return False
return True
f = [0, 1]
while True:
f.append(f[-1] + f[-2])
if is_prime(f[-1]):
n -= 1
if n == 0:
return f[-1]
|
[
[
"1",
"2"
],
[
"2",
"3"
],
[
"3",
"5"
],
[
"4",
"13"
],
[
"5",
"89"
],
[
"6",
"233"
],
[
"7",
"1597"
],
[
"8",
"28657"
],
[
"9",
"514229"
],
[
"10",
"433494437"
]
] |
prime_fib
|
humaneval_java_python_39
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int prime_fib(int n) {
int f0 = 0, f1 = 1;
while (true) {
int p = f0 + f1;
boolean is_prime = p >= 2;
for (int k = 2; k < Math.min(Math.sqrt(p) + 1, p - 1); k++) {
if (p % k == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
n -= 1;
}
if (n == 0) {
return p;
}
f0 = f1;
f1 = p;
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def triples_sum_to_zero(l: list):
for i in range(len(l)):
for j in range(i + 1, len(l)):
for k in range(j + 1, len(l)):
if l[i] + l[j] + l[k] == 0:
return True
return False
|
[
[
"[1, 3, 5, 0]",
"False"
],
[
"[1, 3, 5, -1]",
"False"
],
[
"[1, 3, -2, 1]",
"True"
],
[
"[1, 2, 3, 7]",
"False"
],
[
"[1, 2, 5, 7]",
"False"
],
[
"[2, 4, -5, 3, 9, 7]",
"True"
],
[
"[1]",
"False"
],
[
"[1, 3, 5, -100]",
"False"
],
[
"[100, 3, 5, -100]",
"False"
]
] |
triples_sum_to_zero
|
humaneval_java_python_40
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean triples_sum_to_zero(List<Integer> l) {
for (int i = 0; i < l.size(); i++) {
for (int j = i + 1; j < l.size(); j++) {
for (int k = j + 1; k < l.size(); k++) {
if (l.get(i) + l.get(j) + l.get(k) == 0) {
return true;
}
}
}
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def car_race_collision(n: int):
return n**2
|
[
[
"2",
"4"
],
[
"3",
"9"
],
[
"4",
"16"
],
[
"8",
"64"
],
[
"10",
"100"
]
] |
car_race_collision
|
humaneval_java_python_41
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int car_race_collision(int n) {
return n * n;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def incr_list(l: list):
return [(e + 1) for e in l]
|
[
[
"[]",
"[]"
],
[
"[3, 2, 1]",
"[4, 3, 2]"
],
[
"[5, 2, 5, 2, 3, 3, 9, 0, 123]",
"[6, 3, 6, 3, 4, 4, 10, 1, 124]"
]
] |
incr_list
|
humaneval_java_python_42
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
import java.util.stream.Collectors;
class Solution {
public List<Integer> incr_list(List<Integer> l) {
return l.stream().map(p -> p + 1).collect(Collectors.toList());
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def pairs_sum_to_zero(l):
for i, l1 in enumerate(l):
for j in range(i + 1, len(l)):
if l1 + l[j] == 0:
return True
return False
|
[
[
"[1, 3, 5, 0]",
"False"
],
[
"[1, 3, -2, 1]",
"False"
],
[
"[1, 2, 3, 7]",
"False"
],
[
"[2, 4, -5, 3, 5, 7]",
"True"
],
[
"[1]",
"False"
],
[
"[-3, 9, -1, 3, 2, 30]",
"True"
],
[
"[-3, 9, -1, 3, 2, 31]",
"True"
],
[
"[-3, 9, -1, 4, 2, 30]",
"False"
],
[
"[-3, 9, -1, 4, 2, 31]",
"False"
]
] |
pairs_sum_to_zero
|
humaneval_java_python_43
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean pairs_sum_to_zero(List<Integer> l) {
for (int i = 0; i < l.size(); i++) {
for (int j = i + 1; j < l.size(); j++) {
if (l.get(i) + l.get(j) == 0) {
return true;
}
}
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def change_base(x: int, base: int):
ret = ""
while x > 0:
ret = str(x % base) + ret
x //= base
return ret
|
[
[
"8, 3",
"\"22\""
],
[
"9, 3",
"\"100\""
],
[
"234, 2",
"\"11101010\""
],
[
"16, 2",
"\"10000\""
],
[
"8, 2",
"\"1000\""
],
[
"7, 2",
"\"111\""
]
] |
change_base
|
humaneval_java_python_44
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String change_base(int x, int base) {
StringBuilder ret = new StringBuilder();
while (x > 0) {
ret.append(String.valueOf(x % base));
x /= base;
}
return ret.reverse().toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def triangle_area(a, h):
return a * h / 2.0
|
[
[
"5, 3",
"7.5"
],
[
"2, 2",
"2.0"
],
[
"10, 8",
"40.0"
]
] |
triangle_area
|
humaneval_java_python_45
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public double triangle_area(double a, double h) {
return a * h / 2;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def fib4(n: int):
results = [0, 0, 2, 0]
if n < 4:
return results[n]
for _ in range(4, n + 1):
results.append(results[-1] + results[-2] + results[-3] + results[-4])
results.pop(0)
return results[-1]
|
[
[
"5",
"4"
],
[
"8",
"28"
],
[
"10",
"104"
],
[
"12",
"386"
]
] |
fib4
|
humaneval_java_python_46
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int fib4(int n) {
List<Integer> results = new ArrayList<>();
results.add(0);
results.add(0);
results.add(2);
results.add(0);
if (n < 4) {
return results.get(n);
}
for (int i = 4; i <= n; i++) {
results.add(results.get(0) + results.get(1) + results.get(2) + results.get(3));
results.remove(0);
}
return results.get(3);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def median(l: list):
l = sorted(l)
if len(l) % 2 == 1:
return l[len(l) // 2]
else:
return (l[len(l) // 2 - 1] + l[len(l) // 2]) / 2.0
|
[
[
"[3, 1, 2, 4, 5]",
"3"
],
[
"[-10, 4, 6, 1000, 10, 20]",
"8.0"
],
[
"[5]",
"5"
],
[
"[6, 5]",
"5.5"
],
[
"[8, 1, 3, 9, 9, 2, 7]",
"7"
]
] |
median
|
humaneval_java_python_47
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public double median(List<Integer> l) {
List<Integer> list = l;
Collections.sort(list);
if (l.size() % 2 == 1) {
return l.get(l.size() / 2);
} else {
return (l.get(l.size() / 2 - 1) + l.get(l.size() / 2)) / 2.0;
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_palindrome(text: str):
for i in range(len(text)):
if text[i] != text[len(text) - 1 - i]:
return False
return True
|
[
[
"''",
"True"
],
[
"'aba'",
"True"
],
[
"'aaaaa'",
"True"
],
[
"'zbcd'",
"False"
],
[
"'xywyx'",
"True"
],
[
"'xywyz'",
"False"
],
[
"'xywzx'",
"False"
]
] |
is_palindrome
|
humaneval_java_python_48
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean is_palindrome(String text) {
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) != text.charAt(text.length() - 1 - i)) {
return false;
}
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def modp(n: int, p: int):
ret = 1
for i in range(n):
ret = (2 * ret) % p
return ret
|
[
[
"3, 5",
"3"
],
[
"1101, 101",
"2"
],
[
"0, 101",
"1"
],
[
"3, 11",
"8"
],
[
"100, 101",
"1"
],
[
"30, 5",
"4"
],
[
"31, 5",
"3"
]
] |
modp
|
humaneval_java_python_49
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int modp(int n, int p) {
int ret = 1;
for (int i = 0; i < n; i++) {
ret = (ret * 2) % p;
}
return ret;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def encode_shift(s: str):
"""
returns encoded string by shifting every character by 5 in the alphabet.
"""
return "".join([chr(((ord(ch) + 5 - ord("a")) % 26) + ord("a")) for ch in s])
def decode_shift(s: str):
return "".join([chr(((ord(ch) - 5 - ord("a")) % 26) + ord("a")) for ch in s])
|
[
[
"\"nppetuavkhytds\"",
"\"ikkzopvqfctoyn\""
],
[
"\"jkwevzwwetoiui\"",
"\"efrzqurrzojdpd\""
],
[
"\"deqhgbmrgyvolvllvgu\"",
"\"yzlcbwhmbtqjgqggqbp\""
],
[
"\"adwtpwmzzsba\"",
"\"vyrokrhuunwv\""
],
[
"\"kviyfxcqqk\"",
"\"fqdtasxllf\""
],
[
"\"owuxsmtkqyi\"",
"\"jrpsnhofltd\""
],
[
"\"nnmfgsupnnlfnyke\"",
"\"iihabnpkiigaitfz\""
],
[
"\"neklmdclmzoro\"",
"\"izfghyxghujmj\""
],
[
"\"lesnecsgpsgcya\"",
"\"gznizxnbknbxtv\""
],
[
"\"oxbtwcbwsxinxvdwir\"",
"\"jsworxwrnsdisqyrdm\""
],
[
"\"sdghpnyvoqrwpzgvdu\"",
"\"nybckitqjlmrkubqyp\""
],
[
"\"jyzljgmjrbquen\"",
"\"etugebhemwlpzi\""
],
[
"\"zgyrlfbwabpjhperjslh\"",
"\"ubtmgawrvwkeckzmengc\""
],
[
"\"qleffvhomvtyngciggde\"",
"\"lgzaaqcjhqotibxdbbyz\""
],
[
"\"qqpicuvmrtkj\"",
"\"llkdxpqhmofe\""
],
[
"\"jyyevmecuetxqrirfd\"",
"\"ettzqhzxpzoslmdmay\""
],
[
"\"lmbsrqvjevdtb\"",
"\"ghwnmlqezqyow\""
],
[
"\"whxcodekelxlmln\"",
"\"rcsxjyzfzgsghgi\""
],
[
"\"delrtygeoyvml\"",
"\"yzgmotbzjtqhg\""
],
[
"\"apdqbcrttlq\"",
"\"vkylwxmoogl\""
],
[
"\"xttskzvkfh\"",
"\"soonfuqfac\""
],
[
"\"olbwqqdnru\"",
"\"jgwrllyimp\""
],
[
"\"ehdpgbpcwbqsqr\"",
"\"zcykbwkxrwlnlm\""
],
[
"\"oxbdypniamafgtsz\"",
"\"jswytkidvhvabonu\""
],
[
"\"sdnuydcckyvllunfbxi\"",
"\"nyiptyxxftqggpiawsd\""
],
[
"\"antvcacedbucqjmhl\"",
"\"vioqxvxzywpxlehcg\""
],
[
"\"zogbormycllavatve\"",
"\"ujbwjmhtxggvqvoqz\""
],
[
"\"fuueutygaxwywovpnigy\"",
"\"appzpotbvsrtrjqkidbt\""
],
[
"\"jknughmjbqvtcrulb\"",
"\"efipbchewlqoxmpgw\""
],
[
"\"xbvxtynbqwz\"",
"\"swqsotiwlru\""
],
[
"\"mgctjkezbtnklcsw\"",
"\"hbxoefzuwoifgxnr\""
],
[
"\"fmelllajoemkowluz\"",
"\"ahzgggvejzhfjrgpu\""
],
[
"\"ptozvzdtyvnhzime\"",
"\"kojuquyotqicudhz\""
],
[
"\"xxhgplwbzs\"",
"\"sscbkgrwun\""
],
[
"\"rfzoarauxuka\"",
"\"maujvmvpspfv\""
],
[
"\"twqnkxildqtbrbjwyqrh\"",
"\"orlifsdgylowmwertlmc\""
],
[
"\"eildvqeupsl\"",
"\"zdgyqlzpkng\""
],
[
"\"pnzptdzfhzxpn\"",
"\"kiukoyuacuski\""
],
[
"\"hbmzwirdoar\"",
"\"cwhurdmyjvm\""
],
[
"\"gaqxkjkpnwkca\"",
"\"bvlsfefkirfxv\""
],
[
"\"xddhfaftiziqebsa\"",
"\"syycavaodudlzwnv\""
],
[
"\"ydyqdhblfckp\"",
"\"tytlycwgaxfk\""
],
[
"\"ymypgwmwogoudeq\"",
"\"thtkbrhrjbjpyzl\""
],
[
"\"unvmuxgbdyhchso\"",
"\"piqhpsbwytcxcnj\""
],
[
"\"dhghjsovcb\"",
"\"ycbcenjqxw\""
],
[
"\"piinwbmppf\"",
"\"kddirwhkka\""
],
[
"\"zvyoceomaxjcgwprqm\"",
"\"uqtjxzjhvsexbrkmlh\""
],
[
"\"eijmnrfqtqudyv\"",
"\"zdehimalolpytq\""
],
[
"\"qpeqklfmwnry\"",
"\"lkzlfgahrimt\""
],
[
"\"fwnkdnyqbo\"",
"\"arifyitlwj\""
],
[
"\"smcxegzdxbfd\"",
"\"nhxszbuysway\""
],
[
"\"jvtkgaecmqnpszjvf\"",
"\"eqofbvzxhliknueqa\""
],
[
"\"aurjwvkebktdv\"",
"\"vpmerqfzwfoyq\""
],
[
"\"nfmmmhjeliakugh\"",
"\"iahhhcezgdvfpbc\""
],
[
"\"eyfxptmpshohi\"",
"\"ztaskohkncjcd\""
],
[
"\"glaoltrkxsmxspdvow\"",
"\"bgvjgomfsnhsnkyqjr\""
],
[
"\"zwyupdxanebym\"",
"\"urtpkysvizwth\""
],
[
"\"xkoigfpvcvqcxcgeoq\"",
"\"sfjdbakqxqlxsxbzjl\""
],
[
"\"fgizxalyjcpkvkt\"",
"\"abdusvgtexkfqfo\""
],
[
"\"zirsuhlzwi\"",
"\"udmnpcgurd\""
],
[
"\"zhwqbyhkbqeomarlldcb\"",
"\"ucrlwtcfwlzjhvmggyxw\""
],
[
"\"rvshqbrvsxnjfjakul\"",
"\"mqnclwmqnsieaevfpg\""
],
[
"\"nktgcnuxplhfsm\"",
"\"ifobxipskgcanh\""
],
[
"\"baoiqymypxkvlrn\"",
"\"wvjdlthtksfqgmi\""
],
[
"\"nwagelwecafiphlj\"",
"\"irvbzgrzxvadkcge\""
],
[
"\"kbqtmzbujxumptcvyl\"",
"\"fwlohuwpesphkoxqtg\""
],
[
"\"dujvyrdslwf\"",
"\"ypeqtmyngra\""
],
[
"\"vujolzbqoqekvv\"",
"\"qpejguwljlzfqq\""
],
[
"\"hbbdoumleckjwhws\"",
"\"cwwyjphgzxfercrn\""
],
[
"\"aykhykkfnxckhmzndki\"",
"\"vtfctffaisxfchuiyfd\""
],
[
"\"wpidhybggvempzrfa\"",
"\"rkdyctwbbqzhkumav\""
],
[
"\"dwgrdroeuiduby\"",
"\"yrbmymjzpdypwt\""
],
[
"\"yptrachqjtgrgqxy\"",
"\"tkomvxcleobmblst\""
],
[
"\"gjragaaocfbadfbeebky\"",
"\"bemvbvvjxawvyawzzwft\""
],
[
"\"rnisigwzqqshj\"",
"\"midndbrullnce\""
],
[
"\"gzivhmjtyysqsuqubbur\"",
"\"budqcheottnlnplpwwpm\""
],
[
"\"gfmeiuvbyuuiiflplahw\"",
"\"bahzdpqwtppddagkgvcr\""
],
[
"\"iczpwzppirpxfm\"",
"\"dxukrukkdmksah\""
],
[
"\"hwtxjblmlsikphbivd\"",
"\"crosewghgndfkcwdqy\""
],
[
"\"fwzjefnnnjwhv\"",
"\"aruezaiiiercq\""
],
[
"\"sysvhbbqkh\"",
"\"ntnqcwwlfc\""
],
[
"\"lbwiwpvlcdtvh\"",
"\"gwrdrkqgxyoqc\""
],
[
"\"rlehhmhevv\"",
"\"mgzcchczqq\""
],
[
"\"qtrfjsocbsldii\"",
"\"lomaenjxwngydd\""
],
[
"\"eszhonrsle\"",
"\"znucjimngz\""
],
[
"\"jvzxprqiyfqfj\"",
"\"equskmldtalae\""
],
[
"\"wdzasevrfyobkbro\"",
"\"ryuvnzqmatjwfwmj\""
],
[
"\"hzvhjetyyntxiplf\"",
"\"cuqcezottiosdkga\""
],
[
"\"yfskmymfdjqooty\"",
"\"tanfhthayeljjot\""
],
[
"\"rrtepprngbbv\"",
"\"mmozkkmibwwq\""
],
[
"\"zsqaqzsbxtwpqa\"",
"\"unlvlunwsorklv\""
],
[
"\"kneyiarobkgl\"",
"\"fiztdvmjwfbg\""
],
[
"\"xxbudxuwlhi\"",
"\"sswpysprgcd\""
],
[
"\"fetivyuynb\"",
"\"azodqtptiw\""
],
[
"\"syswumgxpgxmcwzgedq\"",
"\"ntnrphbskbshxrubzyl\""
],
[
"\"xychwdsfyfoly\"",
"\"stxcrynatajgt\""
],
[
"\"nfwrujwavgavutrxuzsg\"",
"\"iarmpervqbvqpomspunb\""
],
[
"\"vuhhhndgmzkwplolb\"",
"\"qpccciybhufrkgjgw\""
],
[
"\"fwqxfhbqjbgryci\"",
"\"arlsacwlewbmtxd\""
],
[
"\"amzcptlnzkor\"",
"\"vhuxkogiufjm\""
]
] |
decode_shift
|
humaneval_java_python_50
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
/**
returns encoded string by shifting every character by 5 in the alphabet.
*/
public String decode_shift(String s) {
StringBuilder sb = new StringBuilder();
for (char ch : s.toCharArray()) {
sb.append((char) ('a' + ((ch + 5 - 'a') % 26)));
}
return sb.toString();
}
public String decodeShift(String s) {
StringBuilder sb = new StringBuilder();
for (char ch : s.toCharArray()) {
sb.append((char) ('a' + ((ch + 21 - 'a') % 26)));
}
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def remove_vowels(text):
return "".join([s for s in text if s.lower() not in ["a", "e", "i", "o", "u"]])
|
[
[
"''",
"''"
],
[
"\"abcdef\\nghijklm\"",
"'bcdf\\nghjklm'"
],
[
"'fedcba'",
"'fdcb'"
],
[
"'eeeee'",
"''"
],
[
"'acBAA'",
"'cB'"
],
[
"'EcBOO'",
"'cB'"
],
[
"'ybcd'",
"'ybcd'"
]
] |
remove_vowels
|
humaneval_java_python_51
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String remove_vowels(String text) {
StringBuilder sb = new StringBuilder();
for (char ch : text.toCharArray()) {
if ("aeiou".indexOf(Character.toLowerCase(ch)) == -1) {
sb.append(ch);
}
}
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def below_threshold(l: list, t: int):
for e in l:
if e >= t:
return False
return True
|
[
[
"[1, 2, 4, 10], 100",
"True"
],
[
"[1, 20, 4, 10], 5",
"False"
],
[
"[1, 20, 4, 10], 21",
"True"
],
[
"[1, 20, 4, 10], 22",
"True"
],
[
"[1, 8, 4, 10], 11",
"True"
],
[
"[1, 8, 4, 10], 10",
"False"
]
] |
below_threshold
|
humaneval_java_python_52
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean below_threshold(List<Integer> l, int t) {
for (int e : l) {
if (e >= t) {
return false;
}
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def add(x: int, y: int):
return x + y
|
[
[
"0, 1",
"1"
],
[
"1, 0",
"1"
],
[
"2, 3",
"5"
],
[
"5, 7",
"12"
],
[
"7, 5",
"12"
]
] |
add
|
humaneval_java_python_53
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int add(int x, int y) {
return x + y;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def same_chars(s0: str, s1: str):
return set(s0) == set(s1)
|
[
[
"'eabcdzzzz', 'dddzzzzzzzddeddabc'",
"True"
],
[
"'abcd', 'dddddddabc'",
"True"
],
[
"'dddddddabc', 'abcd'",
"True"
],
[
"'eabcd', 'dddddddabc'",
"False"
],
[
"'abcd', 'dddddddabcf'",
"False"
],
[
"'eabcdzzzz', 'dddzzzzzzzddddabc'",
"False"
],
[
"'aabb', 'aaccc'",
"False"
]
] |
same_chars
|
humaneval_java_python_54
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean same_chars(String s0, String s1) {
Set<Character> set0 = new HashSet<>();
for (char c : s0.toCharArray()) {
set0.add(c);
}
Set<Character> set1 = new HashSet<>();
for (char c : s1.toCharArray()) {
set1.add(c);
}
return set0.equals(set1);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def fib(n: int):
if n == 0:
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
|
[
[
"10",
"55"
],
[
"1",
"1"
],
[
"8",
"21"
],
[
"11",
"89"
],
[
"12",
"144"
]
] |
fib
|
humaneval_java_python_55
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int fib(int n) {
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
return fib(n - 1) + fib(n - 2);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def correct_bracketing(brackets: str):
depth = 0
for b in brackets:
if b == "<":
depth += 1
else:
depth -= 1
if depth < 0:
return False
return depth == 0
|
[
[
"'<>'",
"True"
],
[
"'<<><>>'",
"True"
],
[
"'<><><<><>><>'",
"True"
],
[
"'<<<><>>>>'",
"False"
],
[
"'><<>'",
"False"
],
[
"'<'",
"False"
],
[
"'<<<<'",
"False"
],
[
"'>'",
"False"
],
[
"'<<>'",
"False"
],
[
"'<><><<><>><>><<>'",
"False"
],
[
"'<><><<><>><>>><>'",
"False"
]
] |
correct_bracketing
|
humaneval_java_python_56
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean correct_bracketing(String brackets) {
int depth = 0;
for (char b : brackets.toCharArray()) {
if (b == '<') {
depth += 1;
} else {
depth -= 1;
}
if (depth < 0) {
return false;
}
}
return depth == 0;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def monotonic(l: list):
if l == sorted(l) or l == sorted(l, reverse=True):
return True
return False
|
[
[
"[1, 2, 4, 10]",
"True"
],
[
"[1, 2, 4, 20]",
"True"
],
[
"[1, 20, 4, 10]",
"False"
],
[
"[4, 1, 0, -10]",
"True"
],
[
"[4, 1, 1, 0]",
"True"
],
[
"[1, 2, 3, 2, 5, 60]",
"False"
],
[
"[1, 2, 3, 4, 5, 60]",
"True"
],
[
"[9, 9, 9, 9]",
"True"
]
] |
monotonic
|
humaneval_java_python_57
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean monotonic(List<Integer> l) {
List<Integer> l1 = new ArrayList<>(l), l2 = new ArrayList<>(l);
Collections.sort(l1);
l2.sort(Collections.reverseOrder());
return l.equals(l1) || l.equals(l2);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def common(l1: list, l2: list):
ret = set()
for e1 in l1:
for e2 in l2:
if e1 == e2:
ret.add(e1)
return sorted(list(ret))
|
[
[
"[1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]",
"[1, 5, 653]"
],
[
"[5, 3, 2, 8], [3, 2]",
"[2, 3]"
],
[
"[4, 3, 2, 8], [3, 2, 4]",
"[2, 3, 4]"
],
[
"[4, 3, 2, 8], []",
"[]"
]
] |
common
|
humaneval_java_python_58
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> common(List<Integer> l1, List<Integer> l2) {
Set<Integer> ret = new HashSet<>(l1);
ret.retainAll(new HashSet<>(l2));
List<Integer> result = new ArrayList<>(ret);
Collections.sort(result);
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def largest_prime_factor(n: int):
def is_prime(k):
if k < 2:
return False
for i in range(2, k - 1):
if k % i == 0:
return False
return True
largest = 1
for j in range(2, n + 1):
if n % j == 0 and is_prime(j):
largest = max(largest, j)
return largest
|
[
[
"15",
"5"
],
[
"27",
"3"
],
[
"63",
"7"
],
[
"330",
"11"
],
[
"13195",
"29"
]
] |
largest_prime_factor
|
humaneval_java_python_59
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int largest_prime_factor(int n) {
int largest = 1;
for (int j = 2; j <= n; j++) {
if (n % j == 0) {
boolean is_prime = j >= 2;
for (int i = 2; i < j - 1; i++) {
if (j % i == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
largest = Math.max(largest, j);
}
}
}
return largest;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def sum_to_n(n: int):
return sum(range(n + 1))
|
[
[
"1",
"1"
],
[
"6",
"21"
],
[
"11",
"66"
],
[
"30",
"465"
],
[
"100",
"5050"
]
] |
sum_to_n
|
humaneval_java_python_60
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int sum_to_n(int n) {
int result = 0;
for (int i = 1; i <= n; i++) {
result += i;
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def correct_bracketing(brackets: str):
depth = 0
for b in brackets:
if b == "(":
depth += 1
else:
depth -= 1
if depth < 0:
return False
return depth == 0
|
[
[
"'()'",
"True"
],
[
"'(()())'",
"True"
],
[
"'()()(()())()'",
"True"
],
[
"'()()((()()())())(()()(()))'",
"True"
],
[
"'((()())))'",
"False"
],
[
"')(()'",
"False"
],
[
"'(((('",
"False"
],
[
"'('",
"False"
],
[
"')'",
"False"
],
[
"'(()'",
"False"
],
[
"'()()(()())())(()'",
"False"
],
[
"'()()(()())()))()'",
"False"
]
] |
correct_bracketing
|
humaneval_java_python_61
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean correct_bracketing(String brackets) {
int depth = 0;
for (char b : brackets.toCharArray()) {
if (b == '(') {
depth += 1;
} else {
depth -= 1;
}
if (depth < 0) {
return false;
}
}
return depth == 0;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def derivative(xs: list):
return [(i * x) for i, x in enumerate(xs)][1:]
|
[
[
"[3, 1, 2, 4, 5]",
"[1, 4, 12, 20]"
],
[
"[1, 2, 3]",
"[2, 6]"
],
[
"[3, 2, 1]",
"[2, 2]"
],
[
"[3, 2, 1, 0, 4]",
"[2, 2, 0, 16]"
],
[
"[1]",
"[]"
]
] |
derivative
|
humaneval_java_python_62
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> derivative(List<Integer> xs) {
List<Integer> result = new ArrayList<>();
for (int i = 1; i < xs.size(); i++) {
result.add(i * xs.get(i));
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def fibfib(n: int):
if n == 0:
return 0
if n == 1:
return 0
if n == 2:
return 1
return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3)
|
[
[
"2",
"1"
],
[
"1",
"0"
],
[
"5",
"4"
],
[
"8",
"24"
],
[
"10",
"81"
],
[
"12",
"274"
],
[
"14",
"927"
]
] |
fibfib
|
humaneval_java_python_63
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int fibfib(int n) {
if (n == 0) {
return 0;
}
if (n == 1) {
return 0;
}
if (n == 2) {
return 1;
}
return fibfib(n - 1) + fibfib(n - 2) + fibfib(n - 3);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
FIX = """
Add more test cases.
"""
def vowels_count(s):
vowels = "aeiouAEIOU"
n_vowels = sum(c in vowels for c in s)
if s[-1] == 'y' or s[-1] == 'Y':
n_vowels += 1
return n_vowels
|
[
[
"\"abcde\"",
"2"
],
[
"\"Alone\"",
"3"
],
[
"\"key\"",
"2"
],
[
"\"bye\"",
"1"
],
[
"\"keY\"",
"2"
],
[
"\"bYe\"",
"1"
],
[
"\"ACEDY\"",
"3"
]
] |
vowels_count
|
humaneval_java_python_64
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int vowels_count(String s) {
String vowels = "aeiouAEIOU";
int n_vowels = 0;
for (char c : s.toCharArray()) {
if (vowels.indexOf(c) != -1) {
n_vowels += 1;
}
}
if (s.charAt(s.length() - 1) == 'y' || s.charAt(s.length() - 1) == 'Y') {
n_vowels += 1;
}
return n_vowels;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def circular_shift(x, shift):
s = str(x)
if shift > len(s):
return s[::-1]
else:
return s[len(s) - shift:] + s[:len(s) - shift]
|
[
[
"100, 2",
"\"001\""
],
[
"12, 2",
"\"12\""
],
[
"97, 8",
"\"79\""
],
[
"12, 1",
"\"21\""
],
[
"11, 101",
"\"11\""
]
] |
circular_shift
|
humaneval_java_python_65
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String circular_shift(int x, int shift) {
String s = String.valueOf(x);
if (shift > s.length()) {
return new StringBuilder(s).reverse().toString();
} else {
return s.substring(s.length() - shift) + s.substring(0, s.length() - shift);
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def digitSum(s):
if s == "": return 0
return sum(ord(char) if char.isupper() else 0 for char in s)
|
[
[
"\"\"",
"0"
],
[
"\"abAB\"",
"131"
],
[
"\"abcCd\"",
"67"
],
[
"\"helloE\"",
"69"
],
[
"\"woArBld\"",
"131"
],
[
"\"aAaaaXa\"",
"153"
],
[
"\" How are yOu?\"",
"151"
],
[
"\"You arE Very Smart\"",
"327"
]
] |
digitSum
|
humaneval_java_python_66
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int digitSum(String s) {
int sum = 0;
for (char c : s.toCharArray()) {
if (Character.isUpperCase(c)) {
sum += c;
}
}
return sum;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def fruit_distribution(s,n):
lis = list()
for i in s.split(' '):
if i.isdigit():
lis.append(int(i))
return n - sum(lis)
|
[
[
"\"5 apples and 6 oranges\", 19",
"8"
],
[
"\"5 apples and 6 oranges\", 21",
"10"
],
[
"\"0 apples and 1 oranges\", 3",
"2"
],
[
"\"1 apples and 0 oranges\", 3",
"2"
],
[
"\"2 apples and 3 oranges\", 100",
"95"
],
[
"\"2 apples and 3 oranges\", 5",
"0"
],
[
"\"1 apples and 100 oranges\", 120",
"19"
]
] |
fruit_distribution
|
humaneval_java_python_67
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int fruit_distribution(String s, int n) {
List<Integer> lis = new ArrayList<>();
for (String i : s.split(" ")) {
try {
lis.add(Integer.parseInt(i));
} catch (NumberFormatException ignored) {
}
}
return n - lis.stream().mapToInt(Integer::intValue).sum();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def pluck(arr):
if(len(arr) == 0): return []
evens = list(filter(lambda x: x%2 == 0, arr))
if(evens == []): return []
return [min(evens), arr.index(min(evens))]
|
[
[
"[4,2,3]",
"[2, 1]"
],
[
"[1,2,3]",
"[2, 1]"
],
[
"[]",
"[]"
],
[
"[5, 0, 3, 0, 4, 2]",
"[0, 1]"
],
[
"[1, 2, 3, 0, 5, 3]",
"[0, 3]"
],
[
"[5, 4, 8, 4 ,8]",
"[4, 1]"
],
[
"[7, 6, 7, 1]",
"[6, 1]"
],
[
"[7, 9, 7, 1]",
"[]"
]
] |
pluck
|
humaneval_java_python_68
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> pluck(List<Integer> arr) {
List<Integer> result = new ArrayList<>();
if (arr.size() == 0) {
return result;
}
int min = Integer.MAX_VALUE;
int minIndex = -1;
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) % 2 == 0) {
if (arr.get(i) < min) {
min = arr.get(i);
minIndex = i;
}
}
}
if (minIndex != -1) {
result.add(min);
result.add(minIndex);
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def search(lst):
frq = [0] * (max(lst) + 1)
for i in lst:
frq[i] += 1;
ans = -1
for i in range(1, len(frq)):
if frq[i] >= i:
ans = i
return ans
|
[
[
"[5, 5, 5, 5, 1]",
"1"
],
[
"[4, 1, 4, 1, 4, 4]",
"4"
],
[
"[3, 3]",
"-1"
],
[
"[8, 8, 8, 8, 8, 8, 8, 8]",
"8"
],
[
"[2, 3, 3, 2, 2]",
"2"
],
[
"[2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1]",
"1"
],
[
"[3, 2, 8, 2]",
"2"
],
[
"[6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10]",
"1"
],
[
"[8, 8, 3, 6, 5, 6, 4]",
"-1"
],
[
"[6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9]",
"1"
],
[
"[1, 9, 10, 1, 3]",
"1"
],
[
"[6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10]",
"5"
],
[
"[1]",
"1"
],
[
"[8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5]",
"4"
],
[
"[2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10]",
"2"
],
[
"[1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3]",
"1"
],
[
"[9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4]",
"4"
],
[
"[2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7]",
"4"
],
[
"[9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1]",
"2"
],
[
"[5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8]",
"-1"
],
[
"[10]",
"-1"
],
[
"[9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2]",
"2"
],
[
"[5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8]",
"1"
],
[
"[7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6]",
"1"
],
[
"[3, 10, 10, 9, 2]",
"-1"
]
] |
search
|
humaneval_java_python_69
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int search(List<Integer> lst) {
int[] frq = new int[Collections.max(lst) + 1];
for (int i : lst) {
frq[i] += 1;
}
int ans = -1;
for (int i = 1; i < frq.length; i++) {
if (frq[i] >= i) {
ans = i;
}
}
return ans;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def strange_sort_list(lst):
res, switch = [], True
while lst:
res.append(min(lst) if switch else max(lst))
lst.remove(res[-1])
switch = not switch
return res
|
[
[
"[1, 2, 3, 4]",
"[1, 4, 2, 3]"
],
[
"[5, 6, 7, 8, 9]",
"[5, 9, 6, 8, 7]"
],
[
"[1, 2, 3, 4, 5]",
"[1, 5, 2, 4, 3]"
],
[
"[5, 6, 7, 8, 9, 1]",
"[1, 9, 5, 8, 6, 7]"
],
[
"[5, 5, 5, 5]",
"[5, 5, 5, 5]"
],
[
"[]",
"[]"
],
[
"[1,2,3,4,5,6,7,8]",
"[1, 8, 2, 7, 3, 6, 4, 5]"
],
[
"[0,2,2,2,5,5,-5,-5]",
"[-5, 5, -5, 5, 0, 2, 2, 2]"
],
[
"[111111]",
"[111111]"
]
] |
strange_sort_list
|
humaneval_java_python_70
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> strange_sort_list(List<Integer> lst) {
List<Integer> res = new ArrayList<>();
boolean _switch = true;
List<Integer> l = new ArrayList<>(lst);
while (l.size() != 0) {
if (_switch) {
res.add(Collections.min(l));
} else {
res.add(Collections.max(l));
}
l.remove(res.get(res.size() - 1));
_switch = !_switch;
}
return res;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def triangle_area(a, b, c):
if a + b <= c or a + c <= b or b + c <= a:
return -1
s = (a + b + c)/2
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
area = round(area, 2)
return area
|
[
[
"3, 4, 5",
"6.00"
],
[
"1, 2, 10",
"-1"
],
[
"4, 8, 5",
"8.18"
],
[
"2, 2, 2",
"1.73"
],
[
"1, 2, 3",
"-1"
],
[
"10, 5, 7",
"16.25"
],
[
"2, 6, 3",
"-1"
],
[
"1, 1, 1",
"0.43"
],
[
"2, 2, 10",
"-1"
]
] |
triangle_area
|
humaneval_java_python_71
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public double triangle_area(double a, double b, double c) {
if (a + b <= c || a + c <= b || b + c <= a) {
return -1;
}
double s = (a + b + c) / 2;
double area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
area = (double) Math.round(area * 100) / 100;
return area;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def will_it_fly(q,w):
if sum(q) > w:
return False
i, j = 0, len(q)-1
while i<j:
if q[i] != q[j]:
return False
i+=1
j-=1
return True
|
[
[
"[3, 2, 3], 9",
"True"
],
[
"[1, 2], 5",
"False"
],
[
"[3], 5",
"True"
],
[
"[3, 2, 3], 1",
"False"
],
[
"[1, 2, 3], 6",
"False"
],
[
"[5], 5",
"True"
]
] |
will_it_fly
|
humaneval_java_python_72
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean will_it_fly(List<Integer> q, int w) {
if (q.stream().reduce(0, Integer::sum) > w) {
return false;
}
int i = 0, j = q.size() - 1;
while (i < j) {
if (!Objects.equals(q.get(i), q.get(j))) {
return false;
}
i += 1;
j -= 1;
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def smallest_change(arr):
ans = 0
for i in range(len(arr) // 2):
if arr[i] != arr[len(arr) - i - 1]:
ans += 1
return ans
|
[
[
"[1,2,3,5,4,7,9,6]",
"4"
],
[
"[1, 2, 3, 4, 3, 2, 2]",
"1"
],
[
"[1, 4, 2]",
"1"
],
[
"[1, 4, 4, 2]",
"1"
],
[
"[1, 2, 3, 2, 1]",
"0"
],
[
"[3, 1, 1, 3]",
"0"
],
[
"[1]",
"0"
],
[
"[0, 1]",
"1"
]
] |
smallest_change
|
humaneval_java_python_73
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int smallest_change(List<Integer> arr) {
int ans = 0;
for (int i = 0; i < arr.size() / 2; i++) {
if (!Objects.equals(arr.get(i), arr.get(arr.size() - i - 1))) {
ans += 1;
}
}
return ans;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def total_match(lst1, lst2):
l1 = 0
for st in lst1:
l1 += len(st)
l2 = 0
for st in lst2:
l2 += len(st)
if l1 <= l2:
return lst1
else:
return lst2
|
[
[
"[], []",
"[]"
],
[
"['hi', 'admin'], ['hi', 'hi']",
"['hi', 'hi']"
],
[
"['hi', 'admin'], ['hi', 'hi', 'admin', 'project']",
"['hi', 'admin']"
],
[
"['4'], ['1', '2', '3', '4', '5']",
"['4']"
],
[
"['hi', 'admin'], ['hI', 'Hi']",
"['hI', 'Hi']"
],
[
"['hi', 'admin'], ['hI', 'hi', 'hi']",
"['hI', 'hi', 'hi']"
],
[
"['hi', 'admin'], ['hI', 'hi', 'hii']",
"['hi', 'admin']"
],
[
"[], ['this']",
"[]"
],
[
"['this'], []",
"[]"
]
] |
total_match
|
humaneval_java_python_74
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<String> total_match(List<String> lst1, List<String> lst2) {
int l1 = 0;
for (String st : lst1) {
l1 += st.length();
}
int l2 = 0;
for (String st : lst2) {
l2 += st.length();
}
if (l1 <= l2) {
return lst1;
} else {
return lst2;
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_multiply_prime(a):
def is_prime(n):
for j in range(2,n):
if n%j == 0:
return False
return True
for i in range(2,101):
if not is_prime(i): continue
for j in range(2,101):
if not is_prime(j): continue
for k in range(2,101):
if not is_prime(k): continue
if i*j*k == a: return True
return False
|
[
[
"5",
"False"
],
[
"30",
"True"
],
[
"8",
"True"
],
[
"10",
"False"
],
[
"125",
"True"
],
[
"3 * 5 * 7",
"True"
],
[
"3 * 6 * 7",
"False"
],
[
"9 * 9 * 9",
"False"
],
[
"11 * 9 * 9",
"False"
],
[
"11 * 13 * 7",
"True"
]
] |
is_multiply_prime
|
humaneval_java_python_75
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean is_multiply_prime(int a) {
class IsPrime {
public static boolean is_prime(int n) {
for (int j = 2; j < n; j++) {
if (n % j == 0) {
return false;
}
}
return true;
}
}
for (int i = 2; i < 101; i++) {
if (!IsPrime.is_prime(i)) {
continue;
}
for (int j = i; j < 101; j++) {
if (!IsPrime.is_prime(j)) {
continue;
}
for (int k = j; k < 101; k++) {
if (!IsPrime.is_prime(k)) {
continue;
}
if (i * j * k == a) {
return true;
}
}
}
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_simple_power(x, n):
if (n == 1):
return (x == 1)
power = 1
while (power < x):
power = power * n
return (power == x)
|
[
[
"16, 2",
"True"
],
[
"143214, 16",
"False"
],
[
"4, 2",
"True"
],
[
"9, 3",
"True"
],
[
"16, 4",
"True"
],
[
"24, 2",
"False"
],
[
"128, 4",
"False"
],
[
"12, 6",
"False"
],
[
"1, 1",
"True"
],
[
"1, 12",
"True"
]
] |
is_simple_power
|
humaneval_java_python_76
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean is_simple_power(int x, int n) {
if (n == 1) {
return x == 1;
}
int power = 1;
while (power < x) {
power = power * n;
}
return power == x;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def iscube(a):
a = abs(a)
return int(round(a ** (1. / 3))) ** 3 == a
|
[
[
"1",
"True"
],
[
"2",
"False"
],
[
"-1",
"True"
],
[
"64",
"True"
],
[
"180",
"False"
],
[
"1000",
"True"
],
[
"0",
"True"
],
[
"1729",
"False"
]
] |
iscube
|
humaneval_java_python_77
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean iscube(int a) {
a = Math.abs(a);
return Math.round(Math.pow(Math.round(Math.pow(a, 1. / 3)), 3)) == a;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def hex_key(num):
primes = ('2', '3', '5', '7', 'B', 'D')
total = 0
for i in range(0, len(num)):
if num[i] in primes:
total += 1
return total
|
[
[
"\"AB\"",
"1"
],
[
"\"1077E\"",
"2"
],
[
"\"ABED1A33\"",
"4"
],
[
"\"2020\"",
"2"
],
[
"\"123456789ABCDEF0\"",
"6"
],
[
"\"112233445566778899AABBCCDDEEFF00\"",
"12"
],
[
"[]",
"0"
]
] |
hex_key
|
humaneval_java_python_78
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int hex_key(String num) {
String primes = "2357BD";
int total = 0;
for (char c : num.toCharArray()) {
if (primes.indexOf(c) != -1) {
total += 1;
}
}
return total;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def decimal_to_binary(decimal):
return "db" + bin(decimal)[2:] + "db"
|
[
[
"0",
"\"db0db\""
],
[
"32",
"\"db100000db\""
],
[
"103",
"\"db1100111db\""
],
[
"15",
"\"db1111db\""
]
] |
decimal_to_binary
|
humaneval_java_python_79
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String decimal_to_binary(int decimal) {
return "db" + Integer.toBinaryString(decimal) + "db";
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_happy(s):
if len(s) < 3:
return False
for i in range(len(s) - 2):
if s[i] == s[i+1] or s[i+1] == s[i+2] or s[i] == s[i+2]:
return False
return True
|
[
[
"\"a\"",
"False"
],
[
"\"aa\"",
"False"
],
[
"\"abcd\"",
"True"
],
[
"\"aabb\"",
"False"
],
[
"\"adb\"",
"True"
],
[
"\"xyy\"",
"False"
],
[
"\"iopaxpoi\"",
"True"
],
[
"\"iopaxioi\"",
"False"
]
] |
is_happy
|
humaneval_java_python_80
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean is_happy(String s) {
if (s.length() < 3) {
return false;
}
for (int i = 0; i < s.length() - 2; i++) {
if (s.charAt(i) == s.charAt(i + 1) || s.charAt(i + 1) == s.charAt(i + 2) || s.charAt(i) == s.charAt(i + 2)) {
return false;
}
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def numerical_letter_grade(grades):
letter_grade = []
for gpa in grades:
if gpa == 4.0:
letter_grade.append("A+")
elif gpa > 3.7:
letter_grade.append("A")
elif gpa > 3.3:
letter_grade.append("A-")
elif gpa > 3.0:
letter_grade.append("B+")
elif gpa > 2.7:
letter_grade.append("B")
elif gpa > 2.3:
letter_grade.append("B-")
elif gpa > 2.0:
letter_grade.append("C+")
elif gpa > 1.7:
letter_grade.append("C")
elif gpa > 1.3:
letter_grade.append("C-")
elif gpa > 1.0:
letter_grade.append("D+")
elif gpa > 0.7:
letter_grade.append("D")
elif gpa > 0.0:
letter_grade.append("D-")
else:
letter_grade.append("E")
return letter_grade
|
[
[
"[4.0, 3, 1.7, 2, 3.5]",
"['A+', 'B', 'C-', 'C', 'A-']"
],
[
"[1.2]",
"['D+']"
],
[
"[0.5]",
"['D-']"
],
[
"[0.0]",
"['E']"
],
[
"[1, 0.3, 1.5, 2.8, 3.3]",
"['D', 'D-', 'C-', 'B', 'B+']"
],
[
"[0, 0.7]",
"['E', 'D-']"
]
] |
numerical_letter_grade
|
humaneval_java_python_81
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<String> numerical_letter_grade(List<Double> grades) {
List<String> letter_grade = new ArrayList<>();
for (double gpa : grades) {
if (gpa == 4.0) {
letter_grade.add("A+");
} else if (gpa > 3.7) {
letter_grade.add("A");
} else if (gpa > 3.3) {
letter_grade.add("A-");
} else if (gpa > 3.0) {
letter_grade.add("B+");
} else if (gpa > 2.7) {
letter_grade.add("B");
} else if (gpa > 2.3) {
letter_grade.add("B-");
} else if (gpa > 2.0) {
letter_grade.add("C+");
} else if (gpa > 1.7) {
letter_grade.add("C");
} else if (gpa > 1.3) {
letter_grade.add("C-");
} else if (gpa > 1.0) {
letter_grade.add("D+");
} else if (gpa > 0.7) {
letter_grade.add("D");
} else if (gpa > 0.0) {
letter_grade.add("D-");
} else {
letter_grade.add("E");
}
}
return letter_grade;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def prime_length(string):
l = len(string)
if l == 0 or l == 1:
return False
for i in range(2, l):
if l % i == 0:
return False
return True
|
[
[
"'Hello'",
"True"
],
[
"'abcdcba'",
"True"
],
[
"'kittens'",
"True"
],
[
"'orange'",
"False"
],
[
"'wow'",
"True"
],
[
"'world'",
"True"
],
[
"'MadaM'",
"True"
],
[
"'Wow'",
"True"
],
[
"''",
"False"
],
[
"'HI'",
"True"
],
[
"'go'",
"True"
],
[
"'gogo'",
"False"
],
[
"'aaaaaaaaaaaaaaa'",
"False"
],
[
"'Madam'",
"True"
],
[
"'M'",
"False"
],
[
"'0'",
"False"
]
] |
prime_length
|
humaneval_java_python_82
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean prime_length(String string) {
int l = string.length();
if (l == 0 || l == 1) {
return false;
}
for (int i = 2; i < l; i++) {
if (l % i == 0) {
return false;
}
}
return true;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def starts_one_ends(n):
if n == 1: return 1
return 18 * (10 ** (n - 2))
|
[
[
"1",
"1"
],
[
"2",
"18"
],
[
"3",
"180"
],
[
"4",
"1800"
],
[
"5",
"18000"
]
] |
starts_one_ends
|
humaneval_java_python_83
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int starts_one_ends(int n) {
if (n == 1) {
return 1;
}
return 18 * (int) Math.pow(10, n - 2);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def solve(N):
return bin(sum(int(i) for i in str(N)))[2:]
|
[
[
"1000",
"\"1\""
],
[
"150",
"\"110\""
],
[
"147",
"\"1100\""
],
[
"333",
"\"1001\""
],
[
"963",
"\"10010\""
]
] |
solve
|
humaneval_java_python_84
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String solve(int N) {
int sum = 0;
for (char c : String.valueOf(N).toCharArray()) {
sum += (c - '0');
}
return Integer.toBinaryString(sum);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def add(lst):
return sum([lst[i] for i in range(1, len(lst), 2) if lst[i]%2 == 0])
|
[
[
"[4, 88]",
"88"
],
[
"[4, 5, 6, 7, 2, 122]",
"122"
],
[
"[4, 0, 6, 7]",
"0"
],
[
"[4, 4, 6, 8]",
"12"
]
] |
add
|
humaneval_java_python_85
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int add(List<Integer> lst) {
int sum = 0;
for (int i = 1; i < lst.size(); i += 2) {
if (lst.get(i) % 2 == 0) {
sum += lst.get(i);
}
}
return sum;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def anti_shuffle(s):
return ' '.join([''.join(sorted(list(i))) for i in s.split(' ')])
|
[
[
"'Hi'",
"'Hi'"
],
[
"'hello'",
"'ehllo'"
],
[
"'number'",
"'bemnru'"
],
[
"'abcd'",
"'abcd'"
],
[
"'Hello World!!!'",
"'Hello !!!Wdlor'"
],
[
"''",
"''"
],
[
"'Hi. My name is Mister Robot. How are you?'",
"'.Hi My aemn is Meirst .Rboot How aer ?ouy'"
]
] |
anti_shuffle
|
humaneval_java_python_86
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String anti_shuffle(String s) {
String[] strings = s.split(" ");
List<String> result = new ArrayList<>();
for (String string : strings) {
char[] chars = string.toCharArray();
Arrays.sort(chars);
result.add(String.copyValueOf(chars));
}
return String.join(" ", result);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def get_row(lst, x):
coords = [(i, j) for i in range(len(lst)) for j in range(len(lst[i])) if lst[i][j] == x]
return sorted(sorted(coords, key=lambda x: x[1], reverse=True), key=lambda x: x[0])
|
[
[
"[\n [1,2,3,4,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1",
"[(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)]"
],
[
"[\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,2,3,4,5,6]\n ], 2",
"[(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]"
],
[
"[\n [1,2,3,4,5,6],\n [1,2,3,4,5,6],\n [1,1,3,4,5,6],\n [1,2,1,4,5,6],\n [1,2,3,1,5,6],\n [1,2,3,4,1,6],\n [1,2,3,4,5,1]\n ], 1",
"[(0, 0), (1, 0), (2, 1), (2, 0), (3, 2), (3, 0), (4, 3), (4, 0), (5, 4), (5, 0), (6, 5), (6, 0)]"
],
[
"[], 1",
"[]"
],
[
"[[1]], 2",
"[]"
],
[
"[[], [1], [1, 2, 3]], 3",
"[(2, 2)]"
]
] |
get_row
|
humaneval_java_python_87
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<List<Integer>> get_row(List<List<Integer>> lst, int x) {
List<List<Integer>> coords = new ArrayList<>();
for (int i = 0; i < lst.size(); i++) {
List<List<Integer>> row = new ArrayList<>();
for (int j = lst.get(i).size() - 1; j >= 0; j--) {
if (lst.get(i).get(j) == x) {
row.add(Arrays.asList(i, j));
}
}
coords.addAll(row);
}
return coords;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def sort_array(array):
return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)
|
[
[
"[]",
"[]"
],
[
"[5]",
"[5]"
],
[
"[2, 4, 3, 0, 1, 5]",
"[0, 1, 2, 3, 4, 5]"
],
[
"[2, 4, 3, 0, 1, 5, 6]",
"[6, 5, 4, 3, 2, 1, 0]"
],
[
"[2, 1]",
"[1, 2]"
],
[
"[15, 42, 87, 32 ,11, 0]",
"[0, 11, 15, 32, 42, 87]"
],
[
"[21, 14, 23, 11]",
"[23, 21, 14, 11]"
]
] |
sort_array
|
humaneval_java_python_88
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> sort_array(List<Integer> array) {
if (array.size() == 0) {
return array;
}
List<Integer> result = new ArrayList<>(array);
if ((result.get(0) + result.get(result.size() - 1)) % 2 == 1) {
Collections.sort(result);
} else {
result.sort(Collections.reverseOrder());
}
return result;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def encrypt(s):
d = 'abcdefghijklmnopqrstuvwxyz'
out = ''
for c in s:
if c in d:
out += d[(d.index(c)+2*2) % 26]
else:
out += c
return out
|
[
[
"'hi'",
"'lm'"
],
[
"'asdfghjkl'",
"'ewhjklnop'"
],
[
"'gf'",
"'kj'"
],
[
"'et'",
"'ix'"
],
[
"'faewfawefaewg'",
"'jeiajeaijeiak'"
],
[
"'hellomyfriend'",
"'lippsqcjvmirh'"
],
[
"'dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh'",
"'hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl'"
],
[
"'a'",
"'e'"
]
] |
encrypt
|
humaneval_java_python_89
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String encrypt(String s) {
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) {
if (Character.isLetter(c)) {
sb.append((char) ('a' + (c - 'a' + 2 * 2) % 26));
} else {
sb.append(c);
}
}
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def next_smallest(lst):
lst = sorted(set(lst))
return None if len(lst) < 2 else lst[1]
|
[
[
"[1, 2, 3, 4, 5]",
"2"
],
[
"[5, 1, 4, 3, 2]",
"2"
],
[
"[]",
"None"
],
[
"[1, 1]",
"None"
],
[
"[1,1,1,1,0]",
"1"
],
[
"[1, 0**0]",
"None"
],
[
"[-35, 34, 12, -45]",
"-35"
]
] |
next_smallest
|
humaneval_java_python_90
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public Optional<Integer> next_smallest(List<Integer> lst) {
Set < Integer > set = new HashSet<>(lst);
List<Integer> l = new ArrayList<>(set);
Collections.sort(l);
if (l.size() < 2) {
return Optional.empty();
} else {
return Optional.of(l.get(1));
}
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def is_bored(S):
import re
sentences = re.split(r'[.?!]\s*', S)
return sum(sentence[0:2] == 'I ' for sentence in sentences)
|
[
[
"\"Hello world\"",
"0"
],
[
"\"Is the sky blue?\"",
"0"
],
[
"\"I love It !\"",
"1"
],
[
"\"bIt\"",
"0"
],
[
"\"I feel good today. I will be productive. will kill It\"",
"2"
],
[
"\"You and I are going for a walk\"",
"0"
]
] |
is_bored
|
humaneval_java_python_91
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int is_bored(String S) {
String [] sentences = S.split("[.?!]\s*");
int count = 0;
for (String sentence : sentences) {
if (sentence.subSequence(0, 2).equals("I ")) {
count += 1;
}
}
return count;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def any_int(x, y, z):
if isinstance(x,int) and isinstance(y,int) and isinstance(z,int):
if (x+y==z) or (x+z==y) or (y+z==x):
return True
return False
return False
|
[
[
"2, 3, 1",
"True"
],
[
"2.5, 2, 3",
"False"
],
[
"1.5, 5, 3.5",
"False"
],
[
"2, 6, 2",
"False"
],
[
"4, 2, 2",
"True"
],
[
"2.2, 2.2, 2.2",
"False"
],
[
"-4, 6, 2",
"True"
],
[
"2, 1, 1",
"True"
],
[
"3, 4, 7",
"True"
],
[
"3.0, 4, 7",
"False"
]
] |
any_int
|
humaneval_java_python_92
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean any_int(Object x, Object y, Object z) {
if (x instanceof Integer && y instanceof Integer && z instanceof Integer) {
return (int) x + (int) y == (int) z || (int) x + (int) z == (int) y || (int) y + (int) z == (int) x;
}
return false;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def encode(message):
vowels = "aeiouAEIOU"
vowels_replace = dict([(i, chr(ord(i) + 2)) for i in vowels])
message = message.swapcase()
return ''.join([vowels_replace[i] if i in vowels else i for i in message])
|
[
[
"'TEST'",
"'tgst'"
],
[
"'Mudasir'",
"'mWDCSKR'"
],
[
"'YES'",
"'ygs'"
],
[
"'This is a message'",
"'tHKS KS C MGSSCGG'"
],
[
"\"I DoNt KnOw WhAt tO WrItE\"",
"'k dQnT kNqW wHcT Tq wRkTg'"
]
] |
encode
|
humaneval_java_python_93
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public String encode(String message) {
String vowels = "aeiouAEIOU";
StringBuilder sb = new StringBuilder();
for (char c : message.toCharArray()) {
char ch = c;
if (Character.isUpperCase(ch)) {
ch = Character.toLowerCase(ch);
if (vowels.indexOf(ch) != -1) {
ch = (char) ('a' + ((ch - 'a' + 28) % 26));
}
} else if (Character.isLowerCase(ch)) {
ch = Character.toUpperCase(ch);
if (vowels.indexOf(ch) != -1) {
ch = (char) ('A' + ((ch - 'A' + 28) % 26));
}
}
sb.append(ch);
}
return sb.toString();
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def skjkasdkd(lst):
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
maxx = 0
i = 0
while i < len(lst):
if(lst[i] > maxx and isPrime(lst[i])):
maxx = lst[i]
i+=1
result = sum(int(digit) for digit in str(maxx))
return result
|
[
[
"[0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3]",
"10"
],
[
"[1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1]",
"25"
],
[
"[1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3]",
"13"
],
[
"[0,724,32,71,99,32,6,0,5,91,83,0,5,6]",
"11"
],
[
"[0,81,12,3,1,21]",
"3"
],
[
"[0,8,1,2,1,7]",
"7"
],
[
"[8191]",
"19"
],
[
"[8191, 123456, 127, 7]",
"19"
],
[
"[127, 97, 8192]",
"10"
]
] |
skjkasdkd
|
humaneval_java_python_94
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int skjkasdkd(List<Integer> lst) {
int maxx = 0;
for (int i : lst) {
if (i > maxx) {
boolean isPrime = i != 1;
for (int j = 2; j < Math.sqrt(i) + 1; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
maxx = i;
}
}
}
int sum = 0;
for (char c : String.valueOf(maxx).toCharArray()) {
sum += (c - '0');
}
return sum;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def check_dict_case(dict):
if len(dict.keys()) == 0:
return False
else:
state = "start"
for key in dict.keys():
if isinstance(key, str) == False:
state = "mixed"
break
if state == "start":
if key.isupper():
state = "upper"
elif key.islower():
state = "lower"
else:
break
elif (state == "upper" and not key.isupper()) or (state == "lower" and not key.islower()):
state = "mixed"
break
else:
break
return state == "upper" or state == "lower"
|
[
[
"{\"p\":\"pineapple\", \"b\":\"banana\"}",
"True"
],
[
"{\"p\":\"pineapple\", \"A\":\"banana\", \"B\":\"banana\"}",
"False"
],
[
"{\"p\":\"pineapple\", 5:\"banana\", \"a\":\"apple\"}",
"False"
],
[
"{\"Name\":\"John\", \"Age\":\"36\", \"City\":\"Houston\"}",
"False"
],
[
"{\"STATE\":\"NC\", \"ZIP\":\"12345\" }",
"True"
],
[
"{\"fruit\":\"Orange\", \"taste\":\"Sweet\" }",
"True"
],
[
"{}",
"False"
]
] |
check_dict_case
|
humaneval_java_python_95
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public boolean check_dict_case(Map<Object, Object> dict) {
if (dict.isEmpty()) {
return false;
}
String state = "start";
for (Map.Entry entry : dict.entrySet()) {
if (!(entry.getKey() instanceof String key)) {
state = "mixed";
break;
}
boolean is_upper = true, is_lower = true;
for (char c : key.toCharArray()) {
if (Character.isLowerCase(c)) {
is_upper = false;
} else if (Character.isUpperCase(c)) {
is_lower = false;
} else {
is_upper = false;
is_lower = false;
}
}
if (state.equals("start")) {
if (is_upper) {
state = "upper";
} else if (is_lower) {
state = "lower";
} else {
break;
}
} else if ((state.equals("upper") && !is_upper) || (state.equals("lower") && !is_lower)) {
state = "mixed";
break;
}
}
return state.equals("upper") || state.equals("lower");
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def count_up_to(n):
primes = []
for i in range(2, n):
is_prime = True
for j in range(2, i):
if i % j == 0:
is_prime = False
break
if is_prime:
primes.append(i)
return primes
|
[
[
"5",
"[2,3]"
],
[
"6",
"[2,3,5]"
],
[
"7",
"[2,3,5]"
],
[
"10",
"[2,3,5,7]"
],
[
"0",
"[]"
],
[
"22",
"[2,3,5,7,11,13,17,19]"
],
[
"1",
"[]"
],
[
"18",
"[2,3,5,7,11,13,17]"
],
[
"47",
"[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]"
],
[
"101",
"[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]"
]
] |
count_up_to
|
humaneval_java_python_96
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public List<Integer> count_up_to(int n) {
List<Integer> primes = new ArrayList<>();
for (int i = 2; i < n; i++) {
boolean is_prime = true;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
is_prime = false;
break;
}
}
if (is_prime) {
primes.add(i);
}
}
return primes;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def multiply(a, b):
return abs(a % 10) * abs(b % 10)
|
[
[
"148, 412",
"16"
],
[
"19, 28",
"72"
],
[
"2020, 1851",
"0"
],
[
"14, -15",
"20"
],
[
"76, 67",
"42"
],
[
"17, 27",
"49"
],
[
"0, 1",
"0"
],
[
"0, 0",
"0"
]
] |
multiply
|
humaneval_java_python_97
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int multiply(int a, int b) {
return Math.abs(a % 10) * Math.abs(b % 10);
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def count_upper(s):
count = 0
for i in range(0,len(s),2):
if s[i] in "AEIOU":
count += 1
return count
|
[
[
"'aBCdEf'",
"1"
],
[
"'abcdefg'",
"0"
],
[
"'dBBE'",
"0"
],
[
"'B'",
"0"
],
[
"'U'",
"1"
],
[
"''",
"0"
],
[
"'EEEE'",
"2"
]
] |
count_upper
|
humaneval_java_python_98
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int count_upper(String s) {
int count = 0;
for (int i = 0; i < s.length(); i += 2) {
if ("AEIOU".indexOf(s.charAt(i)) != -1) {
count += 1;
}
}
return count;
}
}
| |||
[] |
[] |
python
|
java
|
code_translation
|
def closest_integer(value):
from math import floor, ceil
if value.count('.') == 1:
# remove trailing zeros
while (value[-1] == '0'):
value = value[:-1]
num = float(value)
if value[-2:] == '.5':
if num > 0:
res = ceil(num)
else:
res = floor(num)
elif len(value) > 0:
res = int(round(num))
else:
res = 0
return res
|
[
[
"\"10\"",
"10"
],
[
"\"14.5\"",
"15"
],
[
"\"-15.5\"",
"-16"
],
[
"\"15.3\"",
"15"
],
[
"\"0\"",
"0"
]
] |
closest_integer
|
humaneval_java_python_99
|
humaneval_trans
|
import java.util.*;
import java.lang.*;
class Solution {
public int closest_integer(String value) {
if (value.contains(".")) {
while (value.charAt(value.length() - 1) == '0') {
value = value.substring(0, value.length() - 1);
}
}
double num = Double.parseDouble(value);
int res = 0;
if (value.substring(Math.max(value.length() - 2, 0)).equals(".5")) {
if (num > 0) {
res = (int) Math.ceil(num);
} else {
res = (int) Math.floor(num);
}
} else if(value.length() > 0) {
res = (int) Math.round(num);
}
return res;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.