task_id
stringlengths
14
16
prompt
stringlengths
92
811
entry_point
stringlengths
1
30
canonical_solution
stringlengths
16
864
test
stringlengths
117
1.8k
KR_HumanEval/100
def make_a_pile(n): """ 양의 정수 n이 주어지면, n 레벨의 돌 더미를 만들어야 합니다. 첫 번째 레벨에는 n개의 돌이 있습니다. 다음 레벨의 돌 개수는 다음과 같습니다: - n이 홀수이면 다음 홀수. - n이 짝수이면 다음 짝수입니다. 각 레벨에 있는 스톤의 수를 목록으로 반환하며, 여기서 인덱스의 요소 i는 해당 레벨의 스톤 개수(i+1)를 나타냅니다. 예시 >>> make_a_pile(3) [3, 5, 7] """
make_a_pile
return [n + 2*i for i in range(n)]
def check(candidate): # Check some simple cases assert candidate(3) == [3, 5, 7], "Test 3" assert candidate(4) == [4,6,8,10], "Test 4" assert candidate(5) == [5, 7, 9, 11, 13] assert candidate(6) == [6, 8, 10, 12, 14, 16] assert candidate(8) == [8, 10, 12, 14, 16, 18, 20, 22] # Check some ...
KR_HumanEval/101
def words_string(s): """ 쉼표나 공백으로 구분된 단어 문자열이 주어집니다. 여러분의 임무는 문자열을 단어로 분할하고 단어의 배열을 반환하는 것입니다. 예를 들어 words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] """
words_string
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()
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] assert candidate("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] ...
KR_HumanEval/102
def choose_num(x, y): """이 함수는 두 개의 양수 x와 y를 받아 [x, y] 범위를 포함하는 가장 큰 짝수 정수를 반환합니다. 만약에 해당하는 숫자가 없으면 함수는 -1을 반환해야 합니다. 예를 들어 choose_num(12, 15) = 14 choose_num(13, 12) = -1 """
choose_num
if x > y: return -1 if y % 2 == 0: return y if x == y: return -1 return y - 1
def check(candidate): # Check some simple cases assert candidate(12, 15) == 14 assert candidate(13, 12) == -1 assert candidate(33, 12354) == 12354 assert candidate(5234, 5233) == -1 assert candidate(6, 29) == 28 assert candidate(27, 10) == -1 # Check some edge cases that are easy to wo...
KR_HumanEval/103
def rounded_avg(n, m): """두 개의 양의 정수 n과 m이 주어지며, n부터 m까지(n과 m 포함)의 정수의 평균을 계산하는 문제입니다. 답을 가장 가까운 정수로 반올림하고 이를 2진수로 변환합니다. n이 m보다 크면 -1을 반환합니다. 예제: rounded_avg(1, 5) => "0b11" rounded_avg(7, 5) => -1 ROUNDED_AVG(10, 20) => "0b1111" ROUNDED_AVG(20, 33) => "0b11010" """
rounded_avg
if m < n: return -1 summation = 0 for i in range(n, m+1): summation += i return bin(round(summation/(m - n + 1)))
def check(candidate): # Check some simple cases assert candidate(1, 5) == "0b11" assert candidate(7, 13) == "0b1010" assert candidate(964,977) == "0b1111001010" assert candidate(996,997) == "0b1111100100" assert candidate(560,851) == "0b1011000010" assert candidate(185,546) == "0b101101110"...
KR_HumanEval/104
def unique_digits(x): """양의 정수 x의 목록이 주어졌을 때 짝수 자릿수가 없는 모든 요소의 정렬된 리스트를 반환합니다. 참고: 반환된 목록은 증가하는 순서로 정렬되어야 합니다. 예를 들어 >>> unique_digits([15, 33, 1422, 1]) [1, 15, 33] >>> unique_digits([152, 323, 1422, 10]) [] """
unique_digits
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)
def check(candidate): # Check some simple cases assert candidate([15, 33, 1422, 1]) == [1, 15, 33] assert candidate([152, 323, 1422, 10]) == [] assert candidate([12345, 2033, 111, 151]) == [111, 151] assert candidate([135, 103, 31]) == [31, 135] # Check some edge cases that are easy to work ou...
KR_HumanEval/105
def by_length(arr): """ 정수의 배열이 주어지면 1에서 9 사이의 정수들을 정렬하고, 결과 배열을 뒤집은 다음, 각 숫자를 "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"의 해당 이름으로 대체합니다. 예를 들어 arr = [2, 1, 1, 4, 5, 8, 2, 3] -> 정렬 배열 -> [1, 1, 2, 2, 3, 4, 5, 8] -> 역 배열 -> [8, 5, 4, 3, 2, 2, 1, ...
by_length
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[...
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([2, 1, 1, 4, 5, 8, 2, 3]) == ["Eight", "Five", "Four", "Three", "Two", "Two", "One", "One"], "Error" assert candidate([]) == [], "Error" assert candidate([1, -1 ,...
KR_HumanEval/106
def f(n): """ n을 매개 변수로 받아서 인덱스 i에 있는 요소의 값은 i가 짝수일 경우 i의 팩토리얼이고, 그렇지 않으면 1부터 i까지의 합이되는 크기 n의 목록을 반환하는 함수 f를 구현합니다. i는 1부터 시작합니다. i의 계승은 1에서 i까지의 숫자를 곱한 값(1 * 2 * ... * i)입니다. 예시: f(5) == [1, 2, 6, 24, 15] """
f
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
def check(candidate): assert candidate(5) == [1, 2, 6, 24, 15] assert candidate(7) == [1, 2, 6, 24, 15, 720, 28] assert candidate(1) == [1] assert candidate(3) == [1, 2, 6]
KR_HumanEval/107
def even_odd_palindrome(n): """ 양의 정수 n이 주어지면, 범위(1, n)에 속하는 짝수 및 홀수 정수 팔린드롬의 개수를 모두 포함한 튜플을 반환합니다. 예제 1: Input: 3 출력 (1, 2) 설명: 설명: 정수 팔린드롬은 1, 2, 3입니다. 그 중 하나는 짝수이고 두 개는 홀수입니다. 예제 2: 입력: 12 출력 (4, 6) 설명: 설명: 정수 팔린드롬은 1, 2, 3, 4, 5, 6,...
even_odd_palindrome
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 ...
def check(candidate): # Check some simple cases assert candidate(123) == (8, 13) assert candidate(12) == (4, 6) assert candidate(3) == (1, 2) assert candidate(63) == (6, 8) assert candidate(25) == (5, 6) assert candidate(19) == (4, 6) assert candidate(9) == (4, 5), "This prints if this ...
KR_HumanEval/108
def count_nums(arr): """ 정수 배열을 받아 자릿수의 합이 0보다 큰 요소의 수를 반환하는 함수 count_nums를 작성합니다. 숫자가 음수인 경우 첫 번째 부호가 있는 자릿수가 음수가 됩니다: 예를 들어 -123은 부호가 -1, 2, 3인 숫자입니다. >>> count_nums([]) == 0 >>> count_nums([-1, 11, -11]) == 1 >>> count_nums([1, 1, 2]) == 3 """
count_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 len(list(filter(lambda x: x > 0, [digits_sum(i) for i in arr])))
def check(candidate): # Check some simple cases assert candidate([]) == 0 assert candidate([-1, -2, 0]) == 0 assert candidate([1, 1, 2, -2, 3, 4, 5]) == 6 assert candidate([1, 6, 9, -6, 0, 1, 5]) == 5 assert candidate([1, 100, 98, -7, 1, -1]) == 4 assert candidate([12, 23, 34, -45, -56, 0])...
KR_HumanEval/109
def move_one_ball(arr): """N개의 정수로 구성된 배열 'arr'이 있습니다. 배열[1], 배열[2], ..., 배열[N]. 배열의 숫자들은 무작위로 정렬됩니다. 주어진 배열에 대해 다음 연산을 수행하여 배열을 감소하지 않는 순서로 정렬할 수 있는지 확인하는 것이 과제입니다: 오른쪽 시프트 연산을 횟수에 제한 없이 수행할 수 있습니다. 한 번의 오른쪽 이동 연산은 배열의 모든 요소를 올바른 방향으로 한 위치씩 이동하는 것을 의미합니다. 배열의 마지막 요소는 배열의 시작 위치, 즉 0번째 인덱스로 ...
move_one_ball
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
def check(candidate): # Check some simple cases assert candidate([3, 4, 5, 1, 2])==True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([3, 5, 10, 1, 2])==True assert candidate([4, 3, 1, 2])==False # Check some edge cases that are easy to work out by hand. assert ca...
KR_HumanEval/110
def exchange(lst1, lst2): """이 문제에서는 두 개의 숫자 목록을 취하고, 그 사이에서 요소 교환을 수행하여 lst1을 짝수만 있는 목록으로 만드는 것이 가능한지 여부를 결정하는 함수를 구현합니다. lst1과 lst2 사이에서 교환되는 요소의 수에는 제한이 없습니다. lst1과 lst2 간에 요소를 교환하여 lst1의 모든 요소를 짝수로 만들 수 있으면 “YES”를 반환합니다. 그렇지 않으면 “NO”를 반환합니다. 예를 들어 exchange([1, 2, 3, 4], [1, 2, 3, 4]) => ...
exchange
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"
def check(candidate): # Check some simple cases assert candidate([1, 2, 3, 4], [1, 2, 3, 4]) == "YES" assert candidate([1, 2, 3, 4], [1, 5, 3, 4]) == "NO" assert candidate([1, 2, 3, 4], [2, 1, 4, 3]) == "YES" assert candidate([5, 7, 3], [2, 6, 4]) == "YES" assert candidate([5, 7, 3], [2, 6, 3]...
KR_HumanEval/111
def histogram(test): """공백으로 구분된 소문자를 나타내는 문자열이 주어지면, 반복 횟수가 가장 많고 해당 개수가 포함된 문자의 사전을 반환합니다. 여러 문자가 같은 횟수로 반복되면 모두 반환합니다. 예시 histogram('a b c') == {'a': 1, 'b': 1, 'c': 1} histogram('a b b a') == {'a': 2, 'b': 2} histogram('a b c a b') == {'a': 2, 'b': 2} histogram('b b b b a') == {'b':...
histogram
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
def check(candidate): # Check some simple cases assert candidate('a b b a') == {'a':2,'b': 2}, "This prints if this assert fails 1 (good for debugging!)" assert candidate('a b c a b') == {'a': 2, 'b': 2}, "This prints if this assert fails 2 (good for debugging!)" assert candidate('a b c d g') == {'a': ...
KR_HumanEval/112
def reverse_delete(s,c): """작업 두 문자열 s와 c가 주어지면, s의 모든 문자 중 c의 문자와 같은 문자를 삭제한 다음 결과 문자열이 팔린드롬인지 확인해야 합니다. 문자열이 앞뒤로 같은 문자를 읽으면 팔린드롬이라고 합니다. 결과 문자열과 검사에 대한 True/False가 포함된 튜플을 반환해야 합니다. 예제 s = "abcde", c = "ae"의 경우 결과는 ('bcd',False)가 되어야 합니다. s = "abcdef", c = "b"의 경우 결과는 ('acdef',False)가 되어야 ...
reverse_delete
s = ''.join([char for char in s if char not in c]) return (s,s[::-1] == s)
def check(candidate): assert candidate("abcde","ae") == ('bcd',False) assert candidate("abcdef", "b") == ('acdef',False) assert candidate("abcdedcba","ab") == ('cdedc',True) assert candidate("dwik","w") == ('dik',False) assert candidate("a","a") == ('',True) assert candidate("abcdedcba","") == ...
KR_HumanEval/113
def odd_count(lst): """각 문자열이 숫자로만 구성된 문자열 목록이 주어지면 목록을 반환합니다. 출력의 각 요소 i는 “입력의 문자열 i에 있는 홀수 요소의 수”여야 합니다. 여기서 모든 i는 입력의 i번째 문자열에 있는 홀수 자리 수로 대체되어야 합니다. >>> odd_count(['1234567']) ["the number of odd elements 4n the str4ng 4 of the 4nput."] >>> odd_count(['3',"11111111"]) ["the number of od...
odd_count
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
def check(candidate): # Check some simple cases assert candidate(['1234567']) == ["the number of odd elements 4n the str4ng 4 of the 4nput."], "Test 1" assert candidate(['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...
KR_HumanEval/114
def minSubArraySum(nums): """ 정수의 배열 nums가 주어졌을 때, 비어 있지 않은 하위 배열의 최소 합을 구합니다. 예제 minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 minSubArraySum([-1, -2, -3]) == -6 """
minSubArraySum
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
def check(candidate): # Check some simple cases assert candidate([2, 3, 4, 1, 2, 4]) == 1, "This prints if this assert fails 1 (good for debugging!)" assert candidate([-1, -2, -3]) == -6 assert candidate([-1, -2, -3, 2, -10]) == -14 assert candidate([-9999999999999999]) == -9999999999999999 ass...
KR_HumanEval/115
def max_fill(grid, capacity): import math """ 직사각형 격자의 우물이 주어집니다. 각 줄은 하나의 우물을 나타내며, 한 줄의 각 1은 하나의 물 단위를 나타냅니다. 각 우물에는 물을 추출하는 데 사용할 수 있는 해당 버킷이 있으며, 모든 버킷의 용량은 동일합니다. 여러분의 임무는 버킷을 사용하여 우물을 비우는 것입니다. 버킷을 내려야 하는 횟수를 출력합니다. 예제 1: 입력: grid : [[0,0,1,0], [0,1,0,0], [1,1,...
max_fill
return sum([math.ceil(sum(arr)/capacity) for arr in grid])
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1) == 6, "Error" assert candidate([[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2) == 5, "Error" assert candidate([[0,0,0], [0...
KR_HumanEval/116
def sort_array(arr): """ 이 카타에서는 음수가 아닌 정수들의 배열을 정수들의 이진 표현의 1의 개수에 따라 오름차순으로 정렬해야 합니다. 비슷한 수의 1의 경우, 십진수 값을 기준으로 정렬합니다. 다음과 같이 구현해야 합니다: >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5] >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2] >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2,...
sort_array
return sorted(sorted(arr), key=lambda x: bin(x)[2:].count('1'))
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1,5,2,3,4]) == [1, 2, 4, 3, 5] assert candidate([-2,-3,-4,-5,-6]) == [-4, -2, -6, -5, -3] assert candidate([1,0,2,3,4]) == [0, 1, 2, 4, 3] assert candidate([...
KR_HumanEval/117
def select_words(s, n): """문자열 s와 자연수 n이 주어졌을 때, 문자열 s에서 정확히 n개의 자음을 포함하는 모든 단어의 목록을 문자열 s에 나타나는 순서대로 반환하는 함수를 구현하라는 과제가 주어졌습니다. 문자열 s가 비어 있으면 함수는 빈 목록을 반환해야 합니다. 참고: 입력 문자열에 문자와 공백만 포함되어 있다고 가정할 수 있습니다. 예시 select_words("Mary had a little lamb", 4) ==> ["little"] select_words("Mary had a little ...
select_words
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
def check(candidate): # Check some simple cases assert candidate("Mary had a little lamb", 4) == ["little"], "First test error: " + str(candidate("Mary had a little lamb", 4)) assert candidate("Mary had a little lamb", 3) == ["Mary", "lamb"], "Second test error: " + str(candidate("Mary had a little l...
KR_HumanEval/118
def get_closest_vowel(word): """단어가 주어집니다.단 어의 오른쪽에서 두 자음 사이에 있는 가장 가까운 모음을 찾는 것이 과제입니다(대소문자 구분). 시작 모음과 끝 모음은 포함되지 않습니다. 위의 조건을 충족하는 모음을 찾지 못하면 빈 문자열을 반환합니다. 주어진 문자열에 영문자만 포함되어 있다고 가정할 수 있습니다. 예제 get_closest_vowel("yogurt") ==> "u" get_closest_vowel("FULL") ==> "U" get_cl...
get_closest_vowel
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 ""
def check(candidate): # Check some simple cases assert candidate("yogurt") == "u" assert candidate("full") == "u" assert candidate("easy") == "" assert candidate("eAsy") == "" assert candidate("ali") == "" assert candidate("bad") == "a" assert candidate("most") == "o" assert candida...
KR_HumanEval/119
def match_parens(lst): """ 두 문자열의 목록이 주어지며, 두 문자열 모두 열린 괄호 '(' 또는 닫힌 괄호 ')'로만 구성됩니다. 여러분의 임무는 두 문자열을 어떤 순서로 연결할 수 있는지, 그 결과 문자열이 좋은지 확인하는 것입니다. 문자열 S는 S의 모든 괄호가 균형을 이루는 경우에만 좋은 것으로 간주됩니다. 예를 들어 '(())()' 문자열은 양호하지만 '())' 문자열은 그렇지 않습니다. 좋은 문자열을 만드는 방법이 있으면 'Yes'를 반환하고 그렇지 않으면 'No'를 반환합니다. 예제 ...
match_parens
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'...
def check(candidate): # Check some simple cases assert candidate(['()(', ')']) == 'Yes' assert candidate([')', ')']) == 'No' assert candidate(['(()(())', '())())']) == 'No' assert candidate([')())', '(()()(']) == 'Yes' assert candidate(['(())))', '(()())((']) == 'Yes' assert candidate(['()'...
KR_HumanEval/120
def maximum(arr, k): """ 정수의 배열 arr과 양의 정수 k가 주어졌을 때, arr에서 최대 k개의 숫자를 뽑아 길이가 k이고 정렬된 배열을 반환합니다. 예제 1: 입력: arr = [-3, -4, 5], k = 3 출력: [-4, -3, 5] 예제 2: 입력: arr = [4, -4, 4], k = 2 출력 [4, 4] 예제 3: 입력: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1 출력 [2]...
maximum
if k == 0: return [] arr.sort() ans = arr[-k:] return ans
def check(candidate): # Check some simple cases assert candidate([-3, -4, 5], 3) == [-4, -3, 5] assert candidate([4, -4, 4], 2) == [4, 4] assert candidate([-3, 2, 1, 2, -1, -2, 1], 1) == [2] assert candidate([123, -123, 20, 0 , 1, 2, -3], 3) == [2, 20, 123] assert candidate([-123, 20, 0 , 1, 2,...
KR_HumanEval/121
def solution(lst): """비어 있지 않은 정수 목록이 주어지면 짝수 위치에 있는 모든 홀수 요소의 합을 반환합니다. 예제 solution([5, 8, 7, 1]) ==> 12 solution([3, 3, 3, 3, 3]) ==> 9 solution([30, 13, 24, 321]) ==> 0 """
solution
return sum([x for idx, x in enumerate(lst) if idx%2==0 and x%2==1])
def check(candidate): # Check some simple cases assert candidate([5, 8, 7, 1]) == 12 assert candidate([3, 3, 3, 3, 3]) == 9 assert candidate([30, 13, 24, 321]) == 0 assert candidate([5, 9]) == 5 assert candidate([2, 4, 8]) == 0 assert candidate([30, 13, 23, 32]) == 23 assert candidat...
KR_HumanEval/122
def add_elements(arr, k): """ 비어 있지 않은 정수 배열 arr과 정수 k가 주어지면 배열의 첫 번째 k 요소에서 최대 두 자리 숫자를 가진 요소의 합을 반환합니다. 예제: 입력: arr = [111,21,3,4000,5,6,7,8,9], k = 4 출력: 24 # 21 + 3의 합계 제약 조건 1. 1 <= len(arr) <= 100 2. 1 <= k <= len(arr) """
add_elements
return sum(elem for elem in arr[:k] if len(str(elem)) <= 2)
def check(candidate): # Check some simple cases assert candidate([1,-2,-3,41,57,76,87,88,99], 3) == -4 assert candidate([111,121,3,4000,5,6], 2) == 0 assert candidate([11,21,3,90,5,6,7,8,9], 4) == 125 assert candidate([111,21,3,4000,5,6,7,8,9], 4) == 24, "This prints if this assert fails 1 (good fo...
KR_HumanEval/123
def get_odd_collatz(n): """ 양의 정수 n이 주어졌을 때, 콜라츠 수열의 홀수인 정렬된 리스트를 반환합니다. 콜라츠 가설은 다음과 같이 정의된 수열에 관한 수학의 가설로, 양의 정수 n으로 시작한 다음 각 항은 이전 항에서 다음과 같이 얻어집니다: 이전 항이 짝수이면 다음 항은 이전 항의 절반입니다. 이전 항이 홀수인 경우 다음 항은 이전 항의 3배에 1을 더한 값입니다. n의 값에 상관없이 수열은 항상 1에 도달할 것이라고 추측할 수 있습니다. 참고: 1. Collatz(1)은...
get_odd_collatz
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)
def check(candidate): # Check some simple cases assert candidate(14) == [1, 5, 7, 11, 13, 17] assert candidate(5) == [1, 5] assert candidate(12) == [1, 3, 5], "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by hand. assert candidate(...
KR_HumanEval/124
def valid_date(date): """주어진 날짜 문자열의 유효성을 검사하여 날짜가 유효하면 True를 반환하고 그렇지 않으면 False를 반환하는 함수를 작성해야 합니다. 날짜는 다음 규칙을 모두 충족하는 경우에 유효합니다: 1. 날짜 문자열이 비어 있지 않습니다. 2. 1,3,5,7,8,10,12 월의 일 수가 1 이상 31일 이하입니다. 그리고 4,6,9,11 월의 경우 일수가 1 이상 30일 이하입니다. 그리고 2번째 달의 일수는 1일 이상 29일 이하입니다. 3. 월은 1보다 작거나 12보다 커서는 안됩니다. ...
valid_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] a...
def check(candidate): # Check some simple cases assert candidate('03-11-2000') == True assert candidate('15-01-2012') == False assert candidate('04-0-2040') == False assert candidate('06-04-2020') == True assert candidate('01-01-2007') == True assert candidate('03-32-2011') == False ...
KR_HumanEval/125
def split_words(txt): """ 단어 문자열이 주어지면 공백으로 분할된 단어 목록을 반환하고, 텍스트에 공백이 없으면 쉼표 ',', 쉼표가 없으면 알파벳의 홀수 순서로 소문자 수를 반환해야 하며, ord('a') = 0, ord('b') = 1, ... ord('z') = 25를 반환합니다. 예제 split_words("Hello world!") ➞ ["Hello", "world!"] split_words("Hello,world!") ➞ ["Hello", "world!"] split_words("...
split_words
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])
def check(candidate): assert candidate("Hello world!") == ["Hello","world!"] assert candidate("Hello,world!") == ["Hello","world!"] assert candidate("Hello world,!") == ["Hello","world,!"] assert candidate("Hello,Hello,world !") == ["Hello,Hello,world","!"] assert candidate("abcdef") == 3 asser...
KR_HumanEval/126
def is_sorted(lst): """ 숫자 목록이 주어지면 오름차순으로 정렬되었는지 여부를 반환합니다. 목록에 동일한 숫자가 1개 이상 중복되면 False를 반환합니다. 음수는 없고 정수만 있다고 가정합니다. 예제 is_sorted([5]) ➞ True is_sorted([1, 2, 3, 4, 5]) ➞ True is_sorted([1, 3, 2, 4, 5]) ➞ False is_sorted([1, 2, 3, 4, 5, 6]) ➞ True is_sorted([1, 2, 3, 4, 5, 6,...
is_sorted
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
def check(candidate): # Check some simple cases assert candidate([5]) == True assert candidate([1, 2, 3, 4, 5]) == True assert candidate([1, 3, 2, 4, 5]) == False assert candidate([1, 2, 3, 4, 5, 6]) == True assert candidate([1, 2, 3, 4, 5, 6, 7]) == True assert candidate([1, 3, 2, 4, 5, 6,...
KR_HumanEval/127
def intersection(interval1, interval2): """두 개의 간격이 주어지며, 각 간격은 한 쌍의 정수입니다. 예를 들어 간격 = (시작, 끝) = (1, 2)입니다. 주어진 간격은 닫혀 있으므로 간격(시작, 끝)에는 시작과 끝이 모두 포함됩니다. 주어진 각 간격에 대해 시작이 끝보다 작거나 같다고 가정합니다. 여러분의 임무는 이 두 간격의 교집합 길이가 소수인지 확인하는 것입니다. 예를 들어 (1, 3), (2, 4) 간격의 교집합은 (2, 3)으로 그 길이가 1이므로 소수가 아닙니다. 교집...
intersection
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]) l...
def check(candidate): # Check some simple cases assert candidate((1, 2), (2, 3)) == "NO" assert candidate((-1, 1), (0, 4)) == "NO" assert candidate((-3, -1), (-5, 5)) == "YES" assert candidate((-2, 2), (-4, 0)) == "YES" # Check some edge cases that are easy to work out by hand. assert cand...
KR_HumanEval/128
def prod_signs(arr): """ 정수의 배열이 주어지면 1, -1 또는 0으로 표시되는, 배열에 있는 모든 수의 부호들의 곱으로 곱해진 정수들의 크기의 합을 반환해야 합니다. 참고: 빈 배열의 경우 None을 반환합니다. 예제 >>> prod_signs([1, 2, 2, -4]) == -9 >>> prod_signs([0, 1]) == 0 >>> prod_signs([]) == None """
prod_signs
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])
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1, 2, 2, -4]) == -9 assert candidate([0, 1]) == 0 assert candidate([1, 1, 1, 2, 3, -1, 1]) == -10 assert candidate([]) == None assert candidate([2, 4,1, ...
KR_HumanEval/129
def minPath(grid, k): """ 행과 열이 N개인 격자(N >= 2)와 양의 정수 k가 주어지면 격자의 각 셀에는 값이 들어 있습니다. [1, N * N]을 포함하는 범위의 모든 정수는 그리드의 셀에 정확히 한 번만 나타납니다. 그리드에서 길이 k의 최소 경로를 찾아야 합니다. 어느 셀에서든 시작할 수 있으며, 각 단계에서 이웃 셀로 이동할 수 있습니다. 즉, 현재 셀과 가장자리를 공유하는 셀로 이동할 수 있습니다. 길이가 k인 경로는 정확히 k개의 셀을 방문하는 것을 의미합니다(반드시 구분되는 것은 ...
minPath
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 !...
def check(candidate): # Check some simple cases print assert candidate([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3) == [1, 2, 1] assert candidate([[5, 9, 3], [4, 1, 6], [7, 8, 2]], 1) == [1] assert candidate([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]], 4) == [1, 2, 1, 2] assert can...
KR_HumanEval/130
def tri(n): """피보나치 수열은 누구나 알고 있으며 지난 몇 세기 동안 수학자들이 심도 있게 연구한 수열입니다. 그러나 사람들이 모르는 것은 트리보나치 수열입니다. 트리보나치 수열은 재귀에 의해 정의됩니다: tri(1) = 3 tri(n) = 1 + n / 2, n이 짝수인 경우. n이 홀수인 경우 tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1). 예를 들어 tri(2) = 1 + (2 / 2) = 2 tri(4) = 3 tri(3) = tri(2) +...
tri
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
def check(candidate): # Check some simple cases assert candidate(3) == [1, 3, 2.0, 8.0] assert candidate(4) == [1, 3, 2.0, 8.0, 3.0] assert candidate(5) == [1, 3, 2.0, 8.0, 3.0, 15.0] assert candidate(6) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0] assert candidate(7) == [1, 3, 2.0, 8.0, 3.0, 15.0,...
KR_HumanEval/131
def digits(n): """양의 정수 n이 주어지면 홀수 자릿수의 곱을 반환합니다. 모든 자리가 짝수이면 0을 반환합니다. 예를 들어 digits(1) == 1 digits(4) == 0 digits(235) == 15 """
digits
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
def check(candidate): # Check some simple cases assert candidate(5) == 5 assert candidate(54) == 5 assert candidate(120) ==1 assert candidate(5014) == 5 assert candidate(98765) == 315 assert candidate(5576543) == 2625 # Check some edge cases that are easy to work out by hand. asser...
KR_HumanEval/132
def is_nested(string): """ 대괄호만 포함된 문자열을 입력으로 받는 함수를 만듭니다. 이 함수는 대괄호 중 하나 이상의 대괄호가 중첩되어 있는 유효한 대괄호 시퀀스가 있는 경우에만 True를 반환해야 합니다. is_nested('[[]]') ➞ True is_nested('[]]]]]]][[[[[]') ➞ False is_nested('[][]') ➞ False is_nested('[]') ➞ False is_nested('[[][]]') ➞ True is_nested('[[]][[...
is_nested
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) ...
def check(candidate): # Check some simple cases assert candidate('[[]]') == True, "This prints if this assert fails 1 (good for debugging!)" assert candidate('[]]]]]]][[[[[]') == False assert candidate('[][]') == False assert candidate(('[]')) == False assert candidate('[[[[]]]]') == True a...
KR_HumanEval/133
def sum_squares(lst): """숫자 목록이 주어집니다. 주어진 목록에서 제곱된 숫자의 합을 반환해야 합니다, 목록의 각 요소를 먼저 상위 int(Ceiling)으로 반올림합니다. 예시: lst = [1,2,3]의 경우 출력은 14가 되어야 합니다. lst = [1,4,9]의 경우 출력은 98이 되어야 합니다. lst = [1,3,5,7]의 경우 출력은 84가 되어야 합니다. lst = [1.4,4.2,0]의 경우 출력은 29가 되어야 합니다. lst = [-2.4,1,1]의 경우 출력은 6...
sum_squares
import math squared = 0 for i in lst: squared += math.ceil(i)**2 return squared
def check(candidate): # Check some simple cases assert candidate([1,2,3])==14, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1.0,2,3])==14, "This prints if this assert fails 1 (good for debugging!)" assert candidate([1,3,5,7])==84, "This prints if this assert fails 1 (goo...
KR_HumanEval/134
def check_if_last_char_is_a_letter(txt): """ 주어진 문자열의 마지막 문자가 알파벳 문자이고 단어의 일부가 아닌 경우 True를 반환하고, 그렇지 않으면 False를 반환하는 함수를 만듭니다. 참고: '단어'는 공백으로 구분된 문자 그룹입니다. 예시 check_if_last_char_is_a_letter("apple pie") ➞ False check_if_last_char_is_a_letter("apple pi e") ➞ True check_if_last_char_is_a_...
check_if_last_char_is_a_letter
check = txt.split(' ')[-1] return True if len(check) == 1 and (97 <= ord(check.lower()) <= 122) else False
def check(candidate): # Check some simple cases assert candidate("apple") == False assert candidate("apple pi e") == True assert candidate("eeeee") == False assert candidate("A") == True assert candidate("Pumpkin pie ") == False assert candidate("Pumpkin pie 1") == False assert candidat...
KR_HumanEval/135
def can_arrange(arr): """바로 앞 요소보다 크거나 같지 않은 요소의 가장 큰 인덱스를 반환하는 함수를 만듭니다. 그러한 요소가 존재하지 않으면 -1을 반환합니다. 주어진 배열은 중복된 값을 포함하지 않습니다. 예시 can_arrange([1,2,4,3,5]) = 3 can_arrange([1,2,3]) = -1 """
can_arrange
ind=-1 i=1 while i<len(arr): if arr[i]<arr[i-1]: ind=i i+=1 return ind
def check(candidate): # Check some simple cases assert candidate([1,2,4,3,5])==3 assert candidate([1,2,4,5])==-1 assert candidate([1,4,2,5,6,7,8,9,10])==2 assert candidate([4,8,5,7,3])==4 # Check some edge cases that are easy to work out by hand. assert candidate([])==-1
KR_HumanEval/136
def largest_smallest_integers(lst): """ 목록에서 'a'는 음의 정수 중 가장 큰 정수이고 'b'는 양의 정수 중 가장 작은 정수인 튜플(a, b)을 반환하는 함수를 만듭니다. 음수나 양수가 없는 경우 None으로 반환합니다. 예시 largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1) largest_smallest_integers([]) == (None, None) largest_smallest_integers([0]) == (None...
largest_smallest_integers
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)
def check(candidate): # Check some simple cases assert candidate([2, 4, 1, 3, 5, 7]) == (None, 1) assert candidate([2, 4, 1, 3, 5, 7, 0]) == (None, 1) assert candidate([1, 3, 2, 4, 5, 6, -2]) == (-2, 1) assert candidate([4, 5, 3, 6, 2, 7, -7]) == (-7, 2) assert candidate([7, 3, 8, 4, 9, 2, 5, -...
KR_HumanEval/137
def compare_one(a, b): """ 실수를 나타내는 정수, 부동 소수점 또는 문자열을 받아 주어진 변수 유형에서 더 큰 변수를 반환하는 함수를 만듭니다. 값이 같으면 None을 반환합니다 참고: 실수가 문자열로 표시되는 경우 부동 소수점은 . 또는 , compare_one(1, 2.5) ➞ 2.5 compare_one(1, "2,3") ➞ "2,3" compare_one("5,1", "6") ➞ "6" compare_one("1", 1) ➞ None """
compare_one
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
def check(candidate): # Check some simple cases assert candidate(1, 2) == 2 assert candidate(1, 2.5) == 2.5 assert candidate(2, 3) == 3 assert candidate(5, 6) == 6 assert candidate(1, "2,3") == "2,3" assert candidate("5,1", "6") == "6" assert candidate("1", "2") == "2" assert candid...
KR_HumanEval/138
def is_equal_to_sum_even(n): """주어진 숫자 n을 정확히 4개의 양의 짝수 합으로 쓸 수 있는지 평가합니다. 예제 is_equal_to_sum_even(4) == False is_equal_to_sum_even(6) == False is_equal_to_sum_even(8) == True """
is_equal_to_sum_even
return n%2 == 0 and n >= 8
def check(candidate): assert candidate(4) == False assert candidate(6) == False assert candidate(8) == True assert candidate(10) == True assert candidate(11) == False assert candidate(12) == True assert candidate(13) == False assert candidate(16) == True
KR_HumanEval/139
def special_factorial(n): """브라질 계승은 다음과 같이 정의됩니다: brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! 여기서 n > 0 예를 들어 >>> special_factorial(4) 288 이 함수는 정수를 입력으로 받고 이 정수의 특수 를 팩토리얼을 반환해야 합니다. """
special_factorial
fact_i = 1 special_fact = 1 for i in range(1, n+1): fact_i *= i special_fact *= fact_i return special_fact
def check(candidate): # Check some simple cases assert candidate(4) == 288, "Test 4" assert candidate(5) == 34560, "Test 5" assert candidate(7) == 125411328000, "Test 7" # Check some edge cases that are easy to work out by hand. assert candidate(1) == 1, "Test 1"
KR_HumanEval/140
def fix_spaces(text): """ 문자열 텍스트가 주어지면 그 안의 모든 공백을 밑줄로 바꾸고, 문자열에 공백이 2개 이상 연속된 경우 연속된 모든 공백을 -로 바꿉니다. fix_spaces("Example") == "Example" fix_spaces("Example 1") == "Example_1" fix_spaces(" Example 2") == "_Example_2" fix_spaces(" Example 3") == "_Example-3" """
fix_spaces
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: ...
def check(candidate): # Check some simple cases assert candidate("Example") == "Example", "This prints if this assert fails 1 (good for debugging!)" assert candidate("Mudasir Hanif ") == "Mudasir_Hanif_", "This prints if this assert fails 2 (good for debugging!)" assert candidate("Yellow Yellow Dirty ...
KR_HumanEval/141
def file_name_check(file_name): """파일 이름을 나타내는 문자열을 받아 파일 이름이 유효하면 '예'를 반환하고, 그렇지 않으면 '아니오'를 반환하는 함수를 만듭니다. 파일 이름은 다음 조건을 모두 충족하는 경우에만 유효한 것으로 간주됩니다: - 파일 이름에 세 자리('0'-'9')가 넘지 않아야 합니다. - 파일 이름에 정확히 하나의 점 '.'이 포함되어야 합니다. - 점 앞의 하위 문자열은 비어 있으면 안 되며 라틴 알파벳('a'-'z' 및 'A'-'Z')의 문자로 시작해야 합니다. - 점 뒤의 ...
file_name_check
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: ...
def check(candidate): # Check some simple cases assert candidate("example.txt") == 'Yes' assert candidate("1example.dll") == 'No' assert candidate('s1sdf3.asd') == 'No' assert candidate('K.dll') == 'Yes' assert candidate('MY16FILE3.exe') == 'Yes' assert candidate('His12FILE94.exe') == 'No' ...
KR_HumanEval/142
def sum_squares(lst): """" 이 함수는 정수 목록을 받습니다. 목록의 모든 항목에 대해 함수는 인덱스가 3의 배수인 경우 정수 항목을 제곱하고 인덱스가 3의 배수가 아닌 4의 배수인 경우 정수 항목을 큐브화합니다. 목록에서 인덱스가 3 또는 4의 배수가 아닌 항목은 변경하지 않습니다. 그런 다음 함수는 모든 항목의 합계를 반환합니다. 예시 lst = [1,2,3]의 경우 출력은 6이 되어야 합니다. lst = []의 경우 출력은 0이 되어야 합니다. lst = [-1,-5,2,-1,-5]...
sum_squares
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)
def check(candidate): # Check some simple cases assert candidate([1,2,3]) == 6 assert candidate([1,4,9]) == 14 assert candidate([]) == 0 assert candidate([1,1,1,1,1,1,1,1,1]) == 9 assert candidate([-1,-1,-1,-1,-1,-1,-1,-1,-1]) == -3 assert candidate([0]) == 0 assert candidate([-1,-...
KR_HumanEval/143
def words_in_sentence(sentence): """ 문장을 나타내는 문자열이 주어지고, 그 문장에는 공백으로 구분된 단어가 포함되어 있으며, 길이가 소수인 원래 문장의 단어가 포함된 문자열을 반환해야 하며, 새 문자열의 단어 순서는 원래 문자열과 동일해야 합니다. 예제 1: 입력: sentence = "This is a test" 출력 "is" 예 2: 입력: sentence = "lets go for swimming" 출력 출력: "go fo...
words_in_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)
def check(candidate): # Check some simple cases assert candidate("This is a test") == "is" assert candidate("lets go for swimming") == "go for" assert candidate("there is no place available here") == "there is no place" assert candidate("Hi I am Hussein") == "Hi am Hussein" assert candidate("go...
KR_HumanEval/144
def simplify(x, n): """여러분의 과제는 x * n 식을 단순화하는 함수를 구현하는 것입니다. 이 함수는 x * n이 정수로 평가되면 True를 반환하고, 그렇지 않으면 False를 반환합니다. x와 n은 모두 분수의 문자열 표현이며, 분자와 분모가 모두 양의 정수인 <분자>/<분모> 형식을 갖습니다. x와 n은 유효한 분수이며 분모에 0이 없다고 가정할 수 있습니다. simplify("1/5", "5/1") = True simplify("1/6", "2/1") = False simplify("7/...
simplify
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
def check(candidate): # Check some simple cases assert candidate("1/5", "5/1") == True, 'test1' assert candidate("1/6", "2/1") == False, 'test2' assert candidate("5/1", "3/1") == True, 'test3' assert candidate("7/10", "10/2") == False, 'test4' assert candidate("2/10", "50/10") == True, 'test5' ...
KR_HumanEval/145
def order_by_points(nums): """ 주어진 정수 목록을 자릿수의 합에 따라 오름차순으로 정렬하는 함수를 작성합니다. 참고: 자릿수의 합이 비슷한 항목이 여러 개 있는 경우 원래 목록의 인덱스에 따라 정렬합니다. 예를 들어 >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11] >>> order_by_points([]) == [] """
order_by_points
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)
def check(candidate): # Check some simple cases assert candidate([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11] assert candidate([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] assert candidate([]) == [] assert candidate([1,...
KR_HumanEval/146
def specialFilter(nums): """숫자 배열을 입력으로 받아 배열에서 10보다 크고 숫자의 앞자리와 뒷자리가 모두 홀수(1, 3, 5, 7, 9)인 요소의 수를 반환하는 함수를 작성합니다. 예를 들어 specialFilter([15, -73, 14, -15]) => 1 specialFilter([33, -2, -3, 45, 21, 109]) => 2 """
specialFilter
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
def check(candidate): # Check some simple cases assert candidate([5, -2, 1, -5]) == 0 assert candidate([15, -73, 14, -15]) == 1 assert candidate([33, -2, -3, 45, 21, 109]) == 2 assert candidate([43, -12, 93, 125, 121, 109]) == 4 assert candidate([71, -2, -33, 75, 21, 19]) == 3 # Check s...
KR_HumanEval/147
def get_max_triples(n): """ 양의 정수 n이 주어지면 길이 n의 정수 배열 a를 만들어야 합니다. 각 i (1 ≤ i ≤ n)에 대해 a[i] = i * i - i + 1의 값을 구합니다. a의 트리플 수(a[i], a[j], a[k])를 반환합니다 (여기서 i < j < k), 그리고 a[i] + a[j] + a[k]는 3의 배수입니다. 예제 : 입력: n = 5 출력: 1 설명: a = [1, 3, 7, 13, 21] ...
get_max_triples
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)
def check(candidate): assert candidate(5) == 1 assert candidate(6) == 4 assert candidate(10) == 36 assert candidate(100) == 53361
KR_HumanEval/148
def bf(planet1, planet2): """ 태양계에는 태양에 가장 가까운 행성이 수성, 그 다음이 금성, 그 다음이 지구, 화성, 목성, 토성, 천왕성, 해왕성 순으로 8개의 행성이 있습니다. 두 행성 이름을 행성1과 행성2라는 문자열로 받는 함수를 작성합니다. 이 함수는 행성1의 궤도와 행성2의 궤도 사이에 궤도가 있는 모든 행성을 포함하는 튜플을 태양과의 근접도에 따라 정렬하여 반환해야 합니다. 행성1 또는 행성2가 올바른 행성 이름이 아닌 경우 함수는 빈 튜플을 반환해야 합니다. 예제 bf("Jupi...
bf
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_ind...
def check(candidate): # Check some simple cases assert candidate("Jupiter", "Neptune") == ("Saturn", "Uranus"), "First test error: " + str(len(candidate("Jupiter", "Neptune"))) assert candidate("Earth", "Mercury") == ("Venus",), "Second test error: " + str(candidate("Earth", "Mercury")) assert ...
KR_HumanEval/149
def sorted_list_sum(lst): """문자열 목록을 매개변수로 받아 길이가 홀수인 문자열을 삭제하고 정렬된 순서로 결과 목록을 반환하는 함수를 작성하세요. 목록은 항상 문자열 목록이며 숫자의 배열이 아니며 중복이 포함될 수 있습니다. 목록의 순서는 각 단어의 길이에 따라 오름차순이어야 하며, 해당 규칙에 따라 정렬된 목록을 반환해야 합니다. 두 단어의 길이가 같은 경우 목록을 알파벳순으로 정렬합니다. 이 함수는 정렬된 순서대로 문자열 목록을 반환해야 합니다. 모든 단어의 길이가 같다고 가정할 수 있습니다. 예를...
sorted_list_sum
lst.sort() new_lst = [] for i in lst: if len(i)%2 == 0: new_lst.append(i) return sorted(new_lst, key=len)
def check(candidate): # Check some simple cases assert candidate(["aa", "a", "aaa"]) == ["aa"] assert candidate(["school", "AI", "asdf", "b"]) == ["AI", "asdf", "school"] assert candidate(["d", "b", "c", "a"]) == [] assert candidate(["d", "dcba", "abcd", "a"]) == ["abcd", "dcba"] # Check some ...
KR_HumanEval/150
def x_or_y(n, x, y): """n이 소수이면 x의 값을 반환하고, 그렇지 않으면 y의 값을 반환해야 하는 간단한 프로그램입니다. 예시입니다: FOR X_OR_Y(7, 34, 12) == 34 FOR X_OR_Y(15, 8, 5) == 5 """
x_or_y
if n == 1: return y for i in range(2, n): if n % i == 0: return y break else: return x
def check(candidate): # Check some simple cases assert candidate(7, 34, 12) == 34 assert candidate(15, 8, 5) == 5 assert candidate(3, 33, 5212) == 33 assert candidate(1259, 3, 52) == 3 assert candidate(7919, -1, 12) == -1 assert candidate(3609, 1245, 583) == 583 assert candidate(91, 56,...
KR_HumanEval/151
def double_the_difference(lst): """ 숫자 목록이 주어지면 목록에 있는 숫자 중 홀수인 숫자의 제곱의 합을 반환합니다. 음수이거나 정수가 아닌 숫자는 무시합니다. double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10 double_the_difference([-1, -2, 0]) == 0 double_the_difference([9, -2]) == 81 double_the_difference([0]) == 0 입력 목록이...
double_the_difference
return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])
def check(candidate): # Check some simple cases assert candidate([]) == 0 , "This prints if this assert fails 1 (good for debugging!)" assert candidate([5, 4]) == 25 , "This prints if this assert fails 2 (good for debugging!)" assert candidate([0.1, 0.2, 0.3]) == 0 , "This prints if this assert fails 3...
KR_HumanEval/152
def compare(game,guess): """오랫동안 기다려온 이벤트의 결과가 마침내 알려졌을 때의 그 기분은 누구나 기억할 것입니다 그 순간의 감정과 생각은 분명 기록해두고 비교할 가치가 있습니다. 여러분의 임무는 한 사람이 여러 경기의 결과를 올바르게 추측했는지 확인하는 것입니다. 동일한 길이의 점수와 추측의 두 배열이 주어지며, 각 인덱스에는 일치하는 항목이 표시됩니다. 각 추측이 얼마나 틀렸는지를 나타내는 동일한 길이의 배열을 반환합니다. 올바르게 추측한 경우 값은 0이고, 그렇지 않은 경우 값은 추측과 점수의 ...
compare
return [abs(x-y) for x,y in zip(game,guess)]
def check(candidate): # Check some simple cases assert candidate([1,2,3,4,5,1],[1,2,3,4,2,-2])==[0,0,0,0,3,3], "This prints if this assert fails 1 (good for debugging!)" assert candidate([0,0,0,0,0,0],[0,0,0,0,0,0])==[0,0,0,0,0,0], "This prints if this assert fails 1 (good for debugging!)" assert candi...
KR_HumanEval/153
def Strongest_Extension(class_name, extensions): """클래스 이름(문자열)과 확장자 목록이 제공됩니다. 확장은 클래스에 추가 클래스를 로드하는 데 사용됩니다. 확장의 강도는 다음과 같습니다: CAP는 확장자 이름의 대문자 수이고 SM은 확장자 이름의 소문자 수이며, 강도는 CAP - SM의 분수로 주어집니다. 가장 강력한 확장명을 찾아서 이 형식의 문자열을 반환해야 합니다: ClassName.StrongestExtensionName. 같은 강도의 확장명이 두 개 이상 있는 경우 목록에서 가장 ...
Strongest_Extension
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()]) i...
def check(candidate): # Check some simple cases assert candidate('Watashi', ['tEN', 'niNE', 'eIGHt8OKe']) == 'Watashi.eIGHt8OKe' assert candidate('Boku123', ['nani', 'NazeDa', 'YEs.WeCaNe', '32145tggg']) == 'Boku123.YEs.WeCaNe' assert candidate('__YESIMHERE', ['t', 'eMptY', 'nothing', 'zeR00', 'NuLl__'...
KR_HumanEval/154
def cycpattern_check(a , b): """두 단어가 주어집니다. 두 번째 단어 또는 그 회전이 첫 번째 단어의 하위 문자열인 경우 True를 반환해야 합니다. cycpattern_check("abcd","abd") => False cycpattern_check("hello","ell") => True cycpattern_check("whassup","psus") => False cycpattern_check("abab","baa") => True cycpattern_check("eef","eeff") => F...
cycpattern_check
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
def check(candidate): # Check some simple cases #assert True, "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are easy to work out by hand. #assert True, "This prints if this assert fails 2 (also good for debugging!)" assert candidate("xyzw","xyw") == False...
KR_HumanEval/155
def even_odd_count(num): """정수가 주어지면 각각 짝수와 홀수 자릿수를 가진 튜플을 반환합니다. 예제: even_odd_count(-12) ==> (1, 1) even_odd_count(123) ==> (1, 2) """
even_odd_count
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)
def check(candidate): # Check some simple cases assert candidate(7) == (0, 1) assert candidate(-78) == (1, 1) assert candidate(3452) == (2, 2) assert candidate(346211) == (3, 3) assert candidate(-345821) == (3, 3) assert candidate(-2) == (1, 0) assert candidate(-45347) == (2, 3) ass...
KR_HumanEval/156
def int_to_mini_roman(number): """ 양의 정수가 주어지면, 그 정수에 해당하는 로마 숫자를 문자열로 구한 다음 소문자로 반환합니다. 제한 사항: 1 <= num <= 1000 예제 >>> int_to_mini_roman(19) == 'xix' >>> int_to_mini_roman(152) == 'clii' >>> int_to_mini_roman(426) == 'cdxxvi' """
int_to_mini_roman
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...
def check(candidate): # Check some simple cases assert candidate(19) == 'xix' assert candidate(152) == 'clii' assert candidate(251) == 'ccli' assert candidate(426) == 'cdxxvi' assert candidate(500) == 'd' assert candidate(1) == 'i' assert candidate(4) == 'iv' assert candidate(43) ==...
KR_HumanEval/157
def right_angle_triangle(a, b, c): """ 삼각형의 세 변의 길이가 주어집니다. 세 변이 직각 삼각형을 이루면 참을 반환하고, 그렇지 않으면 거짓을 반환합니다. 직각 삼각형은 한 변의 각도가 직각 또는 90도인 삼각형입니다. """
right_angle_triangle
return a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b
def check(candidate): # Check some simple cases assert candidate(3, 4, 5) == True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(1, 2, 3) == False assert candidate(10, 6, 8) == True assert candidate(2, 2, 2) == False assert candidate(7, 24, 25) == True assert c...
KR_HumanEval/158
def find_max(words): """문자열 목록을 받아들이는 함수를 작성합니다. 목록에 다른 단어가 포함되어 있습니다. 최대 고유 문자 수를 가진 단어를 반환합니다. 여러 문자열에 최대 고유 문자 수가 있는 경우 사전적 순서로 먼저 오는 문자열을 반환합니다. find_max(["name", "of", "string"]) == "string" find_max(["name", "enam", "game"]) == "enam" find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa" ""...
find_max
return sorted(words, key = lambda x: (-len(set(x)), x))[0]
def check(candidate): # Check some simple cases assert (candidate(["name", "of", "string"]) == "string"), "t1" assert (candidate(["name", "enam", "game"]) == "enam"), 't2' assert (candidate(["aaaaaaa", "bb", "cc"]) == "aaaaaaa"), 't3' assert (candidate(["abc", "cba"]) == "abc"), 't4' assert (ca...
KR_HumanEval/159
def eat(number, need, remaining): """ 당신은 배고픈 토끼이고 이미 일정 수의 당근을 먹었지만 이제 하루의 식사를 완료하려면 더 많은 당근을 먹어야 합니다. [식사 후 먹은 당근의 총 개수, 식사 후 남은 당근의 개수]의 배열을 반환해야 합니다. 남은 당근이 충분하지 않으면 남은 당근을 모두 먹지만 여전히 배가 고프게 됩니다. 예시: * eat(5, 6, 10) -> [11, 4] * eat(4, 8, 9) -> [12, 1] * eat(1, 10, 10) -> [11, 0...
eat
if(need <= remaining): return [ number + need , remaining-need ] else: return [ number + remaining , 0]
def check(candidate): # Check some simple cases assert True, "This prints if this assert fails 1 (good for debugging!)" assert candidate(5, 6, 10) == [11, 4], "Error" assert candidate(4, 8, 9) == [12, 1], "Error" assert candidate(1, 10, 10) == [11, 0], "Error" assert candidate(2, 11, 5) == [7, ...
KR_HumanEval/160
def do_algebra(operator, operand): """ 연산자와, 피연산자 두 개의 리스트가 주어집니다. 첫 번째 목록에는 기본 대수 연산이 있고 두 번째 목록은 정수의 목록입니다. 주어진 두 목록을 사용하여 대수 식을 작성하고 이 식의 평가를 반환합니다. 기본 대수 연산 더하기 ( + ) 빼기 ( - ) 곱셈 ( * ) 나눗셈 몫 ( // ) 지수 승 ( ** ) 예시 operator['+', '*', '-'] array = [2, 3, 4, 5] ...
do_algebra
expression = str(operand[0]) for oprt, oprn in zip(operator, operand[1:]): expression+= oprt + str(oprn) return eval(expression)
def check(candidate): # Check some simple cases assert candidate(['**', '*', '+'], [2, 3, 4, 5]) == 37 assert candidate(['+', '*', '-'], [2, 3, 4, 5]) == 9 assert candidate(['//', '*'], [7, 3, 4]) == 8, "This prints if this assert fails 1 (good for debugging!)" # Check some edge cases that are eas...
KR_HumanEval/161
def solve(s): """문자열 s가 주어집니다. s[i]가 문자인 경우 대소문자를 아래에서 위로 또는 그 반대로 바꾸고, 그렇지 않으면 그대로 유지합니다. 문자열에 문자가 포함되지 않은 경우 문자열을 반전시킵니다. 함수는 결과 문자열을 반환해야 합니다. 예제 solve("1234") = "4321" solve("ab") = "AB" solve("#a@C") = "#A@c" """
solve
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
def check(candidate): # Check some simple cases assert candidate("AsDf") == "aSdF" assert candidate("1234") == "4321" assert candidate("ab") == "AB" assert candidate("#a@C") == "#A@c" assert candidate("#AsdfW^45") == "#aSDFw^45" assert candidate("#6@2") == "2@6#" # Check some edge case...
KR_HumanEval/162
def string_to_md5(text): """ 문자열 'text'가 주어지면 해당 문자열의 md5 해시 등가 문자열을 반환합니다. 'text'가 빈 문자열이면 None을 반환합니다. >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62' """
string_to_md5
import hashlib return hashlib.md5(text.encode('ascii')).hexdigest() if text else None
def check(candidate): # Check some simple cases assert candidate('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62' assert candidate('') == None assert candidate('A B C') == '0ef78513b0cb8cef12743f5aeb35f888' assert candidate('password') == '5f4dcc3b5aa765d61d8327deb882cf99' # Check some edg...
KR_HumanEval/163
def generate_integers(a, b): """ 두 개의 양의 정수 a와 b가 주어지면, a와 b 사이의 짝수들을 오름차순으로 반환합니다. 예를 들어 generate_integers(2, 8) => [2, 4, 6, 8] generate_integers(8, 2) => [2, 4, 6, 8] generate_integers(10, 14) => [] """
generate_integers
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]
def check(candidate): # Check some simple cases assert candidate(2, 10) == [2, 4, 6, 8], "Test 1" assert candidate(10, 2) == [2, 4, 6, 8], "Test 2" assert candidate(132, 2) == [2, 4, 6, 8], "Test 3" assert candidate(17,89) == [], "Test 4" # Check some edge cases that are easy to work out by ha...