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
def make_a_pile(n): return [n + 2*i for i in range(n)]
[ [ "3", "[3, 5, 7]" ], [ "4", "[4,6,8,10]" ], [ "5", "[5, 7, 9, 11, 13]" ], [ "6", "[6, 8, 10, 12, 14, 16]" ], [ "8", "[8, 10, 12, 14, 16, 18, 20, 22]" ] ]
make_a_pile
humaneval_java_python_100
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> make_a_pile(int n) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < n; i++) { result.add(n + 2 * i); } return result; } }
[]
[]
python
java
code_translation
def words_string(s): if not s: return [] s_list = [] for letter in s: if letter == ',': s_list.append(' ') else: s_list.append(letter) s_list = "".join(s_list) return s_list.split()
[ [ "\"Hi, my name is John\"", "[\"Hi\", \"my\", \"name\", \"is\", \"John\"]" ], [ "\"One, two, three, four, five, six\"", "[\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]" ], [ "\"Hi, my name\"", "[\"Hi\", \"my\", \"name\"]" ], [ "\"One,, two, three, four, five, six,\"", "[\"One\", \"two\", \"three\", \"four\", \"five\", \"six\"]" ], [ "\"\"", "[]" ], [ "\"ahmed , gamal\"", "[\"ahmed\", \"gamal\"]" ] ]
words_string
humaneval_java_python_101
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> words_string(String s) { if (s.length() == 0) { return List.of(); } StringBuilder sb = new StringBuilder(); for (char letter : s.toCharArray()) { if (letter == ',') { sb.append(' '); } else { sb.append(letter); } } return new ArrayList<>(Arrays.asList(sb.toString().split("\s+" ))); } }
[]
[]
python
java
code_translation
def choose_num(x, y): if x > y: return -1 if y % 2 == 0: return y if x == y: return -1 return y - 1
[ [ "12, 15", "14" ], [ "13, 12", "-1" ], [ "33, 12354", "12354" ], [ "5234, 5233", "-1" ], [ "6, 29", "28" ], [ "27, 10", "-1" ], [ "7, 7", "-1" ], [ "546, 546", "546" ] ]
choose_num
humaneval_java_python_102
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int choose_num(int x, int y) { if (x > y) { return -1; } if (y % 2 == 0) { return y; } if (x == y) { return -1; } return y - 1; } }
[]
[]
python
java
code_translation
def rounded_avg(n, m): if m < n: return -1 summation = 0 for i in range(n, m+1): summation += i return bin(round(summation/(m - n + 1)))
[ [ "1, 5", "\"0b11\"" ], [ "7, 13", "\"0b1010\"" ], [ "964, 977", "\"0b1111001010\"" ], [ "996, 997", "\"0b1111100100\"" ], [ "560, 851", "\"0b1011000010\"" ], [ "185, 546", "\"0b101101110\"" ], [ "362, 496", "\"0b110101101\"" ], [ "350, 902", "\"0b1001110010\"" ], [ "197, 233", "\"0b11010111\"" ], [ "7, 5", "-1" ], [ "5, 1", "-1" ], [ "5, 5", "\"0b101\"" ] ]
rounded_avg
humaneval_java_python_103
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public Object rounded_avg(int n, int m) { if (n > m) { return -1; } return Integer.toBinaryString((int) Math.round((double) (m + n) / 2)); } }
[]
[]
python
java
code_translation
def unique_digits(x): odd_digit_elements = [] for i in x: if all (int(c) % 2 == 1 for c in str(i)): odd_digit_elements.append(i) return sorted(odd_digit_elements)
[ [ "[15, 33, 1422, 1]", "[1, 15, 33]" ], [ "[152, 323, 1422, 10]", "[]" ], [ "[12345, 2033, 111, 151]", "[111, 151]" ], [ "[135, 103, 31]", "[31, 135]" ] ]
unique_digits
humaneval_java_python_104
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> unique_digits(List<Integer> x) { List<Integer> odd_digit_elements = new ArrayList<>(); for (int i : x) { boolean is_unique = true; for (char c : String.valueOf(i).toCharArray()) { if ((c - '0') % 2 == 0) { is_unique = false; break; } } if (is_unique) { odd_digit_elements.add(i); } } Collections.sort(odd_digit_elements); return odd_digit_elements; } }
[]
[]
python
java
code_translation
def by_length(arr): dic = { 1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine", } sorted_arr = sorted(arr, reverse=True) new_arr = [] for var in sorted_arr: try: new_arr.append(dic[var]) except: pass return new_arr
[ [ "[2, 1, 1, 4, 5, 8, 2, 3]", "[\"Eight\", \"Five\", \"Four\", \"Three\", \"Two\", \"Two\", \"One\", \"One\"]" ], [ "[]", "[]" ], [ "[1, -1 , 55]", "['One']" ], [ "[1, -1, 3, 2]", "[\"Three\", \"Two\", \"One\"]" ], [ "[9, 4, 8]", "[\"Nine\", \"Eight\", \"Four\"]" ] ]
by_length
humaneval_java_python_105
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> by_length(List<Integer> arr) { List<Integer> sorted_arr = new ArrayList<>(arr); sorted_arr.sort(Collections.reverseOrder()); List<String> new_arr = new ArrayList<>(); for (int var : sorted_arr) { if (var >= 1 && var <= 9) { switch (var) { case 1 -> new_arr.add("One"); case 2 -> new_arr.add("Two"); case 3 -> new_arr.add("Three"); case 4 -> new_arr.add("Four"); case 5 -> new_arr.add("Five"); case 6 -> new_arr.add("Six"); case 7 -> new_arr.add("Seven"); case 8 -> new_arr.add("Eight"); case 9 -> new_arr.add("Nine"); } } } return new_arr; } }
[]
[]
python
java
code_translation
def f(n): ret = [] for i in range(1,n+1): if i%2 == 0: x = 1 for j in range(1,i+1): x *= j ret += [x] else: x = 0 for j in range(1,i+1): x += j ret += [x] return ret
[ [ "5", "[1, 2, 6, 24, 15]" ], [ "7", "[1, 2, 6, 24, 15, 720, 28]" ], [ "1", "[1]" ], [ "3", "[1, 2, 6]" ] ]
f
humaneval_java_python_106
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> f(int n) { List<Integer> ret = new ArrayList<>(); for (int i = 1; i <= n; i++) { if (i % 2 == 0) { int x = 1; for (int j = 1; j <= i; j++) { x *= j; } ret.add(x); } else { int x = 0; for (int j = 1; j <= i; j++) { x += j; } ret.add(x); } } return ret; } }
[]
[]
python
java
code_translation
def even_odd_palindrome(n): def is_palindrome(n): return str(n) == str(n)[::-1] even_palindrome_count = 0 odd_palindrome_count = 0 for i in range(1, n+1): if i%2 == 1 and is_palindrome(i): odd_palindrome_count += 1 elif i%2 == 0 and is_palindrome(i): even_palindrome_count += 1 return (even_palindrome_count, odd_palindrome_count)
[ [ "123", "(8, 13)" ], [ "12", "(4, 6)" ], [ "3", "(1, 2)" ], [ "63", "(6, 8)" ], [ "25", "(5, 6)" ], [ "19", "(4, 6)" ], [ "9", "(4, 5)" ], [ "1", "(0, 1)" ] ]
even_odd_palindrome
humaneval_java_python_107
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> even_odd_palindrome(int n) { int even_palindrome_count = 0, odd_palindrome_count = 0; for (int i = 1; i <= n; i++) { if (String.valueOf(i).equals(new StringBuilder(String.valueOf(i)).reverse().toString())) { if (i % 2 == 1) { odd_palindrome_count += 1; } else { even_palindrome_count += 1; } } } return Arrays.asList(even_palindrome_count, odd_palindrome_count); } }
[]
[]
python
java
code_translation
def count_nums(arr): def digits_sum(n): neg = 1 if n < 0: n, neg = -1 * n, -1 n = [int(i) for i in str(n)] n[0] = n[0] * neg return sum(n) return len(list(filter(lambda x: x > 0, [digits_sum(i) for i in arr])))
[ [ "[]", "0" ], [ "[-1, -2, 0]", "0" ], [ "[1, 1, 2, -2, 3, 4, 5]", "6" ], [ "[1, 6, 9, -6, 0, 1, 5]", "5" ], [ "[1, 100, 98, -7, 1, -1]", "4" ], [ "[12, 23, 34, -45, -56, 0]", "5" ], [ "[-0, 1**0]", "1" ], [ "[1]", "1" ] ]
count_nums
humaneval_java_python_108
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int count_nums(List<Integer> arr) { int count = 0; for (int n: arr) { int neg = 1; if (n < 0) { n = -n; neg = -1; } List<Integer> digits = new ArrayList<>(); for (char digit : String.valueOf(n).toCharArray()) { digits.add(digit - '0'); } digits.set(0, digits.get(0) * neg); if (digits.stream().reduce(0, Integer::sum) > 0) { count += 1; } } return count; } }
[]
[]
python
java
code_translation
def move_one_ball(arr): if len(arr)==0: return True sorted_array=sorted(arr) my_arr=[] min_value=min(arr) min_index=arr.index(min_value) my_arr=arr[min_index:]+arr[0:min_index] for i in range(len(arr)): if my_arr[i]!=sorted_array[i]: return False return True
[ [ "[3, 4, 5, 1, 2]", "True" ], [ "[3, 5, 10, 1, 2]", "True" ], [ "[4, 3, 1, 2]", "False" ], [ "[3, 5, 4, 1, 2]", "False" ], [ "[]", "True" ] ]
move_one_ball
humaneval_java_python_109
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean move_one_ball(List<Integer> arr) { if (arr.size() == 0) { return true; } List<Integer> sorted_arr = new ArrayList<>(arr); Collections.sort(sorted_arr); int min_value = Collections.min(arr); int min_index = arr.indexOf(min_value); List<Integer> my_arr = new ArrayList<>(arr.subList(min_index, arr.size())); my_arr.addAll(arr.subList(0, min_index)); for (int i = 0; i < arr.size(); i++) { if (my_arr.get(i) != sorted_arr.get(i)) { return false; } } return true; } }
[]
[]
python
java
code_translation
def exchange(lst1, lst2): odd = 0 even = 0 for i in lst1: if i%2 == 1: odd += 1 for i in lst2: if i%2 == 0: even += 1 if even >= odd: return "YES" return "NO"
[ [ "[1, 2, 3, 4], [1, 2, 3, 4]", "\"YES\"" ], [ "[1, 2, 3, 4], [1, 5, 3, 4]", "\"NO\"" ], [ "[1, 2, 3, 4], [2, 1, 4, 3]", "\"YES\"" ], [ "[5, 7, 3], [2, 6, 4]", "\"YES\"" ], [ "[5, 7, 3], [2, 6, 3]", "\"NO\"" ], [ "[3, 2, 6, 1, 8, 9], [3, 5, 5, 1, 1, 1]", "\"NO\"" ], [ "[100, 200], [200, 200]", "\"YES\"" ] ]
exchange
humaneval_java_python_110
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String exchange(List<Integer> lst1, List<Integer> lst2) { int odd = 0, even = 0; for (int i : lst1) { if (i % 2 == 1) { odd += 1; } } for (int i : lst2) { if (i % 2 == 0) { even += 1; } } if (even >= odd) { return "YES"; } return "NO"; } }
[]
[]
python
java
code_translation
def histogram(test): dict1={} list1=test.split(" ") t=0 for i in list1: if(list1.count(i)>t) and i!='': t=list1.count(i) if t>0: for i in list1: if(list1.count(i)==t): dict1[i]=t return dict1
[ [ "'a b b a'", "{'a':2,'b': 2}" ], [ "'a b c a b'", "{'a': 2, 'b': 2}" ], [ "'a b c d g'", "{'a': 1, 'b': 1, 'c': 1, 'd': 1, 'g': 1}" ], [ "'r t g'", "{'r': 1,'t': 1,'g': 1}" ], [ "'b b b b a'", "{'b': 4}" ], [ "'r t g'", "{'r': 1,'t': 1,'g': 1}" ], [ "''", "{}" ], [ "'a'", "{'a': 1}" ] ]
histogram
humaneval_java_python_111
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public Map<String, Integer> histogram(String test) { Map<String, Integer> dict1 = new HashMap<>(); List<String> list1 = Arrays.asList(test.split(" " )); int t = 0; for (String i : list1) { if (Collections.frequency(list1, i) > t && !i.isEmpty()) { t = Collections.frequency(list1, i); } } if (t > 0) { for (String i : list1) { if (Collections.frequency(list1, i) == t) { dict1.put(i, t); } } } return dict1; } }
[]
[]
python
java
code_translation
def reverse_delete(s,c): s = ''.join([char for char in s if char not in c]) return (s,s[::-1] == s)
[ [ "\"abcde\", \"ae\"", "('bcd',False)" ], [ "\"abcdef\", \"b\"", "('acdef',False)" ], [ "\"abcdedcba\", \"ab\"", "('cdedc',True)" ], [ "\"dwik\", \"w\"", "('dik',False)" ], [ "\"a\", \"a\"", "('',True)" ], [ "\"abcdedcba\", \"\"", "('abcdedcba',True)" ], [ "\"abcdedcba\", \"v\"", "('abcdedcba',True)" ], [ "\"vabba\", \"v\"", "('abba',True)" ], [ "\"mamma\", \"mia\"", "(\"\", True)" ] ]
reverse_delete
humaneval_java_python_112
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Object> reverse_delete(String s, String c) { StringBuilder sb = new StringBuilder(); for (char ch : s.toCharArray()) { if (c.indexOf(ch) == -1) { sb.append(ch); } } return Arrays.asList(sb.toString(), sb.toString().equals(sb.reverse().toString())); } }
[]
[]
python
java
code_translation
def odd_count(lst): res = [] for arr in lst: n = sum(int(d)%2==1 for d in arr) res.append("the number of odd elements " + str(n) + "n the str"+ str(n) +"ng "+ str(n) +" of the "+ str(n) +"nput.") return res
[ [ "['1234567']", "[\"the number of odd elements 4n the str4ng 4 of the 4nput.\"]" ], [ "['3',\"11111111\"]", "[\"the number of odd elements 1n the str1ng 1 of the 1nput.\", \"the number of odd elements 8n the str8ng 8 of the 8nput.\"]" ], [ "['271', '137', '314']", "[\n 'the number of odd elements 2n the str2ng 2 of the 2nput.',\n 'the number of odd elements 3n the str3ng 3 of the 3nput.',\n 'the number of odd elements 2n the str2ng 2 of the 2nput.'\n ]" ] ]
odd_count
humaneval_java_python_113
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> odd_count(List<String> lst) { List<String> res = new ArrayList<>(); for (String arr : lst) { int n = 0; for (char d : arr.toCharArray()) { if ((d - '0') % 2 == 1) { n += 1; } } res.add("the number of odd elements " + n + "n the str" + n + "ng " + n + " of the " + n + "nput." ); } return res; } }
[]
[]
python
java
code_translation
def minSubArraySum(nums): max_sum = 0 s = 0 for num in nums: s += -num if (s < 0): s = 0 max_sum = max(s, max_sum) if max_sum == 0: max_sum = max(-i for i in nums) min_sum = -max_sum return min_sum
[ [ "[2, 3, 4, 1, 2, 4]", "1" ], [ "[-1, -2, -3]", "-6" ], [ "[-1, -2, -3, 2, -10]", "-14" ], [ "[-9999999999999999]", "-9999999999999999" ], [ "[0, 10, 20, 1000000]", "0" ], [ "[-1, -2, -3, 10, -5]", "-6" ], [ "[100, -1, -2, -3, 10, -5]", "-6" ], [ "[10, 11, 13, 8, 3, 4]", "3" ], [ "[100, -33, 32, -1, 0, -2]", "-33" ], [ "[-10]", "-10" ], [ "[7]", "7" ], [ "[1, -1]", "-1" ] ]
minSubArraySum
humaneval_java_python_114
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int minSubArraySum(List<Integer> nums) { int minSum = Integer.MAX_VALUE; int sum = 0; for (Integer num : nums) { sum += num; if (minSum > sum) { minSum = sum; } if (sum > 0) { sum = 0; } } return minSum; } }
[]
[]
python
java
code_translation
def max_fill(grid, capacity): import math return sum([math.ceil(sum(arr)/capacity) for arr in grid])
[ [ "[[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1", "6" ], [ "[[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2", "5" ], [ "[[0,0,0], [0,0,0]], 5", "0" ], [ "[[1,1,1,1], [1,1,1,1]], 2", "4" ], [ "[[1,1,1,1], [1,1,1,1]], 9", "2" ] ]
max_fill
humaneval_java_python_115
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int max_fill(List<List<Integer>> grid, int capacity) { int sum = 0; for (List<Integer> arr : grid) { sum += Math.ceil((double) arr.stream().reduce(Integer::sum).get() / capacity); } return sum; } }
[]
[]
python
java
code_translation
def sort_array(arr): return sorted(sorted(arr), key=lambda x: bin(x)[2:].count('1'))
[ [ "[1,5,2,3,4]", "[1, 2, 4, 3, 5]" ], [ "[-2,-3,-4,-5,-6]", "[-4, -2, -6, -5, -3]" ], [ "[1,0,2,3,4]", "[0, 1, 2, 4, 3]" ], [ "[]", "[]" ], [ "[2,5,77,4,5,3,5,7,2,3,4]", "[2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77]" ], [ "[3,6,44,12,32,5]", "[32, 3, 5, 6, 12, 44]" ], [ "[2,4,8,16,32]", "[2, 4, 8, 16, 32]" ], [ "[2,4,8,16,32]", "[2, 4, 8, 16, 32]" ] ]
sort_array
humaneval_java_python_116
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> sort_array(List<Integer> arr) { List < Integer > sorted_arr = new ArrayList<>(arr); sorted_arr.sort(new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { int cnt1 = (int) Integer.toBinaryString(Math.abs(o1)).chars().filter(ch -> ch == '1').count(); int cnt2 = (int) Integer.toBinaryString(Math.abs(o2)).chars().filter(ch -> ch == '1').count(); if (cnt1 > cnt2) { return 1; } else if (cnt1 < cnt2) { return -1; } else { return o1.compareTo(o2); } } }); return sorted_arr; } }
[]
[]
python
java
code_translation
def select_words(s, n): result = [] for word in s.split(): n_consonants = 0 for i in range(0, len(word)): if word[i].lower() not in ["a","e","i","o","u"]: n_consonants += 1 if n_consonants == n: result.append(word) return result
[ [ "\"Mary had a little lamb\", 4", "[\"little\"]" ], [ "\"Mary had a little lamb\", 3", "[\"Mary\", \"lamb\"]" ], [ "\"simple white space\", 2", "[]" ], [ "\"Hello world\", 4", "[\"world\"]" ], [ "\"Uncle sam\", 3", "[\"Uncle\"]" ], [ "\"\", 4", "[]" ], [ "\"a b c d e f\", 1", "[\"b\", \"c\", \"d\", \"f\"]" ] ]
select_words
humaneval_java_python_117
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> select_words(String s, int n) { List<String> result = new ArrayList<>(); for (String word : s.split(" ")) { int n_consonants = 0; for (char c : word.toCharArray()) { c = Character.toLowerCase(c); if ("aeiou".indexOf(c) == -1) { n_consonants += 1; } } if (n_consonants == n) { result.add(word); } } return result; } }
[]
[]
python
java
code_translation
def get_closest_vowel(word): if len(word) < 3: return "" vowels = {"a", "e", "i", "o", "u", "A", "E", 'O', 'U', 'I'} for i in range(len(word)-2, 0, -1): if word[i] in vowels: if (word[i+1] not in vowels) and (word[i-1] not in vowels): return word[i] return ""
[ [ "\"yogurt\"", "\"u\"" ], [ "\"full\"", "\"u\"" ], [ "\"easy\"", "\"\"" ], [ "\"eAsy\"", "\"\"" ], [ "\"ali\"", "\"\"" ], [ "\"bad\"", "\"a\"" ], [ "\"most\"", "\"o\"" ], [ "\"ab\"", "\"\"" ], [ "\"ba\"", "\"\"" ], [ "\"quick\"", "\"\"" ], [ "\"anime\"", "\"i\"" ], [ "\"Asia\"", "\"\"" ], [ "\"Above\"", "\"o\"" ] ]
get_closest_vowel
humaneval_java_python_118
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String get_closest_vowel(String word) { if (word.length() < 3) { return ""; } String vowels = "aeiouAEIOU"; for (int i = word.length() - 2; i > 0; i--) { if (vowels.indexOf(word.charAt(i)) != -1 && vowels.indexOf(word.charAt(i + 1)) == -1 && vowels.indexOf(word.charAt(i - 1)) == -1) { return String.valueOf(word.charAt(i)); } } return ""; } }
[]
[]
python
java
code_translation
def match_parens(lst): def check(s): val = 0 for i in s: if i == '(': val = val + 1 else: val = val - 1 if val < 0: return False return True if val == 0 else False S1 = lst[0] + lst[1] S2 = lst[1] + lst[0] return 'Yes' if check(S1) or check(S2) else 'No'
[ [ "['()(', ')']", "'Yes'" ], [ "[')', ')']", "'No'" ], [ "['(()(())', '())())']", "'No'" ], [ "[')())', '(()()(']", "'Yes'" ], [ "['(())))', '(()())((']", "'Yes'" ], [ "['()', '())']", "'No'" ], [ "['(()(', '()))()']", "'Yes'" ], [ "['((((', '((())']", "'No'" ], [ "[')(()', '(()(']", "'No'" ], [ "[')(', ')(']", "'No'" ], [ "['(', ')']", "'Yes'" ], [ "[')', '(']", "'Yes'" ] ]
match_parens
humaneval_java_python_119
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String match_parens(List<String> lst) { List<String> S = Arrays.asList(lst.get(0) + lst.get(1), lst.get(1) + lst.get(0)); for (String s : S) { int val = 0; for (char i : s.toCharArray()) { if (i == '(') { val += 1; } else { val -= 1; } if (val < 0) { break; } } if (val == 0) { return "Yes"; } } return "No"; } }
[]
[]
python
java
code_translation
def maximum(arr, k): if k == 0: return [] arr.sort() ans = arr[-k:] return ans
[ [ "[-3, -4, 5], 3", "[-4, -3, 5]" ], [ "[4, -4, 4], 2", "[4, 4]" ], [ "[-3, 2, 1, 2, -1, -2, 1], 1", "[2]" ], [ "[123, -123, 20, 0 , 1, 2, -3], 3", "[2, 20, 123]" ], [ "[-123, 20, 0 , 1, 2, -3], 4", "[0, 1, 2, 20]" ], [ "[5, 15, 0, 3, -13, -8, 0], 7", "[-13, -8, 0, 0, 3, 5, 15]" ], [ "[-1, 0, 2, 5, 3, -10], 2", "[3, 5]" ], [ "[1, 0, 5, -7], 1", "[5]" ], [ "[4, -4], 2", "[-4, 4]" ], [ "[-10, 10], 2", "[-10, 10]" ], [ "[1, 2, 3, -23, 243, -400, 0], 0", "[]" ] ]
maximum
humaneval_java_python_120
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> maximum(List<Integer> arr, int k) { if (k == 0) { return List.of(); } List<Integer> arr_sort = new ArrayList<>(arr); Collections.sort(arr_sort); return arr_sort.subList(arr_sort.size() - k, arr_sort.size()); } }
[]
[]
python
java
code_translation
def solution(lst): return sum([x for idx, x in enumerate(lst) if idx%2==0 and x%2==1])
[ [ "[5, 8, 7, 1]", "12" ], [ "[3, 3, 3, 3, 3]", "9" ], [ "[30, 13, 24, 321]", "0" ], [ "[5, 9]", "5" ], [ "[2, 4, 8]", "0" ], [ "[30, 13, 23, 32]", "23" ], [ "[3, 13, 2, 9]", "3" ] ]
solution
humaneval_java_python_121
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int solution(List<Integer> lst) { int sum = 0; for (int i = 0; i < lst.size(); i += 2) { if ((lst.get(i) % 2) == 1) { sum += lst.get(i); } } return sum; } }
[]
[]
python
java
code_translation
def add_elements(arr, k): return sum(elem for elem in arr[:k] if len(str(elem)) <= 2)
[ [ "[1,-2,-3,41,57,76,87,88,99], 3", "-4" ], [ "[111,121,3,4000,5,6], 2", "0" ], [ "[11,21,3,90,5,6,7,8,9], 4", "125" ], [ "[111,21,3,4000,5,6,7,8,9], 4", "24" ], [ "[1], 1", "1" ] ]
add_elements
humaneval_java_python_122
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int add_elements(List<Integer> arr, int k) { arr = arr.subList(0, k); Optional<Integer> sum = arr.stream().filter(p -> String.valueOf(Math.abs(p)).length() <= 2).reduce(Integer::sum); return sum.orElse(0); } }
[]
[]
python
java
code_translation
def get_odd_collatz(n): if n%2==0: odd_collatz = [] else: odd_collatz = [n] while n > 1: if n % 2 == 0: n = n/2 else: n = n*3 + 1 if n%2 == 1: odd_collatz.append(int(n)) return sorted(odd_collatz)
[ [ "14", "[1, 5, 7, 11, 13, 17]" ], [ "5", "[1, 5]" ], [ "12", "[1, 3, 5]" ], [ "1", "[1]" ] ]
get_odd_collatz
humaneval_java_python_123
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> get_odd_collatz(int n) { List<Integer> odd_collatz = new ArrayList<>(); if (n % 2 == 1) { odd_collatz.add(n); } while (n > 1) { if (n % 2 == 0) { n = n / 2; } else { n = n * 3 + 1; } if (n % 2 == 1) { odd_collatz.add(n); } } Collections.sort(odd_collatz); return odd_collatz; } }
[]
[]
python
java
code_translation
def valid_date(date): try: date = date.strip() month, day, year = date.split('-') month, day, year = int(month), int(day), int(year) if month < 1 or month > 12: return False if month in [1,3,5,7,8,10,12] and day < 1 or day > 31: return False if month in [4,6,9,11] and day < 1 or day > 30: return False if month == 2 and day < 1 or day > 29: return False except: return False return True
[ [ "'03-11-2000'", "True" ], [ "'15-01-2012'", "False" ], [ "'04-0-2040'", "False" ], [ "'06-04-2020'", "True" ], [ "'01-01-2007'", "True" ], [ "'03-32-2011'", "False" ], [ "''", "False" ], [ "'04-31-3000'", "False" ], [ "'06-06-2005'", "True" ], [ "'21-31-2000'", "False" ], [ "'04-12-2003'", "True" ], [ "'04122003'", "False" ], [ "'20030412'", "False" ], [ "'2003-04'", "False" ], [ "'2003-04-12'", "False" ], [ "'04-2003'", "False" ] ]
valid_date
humaneval_java_python_124
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean valid_date(String date) { try { date = date.strip(); String[] dates = date.split("-" ); String m = dates[0]; while (!m.isEmpty() && m.charAt(0) == '0') { m = m.substring(1); } String d = dates[1]; while (!d.isEmpty() && d.charAt(0) == '0') { d = d.substring(1); } String y = dates[2]; while (!y.isEmpty() && y.charAt(0) == '0') { y = y.substring(1); } int month = Integer.parseInt(m), day = Integer.parseInt(d), year = Integer.parseInt(y); if (month < 1 || month > 12) { return false; } if (Arrays.asList(1, 3, 5, 7, 8, 10, 12).contains(month) && (day < 1 || day > 31)) { return false; } if (Arrays.asList(4, 6, 9, 11).contains(month) && (day < 1 || day > 30)) { return false; } if (month == 2 && (day < 1 || day > 29)) { return false; } return true; } catch (Exception e) { return false; } } }
[]
[]
python
java
code_translation
def split_words(txt): if " " in txt: return txt.split() elif "," in txt: return txt.replace(',',' ').split() else: return len([i for i in txt if i.islower() and ord(i)%2 == 0])
[ [ "\"Hello world!\"", "[\"Hello\",\"world!\"]" ], [ "\"Hello,world!\"", "[\"Hello\",\"world!\"]" ], [ "\"Hello world,!\"", "[\"Hello\",\"world,!\"]" ], [ "\"Hello,Hello,world !\"", "[\"Hello,Hello,world\",\"!\"]" ], [ "\"abcdef\"", "3" ], [ "\"aaabb\"", "2" ], [ "\"aaaBb\"", "1" ], [ "\"\"", "0" ] ]
split_words
humaneval_java_python_125
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public Object split_words(String txt) { if (txt.contains(" " )) { return Arrays.asList(txt.split(" " )); } else if (txt.contains("," )) { return Arrays.asList(txt.split("[,\s]" )); } else { int count = 0; for (char c : txt.toCharArray()) { if (Character.isLowerCase(c) && (c - 'a') % 2 == 1) { count += 1; } } return count; } } }
[]
[]
python
java
code_translation
def is_sorted(lst): count_digit = dict([(i, 0) for i in lst]) for i in lst: count_digit[i]+=1 if any(count_digit[i] > 2 for i in lst): return False if all(lst[i-1] <= lst[i] for i in range(1, len(lst))): return True else: return False
[ [ "[5]", "True" ], [ "[1, 2, 3, 4, 5]", "True" ], [ "[1, 3, 2, 4, 5]", "False" ], [ "[1, 2, 3, 4, 5, 6]", "True" ], [ "[1, 2, 3, 4, 5, 6, 7]", "True" ], [ "[1, 3, 2, 4, 5, 6, 7]", "False" ], [ "[]", "True" ], [ "[1]", "True" ], [ "[3, 2, 1]", "False" ], [ "[1, 2, 2, 2, 3, 4]", "False" ], [ "[1, 2, 3, 3, 3, 4]", "False" ], [ "[1, 2, 2, 3, 3, 4]", "True" ], [ "[1, 2, 3, 4]", "True" ] ]
is_sorted
humaneval_java_python_126
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean is_sorted(List<Integer> lst) { List<Integer> sorted_lst = new ArrayList<>(lst); Collections.sort(sorted_lst); if (!lst.equals(sorted_lst)) { return false; } for (int i = 0; i < lst.size() - 2; i++) { if (lst.get(i) == lst.get(i + 1) && lst.get(i) == lst.get(i + 2)) { return false; } } return true; } }
[]
[]
python
java
code_translation
def intersection(interval1, interval2): def is_prime(num): if num == 1 or num == 0: return False if num == 2: return True for i in range(2, num): if num%i == 0: return False return True l = max(interval1[0], interval2[0]) r = min(interval1[1], interval2[1]) length = r - l if length > 0 and is_prime(length): return "YES" return "NO"
[ [ "(1, 2), (2, 3)", "\"NO\"" ], [ "(-1, 1), (0, 4)", "\"NO\"" ], [ "(-3, -1), (-5, 5)", "\"YES\"" ], [ "(-2, 2), (-4, 0)", "\"YES\"" ], [ "(-11, 2), (-1, -1)", "\"NO\"" ], [ "(1, 2), (3, 5)", "\"NO\"" ], [ "(1, 2), (1, 2)", "\"NO\"" ], [ "(-2, -2), (-3, -2)", "\"NO\"" ] ]
intersection
humaneval_java_python_127
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String intersection(List<Integer> interval1, List<Integer> interval2) { int l = Math.max(interval1.get(0), interval2.get(0)); int r = Math.min(interval1.get(1), interval2.get(1)); int length = r - l; if (length <= 0) { return "NO"; } if (length == 1) { return "NO"; } if (length == 2) { return "YES"; } for (int i = 2; i < length; i++) { if (length % i == 0) { return "NO"; } } return "YES"; } }
[]
[]
python
java
code_translation
def prod_signs(arr): if not arr: return None prod = 0 if 0 in arr else (-1) ** len(list(filter(lambda x: x < 0, arr))) return prod * sum([abs(i) for i in arr])
[ [ "[1, 2, 2, -4]", "-9" ], [ "[0, 1]", "0" ], [ "[1, 1, 1, 2, 3, -1, 1]", "-10" ], [ "[]", "None" ], [ "[2, 4,1, 2, -1, -1, 9]", "20" ], [ "[-1, 1, -1, 1]", "4" ], [ "[-1, 1, 1, 1]", "-4" ], [ "[-1, 1, 1, 0]", "0" ] ]
prod_signs
humaneval_java_python_128
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public Optional<Integer> prod_signs(List<Integer> arr) { if (arr.size() == 0) { return Optional.empty(); } if (arr.contains(0)) { return Optional.of(0); } int prod = (int) (-2 * (arr.stream().filter(p -> p < 0).count() % 2) + 1); return Optional.of(prod * (arr.stream().map(Math::abs).reduce(Integer::sum)).get()); } }
[]
[]
python
java
code_translation
def minPath(grid, k): n = len(grid) val = n * n + 1 for i in range(n): for j in range(n): if grid[i][j] == 1: temp = [] if i != 0: temp.append(grid[i - 1][j]) if j != 0: temp.append(grid[i][j - 1]) if i != n - 1: temp.append(grid[i + 1][j]) if j != n - 1: temp.append(grid[i][j + 1]) val = min(temp) ans = [] for i in range(k): if i % 2 == 0: ans.append(1) else: ans.append(val) return ans
[ [ "[[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3", "[1, 2, 1]" ], [ "[[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1", "[1]" ], [ "[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4", "[1, 2, 1, 2]" ], [ "[[6, 4, 13, 10], [5, 7, 12, 1], [3, 16, 11, 15], [8, 14, 9, 2]], 7", "[1, 10, 1, 10, 1, 10, 1]" ], [ "[[8, 14, 9, 2], [6, 4, 13, 15], [5, 7, 1, 12], [3, 10, 11, 16]], 5", "[1, 7, 1, 7, 1]" ], [ "[[11, 8, 7, 2], [5, 16, 14, 4], [9, 3, 15, 6], [12, 13, 10, 1]], 9", "[1, 6, 1, 6, 1, 6, 1, 6, 1]" ], [ "[[12, 13, 10, 1], [9, 3, 15, 6], [5, 16, 14, 4], [11, 8, 7, 2]], 12", "[1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6]" ], [ "[[2, 7, 4], [3, 1, 5], [6, 8, 9]], 8", "[1, 3, 1, 3, 1, 3, 1, 3]" ], [ "[[6, 1, 5], [3, 8, 9], [2, 7, 4]], 8", "[1, 5, 1, 5, 1, 5, 1, 5]" ], [ "[[1, 2], [3, 4]], 10", "[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]" ], [ "[[1, 3], [3, 2]], 10", "[1, 3, 1, 3, 1, 3, 1, 3, 1, 3]" ] ]
minPath
humaneval_java_python_129
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> minPath(List<List<Integer>> grid, int k) { int n = grid.size(); int val = n * n + 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (grid.get(i).get(j) == 1) { List<Integer> temp = new ArrayList<>(); if (i != 0) { temp.add(grid.get(i - 1).get(j)); } if (j != 0) { temp.add(grid.get(i).get(j - 1)); } if (i != n - 1) { temp.add(grid.get(i + 1).get(j)); } if (j != n - 1) { temp.add(grid.get(i).get(j + 1)); } val = Collections.min(temp); } } } List<Integer> ans = new ArrayList<>(); for (int i = 0; i < k; i++) { if (i % 2 == 0) { ans.add(1); } else { ans.add(val); } } return ans; } }
[]
[]
python
java
code_translation
def tri(n): if n == 0: return [1] my_tri = [1, 3] for i in range(2, n + 1): if i % 2 == 0: my_tri.append(i / 2 + 1) else: my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2) return my_tri
[ [ "3", "[1, 3, 2.0, 8.0]" ], [ "4", "[1, 3, 2.0, 8.0, 3.0]" ], [ "5", "[1, 3, 2.0, 8.0, 3.0, 15.0]" ], [ "6", "[1, 3, 2.0, 8.0, 3.0, 15.0, 4.0]" ], [ "7", "[1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0]" ], [ "8", "[1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0]" ], [ "9", "[1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0]" ], [ "20", "[1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0, 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0]" ], [ "0", "[1]" ], [ "1", "[1, 3]" ] ]
tri
humaneval_java_python_130
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> tri(int n) { if (n == 0) { return List.of(1); } List<Integer> my_tri = new ArrayList<>(Arrays.asList(1, 3)); for (int i = 2; i <= n; i++) { if (i % 2 == 0) { my_tri.add(i / 2 + 1); } else { my_tri.add(my_tri.get(my_tri.size() - 1) + my_tri.get(my_tri.size() - 2) + (i + 3) / 2); } } return my_tri; } }
[]
[]
python
java
code_translation
def digits(n): product = 1 odd_count = 0 for digit in str(n): int_digit = int(digit) if int_digit%2 == 1: product= product*int_digit odd_count+=1 if odd_count ==0: return 0 else: return product
[ [ "5", "5" ], [ "54", "5" ], [ "120", "1" ], [ "5014", "5" ], [ "98765", "315" ], [ "5576543", "2625" ], [ "2468", "0" ] ]
digits
humaneval_java_python_131
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int digits(int n) { int product = 1, odd_count = 0; for (char digit : String.valueOf(n).toCharArray()) { int int_digit = digit - '0'; if (int_digit % 2 == 1) { product *= int_digit; odd_count += 1; } } if (odd_count == 0) { return 0; } else { return product; } } }
[]
[]
python
java
code_translation
def is_nested(string): opening_bracket_index = [] closing_bracket_index = [] for i in range(len(string)): if string[i] == '[': opening_bracket_index.append(i) else: closing_bracket_index.append(i) closing_bracket_index.reverse() cnt = 0 i = 0 l = len(closing_bracket_index) for idx in opening_bracket_index: if i < l and idx < closing_bracket_index[i]: cnt += 1 i += 1 return cnt >= 2
[ [ "'[[]]'", "True" ], [ "'[]]]]]]][[[[[]'", "False" ], [ "'[][]'", "False" ], [ "'[]'", "False" ], [ "'[[[[]]]]'", "True" ], [ "'[]]]]]]]]]]'", "False" ], [ "'[][][[]]'", "True" ], [ "'[[]'", "False" ], [ "'[]]'", "False" ], [ "'[[]][['", "True" ], [ "'[[][]]'", "True" ], [ "''", "False" ], [ "'[[[[[[[['", "False" ], [ "']]]]]]]]'", "False" ] ]
is_nested
humaneval_java_python_132
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean is_nested(String string) { List<Integer> opening_bracket_index = new ArrayList<>(), closing_bracket_index = new ArrayList<>(); for (int i = 0; i < string.length(); i++) { if (string.charAt(i) == '[') { opening_bracket_index.add(i); } else { closing_bracket_index.add(i); } } Collections.reverse(closing_bracket_index); int i = 0, l = closing_bracket_index.size(); for (int idx : opening_bracket_index) { if (i < l && idx < closing_bracket_index.get(i)) { i += 1; } } return i >= 2; } }
[]
[]
python
java
code_translation
def sum_squares(lst): import math squared = 0 for i in lst: squared += math.ceil(i)**2 return squared
[ [ "[1,2,3]", "14" ], [ "[1.0,2,3]", "14" ], [ "[1,3,5,7]", "84" ], [ "[1.4,4.2,0]", "29" ], [ "[-2.4,1,1]", "6" ], [ "[100,1,15,2]", "10230" ], [ "[10000,10000]", "200000000" ], [ "[-1.4,4.6,6.3]", "75" ], [ "[-1.4,17.9,18.9,19.9]", "1086" ], [ "[0]", "0" ], [ "[-1]", "1" ], [ "[-1,1,0]", "2" ] ]
sum_squares
humaneval_java_python_133
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int sum_squares(List<Double> lst) { return lst.stream().map(p -> (int) Math.ceil(p)).map(p -> p * p).reduce(Integer::sum).get(); } }
[]
[]
python
java
code_translation
def check_if_last_char_is_a_letter(txt): check = txt.split(' ')[-1] return True if len(check) == 1 and (97 <= ord(check.lower()) <= 122) else False
[ [ "\"apple\"", "False" ], [ "\"apple pi e\"", "True" ], [ "\"eeeee\"", "False" ], [ "\"A\"", "True" ], [ "\"Pumpkin pie \"", "False" ], [ "\"Pumpkin pie 1\"", "False" ], [ "\"\"", "False" ], [ "\"eeeee e \"", "False" ], [ "\"apple pie\"", "False" ], [ "\"apple pi e \"", "False" ] ]
check_if_last_char_is_a_letter
humaneval_java_python_134
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean check_if_last_char_is_a_letter(String txt) { String[] words = txt.split(" ", -1); String check = words[words.length - 1]; return check.length() == 1 && Character.isLetter(check.charAt(0)); } }
[]
[]
python
java
code_translation
def can_arrange(arr): ind=-1 i=1 while i<len(arr): if arr[i]<arr[i-1]: ind=i i+=1 return ind
[ [ "[1,2,4,3,5]", "3" ], [ "[1,2,4,5]", "-1" ], [ "[1,4,2,5,6,7,8,9,10]", "2" ], [ "[4,8,5,7,3]", "4" ], [ "[]", "-1" ] ]
can_arrange
humaneval_java_python_135
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int can_arrange(List<Integer> arr) { int ind = -1, i = 1; while (i < arr.size()) { if (arr.get(i) < arr.get(i - 1)) { ind = i; } i += 1; } return ind; } }
[]
[]
python
java
code_translation
def largest_smallest_integers(lst): smallest = list(filter(lambda x: x < 0, lst)) largest = list(filter(lambda x: x > 0, lst)) return (max(smallest) if smallest else None, min(largest) if largest else None)
[ [ "[2, 4, 1, 3, 5, 7]", "(None, 1)" ], [ "[2, 4, 1, 3, 5, 7, 0]", "(None, 1)" ], [ "[1, 3, 2, 4, 5, 6, -2]", "(-2, 1)" ], [ "[4, 5, 3, 6, 2, 7, -7]", "(-7, 2)" ], [ "[7, 3, 8, 4, 9, 2, 5, -9]", "(-9, 2)" ], [ "[]", "(None, None)" ], [ "[0]", "(None, None)" ], [ "[-1, -3, -5, -6]", "(-1, None)" ], [ "[-1, -3, -5, -6, 0]", "(-1, None)" ], [ "[-6, -4, -4, -3, 1]", "(-3, 1)" ], [ "[-6, -4, -4, -3, -100, 1]", "(-3, 1)" ] ]
largest_smallest_integers
humaneval_java_python_136
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Optional<Integer>> largest_smallest_integers(List<Integer> lst){ List<Integer> smallest = lst.stream().filter(p -> p < 0).toList(); List<Integer> largest = lst.stream().filter(p -> p > 0).toList(); Optional<Integer> s = Optional.empty(); if (smallest.size() > 0) { s = Optional.of(Collections.max(smallest)); } Optional<Integer> l = Optional.empty(); if (largest.size() > 0) { l = Optional.of(Collections.min(largest)); } return Arrays.asList(s, l); } }
[]
[]
python
java
code_translation
def compare_one(a, b): temp_a, temp_b = a, b if isinstance(temp_a, str): temp_a = temp_a.replace(',','.') if isinstance(temp_b, str): temp_b = temp_b.replace(',','.') if float(temp_a) == float(temp_b): return None return a if float(temp_a) > float(temp_b) else b
[ [ "1, 2", "2" ], [ "1, 2.5", "2.5" ], [ "2, 3", "3" ], [ "5, 6", "6" ], [ "1, \"2,3\"", "\"2,3\"" ], [ "\"5,1\", \"6\"", "\"6\"" ], [ "\"1\", \"2\"", "\"2\"" ], [ "\"1\", 1", "None" ] ]
compare_one
humaneval_java_python_137
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public Optional<Object> compare_one(Object a, Object b) { double temp_a = 0, temp_b = 0; if (a instanceof Integer) { temp_a = (Integer) a * 1.0; } else if (a instanceof Double) { temp_a = (double) a; } else if (a instanceof String) { temp_a = Double.parseDouble(((String) a).replace(',', '.')); } if (b instanceof Integer) { temp_b = (Integer) b * 1.0; } else if (b instanceof Double) { temp_b = (double) b; } else if (b instanceof String) { temp_b = Double.parseDouble(((String) b).replace(',', '.')); } if (temp_a == temp_b) { return Optional.empty(); } else if (temp_a > temp_b) { return Optional.of(a); } else { return Optional.of(b); } } }
[]
[]
python
java
code_translation
def is_equal_to_sum_even(n): return n%2 == 0 and n >= 8
[ [ "4", "False" ], [ "6", "False" ], [ "8", "True" ], [ "10", "True" ], [ "11", "False" ], [ "12", "True" ], [ "13", "False" ], [ "16", "True" ] ]
is_equal_to_sum_even
humaneval_java_python_138
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean is_equal_to_sum_even(int n) { return n % 2 == 0 && n >= 8; } }
[]
[]
python
java
code_translation
def special_factorial(n): fact_i = 1 special_fact = 1 for i in range(1, n+1): fact_i *= i special_fact *= fact_i return special_fact
[ [ "4", "288" ], [ "5", "34560" ], [ "7", "125411328000" ], [ "1", "1" ] ]
special_factorial
humaneval_java_python_139
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public long special_factorial(int n) { long fact_i = 1, special_fact = 1; for (int i = 1; i <= n; i++) { fact_i *= i; special_fact *= fact_i; } return special_fact; } }
[]
[]
python
java
code_translation
def fix_spaces(text): new_text = "" i = 0 start, end = 0, 0 while i < len(text): if text[i] == " ": end += 1 else: if end - start > 2: new_text += "-"+text[i] elif end - start > 0: new_text += "_"*(end - start)+text[i] else: new_text += text[i] start, end = i+1, i+1 i+=1 if end - start > 2: new_text += "-" elif end - start > 0: new_text += "_" return new_text
[ [ "\"Example\"", "\"Example\"" ], [ "\"Mudasir Hanif \"", "\"Mudasir_Hanif_\"" ], [ "\"Yellow Yellow Dirty Fellow\"", "\"Yellow_Yellow__Dirty__Fellow\"" ], [ "\"Exa mple\"", "\"Exa-mple\"" ], [ "\" Exa 1 2 2 mple\"", "\"-Exa_1_2_2_mple\"" ] ]
fix_spaces
humaneval_java_python_140
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String fix_spaces(String text) { StringBuilder sb = new StringBuilder(); int start = 0, end = 0; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == ' ') { end += 1; } else { if (end - start > 2) { sb.append('-'); } else if (end - start > 0) { sb.append("_".repeat(end - start)); } sb.append(text.charAt(i)); start = i + 1; end = i + 1; } } if (end - start > 2) { sb.append('-'); } else if (end - start > 0) { sb.append("_".repeat(end - start)); } return sb.toString(); } }
[]
[]
python
java
code_translation
def file_name_check(file_name): suf = ['txt', 'exe', 'dll'] lst = file_name.split(sep='.') if len(lst) != 2: return 'No' if not lst[1] in suf: return 'No' if len(lst[0]) == 0: return 'No' if not lst[0][0].isalpha(): return 'No' t = len([x for x in lst[0] if x.isdigit()]) if t > 3: return 'No' return 'Yes'
[ [ "\"example.txt\"", "'Yes'" ], [ "\"1example.dll\"", "'No'" ], [ "'s1sdf3.asd'", "'No'" ], [ "'K.dll'", "'Yes'" ], [ "'MY16FILE3.exe'", "'Yes'" ], [ "'His12FILE94.exe'", "'No'" ], [ "'_Y.txt'", "'No'" ], [ "'?aREYA.exe'", "'No'" ], [ "'/this_is_valid.dll'", "'No'" ], [ "'this_is_valid.wow'", "'No'" ], [ "'this_is_valid.txt'", "'Yes'" ], [ "'this_is_valid.txtexe'", "'No'" ], [ "'#this2_i4s_5valid.ten'", "'No'" ], [ "'@this1_is6_valid.exe'", "'No'" ], [ "'this_is_12valid.6exe4.txt'", "'No'" ], [ "'all.exe.txt'", "'No'" ], [ "'I563_No.exe'", "'Yes'" ], [ "'Is3youfault.txt'", "'Yes'" ], [ "'no_one#knows.dll'", "'Yes'" ], [ "'1I563_Yes3.exe'", "'No'" ], [ "'I563_Yes3.txtt'", "'No'" ], [ "'final..txt'", "'No'" ], [ "'final132'", "'No'" ], [ "'_f4indsartal132.'", "'No'" ], [ "'.txt'", "'No'" ], [ "'s.'", "'No'" ] ]
file_name_check
humaneval_java_python_141
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String file_name_check(String file_name) { List<String> suf = Arrays.asList("txt", "exe", "dll"); String[] lst = file_name.split("\\." ); if (lst.length != 2 || !suf.contains(lst[1]) || lst[0].isEmpty() || !Character.isLetter(lst[0].charAt(0))) { return "No"; } int t = (int) lst[0].chars().map(x -> (char) x).filter(Character::isDigit).count(); if (t > 3) { return "No"; } return "Yes"; } }
[]
[]
python
java
code_translation
def sum_squares(lst): " result =[] for i in range(len(lst)): if i %3 == 0: result.append(lst[i]**2) elif i % 4 == 0 and i%3 != 0: result.append(lst[i]**3) else: result.append(lst[i]) return sum(result)
[ [ "[1,2,3]", "6" ], [ "[1,4,9]", "14" ], [ "[]", "0" ], [ "[1,1,1,1,1,1,1,1,1]", "9" ], [ "[-1,-1,-1,-1,-1,-1,-1,-1,-1]", "-3" ], [ "[0]", "0" ], [ "[-1,-5,2,-1,-5]", "-126" ], [ "[-56,-99,1,0,-2]", "3030" ], [ "[-1,0,0,0,0,0,0,0,-1]", "0" ], [ "[-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37]", "-14196" ], [ "[-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10]", "-1448" ] ]
sum_squares
humaneval_java_python_142
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int sum_squares(List<Integer> lst) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < lst.size(); i++) { if (i % 3 == 0) { result.add(lst.get(i) * lst.get(i)); } else if (i % 4 == 0) { result.add((int) Math.pow(lst.get(i), 3)); } else { result.add(lst.get(i)); } } return result.stream().reduce(Integer::sum).orElse(0); } }
[]
[]
python
java
code_translation
def words_in_sentence(sentence): new_lst = [] for word in sentence.split(): flg = 0 if len(word) == 1: flg = 1 for i in range(2, len(word)): if len(word)%i == 0: flg = 1 if flg == 0 or len(word) == 2: new_lst.append(word) return " ".join(new_lst)
[ [ "\"This is a test\"", "\"is\"" ], [ "\"lets go for swimming\"", "\"go for\"" ], [ "\"there is no place available here\"", "\"there is no place\"" ], [ "\"Hi I am Hussein\"", "\"Hi am Hussein\"" ], [ "\"go for it\"", "\"go for it\"" ], [ "\"here\"", "\"\"" ], [ "\"here is\"", "\"is\"" ] ]
words_in_sentence
humaneval_java_python_143
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String words_in_sentence(String sentence) { List<String> new_lst = new ArrayList<>(); for (String word : sentence.split(" " )) { boolean flg = true; if (word.length() == 1) { continue; } for (int i = 2; i < word.length(); i++) { if (word.length() % i == 0) { flg = false; break; } } if (flg) { new_lst.add(word); } } return String.join(" ", new_lst); } }
[]
[]
python
java
code_translation
def simplify(x, n): a, b = x.split("/") c, d = n.split("/") numerator = int(a) * int(c) denom = int(b) * int(d) if (numerator/denom == int(numerator/denom)): return True return False
[ [ "\"1/5\", \"5/1\"", "True" ], [ "\"1/6\", \"2/1\"", "False" ], [ "\"5/1\", \"3/1\"", "True" ], [ "\"7/10\", \"10/2\"", "False" ], [ "\"2/10\", \"50/10\"", "True" ], [ "\"7/2\", \"4/2\"", "True" ], [ "\"11/6\", \"6/1\"", "True" ], [ "\"2/3\", \"5/2\"", "False" ], [ "\"5/2\", \"3/5\"", "False" ], [ "\"2/4\", \"8/4\"", "True" ], [ "\"2/4\", \"4/2\"", "True" ], [ "\"1/5\", \"5/1\"", "True" ], [ "\"1/5\", \"1/5\"", "False" ] ]
simplify
humaneval_java_python_144
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean simplify(String x, String n) { String[] a = x.split("/"); String[] b = n.split("/"); int numerator = Integer.parseInt(a[0]) * Integer.parseInt(b[0]); int denom = Integer.parseInt(a[1]) * Integer.parseInt(b[1]); return numerator / denom * denom == numerator; } }
[]
[]
python
java
code_translation
def order_by_points(nums): def digits_sum(n): neg = 1 if n < 0: n, neg = -1 * n, -1 n = [int(i) for i in str(n)] n[0] = n[0] * neg return sum(n) return sorted(nums, key=digits_sum)
[ [ "[1, 11, -1, -11, -12]", "[-1, -11, 1, -12, 11]" ], [ "[1234,423,463,145,2,423,423,53,6,37,3457,3,56,0,46]", "[0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457]" ], [ "[]", "[]" ], [ "[1, -11, -32, 43, 54, -98, 2, -3]", "[-3, -32, -98, -11, 1, 2, 43, 54]" ], [ "[1,2,3,4,5,6,7,8,9,10,11]", "[1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9]" ], [ "[0,6,6,-76,-21,23,4]", "[-76, -21, 0, 4, 23, 6, 6]" ] ]
order_by_points
humaneval_java_python_145
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> order_by_points(List<Integer> nums) { List<Integer> result = new ArrayList<>(nums); result.sort((o1, o2) -> { int sum1 = 0; int sum2 = 0; for (int i = 0; i < String.valueOf(o1).length(); i++) { if (i != 0 || o1 >= 0) { sum1 += (String.valueOf(o1).charAt(i) - '0' ); if (i == 1 && o1 < 0) { sum1 = -sum1; } } } for (int i = 0; i < String.valueOf(o2).length(); i++) { if (i != 0 || o2 >= 0) { sum2 += (String.valueOf(o2).charAt(i) - '0' ); if (i == 1 && o2 < 0) { sum2 = -sum2; } } } return Integer.compare(sum1, sum2); }); return result; } }
[]
[]
python
java
code_translation
def specialFilter(nums): count = 0 for num in nums: if num > 10: odd_digits = (1, 3, 5, 7, 9) number_as_string = str(num) if int(number_as_string[0]) in odd_digits and int(number_as_string[-1]) in odd_digits: count += 1 return count
[ [ "[5, -2, 1, -5]", "0" ], [ "[15, -73, 14, -15]", "1" ], [ "[33, -2, -3, 45, 21, 109]", "2" ], [ "[43, -12, 93, 125, 121, 109]", "4" ], [ "[71, -2, -33, 75, 21, 19]", "3" ], [ "[1]", "0" ], [ "[]", "0" ] ]
specialFilter
humaneval_java_python_146
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int specialFilter(List<Integer> nums) { int count = 0; for (int num : nums) { if (num > 10) { String odd_digits = "13579"; String number_as_string = String.valueOf(num); if (odd_digits.indexOf(number_as_string.charAt(0)) != -1 && odd_digits.indexOf(number_as_string.charAt(number_as_string.length() - 1)) != -1) { count += 1; } } } return count; } }
[]
[]
python
java
code_translation
def get_max_triples(n): A = [i*i - i + 1 for i in range(1,n+1)] ans = [] for i in range(n): for j in range(i+1,n): for k in range(j+1,n): if (A[i]+A[j]+A[k])%3 == 0: ans += [(A[i],A[j],A[k])] return len(ans)
[ [ "5", "1" ], [ "6", "4" ], [ "10", "36" ], [ "100", "53361" ] ]
get_max_triples
humaneval_java_python_147
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int get_max_triples(int n) { List<Integer> A = new ArrayList<>(); for (int i = 1; i <= n; i++) { A.add(i * i - i + 1); } int count = 0; for (int i = 0; i < A.size(); i++) { for (int j = i + 1; j < A.size(); j++) { for (int k = j + 1; k < A.size(); k++) { if ((A.get(i) + A.get(j) + A.get(k)) % 3 == 0) { count += 1; } } } } return count; } }
[]
[]
python
java
code_translation
def bf(planet1, planet2): planet_names = ("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune") if planet1 not in planet_names or planet2 not in planet_names or planet1 == planet2: return () planet1_index = planet_names.index(planet1) planet2_index = planet_names.index(planet2) if planet1_index < planet2_index: return (planet_names[planet1_index + 1: planet2_index]) else: return (planet_names[planet2_index + 1 : planet1_index])
[ [ "\"Jupiter\", \"Neptune\"", "(\"Saturn\", \"Uranus\")" ], [ "\"Earth\", \"Mercury\"", "(\"Venus\",)" ], [ "\"Mercury\", \"Uranus\"", "(\"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\")" ], [ "\"Neptune\", \"Venus\"", "(\"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\")" ], [ "\"Earth\", \"Earth\"", "()" ], [ "\"Mars\", \"Earth\"", "()" ], [ "\"Jupiter\", \"Makemake\"", "()" ] ]
bf
humaneval_java_python_148
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> bf(String planet1, String planet2) { List<String> planet_names = Arrays.asList("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"); if (!planet_names.contains(planet1) || !planet_names.contains(planet2) || planet1.equals(planet2)) { return List.of(); } int planet1_index = planet_names.indexOf(planet1); int planet2_index = planet_names.indexOf(planet2); if (planet1_index < planet2_index) { return planet_names.subList(planet1_index + 1, planet2_index); } else { return planet_names.subList(planet2_index + 1, planet1_index); } } }
[]
[]
python
java
code_translation
def sorted_list_sum(lst): lst.sort() new_lst = [] for i in lst: if len(i)%2 == 0: new_lst.append(i) return sorted(new_lst, key=len)
[ [ "[\"aa\", \"a\", \"aaa\"]", "[\"aa\"]" ], [ "[\"school\", \"AI\", \"asdf\", \"b\"]", "[\"AI\", \"asdf\", \"school\"]" ], [ "[\"d\", \"b\", \"c\", \"a\"]", "[]" ], [ "[\"d\", \"dcba\", \"abcd\", \"a\"]", "[\"abcd\", \"dcba\"]" ], [ "[\"AI\", \"ai\", \"au\"]", "[\"AI\", \"ai\", \"au\"]" ], [ "[\"a\", \"b\", \"b\", \"c\", \"c\", \"a\"]", "[]" ], [ "['aaaa', 'bbbb', 'dd', 'cc']", "[\"cc\", \"dd\", \"aaaa\", \"bbbb\"]" ] ]
sorted_list_sum
humaneval_java_python_149
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<String> sorted_list_sum(List<String> lst) { List<String> lst_sorted = new ArrayList<>(lst); Collections.sort(lst_sorted); List<String> new_lst = new ArrayList<>(); for (String i : lst_sorted) { if (i.length() % 2 == 0) { new_lst.add(i); } } new_lst.sort(Comparator.comparingInt(String::length)); return new_lst; } }
[]
[]
python
java
code_translation
def x_or_y(n, x, y): if n == 1: return y for i in range(2, n): if n % i == 0: return y break else: return x
[ [ "7, 34, 12", "34" ], [ "15, 8, 5", "5" ], [ "3, 33, 5212", "33" ], [ "1259, 3, 52", "3" ], [ "7919, -1, 12", "-1" ], [ "3609, 1245, 583", "583" ], [ "91, 56, 129", "129" ], [ "6, 34, 1234", "1234" ], [ "1, 2, 0", "0" ], [ "2, 2, 0", "2" ] ]
x_or_y
humaneval_java_python_150
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int x_or_y(int n, int x, int y) { if (n == 1) { return y; } for (int i = 2; i < n; i++) { if (n % i == 0) { return y; } } return x; } }
[]
[]
python
java
code_translation
def double_the_difference(lst): return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])
[ [ "[]", "0" ], [ "[5, 4]", "25" ], [ "[0.1, 0.2, 0.3]", "0" ], [ "[-10, -20, -30]", "0" ], [ "[-1, -2, 8]", "0" ], [ "[0.2, 3, 5]", "34" ] ]
double_the_difference
humaneval_java_python_151
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int double_the_difference(List<Object> lst) { return lst.stream().filter(i -> i instanceof Integer p && p > 0 && p % 2 != 0).map(i -> (Integer) i * (Integer) i).reduce(Integer::sum).orElse(0); } }
[]
[]
python
java
code_translation
def compare(game,guess): return [abs(x-y) for x,y in zip(game,guess)]
[ [ "[1,2,3,4,5,1], [1,2,3,4,2,-2]", "[0,0,0,0,3,3]" ], [ "[0,0,0,0,0,0], [0,0,0,0,0,0]", "[0,0,0,0,0,0]" ], [ "[1,2,3], [-1,-2,-3]", "[2,4,6]" ], [ "[1,2,3,5], [-1,2,3,4]", "[2,0,0,1]" ] ]
compare
humaneval_java_python_152
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> compare(List<Integer> game, List<Integer> guess) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < game.size(); i++) { result.add(Math.abs(game.get(i) - guess.get(i))); } return result; } }
[]
[]
python
java
code_translation
def Strongest_Extension(class_name, extensions): strong = extensions[0] my_val = len([x for x in extensions[0] if x.isalpha() and x.isupper()]) - len([x for x in extensions[0] if x.isalpha() and x.islower()]) for s in extensions: val = len([x for x in s if x.isalpha() and x.isupper()]) - len([x for x in s if x.isalpha() and x.islower()]) if val > my_val: strong = s my_val = val ans = class_name + "." + strong return ans
[ [ "'Watashi', ['tEN', 'niNE', 'eIGHt8OKe']", "'Watashi.eIGHt8OKe'" ], [ "'Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']", "'Boku123.YEs.WeCaNe'" ], [ "'__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__', '123NoooneB321']", "'__YESIMHERE.NuLl__'" ], [ "'K', ['Ta', 'TAR', 't234An', 'cosSo']", "'K.TAR'" ], [ "'__HAHA', ['Tab', '123', '781345', '-_-']", "'__HAHA.123'" ], [ "'YameRore', ['HhAas', 'okIWILL123', 'WorkOut', 'Fails', '-_-']", "'YameRore.okIWILL123'" ], [ "'finNNalLLly', ['Die', 'NowW', 'Wow', 'WoW']", "'finNNalLLly.WoW'" ], [ "'_', ['Bb', '91245']", "'_.Bb'" ], [ "'Sp', ['671235', 'Bb']", "'Sp.671235'" ] ]
Strongest_Extension
humaneval_java_python_153
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String Strongest_Extension(String class_name, List<String> extensions) { String strong = extensions.get(0); int my_val = (int) (strong.chars().filter(Character::isUpperCase).count() - strong.chars().filter(Character::isLowerCase).count()); for (String s : extensions) { int val = (int) (s.chars().filter(Character::isUpperCase).count() - s.chars().filter(Character::isLowerCase).count()); if (val > my_val) { strong = s; my_val = val; } } return class_name + "." + strong; } }
[]
[]
python
java
code_translation
def cycpattern_check(a , b): l = len(b) pat = b + b for i in range(len(a) - l + 1): for j in range(l + 1): if a[i:i+l] == pat[j:j+l]: return True return False
[ [ "\"xyzw\", \"xyw\"", "False" ], [ "\"yello\", \"ell\"", "True" ], [ "\"whattup\", \"ptut\"", "False" ], [ "\"efef\", \"fee\"", "True" ], [ "\"abab\", \"aabb\"", "False" ], [ "\"winemtt\", \"tinem\"", "True" ] ]
cycpattern_check
humaneval_java_python_154
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean cycpattern_check(String a, String b) { int l = b.length(); String pat = b + b; for (int i = 0; i <= a.length() - l; i++) { for (int j = 0; j <= l; j++) { if (a.substring(i, i + l).equals(pat.substring(j, j + l))) { return true; } } } return false; } }
[]
[]
python
java
code_translation
def even_odd_count(num): even_count = 0 odd_count = 0 for i in str(abs(num)): if int(i)%2==0: even_count +=1 else: odd_count +=1 return (even_count, odd_count)
[ [ "7", "(0, 1)" ], [ "-78", "(1, 1)" ], [ "3452", "(2, 2)" ], [ "346211", "(3, 3)" ], [ "-345821", "(3, 3)" ], [ "-2", "(1, 0)" ], [ "-45347", "(2, 3)" ], [ "0", "(1, 0)" ] ]
even_odd_count
humaneval_java_python_155
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> even_odd_count(int num) { int even_count = 0, odd_count = 0; for (char i : String.valueOf(Math.abs(num)).toCharArray()) { if ((i - '0') % 2 == 0) { even_count += 1; } else { odd_count += 1; } } return Arrays.asList(even_count, odd_count); } }
[]
[]
python
java
code_translation
def int_to_mini_roman(number): num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000] sym = ["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"] i = 12 res = '' while number: div = number // num[i] number %= num[i] while div: res += sym[i] div -= 1 i -= 1 return res.lower()
[ [ "19", "'xix'" ], [ "152", "'clii'" ], [ "251", "'ccli'" ], [ "426", "'cdxxvi'" ], [ "500", "'d'" ], [ "1", "'i'" ], [ "4", "'iv'" ], [ "43", "'xliii'" ], [ "90", "'xc'" ], [ "94", "'xciv'" ], [ "532", "'dxxxii'" ], [ "900", "'cm'" ], [ "994", "'cmxciv'" ], [ "1000", "'m'" ] ]
int_to_mini_roman
humaneval_java_python_156
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String int_to_mini_roman(int number) { List<Integer> num = Arrays.asList(1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000); List<String> sym = Arrays.asList("I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"); int i = 12; String res = ""; while (number > 0) { int div = number / num.get(i); number %= num.get(i); while (div != 0) { res += sym.get(i); div -= 1; } i -= 1; } return res.toLowerCase(); } }
[]
[]
python
java
code_translation
def right_angle_triangle(a, b, c): return a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b
[ [ "3, 4, 5", "True" ], [ "1, 2, 3", "False" ], [ "10, 6, 8", "True" ], [ "2, 2, 2", "False" ], [ "7, 24, 25", "True" ], [ "10, 5, 7", "False" ], [ "5, 12, 13", "True" ], [ "15, 8, 17", "True" ], [ "48, 55, 73", "True" ], [ "1, 1, 1", "False" ], [ "2, 2, 10", "False" ] ]
right_angle_triangle
humaneval_java_python_157
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public boolean right_angle_triangle(int a, int b, int c) { return a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b; } }
[]
[]
python
java
code_translation
def find_max(words): return sorted(words, key = lambda x: (-len(set(x)), x))[0]
[ [ "[\"name\", \"of\", \"string\"]", "\"string\"" ], [ "[\"name\", \"enam\", \"game\"]", "\"enam\"" ], [ "[\"aaaaaaa\", \"bb\", \"cc\"]", "\"aaaaaaa\"" ], [ "[\"abc\", \"cba\"]", "\"abc\"" ], [ "[\"play\", \"this\", \"game\", \"of\",\"footbott\"]", "\"footbott\"" ], [ "[\"we\", \"are\", \"gonna\", \"rock\"]", "\"gonna\"" ], [ "[\"we\", \"are\", \"a\", \"mad\", \"nation\"]", "\"nation\"" ], [ "[\"this\", \"is\", \"a\", \"prrk\"]", "\"this\"" ], [ "[\"b\"]", "\"b\"" ], [ "[\"play\", \"play\", \"play\"]", "\"play\"" ] ]
find_max
humaneval_java_python_158
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String find_max(List<String> words) { List<String> words_sort = new ArrayList<>(words); words_sort.sort(new Comparator<String>() { @Override public int compare(String o1, String o2) { Set<Character> s1 = new HashSet<>(); for (char ch : o1.toCharArray()) { s1.add(ch); } Set<Character> s2 = new HashSet<>(); for (char ch : o2.toCharArray()) { s2.add(ch); } if (s1.size() > s2.size()) { return 1; } else if (s1.size() < s2.size()) { return -1; } else { return -o1.compareTo(o2); } } }); return words_sort.get(words_sort.size() - 1); } }
[]
[]
python
java
code_translation
def eat(number, need, remaining): if(need <= remaining): return [ number + need , remaining-need ] else: return [ number + remaining , 0]
[ [ "5, 6, 10", "[11, 4]" ], [ "4, 8, 9", "[12, 1]" ], [ "1, 10, 10", "[11, 0]" ], [ "2, 11, 5", "[7, 0]" ], [ "4, 5, 7", "[9, 2]" ], [ "4, 5, 1", "[5, 0]" ] ]
eat
humaneval_java_python_159
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> eat(int number, int need, int remaining) { if (need <= remaining) { return Arrays.asList(number + need, remaining - need); } else { return Arrays.asList(number + remaining, 0); } } }
[]
[]
python
java
code_translation
def do_algebra(operator, operand): expression = str(operand[0]) for oprt, oprn in zip(operator, operand[1:]): expression+= oprt + str(oprn) return eval(expression)
[ [ "['**', '*', '+'], [2, 3, 4, 5]", "37" ], [ "['+', '*', '-'], [2, 3, 4, 5]", "9" ], [ "['//', '*'], [7, 3, 4]", "8" ] ]
do_algebra
humaneval_java_python_160
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public int do_algebra(List<String> operator, List<Integer> operand) { List<String> ops = new ArrayList<>(operator); List<Integer> nums = new ArrayList<>(operand); for (int i = ops.size() - 1; i >= 0; i--) { if (ops.get(i).equals("**")) { nums.set(i, (int) Math.round(Math.pow(nums.get(i), nums.get(i + 1)))); nums.remove(i + 1); ops.remove(i); } } for (int i = 0; i < ops.size(); i++) { if (ops.get(i).equals("*")) { nums.set(i, nums.get(i) * nums.get(i + 1)); nums.remove(i + 1); ops.remove(i); i--; } else if (ops.get(i).equals("/")) { nums.set(i, nums.get(i) / nums.get(i + 1)); nums.remove(i + 1); ops.remove(i); i--; } } for (int i = 0; i < ops.size(); i++) { if (ops.get(i).equals("+")) { nums.set(i, nums.get(i) + nums.get(i + 1)); nums.remove(i + 1); ops.remove(i); i--; } else if (ops.get(i).equals("-")) { nums.set(i, nums.get(i) - nums.get(i + 1)); nums.remove(i + 1); ops.remove(i); i--; } } return nums.get(0); } }
[]
[]
python
java
code_translation
def solve(s): flg = 0 idx = 0 new_str = list(s) for i in s: if i.isalpha(): new_str[idx] = i.swapcase() flg = 1 idx += 1 s = "" for i in new_str: s += i if flg == 0: return s[len(s)::-1] return s
[ [ "\"AsDf\"", "\"aSdF\"" ], [ "\"1234\"", "\"4321\"" ], [ "\"ab\"", "\"AB\"" ], [ "\"#a@C\"", "\"#A@c\"" ], [ "\"#AsdfW^45\"", "\"#aSDFw^45\"" ], [ "\"#6@2\"", "\"2@6#\"" ], [ "\"#$a^D\"", "\"#$A^d\"" ], [ "\"#ccc\"", "\"#CCC\"" ] ]
solve
humaneval_java_python_161
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public String solve(String s) { boolean flag = true; StringBuilder new_string = new StringBuilder(); for (char i : s.toCharArray()) { if (Character.isUpperCase(i)) { new_string.append(Character.toLowerCase(i)); flag = false; } else if (Character.isLowerCase(i)) { new_string.append(Character.toUpperCase(i)); flag = false; } else { new_string.append(i); } } if (flag) { new_string.reverse(); } return new_string.toString(); } }
[]
[]
python
java
code_translation
def string_to_md5(text): import hashlib return hashlib.md5(text.encode('ascii')).hexdigest() if text else None
[ [ "'Hello world'", "'3e25960a79dbc69b674cd4ec67a72c62'" ], [ "''", "None" ], [ "'A B C'", "'0ef78513b0cb8cef12743f5aeb35f888'" ], [ "'password'", "'5f4dcc3b5aa765d61d8327deb882cf99'" ] ]
string_to_md5
humaneval_java_python_162
humaneval_trans
import java.math.BigInteger; import java.security.*; import java.util.*; import java.lang.*; class Solution { public Optional<String> string_to_md5(String text) throws NoSuchAlgorithmException { if (text.isEmpty()) { return Optional.empty(); } String md5 = new BigInteger(1, java.security.MessageDigest.getInstance("MD5").digest(text.getBytes())).toString(16); md5 = "0".repeat(32 - md5.length()) + md5; return Optional.of(md5); } }
[]
[]
python
java
code_translation
def generate_integers(a, b): lower = max(2, min(a, b)) upper = min(8, max(a, b)) return [i for i in range(lower, upper+1) if i % 2 == 0]
[ [ "2, 10", "[2, 4, 6, 8]" ], [ "10, 2", "[2, 4, 6, 8]" ], [ "132, 2", "[2, 4, 6, 8]" ], [ "17, 89", "[]" ] ]
generate_integers
humaneval_java_python_163
humaneval_trans
import java.util.*; import java.lang.*; class Solution { public List<Integer> generate_integers(int a, int b) { int lower = Math.max(2, Math.min(a, b)); int upper = Math.min(8, Math.max(a, b)); List<Integer> result = new ArrayList<>(); for (int i = lower; i <= upper; i += 2) { result.add(i); } return result; } }