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
listlengths
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...
HumanEval_kotlin/130
/** * You are an expert Kotlin programmer, and here is your task. * You are given a list of numbers. * You need to return the sum of squared numbers in the given list, * round each element in the list to the upper int(Ceiling) first. * Examples: * For lst = [1,2,3] the output should be 14 * For lst = [1,4,9] the...
sumSquares
fun main() { var arg00 : List<Double> = mutableListOf(1.0, 2.0, 3.0) var x0 : Int = sumSquares(arg00); var v0 : Int = 14; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Double> = mutableListOf(1.0, 2.0, 3.0) var x1 : Int = sum...
/** * You are an expert Kotlin programmer, and here is your task. * You are given a list of numbers. * You need to return the sum of squared numbers in the given list, * round each element in the list to the upper int(Ceiling) first. * Examples: * For lst = [1,2,3] the output should be 14 * For lst = [1,4,9] the...
kotlin
[ "fun sumSquares(lst : List<Double>) : Int {", "\treturn lst.map { Math.ceil(it).toInt() }.sumOf { it * it }", "}", "", "" ]
HumanEval_kotlin/39
/** * You are an expert Kotlin programmer, and here is your task. * * Imagine a road that's a perfectly straight infinitely long line. * n cars are driving left to right; simultaneously, a different set of n cars * are driving right to left. The two sets of cars start out being very far from * each other. All ...
carRaceCollision
fun main() { var arg00: Int = 2 var x0: Int = carRaceCollision(arg00) var v0: Int = 4 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 3 var x1: Int = carRaceCollision(arg10) var v1: Int = 9 if (x1 != v1) { throw...
/** * You are an expert Kotlin programmer, and here is your task. * * Imagine a road that's a perfectly straight infinitely long line. * n cars are driving left to right; simultaneously, a different set of n cars * are driving right to left. The two sets of cars start out being very far from * each other. All ...
kotlin
[ "fun carRaceCollision(n: Int): Int {", " return n * n", "}", "", "" ]
HumanEval_kotlin/13
/** * You are an expert Kotlin programmer, and here is your task. * Return a greatest common divisor of two integers a and b * >>> greatest_common_divisor(3, 5) * 1 * >>> greatest_common_divisor(25, 15) * 5 * */ fun greatestCommonDivisor(a: Int, b: Int): Int {
greatestCommonDivisor
fun main() { var arg00: Int = 3 var arg01: Int = 7 var x0: Int = greatestCommonDivisor(arg00, arg01) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 10 var arg11: Int = 15 var x1: Int = greatestCommonDiv...
/** * You are an expert Kotlin programmer, and here is your task. * Return a greatest common divisor of two integers a and b * >>> greatest_common_divisor(3, 5) * 1 * >>> greatest_common_divisor(25, 15) * 5 * */
kotlin
[ "fun greatestCommonDivisor(a: Int, b: Int): Int {", " if (b == 0) {", " return a", " }", " return greatestCommonDivisor(b, a % b)", "}", "", "" ]
HumanEval_kotlin/104
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return a tuple that has the number of even and odd * integer palindromes that fall within the range(1, n), inclusive. * Example 1: * Input: 3 * Output: (1, 2) * Explanation: * Integer palindrome a...
evenOddPalindrome
fun main() { var arg00 : Int = 123 var x0 : List<Int> = evenOddPalindrome(arg00); var v0 : List<Int> = mutableListOf(8, 13); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 12 var x1 : List<Int> = evenOddPalindrome(arg10); ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return a tuple that has the number of even and odd * integer palindromes that fall within the range(1, n), inclusive. * Example 1: * Input: 3 * Output: (1, 2) * Explanation: * Integer palindrome a...
kotlin
[ "fun evenOddPalindrome(n : Int) : List<Int> {", " fun checkPalindrome(num: Int): Boolean {", " return num.toString() == num.toString().reversed()", " }", "\tval countEven = (1..n).count { it % 2 == 0 && checkPalindrome(it) }", " val countOdd = (1..n).count { it % 2 == 1 && checkPalindrome(...
HumanEval_kotlin/56
/** * You are an expert Kotlin programmer, and here is your task. * Return the largest prime factor of n. Assume n > 1 and is not a prime. * >>> largest_prime_factor(13195) * 29 * >>> largest_prime_factor(2048) * 2 * */ fun largestPrimeFactor(n: Int): Int {
largestPrimeFactor
fun main() { var arg00: Int = 15 var x0: Int = largestPrimeFactor(arg00) var v0: Int = 5 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 27 var x1: Int = largestPrimeFactor(arg10) var v1: Int = 3 if (x1 != v1) { ...
/** * You are an expert Kotlin programmer, and here is your task. * Return the largest prime factor of n. Assume n > 1 and is not a prime. * >>> largest_prime_factor(13195) * 29 * >>> largest_prime_factor(2048) * 2 * */
kotlin
[ "fun largestPrimeFactor(n: Int): Int {", " var curN = n", " var maxFactor = 1", " for (i in 2..n) {", " if (i * i > n) {", " break", " }", " while (curN % i == 0) {", " curN /= i", " maxFactor = i", " }", " }", " if ...
HumanEval_kotlin/1
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string containing multiple groups of nested parentheses. Your goal is to * separate those groups into separate strings and return the list of those. * Separate groups are balanced (each open brace is properly closed) and...
separateParenGroups
fun main() { var arg00: String = "(()()) ((())) () ((())()())" var x0: List<String> = separateParenGroups(arg00) var v0: List<String> = mutableListOf("(()())", "((()))", "()", "((())()())") if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10:...
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string containing multiple groups of nested parentheses. Your goal is to * separate those groups into separate strings and return the list of those. * Separate groups are balanced (each open brace is properly closed) and...
kotlin
[ "fun separateParenGroups(parenString: String): List<String> {", " var balance: Int = 0", " var currentString: String = \"\"", " val answer = mutableListOf<String>()", " parenString.forEachIndexed { index, char ->", " if (char == '(') {", " currentString += char", " ...
HumanEval_kotlin/66
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a non-empty list of positive integers. Return the greatest integer that is greater than * zero, and has a frequency greater than or equal to the value of the integer itself. * The frequency of an integer is the number of times it ap...
search
fun main() { var arg00: List<Int> = mutableListOf(5, 5, 5, 5, 1) var x0: Int = search(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(4, 1, 4, 1, 4, 4) var x1: Int = search(arg10) ...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a non-empty list of positive integers. Return the greatest integer that is greater than * zero, and has a frequency greater than or equal to the value of the integer itself. * The frequency of an integer is the number of times it ap...
kotlin
[ "fun search(lst: List<Int>): Int {", " val frequencyMap = lst.groupingBy { it }.eachCount()", " return frequencyMap.filter { it.key <= it.value }.keys.maxOrNull() ?: -1", "}", "" ]
HumanEval_kotlin/151
/** * You are an expert Kotlin programmer, and here is your task. * You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word * cycpattern_check("abcd","abd") => False * cycpattern_check("hello","ell") => True * cycpattern_check("whassup","psus") => ...
cycpatternCheck
fun main() { var arg00 : String = "xyzw" var arg01 : String = "xyw" var x0 : Boolean = cycpatternCheck(arg00, arg01); var v0 : Boolean = false; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "yello" var arg11 : String ...
/** * You are an expert Kotlin programmer, and here is your task. * You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word * cycpattern_check("abcd","abd") => False * cycpattern_check("hello","ell") => True * cycpattern_check("whassup","psus") => ...
kotlin
[ "fun cycpatternCheck(a : String, b : String) : Boolean {", " val rotations = mutableListOf<String>()", " for (i in b.indices) {", " val rotation = b.substring(i) + b.substring(0, i)", " rotations.add(rotation)", " }", " return rotations.any { rotation -> a.contains(rotation) }"...
HumanEval_kotlin/122
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you * should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the * alphabet, or...
splitWords
fun main() { var arg00 : String = "Hello world!" var x0 : Any = splitWords(arg00); var v0 : Any = mutableListOf("Hello", "world!"); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "Hello,world!" var x1 : Any = splitWords(ar...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you * should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the * alphabet, or...
kotlin
[ "fun splitWords(txt : String) : Any {", " if (txt.contains(\" \")) {", " return txt.split(\"\\\\s+\".toRegex())", " }", " if (txt.contains(\",\")) {", " return txt.split(\",\")", " }", " val count = txt.count { it in 'a'..'z' && (it - 'a') % 2 == 1 }", " return count"...
HumanEval_kotlin/5
/** * You are an expert Kotlin programmer, and here is your task. * Insert a number 'delimeter' between every two consecutive elements of input list `numbers' * >>> intersperse([], 4) * [] * >>> intersperse([1, 2, 3], 4) * [1, 4, 2, 4, 3] * */ fun intersperse(numbers: List<Any>, delimeter: Int): List<Any> {
intersperse
fun main() { var arg00: List<Any> = mutableListOf() var arg01: Int = 7 var x0: List<Any> = intersperse(arg00, arg01) var v0: List<Any> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Any> = mutableListOf(5, 6, ...
/** * You are an expert Kotlin programmer, and here is your task. * Insert a number 'delimeter' between every two consecutive elements of input list `numbers' * >>> intersperse([], 4) * [] * >>> intersperse([1, 2, 3], 4) * [1, 4, 2, 4, 3] * */
kotlin
[ "fun intersperse(numbers: List<Any>, delimeter: Int): List<Any> {", " return numbers.flatMapIndexed { index, value ->", " if (index == 0) {", " listOf(value)", " } else {", " listOf(delimeter, value)", " }", " }", "}", "", "" ]
HumanEval_kotlin/142
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function which sorts the given list of integers * in ascending order according to the sum of their digits. * Note: if there are several items with similar sum of their digits, * order them based on their index in original list. * For e...
orderByPoints
fun main() { var arg00 : List<Int> = mutableListOf(1, 11, -1, -11, -12) var x0 : List<Int> = orderByPoints(arg00); var v0 : List<Int> = mutableListOf(-1, -11, 1, -12, 11); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = muta...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function which sorts the given list of integers * in ascending order according to the sum of their digits. * Note: if there are several items with similar sum of their digits, * order them based on their index in original list. * For e...
kotlin
[ "fun orderByPoints(nums : List<Int>) : List<Int> {", " fun countDigitSum(num: Int): Int {", " val sign = if (num >= 0) 1 else -1", " var x = Math.abs(num)", " var digitSum = 0", " while (x > 0) {", " if (x < 10) {", " digitSum += x * sign", " ...
HumanEval_kotlin/48
/** * You are an expert Kotlin programmer, and here is your task. * * remove_vowels is a function that takes string and returns string without vowels. * >>> remove_vowels('') * '' * >>> remove_vowels("abcdef\nghijklm") * 'bcdf\nghjklm' * >>> remove_vowels('abcdef') * 'bcdf' * >>> remove_vowels('aaaaa') * '' ...
removeVowels
fun main() { var arg00: String = "" var x0: String = removeVowels(arg00) var v0: String = "" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "abcdef\nghijklm" var x1: String = removeVowels(arg10) var v1: String = "bcdf\n...
/** * You are an expert Kotlin programmer, and here is your task. * * remove_vowels is a function that takes string and returns string without vowels. * >>> remove_vowels('') * '' * >>> remove_vowels("abcdef\nghijklm") * 'bcdf\nghjklm' * >>> remove_vowels('abcdef') * 'bcdf' * >>> remove_vowels('aaaaa') * '' ...
kotlin
[ "fun removeVowels(text: String): String {", " val vowels = setOf('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')", " return text.filter { it !in vowels }", "}", "", "" ]
HumanEval_kotlin/155
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that accepts a list of strings. * The list contains different words. Return the word with maximum number * of unique characters. If multiple strings have maximum number of unique * characters, return the one which comes first in l...
findMax
fun main() { var arg00 : List<String> = mutableListOf("name", "of", "string") var x0 : String = findMax(arg00); var v0 : String = "string"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<String> = mutableListOf("name", "enam", "ga...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that accepts a list of strings. * The list contains different words. Return the word with maximum number * of unique characters. If multiple strings have maximum number of unique * characters, return the one which comes first in l...
kotlin
[ "fun findMax(words : List<String>) : String {", " var maxUniqueCharsWord = \"\"", " var maxUniqueCharsCount = 0", "", " for (word in words) {", " val uniqueCharsCount = word.toSet().size", " if (uniqueCharsCount > maxUniqueCharsCount ||", " (uniqueCharsCount == maxUni...
HumanEval_kotlin/125
/** * You are an expert Kotlin programmer, and here is your task. * * You are given an array arr of integers and you need to return * sum of magnitudes of integers multiplied by product of all signs * of each number in the array, represented by 1, -1 or 0. * Note: return for empty arr. * Example: * >>> prod_si...
prodSigns
fun main() { var arg00 : List<Int> = mutableListOf(1, 2, 2, -4) var x0 : Int? = prodSigns(arg00); var v0 : Int? = -9; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(0, 1) var x1 : Int? = prodSigns(arg10); ...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given an array arr of integers and you need to return * sum of magnitudes of integers multiplied by product of all signs * of each number in the array, represented by 1, -1 or 0. * Note: return for empty arr. * Example: * >>> prod_si...
kotlin
[ "fun prodSigns(arr : List<Int>) : Int? {", " if (arr.size == 0) {", " return null", " }", "\treturn arr.sumOf { Math.abs(it) } * if (0 in arr) 0 else if (arr.count { it < 0 } % 2 == 1) -1 else 1", "}", "", "" ]
HumanEval_kotlin/149
/** * You are an expert Kotlin programmer, and here is your task. * I think we all remember that feeling when the result of some long-awaited * event is finally known. The feelings and thoughts you have at that moment are * definitely worth noting down and comparing. * Your task is to determine if a person correct...
compare
fun main() { var arg00 : List<Int> = mutableListOf(1, 2, 3, 4, 5, 1) var arg01 : List<Int> = mutableListOf(1, 2, 3, 4, 2, -2) var x0 : List<Int> = compare(arg00, arg01); var v0 : List<Int> = mutableListOf(0, 0, 0, 0, 3, 3); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pa...
/** * You are an expert Kotlin programmer, and here is your task. * I think we all remember that feeling when the result of some long-awaited * event is finally known. The feelings and thoughts you have at that moment are * definitely worth noting down and comparing. * Your task is to determine if a person correct...
kotlin
[ "fun compare(game : List<Int>, guess : List<Int>) : List<Int> {", " return game.zip(guess) { score, guessed ->", " kotlin.math.abs(score - guessed)", " }", "}", "", "" ]
HumanEval_kotlin/139
/** * You are an expert Kotlin programmer, and here is your task. * " * This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a * multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The ...
sumSquares
fun main() { var arg00 : List<Int> = mutableListOf(1, 2, 3) var x0 : Int = sumSquares(arg00); var v0 : Int = 6; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(1, 4, 9) var x1 : Int = sumSquares(arg10); ...
/** * You are an expert Kotlin programmer, and here is your task. * " * This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a * multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The ...
kotlin
[ "fun sumSquares(lst : List<Int>) : Int {", " return lst.mapIndexed { index, value ->", " when {", " index % 3 == 0 -> value * value", " index % 4 == 0 -> value * value * value", " else -> value", " }", " }.sum()", "}", "", "" ]
HumanEval_kotlin/131
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that returns True if the last character * of a given string is an alphabetical character and is not * a part of a word, and False otherwise. * Note: "word" is a group of characters separated by space. * Examples: * check_if_...
checkIfLastCharIsALetter
fun main() { var arg00: String = "apple" var x0: Boolean = checkIfLastCharIsALetter(arg00); var v0: Boolean = false; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "apple pi e" var x1: Boolean = checkIfLastCharIsALetter(arg...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that returns True if the last character * of a given string is an alphabetical character and is not * a part of a word, and False otherwise. * Note: "word" is a group of characters separated by space. * Examples: * check_if_...
kotlin
[ "fun checkIfLastCharIsALetter(txt: String): Boolean {", " fun alphabeticChar(c: Char) = 'a' <= c.lowercaseChar() && c.lowercaseChar() <= 'z'", " return txt.isNotEmpty() && alphabeticChar(txt.last()) && (txt.length == 1 || !alphabeticChar(txt[txt.length - 2]))", "}", "", "" ]
HumanEval_kotlin/156
/** * You are an expert Kotlin programmer, and here is your task. * * You're a hungry rabbit, and you already have eaten a certain number of carrots, * but now you need to eat more carrots to complete the day's meals. * you should return an array of [ total number of eaten carrots after your meals, * ...
eat
fun main() { var arg00 : Int = 5 var arg01 : Int = 6 var arg02 : Int = 10 var x0 : List<Int> = eat(arg00, arg01, arg02); var v0 : List<Int> = mutableListOf(11, 4); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 4 var ...
/** * You are an expert Kotlin programmer, and here is your task. * * You're a hungry rabbit, and you already have eaten a certain number of carrots, * but now you need to eat more carrots to complete the day's meals. * you should return an array of [ total number of eaten carrots after your meals, * ...
kotlin
[ "fun eat(number : Int, need : Int, remaining : Int) : List<Int> {", "\tval totalEaten = if (need <= remaining) number + need else number + remaining", " val carrotsLeft = if (need <= remaining) remaining - need else 0", " return listOf(totalEaten, carrotsLeft)", "}", "", "" ]
HumanEval_kotlin/41
/** * You are an expert Kotlin programmer, and here is your task. * * pairs_sum_to_zero takes a list of integers as an input. * it returns True if there are two distinct elements in the list that * sum to zero, and False otherwise. * >>> pairs_sum_to_zero([1, 3, 5, 0]) * False * >>> pairs_sum_to_zero([1, 3, -2, ...
pairsSumToZero
fun main() { var arg00: List<Int> = mutableListOf(1, 3, 5, 0) var x0: Boolean = pairsSumToZero(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, 3, -2, 1) var x1: Boolean = pa...
/** * You are an expert Kotlin programmer, and here is your task. * * pairs_sum_to_zero takes a list of integers as an input. * it returns True if there are two distinct elements in the list that * sum to zero, and False otherwise. * >>> pairs_sum_to_zero([1, 3, 5, 0]) * False * >>> pairs_sum_to_zero([1, 3, -2, ...
kotlin
[ "fun pairsSumToZero(l: List<Int>): Boolean {", " if (l.count { it == 0 } >= 2) {", " return true", " }", " val valueSet = l.toSet()", " valueSet.forEach { value ->", " if (value != 0 && valueSet.contains(-value)) {", " return true", " }", " }", " ...
HumanEval_kotlin/110
/** * You are an expert Kotlin programmer, and here is your task. * Given a list of strings, where each string consists of only digits, return a list. * Each element i of the output should be "the number of odd elements in the * string i of the input." where all the i's should be replaced by the number * of odd di...
oddCount
fun main() { var arg00 : List<String> = mutableListOf("1234567") var x0 : List<String> = oddCount(arg00); var v0 : List<String> = mutableListOf("the number of odd elements 4n the str4ng 4 of the 4nput."); 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. * Given a list of strings, where each string consists of only digits, return a list. * Each element i of the output should be "the number of odd elements in the * string i of the input." where all the i's should be replaced by the number * of odd di...
kotlin
[ "fun oddCount(lst : List<String>) : List<String> {", " return lst.map { str ->", " val oddCount = str.count { it in listOf('1', '3', '5', '7', '9') }", " \"the number of odd elements ${oddCount}n the str${oddCount}ng ${oddCount} of the ${oddCount}nput.\"", " }", "}", "", "" ]
HumanEval_kotlin/28
/** * You are an expert Kotlin programmer, and here is your task. * Concatenate list of strings into a single string * >>> concatenate([]) * '' * >>> concatenate(['a', 'b', 'c']) * 'abc' * */ fun concatenate(strings: List<String>): String {
concatenate
fun main() { var arg00: List<String> = mutableListOf() var x0: String = concatenate(arg00) var v0: String = "" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<String> = mutableListOf("x", "y", "z") var x1: String = concatenate(a...
/** * You are an expert Kotlin programmer, and here is your task. * Concatenate list of strings into a single string * >>> concatenate([]) * '' * >>> concatenate(['a', 'b', 'c']) * 'abc' * */
kotlin
[ "fun concatenate(strings: List<String>): String {", " return strings.joinToString(\"\")", "}", "", "" ]
HumanEval_kotlin/114
/** * You are an expert Kotlin programmer, and here is your task. * Given a string s and a natural number n, you have been tasked to implement * a function that returns a list of all words from string s that contain exactly * n consonants, in order these words appear in the string s. * If the string s is empty t...
selectWords
fun main() { var arg00 : String = "Mary had a little lamb" var arg01 : Int = 4 var x0 : List<Any> = selectWords(arg00, arg01); var v0 : List<Any> = mutableListOf("little"); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "M...
/** * You are an expert Kotlin programmer, and here is your task. * Given a string s and a natural number n, you have been tasked to implement * a function that returns a list of all words from string s that contain exactly * n consonants, in order these words appear in the string s. * If the string s is empty t...
kotlin
[ "fun selectWords(s : String, n : Int) : List<Any> {", " val vowels = setOf('a', 'e', 'i', 'o', 'u')", " return s.split(\" \").filter { word -> word.lowercase().count { c -> c !in vowels } == n }", "}", "", "" ]
HumanEval_kotlin/45
/** * You are an expert Kotlin programmer, and here is your task. * Return median of elements in the list l. * >>> median([3, 1, 2, 4, 5]) * 3 * >>> median([-10, 4, 6, 1000, 10, 20]) * 15.0 * */ fun median(l: List<Int>): Double {
median
fun main() { var arg00: List<Int> = mutableListOf(3, 1, 2, 4, 5) var x0: Double = median(arg00) var v0: Double = 3.0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(-10, 4, 6, 1000, 10, 20) var x1: Double = ...
/** * You are an expert Kotlin programmer, and here is your task. * Return median of elements in the list l. * >>> median([3, 1, 2, 4, 5]) * 3 * >>> median([-10, 4, 6, 1000, 10, 20]) * 15.0 * */
kotlin
[ "fun median(l: List<Int>): Double {", " val sortedList = l.sorted()", " val middle = sortedList.size / 2", "", " return if (sortedList.size % 2 == 0) {", " (sortedList[middle - 1] + sortedList[middle]) / 2.0", " } else {", " sortedList[middle].toDouble()", " }", "}", ...
HumanEval_kotlin/116
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a list of two strings, both strings consist of open * parentheses '(' or close parentheses ')' only. * Your job is to check if it is possible to concatenate the two strings in * some order, that the resulting string will be good. ...
matchParens
fun main() { var arg00 : List<String> = mutableListOf("()(", ")") var x0 : String = matchParens(arg00); var v0 : String = "Yes"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<String> = mutableListOf(")", ")") var x1 : String ...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a list of two strings, both strings consist of open * parentheses '(' or close parentheses ')' only. * Your job is to check if it is possible to concatenate the two strings in * some order, that the resulting string will be good. ...
kotlin
[ "fun matchParens(lst : List<String>) : String {", "\tfun checkGood(str: String): Boolean {", " val balance = str.runningFold(0) { sum, c ->", " if (c == '(') {", " sum + 1", " } else {", " sum - 1", " }", " }", " r...
HumanEval_kotlin/147
/** * You are an expert Kotlin programmer, and here is your task. * A simple program which should return the value of x if n is * a prime number and should return the value of y otherwise. * Examples: * for x_or_y(7, 34, 12) == 34 * for x_or_y(15, 8, 5) == 5 * * */ fun xOrY(n : Int, x : Int, y : Int) : Int ...
xOrY
fun main() { var arg00 : Int = 7 var arg01 : Int = 34 var arg02 : Int = 12 var x0 : Int = xOrY(arg00, arg01, arg02); var v0 : Int = 34; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 15 var arg11 : Int = 8 var arg...
/** * You are an expert Kotlin programmer, and here is your task. * A simple program which should return the value of x if n is * a prime number and should return the value of y otherwise. * Examples: * for x_or_y(7, 34, 12) == 34 * for x_or_y(15, 8, 5) == 5 * * */
kotlin
[ "fun xOrY(n : Int, x : Int, y : Int) : Int {", " 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/117
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array arr of integers and a positive integer k, return a sorted list * of length k with the maximum k numbers in arr. * Example 1: * Input: arr = [-3, -4, 5], k = 3 * Output: [-4, -3, 5] * Example 2: * Input: arr = [...
maximum
fun main() { var arg00 : List<Int> = mutableListOf(-3, -4, 5) var arg01 : Int = 3 var x0 : List<Any> = maximum(arg00, arg01); var v0 : List<Any> = mutableListOf(-4, -3, 5); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> =...
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array arr of integers and a positive integer k, return a sorted list * of length k with the maximum k numbers in arr. * Example 1: * Input: arr = [-3, -4, 5], k = 3 * Output: [-4, -3, 5] * Example 2: * Input: arr = [...
kotlin
[ "fun maximum(arr : List<Int>, k : Int) : List<Any> {", "\treturn arr.sorted().takeLast(k)", "}", "", "" ]
HumanEval_kotlin/109
/** * You are an expert Kotlin programmer, and here is your task. * Task * We are given two strings s and c. You have to delete all the characters in s that are equal to any character in c * then check if the result string is palindrome. * A string is called palindrome if it reads the same backward as forward. * ...
reverseDelete
fun main() { var arg00 : String = "abcde" var arg01 : String = "ae" var x0 : Pair<String, Boolean> = reverseDelete(arg00, arg01); var v0 : Pair<String, Boolean> = Pair("bcd", false) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : St...
/** * You are an expert Kotlin programmer, and here is your task. * Task * We are given two strings s and c. You have to delete all the characters in s that are equal to any character in c * then check if the result string is palindrome. * A string is called palindrome if it reads the same backward as forward. * ...
kotlin
[ "fun reverseDelete(s : String, c : String) : Pair<String, Boolean> {", "\tval cleanedString = s.filter { it !in c }", " return Pair(cleanedString, cleanedString == cleanedString.reversed())", "}", "", "" ]
HumanEval_kotlin/112
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a rectangular grid of wells. Each row represents a single well, * and each 1 in a row represents a single unit of water. * Each well has a corresponding bucket that can be used to extract water from it, * and all buckets have the ...
maxFill
fun main() { var arg00 : List<List<Int>> = mutableListOf(mutableListOf(0, 0, 1, 0), mutableListOf(0, 1, 0, 0), mutableListOf(1, 1, 1, 1)) var arg01 : Int = 1 var x0 : Int = maxFill(arg00, arg01); var v0 : Int = 6; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = "...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a rectangular grid of wells. Each row represents a single well, * and each 1 in a row represents a single unit of water. * Each well has a corresponding bucket that can be used to extract water from it, * and all buckets have the ...
kotlin
[ "fun maxFill(grid : List<List<Int>>, capacity : Int) : Int {", " val compressedWells = grid.map { row -> row.count { it == 1 } }", " return compressedWells.sumOf { wellSize -> (wellSize + capacity - 1) / capacity }", "}", "", "" ]
HumanEval_kotlin/55
/** * You are an expert Kotlin programmer, and here is your task. * Return sorted unique common elements for two lists. * >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) * [1, 5, 653] * >>> common([5, 3, 2, 8], [3, 2]) * [2, 3] * */ fun common(l1: List<Int>, l2: List<Int>): List<Int> {
common
fun main() { var arg00: List<Int> = mutableListOf(1, 4, 3, 34, 653, 2, 5) var arg01: List<Int> = mutableListOf(5, 7, 1, 5, 9, 653, 121) var x0: List<Int> = common(arg00, arg01) var v0: List<Int> = mutableListOf(1, 5, 653) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass...
/** * You are an expert Kotlin programmer, and here is your task. * Return sorted unique common elements for two lists. * >>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]) * [1, 5, 653] * >>> common([5, 3, 2, 8], [3, 2]) * [2, 3] * */
kotlin
[ "fun common(l1: List<Int>, l2: List<Int>): List<Int> {", " return l1.toSet().intersect(l2.toSet()).toList().sorted()", "}", "", "" ]
HumanEval_kotlin/36
/** * 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 odd indicies, while its values at the even indicies are equal * to the values of the even indicies of l, but sorted. * >>> sort_even([1, 2, 3]) * [1, 2, 3]...
sortEven
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 3) var x0: List<Int> = sortEven(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 odd indicies, while its values at the even indicies are equal * to the values of the even indicies of l, but sorted. * >>> sort_even([1, 2, 3]) * [1, 2, 3]...
kotlin
[ "fun sortEven(l: List<Int>): List<Int> {", " val sortedEvens = l.withIndex()", " .filter { (index, _) -> (index % 2) == 0 }", " .map { it.value }", " .sorted()", " return l.mapIndexed { index, value ->", " if (index % 2 == 0) sortedEvens[index / 2] else value", " }...
HumanEval_kotlin/68
/** * You are an expert Kotlin programmer, and here is your task. * * Given the lengths of the three sides of a triangle. Return the area of * the triangle rounded to 2 decimal points if the three sides form a valid triangle. * Otherwise return -1 * Three sides make a valid triangle when the sum of any two sides i...
triangleArea
fun main() { var arg00: Int = 3 var arg01: Int = 4 var arg02: Int = 5 var x0: Any = triangleArea(arg00, arg01, arg02) var v0: Any = 6.0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 1 var arg11: Int = 2 var arg12:...
/** * You are an expert Kotlin programmer, and here is your task. * * Given the lengths of the three sides of a triangle. Return the area of * the triangle rounded to 2 decimal points if the three sides form a valid triangle. * Otherwise return -1 * Three sides make a valid triangle when the sum of any two sides i...
kotlin
[ "fun triangleArea(a: Int, b: Int, c: Int): Any {", " if (a + b <= c || a + c <= b || b + c <= a) {", " return -1", " }", "", " val s = (a + b + c) / 2.0", " val area = Math.sqrt(s * (s - a) * (s - b) * (s - c))", " return String.format(\"%.2f\", area).toDouble()", "}", "", ...
HumanEval_kotlin/60
/** * You are an expert Kotlin programmer, and here is your task. * The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: * fibfib(0) == 0 * fibfib(1) == 0 * fibfib(2) == 1 * fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). * Please write a function to effici...
fibfib
fun main() { var arg00: Int = 2 var x0: Int = fibfib(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 1 var x1: Int = fibfib(arg10) var v1: Int = 0 if (x1 != v1) { throw Exception("Exceptio...
/** * You are an expert Kotlin programmer, and here is your task. * The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: * fibfib(0) == 0 * fibfib(1) == 0 * fibfib(2) == 1 * fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). * Please write a function to effici...
kotlin
[ "fun fibfib(n: Int): Int {", " val fibs = mutableListOf(0, 0, 1)", " var index = 0", " while (fibs.size <= n) {", " fibs.add(fibs[index] + fibs[index + 1] + fibs[index + 2])", " index++", " }", " return fibs[n]", "}", "", "" ]
HumanEval_kotlin/101
/** * You are an expert Kotlin programmer, and here is your task. * Given a list of positive integers x. return a sorted list of all * elements that hasn't any even digit. * Note: Returned list should be sorted in increasing order. * * For example: * >>> unique_digits([15, 33, 1422, 1]) * [1, 15, 33] * >>> un...
uniqueDigits
fun main() { var arg00: List<Int> = mutableListOf(15, 33, 1422, 1) var x0: List<Int> = uniqueDigits(arg00); var v0: List<Int> = mutableListOf(1, 15, 33); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(152, 323,...
/** * You are an expert Kotlin programmer, and here is your task. * Given a list of positive integers x. return a sorted list of all * elements that hasn't any even digit. * Note: Returned list should be sorted in increasing order. * * For example: * >>> unique_digits([15, 33, 1422, 1]) * [1, 15, 33] * >>> un...
kotlin
[ "fun uniqueDigits(x: List<Int>): List<Int> {", " return x.filter { num ->", " num.toString().all { it.digitToInt() % 2 != 0 }", " }.sorted()", "}", "", "" ]
HumanEval_kotlin/19
/** * You are an expert Kotlin programmer, and here is your task. * Input is a space-delimited string of numberals from 'zero' to 'nine'. * Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. * Return the string with numbers sorted from smallest to largest * >>> sor...
sortNumbers
fun main() { var arg00: String = "" var x0: String = sortNumbers(arg00) var v0: String = "" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "three" var x1: String = sortNumbers(arg10) var v1: String = "three" if (x1 ...
/** * You are an expert Kotlin programmer, and here is your task. * Input is a space-delimited string of numberals from 'zero' to 'nine'. * Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. * Return the string with numbers sorted from smallest to largest * >>> sor...
kotlin
[ "fun sortNumbers(numbers: String): String {", " val mapping = mapOf(", " \"zero\" to 0,", " \"one\" to 1,", " \"two\" to 2,", " \"three\" to 3,", " \"four\" to 4,", " \"five\" to 5,", " \"six\" to 6,", " \"seven\" to 7,", " \"eigh...
HumanEval_kotlin/97
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, you have to make a pile of n levels of stones. * The first level has n stones. * The number of stones in the next level is: * - the next odd number if n is odd. * - the next even number if n is even. * Retur...
makeAPile
fun main() { var arg00: Int = 3 var x0: List<Int> = makeAPile(arg00) var v0: List<Int> = mutableListOf(3, 5, 7) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 4 var x1: List<Int> = makeAPile(arg10) var v1: List<Int> = muta...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, you have to make a pile of n levels of stones. * The first level has n stones. * The number of stones in the next level is: * - the next odd number if n is odd. * - the next even number if n is even. * Retur...
kotlin
[ "fun makeAPile(n: Int): List<Int> {", " return (0 until n).map { n + it * 2 }", "}", "", "" ]
HumanEval_kotlin/126
/** * You are an expert Kotlin programmer, and here is your task. * * Given a grid with N rows and N columns (N >= 2) and a positive integer k, * each cell of the grid contains a value. Every integer in the range [1, N * N] * inclusive appears exactly once on the cells of the grid. * You have to find the minimum...
minpath
fun main() { var arg00 : List<List<Int>> = mutableListOf(mutableListOf(1, 2, 3), mutableListOf(4, 5, 6), mutableListOf(7, 8, 9)) var arg01 : Int = 3 var x0 : List<Int> = minpath(arg00, arg01); var v0 : List<Int> = mutableListOf(1, 2, 1); if (x0 != v0) { throw Exception("Exception -- test cas...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a grid with N rows and N columns (N >= 2) and a positive integer k, * each cell of the grid contains a value. Every integer in the range [1, N * N] * inclusive appears exactly once on the cells of the grid. * You have to find the minimum...
kotlin
[ "fun minpath(grid : List<List<Int>>, k : Int) : List<Int> {", " val n = grid.size", " var bestPath = List(k) { Int.MAX_VALUE }", "", " fun dfs(x: Int, y: Int, step: Int, path: MutableList<Int>) {", " if (step == k) {", " for (i in 0 until k) {", " if (path[i] ...
HumanEval_kotlin/134
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes integers, floats, or strings representing * real numbers, and returns the larger variable in its given variable type. * Return if the values are equal. * Note: If a real number is represented as a string, the floati...
compareOne
fun main() { var arg00 : Any = 1 var arg01 : Any = 2 var x0 : Any? = compareOne(arg00, arg01); var v0 : Any? = 2; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Any = 1 var arg11 : Any = 2.5 var x1 : Any? = compareOne(arg10...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes integers, floats, or strings representing * real numbers, and returns the larger variable in its given variable type. * Return if the values are equal. * Note: If a real number is represented as a string, the floati...
kotlin
[ "fun compareOne(a : Any, b : Any) : Any? {", "\tfun toNumber(x: Any): Double {", " if (x is String) {", " return x.replace(',', '.').toDouble()", " }", " if (x is Double) {", " return x", " }", " if (x is Int) {", " return x.toDou...
HumanEval_kotlin/136
/** * You are an expert Kotlin programmer, and here is your task. * The Brazilian factorial is defined as: * brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! * where n > 0 * For example: * >>> special_factorial(4) * 288 * The function will receive an integer as input and should return the special * f...
specialFactorial
fun main() { var arg00 : Long = 4 var x0 : Long = specialFactorial(arg00); var v0 : Long = 288; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Long = 5 var x1 : Long = specialFactorial(arg10); var v1 : Long = 34560; if (x1 ...
/** * You are an expert Kotlin programmer, and here is your task. * The Brazilian factorial is defined as: * brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! * where n > 0 * For example: * >>> special_factorial(4) * 288 * The function will receive an integer as input and should return the special * f...
kotlin
[ "fun specialFactorial(n : Long) : Long {", " fun factorial(n: Long): Long {", " return if (n <= 1) 1 else n * factorial(n - 1)", " }", " var result = 1L", " for (i in 1..n) {", " result *= factorial(i)", " }", " return result", "}", "", "" ]
HumanEval_kotlin/7
/** * You are an expert Kotlin programmer, and here is your task. * Filter an input list of strings only for ones that contain given substring * >>> filter_by_substring([], 'a') * [] * >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a') * ['abc', 'bacd', 'array'] * */ fun filterBySubstring(strings: Li...
filterBySubstring
fun main() { var arg00: List<String> = mutableListOf() var arg01: String = "john" var x0: List<String> = filterBySubstring(arg00, arg01) var v0: List<String> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Stri...
/** * You are an expert Kotlin programmer, and here is your task. * Filter an input list of strings only for ones that contain given substring * >>> filter_by_substring([], 'a') * [] * >>> filter_by_substring(['abc', 'bacd', 'cde', 'array'], 'a') * ['abc', 'bacd', 'array'] * */
kotlin
[ "fun filterBySubstring(strings: List<String>, substring: String): List<String> {", " return strings.filter { it.contains(substring) }", "}", "", "" ]
HumanEval_kotlin/47
/** * You are an expert Kotlin programmer, and here is your task. * Return 2^n modulo p (be aware of numerics). * >>> modp(3, 5) * 3 * >>> modp(1101, 101) * 2 * >>> modp(0, 101) * 1 * >>> modp(3, 11) * 8 * >>> modp(100, 101) * 1 * */ fun modp(n: Int, p: Int): Int {
modp
fun main() { var arg00: Int = 3 var arg01: Int = 5 var x0: Int = modp(arg00, arg01) var v0: Int = 3 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 1101 var arg11: Int = 101 var x1: Int = modp(arg10, arg11) var v1: ...
/** * You are an expert Kotlin programmer, and here is your task. * Return 2^n modulo p (be aware of numerics). * >>> modp(3, 5) * 3 * >>> modp(1101, 101) * 2 * >>> modp(0, 101) * 1 * >>> modp(3, 11) * 8 * >>> modp(100, 101) * 1 * */
kotlin
[ "fun modp(n: Int, p: Int): Int {", " var answer = 1", " repeat(n) {", " answer = (answer * 2) % p", " }", " return answer", "}", "", "" ]
HumanEval_kotlin/8
/** * You are an expert Kotlin programmer, and here is your task. * For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. * Empty sum should be equal to 0 and empty product should be equal to 1. * >>> sum_product([]) * (0, 1) * >>> sum_product([1, 2, 3, 4]) ...
sumProduct
fun main() { var arg00: List<Int> = mutableListOf() var x0: List<Int> = sumProduct(arg00) var v0: List<Int> = mutableListOf(0, 1) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 1, 1) var x1: List<Int> = ...
/** * You are an expert Kotlin programmer, and here is your task. * For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. * Empty sum should be equal to 0 and empty product should be equal to 1. * >>> sum_product([]) * (0, 1) * >>> sum_product([1, 2, 3, 4]) ...
kotlin
[ "fun sumProduct(numbers: List<Int>): List<Int> {", " val sum = numbers.sum()", " val prod = numbers.fold(1) { prod, value -> prod * value }", " return listOf(sum, prod)", "}", "", "" ]