Dataset Viewer
Auto-converted to Parquet Duplicate
task_id
stringlengths
18
20
prompt
stringlengths
177
1.43k
entry_point
stringlengths
1
24
test
stringlengths
287
23.1k
description
stringlengths
146
1.37k
language
stringclasses
1 value
canonical_solution
sequencelengths
5
37
HumanEval_kotlin/32
/** * You are an expert Kotlin programmer, and here is your task. * This function takes a list l and returns a list l' such that * l' is identical to l in the indices that are not divisible by three, while its values at the indices that are divisible by three are equal * to the values of the corresponding indices o...
sortThird
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3) var x0: List<Int> = sortThird(arg00) var v0: List<Int> = mutableListOf(1, 2, 3) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 3, -5, 2, -3, 3, 9, 0...
/** * You are an expert Kotlin programmer, and here is your task. * This function takes a list l and returns a list l' such that * l' is identical to l in the indices that are not divisible by three, while its values at the indices that are divisible by three are equal * to the values of the corresponding indices o...
kotlin
[ "fun sortThird(l: List<Int>): List<Int> {", " val sortedThirds = l.withIndex()", " .filter { (index, _) -> (index % 3) == 0 }", " .map { it.value }", " .sorted()", " return l.mapIndexed { index, value ->", " if (index % 3 == 0) sortedThirds[index / 3] else value", " ...
HumanEval_kotlin/74
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes an integer a and returns True * if this integer is a cube of some integer number. * Note: you may assume the input is always valid. * Examples: * iscube(1) ==> True * iscube(2) ==> False * iscube(-1) ==> True * is...
iscube
fun main() { var arg00: Int = 1 var x0: Boolean = iscube(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 2 var x1: Boolean = iscube(arg10) var v1: Boolean = false if (x1 != v1) { th...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes an integer a and returns True * if this integer is a cube of some integer number. * Note: you may assume the input is always valid. * Examples: * iscube(1) ==> True * iscube(2) ==> False * iscube(-1) ==> True * is...
kotlin
[ "fun iscube(a: Int): Boolean {", " for (i in 0..Math.abs(a)) {", " val cube = i * i * i", " if (cube == Math.abs(a)) {", " return true", " }", " if (cube > Math.abs(a)) {", " return false", " }", " }", " return false", "}", ""...
HumanEval_kotlin/160
/** * You are an expert Kotlin programmer, and here is your task. * * Given two positive integers a and b, return the even digits between a * and b, in ascending order. * For example: * generate_integers(2, 8) => [2, 4, 6, 8] * generate_integers(8, 2) => [2, 4, 6, 8] * generate_integers(10, 14) => [] * */ fun...
generateIntegers
fun main() { var arg00 : Int = 2 var arg01 : Int = 10 var x0 : List<Int> = generateIntegers(arg00, arg01); var v0 : List<Int> = mutableListOf(2, 4, 6, 8); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 10 var arg11 : Int ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given two positive integers a and b, return the even digits between a * and b, in ascending order. * For example: * generate_integers(2, 8) => [2, 4, 6, 8] * generate_integers(8, 2) => [2, 4, 6, 8] * generate_integers(10, 14) => [] * */
kotlin
[ "fun generateIntegers(a : Int, b : Int) : List<Int> {", "\tval l = Math.min(a, b)", " val r = Math.max(a, b)", " return (0..8).filter { it % 2 == 0 && l <= it && it <= r }", "}", "", "" ]
HumanEval_kotlin/88
/** * You are an expert Kotlin programmer, and here is your task. * * You'll be given a string of words, and your task is to count the number * of boredoms. A boredom is a sentence that starts with the word "I". * Sentences are delimited by '.', '?' or '!'. * For example: * >>> is_bored("Hello world") * 0 * >>...
isBored
fun main() { var arg00: String = "Hello world" var x0: Int = isBored(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "Is the sky blue?" var x1: Int = isBored(arg10) var v1: Int = 0 if (x1 != v1...
/** * You are an expert Kotlin programmer, and here is your task. * * You'll be given a string of words, and your task is to count the number * of boredoms. A boredom is a sentence that starts with the word "I". * Sentences are delimited by '.', '?' or '!'. * For example: * >>> is_bored("Hello world") * 0 * >>...
kotlin
[ "fun isBored(s: String): Int {", " return s.split(\"[.?!]\\\\W*\".toRegex()).count { it.startsWith(\"I \") }", "}", "", "" ]
HumanEval_kotlin/89
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes 3 numbers. * Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. * Returns false in any other cases. * * Examples * any_int(5, 2, 7) ➞ True * * any_int(3, 2, 2) ...
anyInt
fun main() { var arg00: Any = 2 var arg01: Any = 3 var arg02: Any = 1 var x0: Boolean = anyInt(arg00, arg01, arg02) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Any = 2.5 var arg11: Any = 2 var a...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes 3 numbers. * Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. * Returns false in any other cases. * * Examples * any_int(5, 2, 7) ➞ True * * any_int(3, 2, 2) ...
kotlin
[ "fun anyInt(x: Any, y: Any, z: Any): Boolean {", " if (x is Int && y is Int && z is Int) {", " return x == y + z || y == x + z || z == x + y", " }", " return false", "}", "", "" ]
HumanEval_kotlin/119
/** * You are an expert Kotlin programmer, and here is your task. * * Given a non-empty array of integers arr and an integer k, return * the sum of the elements with at most two digits from the first k elements of arr. * Example: * Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4 * Output: 24 # sum of 21 +...
addElements
fun main() { var arg00 : List<Int> = mutableListOf(1, -2, -3, 41, 57, 76, 87, 88, 99) var arg01 : Int = 3 var x0 : Int = addElements(arg00, arg01); var v0 : Int = -4; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutab...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a non-empty array of integers arr and an integer k, return * the sum of the elements with at most two digits from the first k elements of arr. * Example: * Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4 * Output: 24 # sum of 21 +...
kotlin
[ "fun addElements(arr : List<Int>, k : Int) : Int {", "\treturn arr.take(k).filter { it < 100 }.sum()", "}", "", "" ]
HumanEval_kotlin/3
/** * You are an expert Kotlin programmer, and here is your task. * You're given a list of deposit and withdrawal operations on a bank account that starts with * zero balance. Your task is to detect if at any point the balance of account fallls below zero, and * at that point function should return True. Otherwise ...
belowZero
fun main() { var arg00: List<Int> = mutableListOf() var x0: Boolean = belowZero(arg00) var v0: Boolean = false if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 2, -3, 1, 2, -3) var x1: Boolean = belowZero(...
/** * You are an expert Kotlin programmer, and here is your task. * You're given a list of deposit and withdrawal operations on a bank account that starts with * zero balance. Your task is to detect if at any point the balance of account fallls below zero, and * at that point function should return True. Otherwise ...
kotlin
[ "fun belowZero(operations: List<Int>): Boolean {", " return operations.runningFold(0) { sum, value ->", " sum + value", " }.any { it < 0 }", "}", "", "" ]
HumanEval_kotlin/84
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a 2 dimensional data, as a nested lists, * which is similar to matrix, however, unlike matrices, * each row may contain a different number of columns. * Given lst, and integer x, find integers x in the list, * and return list of t...
getRow
fun main() { var arg00: List<List<Int>> = mutableListOf() var arg01: Int = 1 var x0: List<List<Int>> = getRow(arg00, arg01) var v0: List<List<Int>> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<List<Int>> = m...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a 2 dimensional data, as a nested lists, * which is similar to matrix, however, unlike matrices, * each row may contain a different number of columns. * Given lst, and integer x, find integers x in the list, * and return list of t...
kotlin
[ "fun getRow(lst: List<List<Int>>, x: Int): List<List<Int>> {", " val coordinates = mutableListOf<List<Int>>()", " lst.forEachIndexed { row, ints ->", " ints.forEachIndexed { col, value ->", " if (value == x) {", " coordinates.add(listOf(row, col))", " }"...
HumanEval_kotlin/17
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string representing musical notes in a special ASCII format. * Your task is to parse this string and return list of integers corresponding to how many beats does each * not last. * Here is a legend: * 'o' - whole note...
parseMusic
fun main() { var arg00: String = "" var x0: List<Any> = parseMusic(arg00) var v0: List<Any> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "o o o o" var x1: List<Any> = parseMusic(arg10) var v1: List<A...
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string representing musical notes in a special ASCII format. * Your task is to parse this string and return list of integers corresponding to how many beats does each * not last. * Here is a legend: * 'o' - whole note...
kotlin
[ "fun parseMusic(musicString: String): List<Any> {", " if (musicString.length == 0) {", " return emptyList()", " }", " return musicString.split(\" \").map { note ->", " when (note) {", " \"o\" -> 4", " \"o|\" -> 2", " \".|\" -> 1", " ...
HumanEval_kotlin/57
/** * You are an expert Kotlin programmer, and here is your task. * sum_to_n is a function that sums numbers from 1 to n. * >>> sum_to_n(30) * 465 * >>> sum_to_n(100) * 5050 * >>> sum_to_n(5) * 15 * >>> sum_to_n(10) * 55 * >>> sum_to_n(1) * 1 * */ fun sumToN(n: Int): Int {
sumToN
fun main() { var arg00: Int = 1 var x0: Int = sumToN(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 6 var x1: Int = sumToN(arg10) var v1: Int = 21 if (x1 != v1) { throw Exception("Excepti...
/** * You are an expert Kotlin programmer, and here is your task. * sum_to_n is a function that sums numbers from 1 to n. * >>> sum_to_n(30) * 465 * >>> sum_to_n(100) * 5050 * >>> sum_to_n(5) * 15 * >>> sum_to_n(10) * 55 * >>> sum_to_n(1) * 1 * */
kotlin
[ "fun sumToN(n: Int): Int {", " return n * (n + 1) / 2", "}", "", "" ]
HumanEval_kotlin/87
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a list of integers. * Write a function next_smallest() that returns the 2nd smallest element of the list. * Return if there is no such element. * * next_smallest([1, 2, 3, 4, 5]) == 2 * next_smallest([5, 1, 4, 3, 2]) == 2 * nex...
nextSmallest
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3, 4, 5) var x0: Int? = nextSmallest(arg00) var v0: Int? = 2 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 1, 4, 3, 2) var x1: Int? = nextSmallest...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a list of integers. * Write a function next_smallest() that returns the 2nd smallest element of the list. * Return if there is no such element. * * next_smallest([1, 2, 3, 4, 5]) == 2 * next_smallest([5, 1, 4, 3, 2]) == 2 * nex...
kotlin
[ "fun nextSmallest(lst: List<Int>): Int? {", " val sortedValues = lst.toSortedSet()", " if (sortedValues.size <= 1) {", " return null", " }", " return sortedValues.take(2).last()", "}", "", "" ]
HumanEval_kotlin/34
/** * You are an expert Kotlin programmer, and here is your task. * Return maximum element in the list. * >>> max_element([1, 2, 3]) * 3 * >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) * 123 * */ fun maxElement(l: List<Int>): Int {
maxElement
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3) var x0: Int = maxElement(arg00) var v0: Int = 3 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10) var x1: Int =...
/** * You are an expert Kotlin programmer, and here is your task. * Return maximum element in the list. * >>> max_element([1, 2, 3]) * 3 * >>> max_element([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) * 123 * */
kotlin
[ "fun maxElement(l: List<Int>): Int {", " return l.max()", "}", "", "" ]
HumanEval_kotlin/21
/** * You are an expert Kotlin programmer, and here is your task. * Given list of numbers (of at least two elements), apply a linear transform to that list, * such that the smallest number will become 0 and the largest will become 1 * >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0]) * [0.0, 0.25, 0.5, 0.75, 1.0] * ...
rescaleToUnit
fun main() { var arg00: List<Double> = mutableListOf(2.0, 49.9) var x0: List<Double> = rescaleToUnit(arg00) var v0: List<Double> = mutableListOf(0.0, 1.0) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Double> = mutableListOf(100.0...
/** * You are an expert Kotlin programmer, and here is your task. * Given list of numbers (of at least two elements), apply a linear transform to that list, * such that the smallest number will become 0 and the largest will become 1 * >>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0]) * [0.0, 0.25, 0.5, 0.75, 1.0] * ...
kotlin
[ "fun rescaleToUnit(numbers: List<Double>): List<Double> {", " val min = numbers.min()", " val max = numbers.max()", " return numbers.map { value -> (value - min) / (max - min) }", "}", "", "" ]
HumanEval_kotlin/42
/** * You are an expert Kotlin programmer, and here is your task. * Change numerical base of input number x to base. * return string representation after the conversion. * base numbers are less than 10. * >>> change_base(8, 3) * '22' * >>> change_base(8, 2) * '1000' * >>> change_base(7, 2) * '111' * */ fun ...
changeBase
fun main() { var arg00: Int = 8 var arg01: Int = 3 var x0: String = changeBase(arg00, arg01) var v0: String = "22" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 9 var arg11: Int = 3 var x1: String = changeBase(arg10, ...
/** * You are an expert Kotlin programmer, and here is your task. * Change numerical base of input number x to base. * return string representation after the conversion. * base numbers are less than 10. * >>> change_base(8, 3) * '22' * >>> change_base(8, 2) * '1000' * >>> change_base(7, 2) * '111' * */
kotlin
[ "fun changeBase(x: Int, base: Int): String {", " // Handle the case when the input number is 0", " if (x == 0) return \"0\"", "", " var num = x", " val result = StringBuilder()", "", " while (num > 0) {", " // Prepend the remainder (digit in the new base) to the result", " ...
HumanEval_kotlin/27
/** * You are an expert Kotlin programmer, and here is your task. * For a given string, flip lowercase characters to uppercase and uppercase to lowercase. * >>> flip_case('Hello') * 'hELLO' * */ fun flipCase(string: String): String {
flipCase
fun main() { var arg00: String = "" var x0: String = flipCase(arg00) var v0: String = "" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "Hello!" var x1: String = flipCase(arg10) var v1: String = "hELLO!" if (x1 != v...
/** * You are an expert Kotlin programmer, and here is your task. * For a given string, flip lowercase characters to uppercase and uppercase to lowercase. * >>> flip_case('Hello') * 'hELLO' * */
kotlin
[ "fun flipCase(string: String): String {", " return string.map { char ->", " if (char.isLowerCase()) {", " char.uppercase()", " } else {", " char.lowercase()", " }", " }.joinToString(\"\")", "}", "", "" ]
HumanEval_kotlin/141
/** * You are an expert Kotlin programmer, and here is your task. * Your task is to implement a function that will simplify the expression * x * n. The function returns True if x * n evaluates to a whole number and False * otherwise. Both x and n, are string representation of a fraction, and have the following form...
simplify
fun main() { var arg00 : String = "1/5" var arg01 : String = "5/1" var x0 : Boolean = simplify(arg00, arg01); var v0 : Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "1/6" var arg11 : String = "2/1" ...
/** * You are an expert Kotlin programmer, and here is your task. * Your task is to implement a function that will simplify the expression * x * n. The function returns True if x * n evaluates to a whole number and False * otherwise. Both x and n, are string representation of a fraction, and have the following form...
kotlin
[ "fun simplify(x : String, n : String) : Boolean {", " val (numeratorX, denominatorX) = x.split(\"/\").map { it.toInt() }", " val (numeratorN, denominatorN) = n.split(\"/\").map { it.toInt() }", "", " val productNumerator = numeratorX * numeratorN", " val productDenominator = denominatorX * den...
HumanEval_kotlin/98
/** * You are an expert Kotlin programmer, and here is your task. * * You will be given a string of words separated by commas or spaces. Your task is * to split the string into words and return an array of the words. * * For example: * words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] * w...
wordsString
fun main() { var arg00: String = "Hi, my name is John" var x0: List<String> = wordsString(arg00) var v0: List<String> = mutableListOf("Hi", "my", "name", "is", "John") if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "One, two, t...
/** * You are an expert Kotlin programmer, and here is your task. * * You will be given a string of words separated by commas or spaces. Your task is * to split the string into words and return an array of the words. * * For example: * words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"] * w...
kotlin
[ "fun wordsString(s: String): List<String> {", " return s.split(\"[, ]+\".toRegex()).filterNot { it.isEmpty() }", "}", "", "" ]
HumanEval_kotlin/75
/** * You are an expert Kotlin programmer, and here is your task. * You have been tasked to write a function that receives * a hexadecimal number as a string and counts the number of hexadecimal * digits that are primes (prime number, or a prime, is a natural number * greater than 1 that is not a product of two sm...
hexKey
fun main() { var arg00: String = "AB" var x0: Int = hexKey(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "1077E" var x1: Int = hexKey(arg10) var v1: Int = 2 if (x1 != v1) { throw Exce...
/** * You are an expert Kotlin programmer, and here is your task. * You have been tasked to write a function that receives * a hexadecimal number as a string and counts the number of hexadecimal * digits that are primes (prime number, or a prime, is a natural number * greater than 1 that is not a product of two sm...
kotlin
[ "fun hexKey(num: String): Int {", " val primeHexDigits = setOf('2', '3', '5', '7', 'B', 'D')", " return num.count { it in primeHexDigits }", "}", "", "" ]
HumanEval_kotlin/92
/** * You are an expert Kotlin programmer, and here is your task. * * Given a dictionary, return True if all keys are strings in lower * case or all keys are strings in upper case, else return False. * The function should return False is the given dictionary is empty. * Examples: * check_dict_case({"a":"apple", "...
checkDictCase
fun main() { var arg00: Map<Any?, Any?> = mutableMapOf("p" to "pineapple", "b" to "banana") var x0: Boolean = checkDictCase(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Map<Any?, Any?> = mutableMapOf("p" ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a dictionary, return True if all keys are strings in lower * case or all keys are strings in upper case, else return False. * The function should return False is the given dictionary is empty. * Examples: * check_dict_case({"a":"apple", "...
kotlin
[ "fun checkDictCase(dict: Map<Any?, Any?>): Boolean {", " if (dict.isEmpty()) {", " return false", " }", " return (dict.keys.all { it is String && it.lowercase() == it }) ||", " (dict.values.all { it is String && it.uppercase() == it })", "}", "", "" ]
HumanEval_kotlin/4
/** * You are an expert Kotlin programmer, and here is your task. * For a given list of input numbers, calculate Mean Absolute Deviation * around the mean of this dataset. * Mean Absolute Deviation is the average absolute difference between each * element and a centerpoint (mean in this case): * MAD = average | x...
meanAbsoluteDeviation
fun main() { var arg00: List<Double> = mutableListOf(1.0, 2.0, 3.0) var x0: Double = meanAbsoluteDeviation(arg00) var v0: Double = 0.6666666666666666 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Double> = mutableListOf(1.0, 2.0, ...
/** * You are an expert Kotlin programmer, and here is your task. * For a given list of input numbers, calculate Mean Absolute Deviation * around the mean of this dataset. * Mean Absolute Deviation is the average absolute difference between each * element and a centerpoint (mean in this case): * MAD = average | x...
kotlin
[ "fun meanAbsoluteDeviation(numbers: List<Double>): Double {", " val mean = numbers.average()", " return numbers.map { Math.abs(it - mean) }.average()", "}", "", "" ]
HumanEval_kotlin/62
/** * You are an expert Kotlin programmer, and here is your task. * Circular shift the digits of the integer x, shift the digits right by shift * and return the result as a string. * If shift > number of digits, return digits reversed. * >>> circular_shift(12, 1) * "21" * >>> circular_shift(12, 2) * "12" * */...
circularShift
fun main() { var arg00: Int = 100 var arg01: Int = 2 var x0: String = circularShift(arg00, arg01) var v0: String = "001" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 12 var arg11: Int = 2 var x1: String = circularShi...
/** * You are an expert Kotlin programmer, and here is your task. * Circular shift the digits of the integer x, shift the digits right by shift * and return the result as a string. * If shift > number of digits, return digits reversed. * >>> circular_shift(12, 1) * "21" * >>> circular_shift(12, 2) * "12" * */...
kotlin
[ "fun circularShift(x: Int, shift: Int): String {", " val digits = x.toString() // Convert the integer to its string representation", " val length = digits.length // Get the number of digits", " val effectiveShift = if (shift > length) length else shift % length // Calculate the effective shift", ""...
HumanEval_kotlin/43
/** * You are an expert Kotlin programmer, and here is your task. * Given length of a side and high return area for a triangle. * >>> triangle_area(5, 3) * 7.5 * */ fun triangleArea(a: Int, h: Int): Double {
triangleArea
fun main() { var arg00: Int = 5 var arg01: Int = 3 var x0: Double = triangleArea(arg00, arg01) var v0: Double = 7.5 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 2 var arg11: Int = 2 var x1: Double = triangleArea(arg1...
/** * You are an expert Kotlin programmer, and here is your task. * Given length of a side and high return area for a triangle. * >>> triangle_area(5, 3) * 7.5 * */
kotlin
[ "fun triangleArea(a: Int, h: Int): Double {", " return a * h / 2.0", "}", "", "" ]
HumanEval_kotlin/128
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive integer n, return the product of the odd digits. * Return 0 if all digits are even. * For example: * digits(1) == 1 * digits(4) == 0 * digits(235) == 15 * */ fun digits(n : Int) : Int {
digits
fun main() { var arg00 : Int = 5 var x0 : Int = digits(arg00); var v0 : Int = 5; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 54 var x1 : Int = digits(arg10); var v1 : Int = 5; if (x1 != v1) { throw Exceptio...
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive integer n, return the product of the odd digits. * Return 0 if all digits are even. * For example: * digits(1) == 1 * digits(4) == 0 * digits(235) == 15 * */
kotlin
[ "fun digits(n : Int) : Int {", " val oddDigitsProduct = n.toString()", " .filter { it.digitToInt() % 2 != 0 }", " .map { it.toString().toInt() }", " .fold(1) { acc, i -> acc * i }", "", " return if (oddDigitsProduct == 1 && n.toString().all { it.digitToInt() % 2 == 0 }) 0 else...
HumanEval_kotlin/129
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes a string as input which contains only square brackets. * The function should return True if and only if there is a valid subsequence of brackets * where at least one bracket in the subsequence is nested. * is_neste...
isNested
fun main() { var arg00 : String = "[[]]" var x0 : Boolean = isNested(arg00); var v0 : Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "[]]]]]]][[[[[]" var x1 : Boolean = isNested(arg10); var v1 : Boolean...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes a string as input which contains only square brackets. * The function should return True if and only if there is a valid subsequence of brackets * where at least one bracket in the subsequence is nested. * is_neste...
kotlin
[ "fun isNested(string : String) : Boolean {", " var depth = 0", " var foundNest = false", " for (char in string) {", " when (char) {", " '[' -> depth++", " ']' -> depth--", " }", " if (depth > 1) foundNest = true", " if (depth == 0 && found...
HumanEval_kotlin/46
/** * You are an expert Kotlin programmer, and here is your task. * * Checks if given string is a palindrome * >>> is_palindrome('') * True * >>> is_palindrome('aba') * True * >>> is_palindrome('aaaaa') * True * >>> is_palindrome('zbcd') * False * */ fun isPalindrome(text: String): Boolean {
isPalindrome
fun main() { var arg00: String = "" var x0: Boolean = isPalindrome(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "aba" var x1: Boolean = isPalindrome(arg10) var v1: Boolean = true if (...
/** * You are an expert Kotlin programmer, and here is your task. * * Checks if given string is a palindrome * >>> is_palindrome('') * True * >>> is_palindrome('aba') * True * >>> is_palindrome('aaaaa') * True * >>> is_palindrome('zbcd') * False * */
kotlin
[ "fun isPalindrome(text: String): Boolean {", " return text == text.reversed()", "}", "", "" ]
HumanEval_kotlin/93
/** * You are an expert Kotlin programmer, and here is your task. * Implement a function that takes a non-negative integer and returns an array of the first n * integers that are prime numbers and less than n. * for example: * count_up_to(5) => [2,3] * count_up_to(11) => [2,3,5,7] * count_up_to(0) => [] * count...
countUpTo
fun main() { var arg00: Int = 5 var x0: List<Any> = countUpTo(arg00) var v0: List<Any> = mutableListOf(2, 3) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 6 var x1: List<Any> = countUpTo(arg10) var v1: List<Any> = mutable...
/** * You are an expert Kotlin programmer, and here is your task. * Implement a function that takes a non-negative integer and returns an array of the first n * integers that are prime numbers and less than n. * for example: * count_up_to(5) => [2,3] * count_up_to(11) => [2,3,5,7] * count_up_to(0) => [] * count...
kotlin
[ "fun countUpTo(n: Int): List<Any> {", " fun isPrime(num: Int): Boolean {", " if (num == 1) {", " return false", " }", " for (i in 2..num) {", " if (i * i > num) {", " break", " }", " if (num % i == 0) {", " ...
HumanEval_kotlin/90
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes a message, and encodes in such a * way that it swaps case of all letters, replaces all vowels in * the message with the letter that appears 2 places ahead of that * vowel in the english alphabet. * Assume only letter...
encode
fun main() { var arg00: String = "TEST" var x0: String = encode(arg00) var v0: String = "tgst" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "Mudasir" var x1: String = encode(arg10) var v1: String = "mWDCSKR" if (x...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes a message, and encodes in such a * way that it swaps case of all letters, replaces all vowels in * the message with the letter that appears 2 places ahead of that * vowel in the english alphabet. * Assume only letter...
kotlin
[ "fun encode(message: String): String {", " val vowelMap = mapOf(", " 'a' to 'c', 'A' to 'C',", " 'e' to 'g', 'E' to 'G',", " 'i' to 'k', 'I' to 'K',", " 'o' to 'q', 'O' to 'Q',", " 'u' to 'w', 'U' to 'W'", " )", " return message.map { char ->", " ...
HumanEval_kotlin/150
/** * You are an expert Kotlin programmer, and here is your task. * You will be given the name of a class (a string) and a list of extensions. * The extensions are to be used to load additional classes to the class. The * strength of the extension is as follows: Let CAP be the number of the uppercase * letters in ...
strongestExtension
fun main() { var arg00 : String = "Watashi" var arg01 : List<String> = mutableListOf("tEN", "niNE", "eIGHt8OKe") var x0 : String = strongestExtension(arg00, arg01); var v0 : String = "Watashi.eIGHt8OKe"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) ...
/** * You are an expert Kotlin programmer, and here is your task. * You will be given the name of a class (a string) and a list of extensions. * The extensions are to be used to load additional classes to the class. The * strength of the extension is as follows: Let CAP be the number of the uppercase * letters in ...
kotlin
[ "fun strongestExtension(className : String, extensions : List<String>) : String {", " var strongestExtension = \"\"", " var maxStrength = Int.MIN_VALUE", "", " extensions.forEach { extension ->", " val strength = extension.count { it.isUpperCase() } - extension.count { it.isLowerCase() }",...
HumanEval_kotlin/40
/** * You are an expert Kotlin programmer, and here is your task. * Return list with elements incremented by 1. * >>> incr_list([1, 2, 3]) * [2, 3, 4] * >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123]) * [6, 4, 6, 3, 4, 4, 10, 1, 124] * */ fun incrList(l: List<Int>): List<Int> {
incrList
fun main() { var arg00: List<Int> = mutableListOf() var x0: List<Int> = incrList(arg00) var v0: List<Int> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(3, 2, 1) var x1: List<Int> = incrLi...
/** * You are an expert Kotlin programmer, and here is your task. * Return list with elements incremented by 1. * >>> incr_list([1, 2, 3]) * [2, 3, 4] * >>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123]) * [6, 4, 6, 3, 4, 4, 10, 1, 124] * */
kotlin
[ "fun incrList(l: List<Int>): List<Int> {", " return l.map { it + 1 }", "}", "", "" ]
HumanEval_kotlin/51
/** * You are an expert Kotlin programmer, and here is your task. * * Check if two words have the same characters. * >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc') * True * >>> same_chars('abcd', 'dddddddabc') * True * >>> same_chars('dddddddabc', 'abcd') * True * >>> same_chars('eabcd', 'dddddddabc') * Fa...
sameChars
fun main() { var arg00: String = "eabcdzzzz" var arg01: String = "dddzzzzzzzddeddabc" var x0: Boolean = sameChars(arg00, arg01) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "abcd" var arg11: Str...
/** * You are an expert Kotlin programmer, and here is your task. * * Check if two words have the same characters. * >>> same_chars('eabcdzzzz', 'dddzzzzzzzddeddabc') * True * >>> same_chars('abcd', 'dddddddabc') * True * >>> same_chars('dddddddabc', 'abcd') * True * >>> same_chars('eabcd', 'dddddddabc') * Fa...
kotlin
[ "fun sameChars(s0: String, s1: String): Boolean {", " return s0.toSet() == s1.toSet()", "}", "", "" ]
HumanEval_kotlin/99
/** * You are an expert Kotlin programmer, and here is your task. * This function takes two positive numbers x and y and returns the * biggest even integer number that is in the range [x, y] inclusive. If * there's no such number, then the function should return -1. * For example: * choose_num(12, 15) = 14 * ch...
chooseNum
fun main() { var arg00: Int = 12 var arg01: Int = 15 var x0: Int = chooseNum(arg00, arg01) var v0: Int = 14 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 13 var arg11: Int = 12 var x1: Int = chooseNum(arg10, arg11) ...
/** * You are an expert Kotlin programmer, and here is your task. * This function takes two positive numbers x and y and returns the * biggest even integer number that is in the range [x, y] inclusive. If * there's no such number, then the function should return -1. * For example: * choose_num(12, 15) = 14 * ch...
kotlin
[ "fun chooseNum(x: Int, y: Int): Int {", " if (x > y) {", " return -1", " }", " if (y % 2 == 0) {", " return y", " }", " if (x < y) {", " return y - 1", " }", " return -1", "}", "", "" ]
HumanEval_kotlin/65
/** * You are an expert Kotlin programmer, and here is your task. * * "Given an array representing a branch of a tree that has non-negative integer nodes * your task is to pluck one of the nodes and return it. * The plucked node should be the node with the smallest even value. * If multiple nodes with the same sma...
pluck
fun main() { var arg00: List<Int> = mutableListOf(4, 2, 3) var x0: List<Int> = pluck(arg00) var v0: List<Int> = mutableListOf(2, 1) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 2, 3) var x1: List<Int> ...
/** * You are an expert Kotlin programmer, and here is your task. * * "Given an array representing a branch of a tree that has non-negative integer nodes * your task is to pluck one of the nodes and return it. * The plucked node should be the node with the smallest even value. * If multiple nodes with the same sma...
kotlin
[ "fun pluck(arr: List<Int>): List<Int> {", " // Filter the list to get even numbers along with their indices", " val evenNumbersWithIndices = arr.withIndex()", " .filter { it.value % 2 == 0 }", " .map { Pair(it.value, it.index) }", "", " // Find the smallest even number (if Int)", ...
HumanEval_kotlin/158
/** * You are an expert Kotlin programmer, and here is your task. * You are given a string s. * if s[i] is a letter, reverse its case from lower to upper or vise versa, * otherwise keep it as it is. * If the string contains no letters, reverse the string. * The function should return the resulted string. * Examp...
solve
fun main() { var arg00 : String = "AsDf" var x0 : String = solve(arg00); var v0 : String = "aSdF"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "1234" var x1 : String = solve(arg10); var v1 : String = "4321"; if ...
/** * You are an expert Kotlin programmer, and here is your task. * You are given a string s. * if s[i] is a letter, reverse its case from lower to upper or vise versa, * otherwise keep it as it is. * If the string contains no letters, reverse the string. * The function should return the resulted string. * Examp...
kotlin
[ "fun solve(s : String) : String {", " val containsLetters = s.any { it.isLetter() }", " if (!containsLetters) {", " return s.reversed()", " }", " return s.map { char ->", " when {", " char.isUpperCase() -> char.lowercase()", " char.isLowerCase() -> cha...
HumanEval_kotlin/106
/** * You are an expert Kotlin programmer, and here is your task. * We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The * numbers in the array will be randomly ordered. Your task is to determine if * it is possible to get an array sorted in non-decreasing order by performing * the following operat...
moveOneBall
fun main() { var arg00: List<Int> = mutableListOf(3, 4, 5, 1, 2) var x0: Boolean = moveOneBall(arg00); var v0: Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(3, 5, 10, 1, 2) var x1: Boolean ...
/** * You are an expert Kotlin programmer, and here is your task. * We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The * numbers in the array will be randomly ordered. Your task is to determine if * it is possible to get an array sorted in non-decreasing order by performing * the following operat...
kotlin
[ "fun moveOneBall(arr: List<Int>): Boolean {", " if (arr.isEmpty()) {", " return true", " }", "", " var pivotCount = 0", " var pivotIndex = -1", " for (i in 1 until arr.size) {", " if (arr[i] < arr[i - 1]) {", " pivotCount++", " pivotIndex = i", ...
HumanEval_kotlin/58
/** * You are an expert Kotlin programmer, and here is your task. * brackets is a string of "(" and ")". * return True if every opening bracket has a corresponding closing bracket. * >>> correct_bracketing("(") * False * >>> correct_bracketing("()") * True * >>> correct_bracketing("(()())") * True * >>> corr...
correctBracketing2
fun main() { var arg00: String = "()" var x0: Boolean = correctBracketing2(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "(()())" var x1: Boolean = correctBracketing2(arg10) var v1: Boolea...
/** * You are an expert Kotlin programmer, and here is your task. * brackets is a string of "(" and ")". * return True if every opening bracket has a corresponding closing bracket. * >>> correct_bracketing("(") * False * >>> correct_bracketing("()") * True * >>> correct_bracketing("(()())") * True * >>> corr...
kotlin
[ "fun correctBracketing2(brackets: String): Boolean {", " val balance = brackets.runningFold(0) { balance, c ->", " when (c) {", " '(' -> balance + 1", " ')' -> balance - 1", " else -> throw Exception(\"Illegal symbol\")", " }", " }", " return b...
HumanEval_kotlin/67
/** * You are an expert Kotlin programmer, and here is your task. * * Given list of integers, return list in strange order. * Strange sorting, is when you start with the minimum value, * then maximum of the remaining integers, then minimum and so on. * Examples: * strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3] ...
strangeSortList
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3, 4) var x0: List<Int> = strangeSortList(arg00) var v0: List<Int> = mutableListOf(1, 4, 2, 3) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 6, 7, 8, ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given list of integers, return list in strange order. * Strange sorting, is when you start with the minimum value, * then maximum of the remaining integers, then minimum and so on. * Examples: * strange_sort_list([1, 2, 3, 4]) == [1, 4, 2, 3] ...
kotlin
[ "fun strangeSortList(lst: List<Int>): List<Int> {", " if (lst.isEmpty()) return lst", "", " val sortedList = lst.sorted().toMutableList()", " val result = mutableListOf<Int>()", " var addingMinimum = true", "", " while (sortedList.isNotEmpty()) {", " if (addingMinimum) {", " ...
HumanEval_kotlin/154
/** * You are an expert Kotlin programmer, and here is your task. * * Given the lengths of the three sides of a triangle. Return True if the three * sides form a right-angled triangle, False otherwise. * A right-angled triangle is a triangle in which one angle is right angle or * 90 degree. * Example: * right_a...
rightAngleTriangle
fun main() { var arg00 : Int = 3 var arg01 : Int = 4 var arg02 : Int = 5 var x0 : Boolean = rightAngleTriangle(arg00, arg01, arg02); var v0 : Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 1 var arg11 ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given the lengths of the three sides of a triangle. Return True if the three * sides form a right-angled triangle, False otherwise. * A right-angled triangle is a triangle in which one angle is right angle or * 90 degree. * Example: * right_a...
kotlin
[ "fun rightAngleTriangle(a : Int, b : Int, c : Int) : Boolean {", " fun sq(num: Int) = num * num", "\treturn sq(listOf(a, b, c).max()) * 2 == sq(a) + sq(b) + sq(c)", "}", "", "" ]
HumanEval_kotlin/113
/** * You are an expert Kotlin programmer, and here is your task. * * In this Kata, you have to sort an array of non-negative integers according to * number of ones in their binary representation in ascending order. * For similar number of ones, sort based on decimal value. * It must be implemented like this: * ...
sortArrayByBinary
fun main() { var arg00: List<Int> = mutableListOf(1, 5, 2, 3, 4) var x0: List<Int> = sortArrayByBinary(arg00); var v0: List<Int> = mutableListOf(1, 2, 4, 3, 5); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(-2...
/** * You are an expert Kotlin programmer, and here is your task. * * In this Kata, you have to sort an array of non-negative integers according to * number of ones in their binary representation in ascending order. * For similar number of ones, sort based on decimal value. * It must be implemented like this: * ...
kotlin
[ "fun sortArrayByBinary(arr: List<Int>): List<Int> {", " fun countOnes(num: Int) = num.toString(2).count { c -> c == '1' }", " return arr.sortedWith(", " Comparator<Int> { num1, num2 ->", " countOnes(num1).compareTo(countOnes(num2))", " }.thenBy { it }", " )", "}", "...
HumanEval_kotlin/124
/** * You are an expert Kotlin programmer, and here is your task. * You are given two intervals, * where each interval is a pair of integers. For example, interval = (start, end) = (1, 2). * The given intervals are closed which means that the interval (start, end) * includes both start and end. * For each given i...
intersection
fun main() { var arg00 : List<Int> = mutableListOf(1, 2) var arg01 : List<Int> = mutableListOf(2, 3) var x0 : String = intersection(arg00, arg01); var v0 : String = "NO"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = m...
/** * You are an expert Kotlin programmer, and here is your task. * You are given two intervals, * where each interval is a pair of integers. For example, interval = (start, end) = (1, 2). * The given intervals are closed which means that the interval (start, end) * includes both start and end. * For each given i...
kotlin
[ "fun intersection(interval1 : List<Int>, interval2 : List<Int>) : String {", " fun isPrime(num: Int): Boolean {", " if (num <= 1) {", " return false", " }", " for (i in 2..num) {", " if (i * i > num) {", " break", " }", " ...
HumanEval_kotlin/71
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that accepts two lists of strings and returns the list that has * total number of chars in the all strings of the list less than the other list. * if the two lists have the same number of chars, return the first list. * Exampl...
totalMatch
fun main() { var arg00: List<String> = mutableListOf() var arg01: List<String> = mutableListOf() var x0: List<String> = totalMatch(arg00, arg01) var v0: List<String> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: L...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that accepts two lists of strings and returns the list that has * total number of chars in the all strings of the list less than the other list. * if the two lists have the same number of chars, return the first list. * Exampl...
kotlin
[ "fun totalMatch(lst1: List<String>, lst2: List<String>): List<String> {", " val totalCharsLst1 = lst1.sumOf { it.length }", " val totalCharsLst2 = lst2.sumOf { it.length }", "", " return if (totalCharsLst1 <= totalCharsLst2) lst1 else lst2", "}", "", "" ]
HumanEval_kotlin/0
/** * You are an expert Kotlin programmer, and here is your task. * Check if in the given list of numbers, there are any two numbers closer to each other than * the given threshold. * >>> has_close_elements([1.0, 2.0, 3.0], 0.5) * False * >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) * True * */ ...
hasCloseElements
fun main() { var arg00: List<Double> = mutableListOf(1.0, 2.0, 3.9, 4.0, 5.0, 2.2) var arg01: Double = 0.3 var x0: Boolean = hasCloseElements(arg00, arg01) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<D...
/** * You are an expert Kotlin programmer, and here is your task. * Check if in the given list of numbers, there are any two numbers closer to each other than * the given threshold. * >>> has_close_elements([1.0, 2.0, 3.0], 0.5) * False * >>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) * True * */
kotlin
[ "fun hasCloseElements(numbers: List<Double>, threshold: Double): Boolean {", " return numbers.sorted().zipWithNext { a, b -> b - a <= threshold }.any { it }", "}", "", "" ]
HumanEval_kotlin/100
/** * You are an expert Kotlin programmer, and here is your task. * You are given two positive integers n and m, and your task is to compute the * average of the integers from n through m (including n and m). * Round the answer to the nearest integer and convert that to binary. * If n is greater than m, return "-1...
roundedAvg
fun main() { var arg00: Int = 1 var arg01: Int = 5 var x0: String = roundedAvg(arg00, arg01); var v0: String = "0b11"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 7 var arg11: Int = 13 var x1: String = roundedAvg(ar...
/** * You are an expert Kotlin programmer, and here is your task. * You are given two positive integers n and m, and your task is to compute the * average of the integers from n through m (including n and m). * Round the answer to the nearest integer and convert that to binary. * If n is greater than m, return "-1...
kotlin
[ "fun roundedAvg(n: Int, m: Int): String {", " if (n > m) {", " return \"-1\"", " }", " return \"0b\" + ((n + m) / 2).toString(2)", "}", "", "" ]
HumanEval_kotlin/70
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array arr of integers, find the minimum number of elements that * need to be changed to make the array palindromic. A palindromic array is an array that * is read the same backwards and forwards. In one change, you can change one element...
smallestChange
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3, 5, 4, 7, 9, 6) var x0: Int = smallestChange(arg00) var v0: Int = 4 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 2, 3, 4, 3, 2, 2) var x1: Int ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array arr of integers, find the minimum number of elements that * need to be changed to make the array palindromic. A palindromic array is an array that * is read the same backwards and forwards. In one change, you can change one element...
kotlin
[ "fun smallestChange(arr: List<Int>): Int {", " return arr.zip(arr.reversed()).count { (a, b) -> a != b } / 2", "}", "", "" ]
HumanEval_kotlin/81
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive integer N, return the total sum of its digits in binary. * * Example * For N = 1000, the sum of digits will be 1 the output should be "1". * For N = 150, the sum of digits will be 6 the output should be "110". * For ...
solve
fun main() { var arg00: Int = 1000 var x0: String = solve(arg00) var v0: String = "1" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 150 var x1: String = solve(arg10) var v1: String = "110" if (x1 != v1) { thro...
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive integer N, return the total sum of its digits in binary. * * Example * For N = 1000, the sum of digits will be 1 the output should be "1". * For N = 150, the sum of digits will be 6 the output should be "110". * For ...
kotlin
[ "fun solve(n: Int): String {", " var cur = n", " var digitSum = 0", " while (cur > 0) {", " digitSum += cur % 10", " cur /= 10", " }", " return digitSum.toString(2)", "}", "", "" ]
HumanEval_kotlin/78
/** * You are an expert Kotlin programmer, and here is your task. * It is the last week of the semester, and the teacher has to give the grades * to students. The teacher has been making her own algorithm for grading. * The only problem is, she has lost the code she used for grading. * She has given you a list of ...
numericalLetterGrade
fun main() { var arg00: List<Double> = mutableListOf(4.0, 3.0, 1.7, 2.0, 3.5) var x0: List<String> = numericalLetterGrade(arg00) var v0: List<String> = mutableListOf("A+", "B", "C-", "C", "A-") if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var ar...
/** * You are an expert Kotlin programmer, and here is your task. * It is the last week of the semester, and the teacher has to give the grades * to students. The teacher has been making her own algorithm for grading. * The only problem is, she has lost the code she used for grading. * She has given you a list of ...
kotlin
[ "fun numericalLetterGrade(grades: List<Double>): List<String> {", " return grades.map { gpa ->", " when {", " gpa >= 4.0 -> \"A+\"", " gpa > 3.7 -> \"A\"", " gpa > 3.3 -> \"A-\"", " gpa > 3.0 -> \"B+\"", " gpa > 2.7 -> \"B\"", " ...
HumanEval_kotlin/54
/** * You are an expert Kotlin programmer, and here is your task. * Return True is list elements are monotonically increasing or decreasing. * >>> monotonic([1, 2, 4, 20]) * True * >>> monotonic([1, 20, 4, 10]) * False * >>> monotonic([4, 1, 0, -10]) * True * */ fun monotonic(l: List<Int>): Boolean {
monotonic
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 4, 10) var x0: Boolean = monotonic(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 2, 4, 20) var x1: Boolean = monoton...
/** * You are an expert Kotlin programmer, and here is your task. * Return True is list elements are monotonically increasing or decreasing. * >>> monotonic([1, 2, 4, 20]) * True * >>> monotonic([1, 20, 4, 10]) * False * >>> monotonic([4, 1, 0, -10]) * True * */
kotlin
[ "fun monotonic(l: List<Int>): Boolean {", " val lSorted = l.sorted()", " return l == lSorted || l == lSorted.reversed()", "}", "", "" ]
HumanEval_kotlin/94
/** * You are an expert Kotlin programmer, and here is your task. * Complete the function that takes two integers and returns * the product of their unit digits. * Assume the input is always valid. * Examples: * multiply(148, 412) should return 16. * multiply(19, 28) should return 72. * multiply(2020, 1851) sho...
multiply
fun main() { var arg00: Int = 148 var arg01: Int = 412 var x0: Int = multiply(arg00, arg01) var v0: Int = 16 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 19 var arg11: Int = 28 var x1: Int = multiply(arg10, arg11) ...
/** * You are an expert Kotlin programmer, and here is your task. * Complete the function that takes two integers and returns * the product of their unit digits. * Assume the input is always valid. * Examples: * multiply(148, 412) should return 16. * multiply(19, 28) should return 72. * multiply(2020, 1851) sho...
kotlin
[ "fun multiply(a: Int, b: Int): Int {", " return Math.abs((a % 10) * (b % 10))", "}", "", "" ]
HumanEval_kotlin/79
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that takes a string and returns True if the string * length is a prime number or False otherwise * Examples * prime_length('Hello') == True * prime_length('abcdcba') == True * prime_length('kittens') == True * prime_length('ora...
primeLength
fun main() { var arg00: String = "Hello" var x0: Boolean = primeLength(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "abcdcba" var x1: Boolean = primeLength(arg10) var v1: Boolean = true ...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that takes a string and returns True if the string * length is a prime number or False otherwise * Examples * prime_length('Hello') == True * prime_length('abcdcba') == True * prime_length('kittens') == True * prime_length('ora...
kotlin
[ "fun primeLength(string: String): Boolean {", " fun isPrime(num: Int): Boolean {", " if (num == 1 || num == 0) {", " return false", " }", " for (i in 2..num) {", " if (i * i > num) {", " break", " }", " if (num % i ...
HumanEval_kotlin/140
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a string representing a sentence, * the sentence contains some words separated by a space, * and you have to return a string that contains the words from the original sentence, * whose lengths are prime numbers, * the order of the...
wordsInSentence
fun main() { var arg00 : String = "This is a test" var x0 : String = wordsInSentence(arg00); var v0 : String = "is"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "lets go for swimming" var x1 : String = wordsInSentence(a...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a string representing a sentence, * the sentence contains some words separated by a space, * and you have to return a string that contains the words from the original sentence, * whose lengths are prime numbers, * the order of the...
kotlin
[ "fun wordsInSentence(sentence : String) : String {", " fun isPrime(num: Int): Boolean {", " if (num <= 1) {", " return false", " }", " for (i in 2..num) {", " if (i * i > num) {", " break", " }", " if (num % i == 0)...
HumanEval_kotlin/127
/** * You are an expert Kotlin programmer, and here is your task. * Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in * the last couple centuries. However, what people don't know is Tribonacci sequence. * Tribonacci sequence is defined by the recurrence: * tri(1) = 3 * tri(n) = 1 + n /...
tri
fun main() { var arg00 : Int = 3 var x0 : List<Int> = tri(arg00); var v0 : List<Int> = mutableListOf(1, 3, 2, 8); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 4 var x1 : List<Int> = tri(arg10); var v1 : List<Int> = muta...
/** * You are an expert Kotlin programmer, and here is your task. * Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in * the last couple centuries. However, what people don't know is Tribonacci sequence. * Tribonacci sequence is defined by the recurrence: * tri(1) = 3 * tri(n) = 1 + n /...
kotlin
[ "fun tri(n : Int) : List<Int> {", " if (n == 0) {", " return listOf(1)", " }", "\tval tris = mutableListOf(1, 3)", " while(tris.size <= n) {", " val ind = tris.size", " if (ind % 2 == 0) {", " tris.add(1 + ind / 2)", " } else {", " tris....
HumanEval_kotlin/133
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that returns a tuple (a, b), where 'a' is * the largest of negative integers, and 'b' is the smallest * of positive integers in a list. * If there is no negative or positive integers, return them as None. * Examples: * large...
largestSmallestIntegers
fun main() { var arg00 : List<Int> = mutableListOf(2, 4, 1, 3, 5, 7) var x0 : List<Int?> = largestSmallestIntegers(arg00); var v0 : List<Int?> = mutableListOf(null, 1); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutable...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that returns a tuple (a, b), where 'a' is * the largest of negative integers, and 'b' is the smallest * of positive integers in a list. * If there is no negative or positive integers, return them as None. * Examples: * large...
kotlin
[ "fun largestSmallestIntegers(lst : List<Int>) : List<Int?> {", " val negatives = lst.filter { it < 0 }", " val positives = lst.filter { it > 0 }", "", " val largestNegative = negatives.maxOrNull()", " val smallestPositive = positives.minOrNull()", "", " return listOf(largestNegative, sm...
HumanEval_kotlin/18
/** * You are an expert Kotlin programmer, and here is your task. * Find how many times a given substring can be found in the original string. Count overlaping cases. * >>> how_many_times('', 'a') * 0 * >>> how_many_times('aaa', 'a') * 3 * >>> how_many_times('aaaa', 'aa') * 3 * */ fun howManyTimes(string: Str...
howManyTimes
fun main() { var arg00: String = "" var arg01: String = "x" var x0: Int = howManyTimes(arg00, arg01) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "xyxyxyx" var arg11: String = "x" var x1: Int = how...
/** * You are an expert Kotlin programmer, and here is your task. * Find how many times a given substring can be found in the original string. Count overlaping cases. * >>> how_many_times('', 'a') * 0 * >>> how_many_times('aaa', 'a') * 3 * >>> how_many_times('aaaa', 'aa') * 3 * */
kotlin
[ "fun howManyTimes(string: String, substring: String): Int {", " return string.indices.count { startIndex ->", " val endIndex = startIndex + substring.length", " if (endIndex > string.length) {", " false", " } else {", " string.substring(startIndex, endIndex)...
HumanEval_kotlin/159
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string 'text', return its md5 hash equivalent string. * If 'text' is an empty string, return . * >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62' * */ fun stringToMd5(text : String) : String? {
stringToMd5
fun main() { var arg00 : String = "Hello world" var x0 : String? = stringToMd5(arg00); var v0 : String? = "3e25960a79dbc69b674cd4ec67a72c62"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "" var x1 : String? = stringToMd5...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string 'text', return its md5 hash equivalent string. * If 'text' is an empty string, return . * >>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62' * */
kotlin
[ "fun stringToMd5(text : String) : String? {", "", " if (text.isEmpty()) return null", "", " // Get MD5 MessageDigest instance", " val md = java.security.MessageDigest.getInstance(\"MD5\")", "", " // Digest the input string bytes, then convert the digest bytes to a hex string", " val h...
HumanEval_kotlin/118
/** * You are an expert Kotlin programmer, and here is your task. * Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. * * Examples * solution([5, 8, 7, 1]) ==> 12 * solution([3, 3, 3, 3, 3]) ==> 9 * solution([30, 13, 24, 321]) ==>0 * */ fun solution(lst...
solution
fun main() { var arg00 : List<Int> = mutableListOf(3, 3, 3, 3, 3) var x0 : Int = solution(arg00); var v0 : Int = 9; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(30, 13, 24, 321) var x1 : Int = solution(a...
/** * You are an expert Kotlin programmer, and here is your task. * Given a non-empty list of integers, return the sum of all of the odd elements that are in even positions. * * Examples * solution([5, 8, 7, 1]) ==> 12 * solution([3, 3, 3, 3, 3]) ==> 9 * solution([30, 13, 24, 321]) ==>0 * */
kotlin
[ "fun solution(lst : List<Int>) : Int {", "\treturn lst.filterIndexed { index, i ->", " index % 2 == 0 && i % 2 == 1", " }.sum()", "}", "", "" ]
HumanEval_kotlin/33
/** * You are an expert Kotlin programmer, and here is your task. * Return sorted unique elements in a list * >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123]) * [0, 2, 3, 5, 9, 123] * */ fun unique(l: List<Int>): List<Int> {
unique
fun main() { var arg00: List<Int> = mutableListOf(5, 3, 5, 2, 3, 3, 9, 0, 123) var x0: List<Int> = unique(arg00) var v0: List<Int> = mutableListOf(0, 2, 3, 5, 9, 123) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } }
/** * You are an expert Kotlin programmer, and here is your task. * Return sorted unique elements in a list * >>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123]) * [0, 2, 3, 5, 9, 123] * */
kotlin
[ "fun unique(l: List<Int>): List<Int> {", " return l.toSortedSet().toList()", "}", "", "" ]
HumanEval_kotlin/153
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer, obtain its roman numeral equivalent as a string, * and return it in lowercase. * Restrictions: 1 <= num <= 1000 * Examples: * >>> int_to_mini_roman(19) == 'xix' * >>> int_to_mini_roman(152) == 'clii' * >>> int_to_mi...
intToMiniRoman
fun main() { var arg00 : Int = 19 var x0 : String = intToMiniRoman(arg00); var v0 : String = "xix"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 152 var x1 : String = intToMiniRoman(arg10); var v1 : String = "clii"; ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer, obtain its roman numeral equivalent as a string, * and return it in lowercase. * Restrictions: 1 <= num <= 1000 * Examples: * >>> int_to_mini_roman(19) == 'xix' * >>> int_to_mini_roman(152) == 'clii' * >>> int_to_mi...
kotlin
[ "fun intToMiniRoman(number : Int) : String {", " val romanNumerals = listOf(", " 1000 to \"m\",", " 900 to \"cm\",", " 500 to \"d\",", " 400 to \"cd\",", " 100 to \"c\",", " 90 to \"xc\",", " 50 to \"l\",", " 40 to \"xl\",", " 10 ...
HumanEval_kotlin/123
/** * You are an expert Kotlin programmer, and here is your task. * * Given a list of numbers, return whether or not they are sorted * in ascending order. If list has more than 1 duplicate of the same * number, return False. Assume no negative numbers and only integers. * Examples * is_sorted([5]) ➞ True * is_s...
isSorted
fun main() { var arg00 : List<Int> = mutableListOf(5) var x0 : Boolean = isSorted(arg00); var v0 : Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(1, 2, 3, 4, 5) var x1 : Boolean = isSorted(...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a list of numbers, return whether or not they are sorted * in ascending order. If list has more than 1 duplicate of the same * number, return False. Assume no negative numbers and only integers. * Examples * is_sorted([5]) ➞ True * is_s...
kotlin
[ "fun isSorted(lst : List<Int>) : Boolean {", "\tval diffs = lst.zipWithNext { a, b -> b - a }", " return diffs.all { it >= 0 } && diffs.zipWithNext().all { (a, b) -> a + b > 0 }", "}", "", "" ]
HumanEval_kotlin/20
/** * You are an expert Kotlin programmer, and here is your task. * From a supplied list of numbers (of length at least two) select and return two that are the closest to each * other and return them in order (smaller number, larger number). * >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) * (2.0, 2.2) ...
findClosestElements
fun main() { var arg00: List<Double> = mutableListOf(1.0, 2.0, 3.9, 4.0, 5.0, 2.2) var x0: List<Double> = findClosestElements(arg00) var v0: List<Double> = mutableListOf(3.9, 4.0) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Doub...
/** * You are an expert Kotlin programmer, and here is your task. * From a supplied list of numbers (of length at least two) select and return two that are the closest to each * other and return them in order (smaller number, larger number). * >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.2]) * (2.0, 2.2) ...
kotlin
[ "fun findClosestElements(numbers: List<Double>): List<Double> {", " return numbers.sorted().zipWithNext().sortedBy { (a, b) -> (b - a) }.first().toList()", "}", "", "" ]
HumanEval_kotlin/53
/** * You are an expert Kotlin programmer, and here is your task. * brackets is a string of "<" and ">". * return True if every opening bracket has a corresponding closing bracket. * >>> correct_bracketing("<") * False * >>> correct_bracketing("<>") * True * >>> correct_bracketing("<<><>>") * True * >>> corr...
correctBracketing
fun main() { var arg00: String = "<>" var x0: Boolean = correctBracketing(arg00) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "<<><>>" var x1: Boolean = correctBracketing(arg10) var v1: Boolean ...
/** * You are an expert Kotlin programmer, and here is your task. * brackets is a string of "<" and ">". * return True if every opening bracket has a corresponding closing bracket. * >>> correct_bracketing("<") * False * >>> correct_bracketing("<>") * True * >>> correct_bracketing("<<><>>") * True * >>> corr...
kotlin
[ "fun correctBracketing(brackets: String): Boolean {", " val balance = brackets.runningFold(0) { balance, c ->", " when (c) {", " '<' -> balance + 1", " '>' -> balance - 1", " else -> throw Exception(\"Illegal symbol\")", " }", " }", " return ba...
End of preview. Expand in Data Studio

Benchmark summary

We introduce HumanEval for Kotlin, created from scratch by human experts. Solutions and tests for all 161 HumanEval tasks are written by an expert olympiad programmer with 6 years of experience in Kotlin, and independently checked by a programmer with 4 years of experience in Kotlin. The tests we implement are equivalent to the original HumanEval tests for Python.

How to use

The benchmark is prepared in a format suitable for MXEval and can be easily integrated into the MXEval pipeline.

When testing models on this benchmark, during the code generation step we use early stopping on the }\n} sequence to expedite the process. We also perform some code post-processing before evaluation — specifically, we remove all comments and signatures.

The code for running an example model on the benchmark using the early stopping and post-processing is available below.

import json
import re

from datasets import load_dataset
import jsonlines
import torch
from transformers import (
    AutoTokenizer,
    AutoModelForCausalLM,
    StoppingCriteria,
    StoppingCriteriaList,
)
from tqdm import tqdm 
from mxeval.evaluation import evaluate_functional_correctness


class StoppingCriteriaSub(StoppingCriteria):
    def __init__(self, stops, tokenizer):
        (StoppingCriteria.__init__(self),)
        self.stops = rf"{stops}"
        self.tokenizer = tokenizer

    def __call__(
        self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs
    ) -> bool:
        last_three_tokens = [int(x) for x in input_ids.data[0][-3:]]
        decoded_last_three_tokens = self.tokenizer.decode(last_three_tokens)

        return bool(re.search(self.stops, decoded_last_three_tokens))


def generate(problem):
    criterion = StoppingCriteriaSub(stops="\n}\n", tokenizer=tokenizer)
    stopping_criteria = StoppingCriteriaList([criterion])
    
    problem = tokenizer.encode(problem, return_tensors="pt").to('cuda')
    sample = model.generate(
        problem,
        max_new_tokens=256,
        min_new_tokens=128,
        pad_token_id=tokenizer.eos_token_id,
        do_sample=False,
        num_beams=1,
        stopping_criteria=stopping_criteria,
    )
    
    answer = tokenizer.decode(sample[0], skip_special_tokens=True)
    return answer


def clean_asnwer(code):
    # Clean comments
    code_without_line_comments = re.sub(r"//.*", "", code)
    code_without_all_comments = re.sub(
        r"/\*.*?\*/", "", code_without_line_comments, flags=re.DOTALL
    )
    #Clean signatures
    lines = code.split("\n")
    for i, line in enumerate(lines):
        if line.startswith("fun "):
            return "\n".join(lines[i + 1:])
            
    return code


model_name = "JetBrains/CodeLlama-7B-Kexer"
dataset = load_dataset("jetbrains/Kotlin_HumanEval")['train']
problem_dict = {problem['task_id']: problem for problem in dataset}

model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16).to('cuda')
tokenizer = AutoTokenizer.from_pretrained(model_name)

output = []
for key in tqdm(list(problem_dict.keys()), leave=False):
    problem = problem_dict[key]["prompt"]
    answer = generate(problem)
    answer = clean_asnwer(answer)
    output.append({"task_id": key, "completion": answer, "language": "kotlin"})

output_file = f"answers"
with jsonlines.open(output_file, mode="w") as writer:
    for line in output:
        writer.write(line)

evaluate_functional_correctness(
    sample_file=output_file,
    k=[1],
    n_workers=16,
    timeout=15,
    problem_file=problem_dict,
)

with open(output_file + '_results.jsonl') as fp:
    total = 0
    correct = 0
    for line in fp:
        sample_res = json.loads(line)
        print(sample_res)
        total += 1
        correct += sample_res['passed']

print(f'Pass rate: {correct/total}')

Results

We evaluated multiple coding models using this benchmark, and the results are presented in the figure below: results

Downloads last month
125

Collection including JetBrains/Kotlin_HumanEval