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/25
/** * You are an expert Kotlin programmer, and here is your task. * Return list of prime factors of given integer in the order from smallest to largest. * Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. * Input number should be equal to the product ...
factorize
fun main() { var arg00: Int = 2 var x0: List<Int> = factorize(arg00) var v0: List<Int> = mutableListOf(2) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 4 var x1: List<Int> = factorize(arg10) var v1: List<Int> = mutableLis...
/** * You are an expert Kotlin programmer, and here is your task. * Return list of prime factors of given integer in the order from smallest to largest. * Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. * Input number should be equal to the product ...
kotlin
[ "fun factorize(n: Int): List<Int> {", " var curN = n", " val factors = mutableListOf<Int>()", " for (i in 2..n) {", " if (i * i > n) {", " break", " }", " while (curN % i == 0) {", " curN /= i", " factors.add(i)", " }", " ...
HumanEval_kotlin/69
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that returns True if the object q will fly, and False otherwise. * The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w. * Example: * ...
willItFly
fun main() { var arg00: List<Int> = mutableListOf(3, 2, 3) var arg01: Int = 9 var x0: Boolean = willItFly(arg00, arg01) 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) var ar...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that returns True if the object q will fly, and False otherwise. * The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w. * Example: * ...
kotlin
[ "fun willItFly(q: List<Int>, w: Int): Boolean {", " val isPalindromic = q == q.reversed()", " val sum = q.sum()", " return isPalindromic && sum <= w", "}", "", "" ]
HumanEval_kotlin/52
/** * You are an expert Kotlin programmer, and here is your task. * Return n-th Fibonacci number. * >>> fib(10) * 55 * >>> fib(1) * 1 * >>> fib(8) * 21 * */ fun fib(n: Int): Int {
fib
fun main() { var arg00: Int = 10 var x0: Int = fib(arg00) var v0: Int = 55 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 1 var x1: Int = fib(arg10) var v1: Int = 1 if (x1 != v1) { throw Exception("Exception --...
/** * You are an expert Kotlin programmer, and here is your task. * Return n-th Fibonacci number. * >>> fib(10) * 55 * >>> fib(1) * 1 * >>> fib(8) * 21 * */
kotlin
[ "fun fib(n: Int): Int {", " val fibs = mutableListOf(0, 1)", " while (fibs.size <= n) {", " fibs.add(fibs[fibs.size - 2] + fibs[fibs.size - 1])", " }", " return fibs[n]", "}", "", "" ]
HumanEval_kotlin/6
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string represented multiple groups for nested parentheses separated by spaces. * For each of the group, output the deepest level of nesting of parentheses. * E.g. (()()) has maximum two levels of nesting while ((())) has...
parseNestedParens
fun main() { var arg00: String = "(()()) ((())) () ((())()())" var x0: List<Int> = parseNestedParens(arg00) var v0: List<Int> = mutableListOf(2, 3, 1, 3) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "() (()) ((())) (((())))" ...
/** * You are an expert Kotlin programmer, and here is your task. * Input to this function is a string represented multiple groups for nested parentheses separated by spaces. * For each of the group, output the deepest level of nesting of parentheses. * E.g. (()()) has maximum two levels of nesting while ((())) has...
kotlin
[ "fun parseNestedParens(parenString: String): List<Int> {", " return parenString.split(\" \").map {", " it.runningFold(0) { balance, char ->", " when (char) {", " '(' -> {", " balance + 1", " }", "", " ')' -> {", "...
HumanEval_kotlin/73
/** * You are an expert Kotlin programmer, and here is your task. * Your task is to write a function that returns true if a number x is a simple * power of n and false in other cases. * x is a simple power of n if n**int=x * For example: * is_simple_power(1, 4) => true * is_simple_power(2, 2) => true * is_simpl...
isSimplePower
fun main() { var arg00: Int = 16 var arg01: Int = 2 var x0: Boolean = isSimplePower(arg00, arg01) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 143214 var arg11: Int = 16 var x1: Boolean = isSim...
/** * You are an expert Kotlin programmer, and here is your task. * Your task is to write a function that returns true if a number x is a simple * power of n and false in other cases. * x is a simple power of n if n**int=x * For example: * is_simple_power(1, 4) => true * is_simple_power(2, 2) => true * is_simpl...
kotlin
[ "fun isSimplePower(x: Int, n: Int): Boolean {", " var cur = x", " while (cur > 1 && n > 1 && cur % n == 0) {", " cur /= n", " }", " return cur == 1", "}", "", "" ]
HumanEval_kotlin/83
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes a string and returns an ordered version of it. * Ordered version of a string is a string where all words (separated by space) * are replaced by a new word where all the characters are arranged in * ascending order bas...
antiShuffle
fun main() { var arg00: String = "Hi" var x0: String = antiShuffle(arg00) var v0: String = "Hi" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "hello" var x1: String = antiShuffle(arg10) var v1: String = "ehllo" if ...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function that takes a string and returns an ordered version of it. * Ordered version of a string is a string where all words (separated by space) * are replaced by a new word where all the characters are arranged in * ascending order bas...
kotlin
[ "fun antiShuffle(s: String): String {", " val words = s.split(\" \")", " val sortedWords = words.map { word ->", " if (word.trim().isNotEmpty()) word.toCharArray().sorted().joinToString(\"\") else word", " }", " return sortedWords.joinToString(\" \")", "}", "", "" ]
HumanEval_kotlin/22
/** * You are an expert Kotlin programmer, and here is your task. * Filter given list of any Kotlin values only for integers * >>> filter_integers(['a', 3.14, 5]) * [5] * >>> filter_integers([1, 2, 3, 'abc', {}, []]) * [1, 2, 3] * */ fun filterIntegers(values: List<Any>): List<Any> {
filterIntegers
fun main() { var arg00: List<Any> = mutableListOf() var x0: List<Any> = filterIntegers(arg00) var v0: List<Any> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Any> = mutableListOf(4, mutableMapOf<Any, Any>(), muta...
/** * You are an expert Kotlin programmer, and here is your task. * Filter given list of any Kotlin values only for integers * >>> filter_integers(['a', 3.14, 5]) * [5] * >>> filter_integers([1, 2, 3, 'abc', {}, []]) * [1, 2, 3] * */
kotlin
[ "fun filterIntegers(values: List<Any>): List<Any> {", " return values.filterIsInstance<Int>()", "}", "", "" ]
HumanEval_kotlin/26
/** * You are an expert Kotlin programmer, and here is your task. * From a list of integers, remove all elements that occur more than once. * Keep order of elements left the same as in the input. * >>> remove_duplicates([1, 2, 3, 2, 4]) * [1, 3, 4] * */ fun removeDuplicates(numbers: List<Int>): List<Int> {
removeDuplicates
fun main() { var arg00: List<Int> = mutableListOf() var x0: List<Int> = removeDuplicates(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(1, 2, 3, 4) var x1: List<In...
/** * You are an expert Kotlin programmer, and here is your task. * From a list of integers, remove all elements that occur more than once. * Keep order of elements left the same as in the input. * >>> remove_duplicates([1, 2, 3, 2, 4]) * [1, 3, 4] * */
kotlin
[ "fun removeDuplicates(numbers: List<Int>): List<Int> {", " val occurrenceMap = numbers.groupingBy { it }.eachCount()", " return numbers.filter { occurrenceMap[it] == 1 }", "}", "", "" ]
HumanEval_kotlin/105
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function count_nums which takes an array of integers and returns * the number of elements which has a sum of digits > 0. * If a number is negative, then its first signed digit will be negative: * e.g. -123 has signed digits -1, 2, and 3....
countNums
fun main() { var arg00: List<Int> = mutableListOf() var x0: Int = countNums(arg00); var v0: Int = 0; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(-1, -2, 0) var x1: Int = countNums(arg10); var v1: Int...
/** * You are an expert Kotlin programmer, and here is your task. * * Write a function count_nums which takes an array of integers and returns * the number of elements which has a sum of digits > 0. * If a number is negative, then its first signed digit will be negative: * e.g. -123 has signed digits -1, 2, and 3....
kotlin
[ "fun countNums(arr: List<Int>): 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/35
/** * You are an expert Kotlin programmer, and here is your task. * Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. * >>> fizz_buzz(50) * 0 * >>> fizz_buzz(78) * 2 * >>> fizz_buzz(79) * 3 * */ fun fizzBuzz(n: Int): Int {
fizzBuzz
fun main() { var arg00: Int = 50 var x0: Int = fizzBuzz(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 78 var x1: Int = fizzBuzz(arg10) var v1: Int = 2 if (x1 != v1) { throw Exception("Ex...
/** * You are an expert Kotlin programmer, and here is your task. * Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. * >>> fizz_buzz(50) * 0 * >>> fizz_buzz(78) * 2 * >>> fizz_buzz(79) * 3 * */
kotlin
[ "fun fizzBuzz(n: Int): Int {", " return (1 until n).map { value ->", " if (value % 11 == 0 || value % 13 == 0) {", " value.toString().count { c -> c == '7' }", " } else {", " 0", " }", " }.sum()", "}", "", "" ]
HumanEval_kotlin/30
/** * You are an expert Kotlin programmer, and here is your task. * Return only positive numbers in the list. * >>> get_positive([-1, 2, -4, 5, 6]) * [2, 5, 6] * >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) * [5, 3, 2, 3, 9, 123, 1] * */ fun getPositive(l: List<Int>): List<Int> {
getPositive
fun main() { var arg00: List<Int> = mutableListOf(-1, -2, 4, 5, 6) var x0: List<Int> = getPositive(arg00) var v0: List<Int> = mutableListOf(4, 5, 6) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 3, -5, 2, 3...
/** * You are an expert Kotlin programmer, and here is your task. * Return only positive numbers in the list. * >>> get_positive([-1, 2, -4, 5, 6]) * [2, 5, 6] * >>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10]) * [5, 3, 2, 3, 9, 123, 1] * */
kotlin
[ "fun getPositive(l: List<Int>): List<Int> {", " return l.filter { it > 0 }", "}", "", "" ]
HumanEval_kotlin/80
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return the count of the numbers of n-digit * positive integers that start or end with 1. * */ fun startsOneEnds(n: Int): Int {
startsOneEnds
fun main() { var arg00: Int = 1 var x0: Int = startsOneEnds(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 2 var x1: Int = startsOneEnds(arg10) var v1: Int = 18 if (x1 != v1) { throw Exce...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return the count of the numbers of n-digit * positive integers that start or end with 1. * */
kotlin
[ "fun startsOneEnds(n: Int): Int {", " if (n == 1) {", " return 1", " }", " var answer = 18", " repeat(n - 2) {", " answer *= 10", " }", " return answer", "}", "", "" ]
HumanEval_kotlin/11
/** * You are an expert Kotlin programmer, and here is your task. * Input are two strings a and b consisting only of 1s and 0s. * Perform binary XOR on these inputs and return result also as a string. * >>> string_xor('010', '110') * '100' * */ fun stringXor(a: String, b: String): String {
stringXor
fun main() { var arg00: String = "111000" var arg01: String = "101010" var x0: String = stringXor(arg00, arg01) var v0: String = "010010" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "1" var arg11: String = "1" va...
/** * You are an expert Kotlin programmer, and here is your task. * Input are two strings a and b consisting only of 1s and 0s. * Perform binary XOR on these inputs and return result also as a string. * >>> string_xor('010', '110') * '100' * */
kotlin
[ "fun stringXor(a: String, b: String): String {", " return a.indices.map { index ->", " if (a[index] == b[index]) '0' else '1'", " }.joinToString(\"\")", "}", "", "" ]
HumanEval_kotlin/2
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive floating point number, it can be decomposed into * an integer part (largest integer smaller than the given number) and decimals * (leftover part always smaller than 1). * Return the decimal part of the number. * >>> truncate_num...
truncateNumber
fun main() { var arg00: Double = 3.5 var x0: Double = truncateNumber(arg00) var v0: Double = 0.5 if (Math.abs(x0 - v0) > 1e-9) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Double = 1.33 var x1: Double = truncateNumber(arg10) var v1: Double ...
/** * You are an expert Kotlin programmer, and here is your task. * Given a positive floating point number, it can be decomposed into * an integer part (largest integer smaller than the given number) and decimals * (leftover part always smaller than 1). * Return the decimal part of the number. * >>> truncate_num...
kotlin
[ "fun truncateNumber(number: Double): Double {", " return number - Math.floor(number)", "}", "", "" ]
HumanEval_kotlin/138
/** * You are an expert Kotlin programmer, and here is your task. * Create a function which takes a string representing a file's name, and returns * 'Yes' if the the file's name is valid, and returns 'No' otherwise. * A file's name is considered to be valid if and only if all the following conditions * are met: ...
fileNameCheck
fun main() { var arg00 : String = "example.txt" var x0 : String = fileNameCheck(arg00); var v0 : String = "Yes"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "1example.dll" var x1 : String = fileNameCheck(arg10); var...
/** * You are an expert Kotlin programmer, and here is your task. * Create a function which takes a string representing a file's name, and returns * 'Yes' if the the file's name is valid, and returns 'No' otherwise. * A file's name is considered to be valid if and only if all the following conditions * are met: ...
kotlin
[ "fun fileNameCheck(fileName : String) : String {", " val parts = fileName.split('.')", "", " if (parts.size != 2 || parts[0].isEmpty() || !parts[0][0].isLetter()) {", " return \"No\"", " }", " if (parts[0].count { it.isDigit() } > 3) {", " return \"No\"", " }", " va...
HumanEval_kotlin/37
/** * You are an expert Kotlin programmer, and here is your task. * * prime_fib returns n-th number that is a Fibonacci number and it's also prime. * >>> prime_fib(1) * 2 * >>> prime_fib(2) * 3 * >>> prime_fib(3) * 5 * >>> prime_fib(4) * 13 * >>> prime_fib(5) * 89 * */ fun primeFib(n: Int): Int {
primeFib
fun main() { var arg00: Int = 1 var x0: Int = primeFib(arg00) var v0: Int = 2 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 2 var x1: Int = primeFib(arg10) var v1: Int = 3 if (x1 != v1) { throw Exception("Exce...
/** * You are an expert Kotlin programmer, and here is your task. * * prime_fib returns n-th number that is a Fibonacci number and it's also prime. * >>> prime_fib(1) * 2 * >>> prime_fib(2) * 3 * >>> prime_fib(3) * 5 * >>> prime_fib(4) * 13 * >>> prime_fib(5) * 89 * */
kotlin
[ "fun primeFib(n: 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/24
/** * You are an expert Kotlin programmer, and here is your task. * For a given number n, find the largest number that divides n evenly, smaller than n * >>> largest_divisor(15) * 5 * */ fun largestDivisor(n: Int): Int {
largestDivisor
fun main() { var arg00: Int = 3 var x0: Int = largestDivisor(arg00) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 7 var x1: Int = largestDivisor(arg10) var v1: Int = 1 if (x1 != v1) { throw Exc...
/** * You are an expert Kotlin programmer, and here is your task. * For a given number n, find the largest number that divides n evenly, smaller than n * >>> largest_divisor(15) * 5 * */
kotlin
[ "fun largestDivisor(n: Int): Int {", " for (i in 2..n) {", " if (i * i > n) {", " break", " }", " if (n % i == 0) {", " return n / i", " }", " }", " return 1", "}", "", "" ]
HumanEval_kotlin/145
/** * You are an expert Kotlin programmer, and here is your task. * * There are eight planets in our solar system: the closest to the Sun * is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, * Uranus, Neptune. * Write a function that takes two planet names as strings planet1 and planet2. * T...
bf
fun main() { var arg00 : String = "Jupiter" var arg01 : String = "Neptune" var x0 : List<String> = bf(arg00, arg01); var v0 : List<String> = mutableListOf("Saturn", "Uranus"); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String =...
/** * You are an expert Kotlin programmer, and here is your task. * * There are eight planets in our solar system: the closest to the Sun * is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, * Uranus, Neptune. * Write a function that takes two planet names as strings planet1 and planet2. * T...
kotlin
[ "fun bf(planet1 : String, planet2 : String) : List<String> {", " val planets = listOf(\"Mercury\", \"Venus\", \"Earth\", \"Mars\", \"Jupiter\", \"Saturn\", \"Uranus\", \"Neptune\")", "\tval ind1 = planets.indexOf(planet1)", " val ind2 = planets.indexOf(planet2)", " if (ind1 == -1 || ind2 == -1 || i...
HumanEval_kotlin/120
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence. * The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined * as follows: start with any positive integer n. Then each te...
getOddCollatz
fun main() { var arg00 : Int = 14 var x0 : List<Int> = getOddCollatz(arg00); var v0 : List<Int> = mutableListOf(1, 5, 7, 11, 13, 17); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 5 var x1 : List<Int> = getOddCollatz(arg10);...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence. * The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined * as follows: start with any positive integer n. Then each te...
kotlin
[ "fun getOddCollatz(n : Int) : List<Int> {", " var current = n", " val oddNumbers = mutableSetOf<Int>()", "", " while (current != 1) {", " if (current % 2 != 0) oddNumbers.add(current)", " current = if (current % 2 == 0) {", " current / 2", " } else {", " ...
HumanEval_kotlin/76
/** * You are an expert Kotlin programmer, and here is your task. * You will be given a number in decimal form and your task is to convert it to * binary format. The function should return a string, with each character representing a binary * number. Each character in the string will be '0' or '1'. * There will b...
decimalToBinary
fun main() { var arg00: Int = 0 var x0: String = decimalToBinary(arg00) var v0: String = "db0db" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 32 var x1: String = decimalToBinary(arg10) var v1: String = "db100000db" i...
/** * You are an expert Kotlin programmer, and here is your task. * You will be given a number in decimal form and your task is to convert it to * binary format. The function should return a string, with each character representing a binary * number. Each character in the string will be '0' or '1'. * There will b...
kotlin
[ "fun decimalToBinary(decimal: Int): String {", " val binaryString = decimal.toString(2)", " return \"db${binaryString}db\"", "}", "", "" ]
HumanEval_kotlin/15
/** * You are an expert Kotlin programmer, and here is your task. * Return a string containing space-delimited numbers starting from 0 upto n inclusive. * >>> string_sequence(0) * '0' * >>> string_sequence(5) * '0 1 2 3 4 5' * */ fun stringSequence(n: Int): String {
stringSequence
fun main() { var arg00: Int = 0 var x0: String = stringSequence(arg00) var v0: String = "0" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 3 var x1: String = stringSequence(arg10) var v1: String = "0 1 2 3" if (x1 != v...
/** * You are an expert Kotlin programmer, and here is your task. * Return a string containing space-delimited numbers starting from 0 upto n inclusive. * >>> string_sequence(0) * '0' * >>> string_sequence(5) * '0 1 2 3 4 5' * */
kotlin
[ "fun stringSequence(n: Int): String {", " return (0..n).joinToString(\" \")", "}", "", "" ]
HumanEval_kotlin/107
/** * You are an expert Kotlin programmer, and here is your task. * In this problem, you will implement a function that takes two lists of numbers, * and determines whether it is possible to perform an exchange of elements * between them to make lst1 a list of only even numbers. * There is no limit on the number o...
exchange
fun main() { var arg00 : List<Int> = mutableListOf(1, 2, 3, 4) var arg01 : List<Int> = mutableListOf(1, 2, 3, 4) var x0 : String = exchange(arg00, arg01); var v0 : String = "YES"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List...
/** * You are an expert Kotlin programmer, and here is your task. * In this problem, you will implement a function that takes two lists of numbers, * and determines whether it is possible to perform an exchange of elements * between them to make lst1 a list of only even numbers. * There is no limit on the number o...
kotlin
[ "fun exchange(lst1 : List<Int>, lst2 : List<Int>) : String {", "\tval countEven = lst1.count { it % 2 == 0 } + lst2.count { it % 2 == 0 }", " return if (countEven >= lst1.size) {", " \"YES\"", " } else {", " \"NO\"", " }", "}", "", "" ]
HumanEval_kotlin/16
/** * You are an expert Kotlin programmer, and here is your task. * Given a string, find out how many distinct characters (regardless of case) does it consist of * >>> count_distinct_characters('xyzXYZ') * 3 * >>> count_distinct_characters('Jerry') * 4 * */ fun countDistinctCharacters(string: String): Int {
countDistinctCharacters
fun main() { var arg00: String = "" var x0: Int = countDistinctCharacters(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "abcde" var x1: Int = countDistinctCharacters(arg10) var v1: Int = 5 if...
/** * You are an expert Kotlin programmer, and here is your task. * Given a string, find out how many distinct characters (regardless of case) does it consist of * >>> count_distinct_characters('xyzXYZ') * 3 * >>> count_distinct_characters('Jerry') * 4 * */
kotlin
[ "fun countDistinctCharacters(string: String): Int {", " return string.lowercase().toSet().size", "}", "", "" ]
HumanEval_kotlin/61
/** * You are an expert Kotlin programmer, and here is your task. * Write a function vowels_count which takes a string representing * a word as input and returns the number of vowels in the string. * Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a * vowel, but only when it is at the end of the...
vowelsCount
fun main() { var arg00: String = "abcde" var x0: Int = vowelsCount(arg00) var v0: Int = 2 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "Alone" var x1: Int = vowelsCount(arg10) var v1: Int = 3 if (x1 != v1) { ...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function vowels_count which takes a string representing * a word as input and returns the number of vowels in the string. * Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a * vowel, but only when it is at the end of the...
kotlin
[ "fun vowelsCount(s: String): Int {", " val vowels = setOf('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')", " return s.count { it in vowels } + if (s.last().lowercase() == \"y\") 1 else 0", "}", "", "" ]
HumanEval_kotlin/115
/** * You are an expert Kotlin programmer, and here is your task. * You are given a word. Your task is to find the closest vowel that stands between * two consonants from the right side of the word (case sensitive). * * Vowels in the beginning and ending doesn't count. Return empty string if you didn't * find any...
getClosestVowel
fun main() { var arg00: String = "yogurt" var x0: String = getClosestVowel(arg00); var v0: String = "u"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "full" var x1: String = getClosestVowel(arg10); var v1: String = "u...
/** * You are an expert Kotlin programmer, and here is your task. * You are given a word. Your task is to find the closest vowel that stands between * two consonants from the right side of the word (case sensitive). * * Vowels in the beginning and ending doesn't count. Return empty string if you didn't * find any...
kotlin
[ "fun getClosestVowel(word: String): String {", " val vowels = setOf('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')", " val position = word.indices.reversed().firstOrNull { ind ->", " 0 < ind && ind < word.length - 1 && word[ind] in vowels && word[ind - 1] !in vowels && word[ind + 1] !in vowels...
HumanEval_kotlin/111
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array of integers nums, find the minimum sum of any non-empty sub-array * of nums. * Example * minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 * minSubArraySum([-1, -2, -3]) == -6 * */ fun minsubarraysum(nums : List<Long>) : Long {
minsubarraysum
fun main() { var arg00 : List<Long> = mutableListOf(2, 3, 4, 1, 2, 4) var x0 : Long = minsubarraysum(arg00); var v0 : Long = 1; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Long> = mutableListOf(-1, -2, -3) var x1 : Long = m...
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array of integers nums, find the minimum sum of any non-empty sub-array * of nums. * Example * minSubArraySum([2, 3, 4, 1, 2, 4]) == 1 * minSubArraySum([-1, -2, -3]) == -6 * */
kotlin
[ "fun minsubarraysum(nums : List<Long>) : Long {", " var answer = nums[0]", "\tnums.indices.forEach { i ->", " nums.indices.forEach { j ->", " if (i <= j) {", " answer = Math.min(nums.subList(i, j + 1).sum(), answer)", " }", " }", " }", " ...
HumanEval_kotlin/82
/** * You are an expert Kotlin programmer, and here is your task. * Given a non-empty list of integers lst. add the even elements that are at odd indices.. * Examples: * add([4, 2, 6, 7]) ==> 2 * */ fun add(lst: List<Int>): Int {
add
fun main() { var arg00: List<Int> = mutableListOf(4, 88) var x0: Int = add(arg00) var v0: Int = 88 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(4, 5, 6, 7, 2, 122) var x1: Int = add(arg10) var v1: Int...
/** * You are an expert Kotlin programmer, and here is your task. * Given a non-empty list of integers lst. add the even elements that are at odd indices.. * Examples: * add([4, 2, 6, 7]) ==> 2 * */
kotlin
[ "fun add(lst: List<Int>): Int {", " var answer = 0", " lst.forEachIndexed { index, value ->", " if (index % 2 == 1 && value % 2 == 0) {", " answer += value", " }", " }", " return answer", "}", "", "" ]
HumanEval_kotlin/49
/** * You are an expert Kotlin programmer, and here is your task. * Return True if all numbers in the list l are below threshold t. * >>> below_threshold([1, 2, 4, 10], 100) * True * >>> below_threshold([1, 20, 4, 10], 5) * False * */ fun belowThreshold(l: List<Int>, t: Int): Boolean {
belowThreshold
fun main() { var arg00: List<Int> = mutableListOf(1, 2, 4, 10) var arg01: Int = 100 var x0: Boolean = belowThreshold(arg00, arg01) var v0: Boolean = true if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 20...
/** * You are an expert Kotlin programmer, and here is your task. * Return True if all numbers in the list l are below threshold t. * >>> below_threshold([1, 2, 4, 10], 100) * True * >>> below_threshold([1, 20, 4, 10], 5) * False * */
kotlin
[ "fun belowThreshold(l: List<Int>, t: Int): Boolean {", " return l.all { it < t }", "}", "", "" ]
HumanEval_kotlin/29
/** * You are an expert Kotlin programmer, and here is your task. * Filter an input list of strings only for ones that start with a given prefix. * >>> filter_by_prefix([], 'a') * [] * >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a') * ['abc', 'array'] * */ fun filterByPrefix(strings: List<String>, pre...
filterByPrefix
fun main() { var arg00: List<String> = mutableListOf() var arg01: String = "john" var x0: List<String> = filterByPrefix(arg00, arg01) var v0: List<String> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<String>...
/** * You are an expert Kotlin programmer, and here is your task. * Filter an input list of strings only for ones that start with a given prefix. * >>> filter_by_prefix([], 'a') * [] * >>> filter_by_prefix(['abc', 'bcd', 'cde', 'array'], 'a') * ['abc', 'array'] * */
kotlin
[ "fun filterByPrefix(strings: List<String>, prefix: String): List<String> {", " return strings.filter { it.startsWith(prefix) }", "}", "", "" ]
HumanEval_kotlin/144
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a positive integer n. You have to create an integer array a of length n. * For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1. * Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, * and a[i] + a[j...
getMaxTriples
fun main() { var arg00 : Int = 5 var x0 : Int = getMaxTriples(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 = getMaxTriples(arg10); var v1 : Int = 4; if (x1 != v1) { t...
/** * You are an expert Kotlin programmer, and here is your task. * * You are given a positive integer n. You have to create an integer array a of length n. * For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1. * Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, * and a[i] + a[j...
kotlin
[ "fun getMaxTriples(n : Int) : Int {", " val counts = IntArray(3) { 0 }", " for (i in 1..n) {", " val value = (i * i - i + 1) % 3", " counts[value]++", " }", " val triples = (counts[0] * (counts[0] - 1) * (counts[0] - 2)) / 6 +", " (counts[1] * (counts[1] - 1) * (co...
HumanEval_kotlin/86
/** * You are an expert Kotlin programmer, and here is your task. * Create a function encrypt that takes a string as an argument and * returns a string encrypted with the alphabet being rotated. * The alphabet should be rotated in a manner such that the letters * shift down by two multiplied to two places. * For ...
encrypt
fun main() { var arg00: String = "hi" var x0: String = encrypt(arg00) var v0: String = "lm" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "asdfghjkl" var x1: String = encrypt(arg10) var v1: String = "ewhjklnop" if ...
/** * You are an expert Kotlin programmer, and here is your task. * Create a function encrypt that takes a string as an argument and * returns a string encrypted with the alphabet being rotated. * The alphabet should be rotated in a manner such that the letters * shift down by two multiplied to two places. * For ...
kotlin
[ "fun encrypt(s: String): String {", " val shift = 4", " return s.map { char ->", " val shifted = ((char - 'a' + shift) % 26) + 'a'.code", " shifted.toChar()", " }.joinToString(\"\")", "}", "", "" ]
HumanEval_kotlin/23
/** * You are an expert Kotlin programmer, and here is your task. * Return length of given string * >>> strlen('') * 0 * >>> strlen('abc') * 3 * */ fun strlen(string: String): Int {
strlen
fun main() { var arg00: String = "" var x0: Int = strlen(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "x" var x1: Int = strlen(arg10) var v1: Int = 1 if (x1 != v1) { throw Exception(...
/** * You are an expert Kotlin programmer, and here is your task. * Return length of given string * >>> strlen('') * 0 * >>> strlen('abc') * 3 * */
kotlin
[ "fun strlen(string: String): Int {", " return string.length", "}", "", "" ]
HumanEval_kotlin/135
/** * You are an expert Kotlin programmer, and here is your task. * Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers * Example * is_equal_to_sum_even(4) == False * is_equal_to_sum_even(6) == False * is_equal_to_sum_even(8) == True * */ fun isEqualToSumEven(n : Int...
isEqualToSumEven
fun main() { var arg00 : Int = 4 var x0 : Boolean = isEqualToSumEven(arg00); var v0 : Boolean = false; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 6 var x1 : Boolean = isEqualToSumEven(arg10); var v1 : Boolean = false;...
/** * You are an expert Kotlin programmer, and here is your task. * Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers * Example * is_equal_to_sum_even(4) == False * is_equal_to_sum_even(6) == False * is_equal_to_sum_even(8) == True * */
kotlin
[ "fun isEqualToSumEven(n : Int) : Boolean {", " return n % 2 == 0 && n >= 8", "}", "", "" ]
HumanEval_kotlin/72
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that returns true if the given number is the multiplication of 3 prime numbers * and false otherwise. * Knowing that (a) is less than 100. * Example: * is_multiply_prime(30) == True * 30 = 2 * 3 * 5 * */ fun isMultiplyPrime(a:...
isMultiplyPrime
fun main() { var arg00: Int = 5 var x0: Boolean = isMultiplyPrime(arg00) var v0: Boolean = false if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 30 var x1: Boolean = isMultiplyPrime(arg10) var v1: Boolean = true if (x1 ...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that returns true if the given number is the multiplication of 3 prime numbers * and false otherwise. * Knowing that (a) is less than 100. * Example: * is_multiply_prime(30) == True * 30 = 2 * 3 * 5 * */
kotlin
[ "fun isMultiplyPrime(a: Int): Boolean {", " var cur = a", " val factors = mutableListOf<Int>()", " for (i in 2..a) {", " if (i * i > a) {", " break", " }", " while (cur % i == 0) {", " cur /= i", " factors.add(i)", " }", " ...
HumanEval_kotlin/59
/** * You are an expert Kotlin programmer, and here is your task. * xs represent coefficients of a polynomial. * xs[0] + xs[1] * x + xs[2] * x^2 + .... * Return derivative of this polynomial in the same form. * >>> derivative([3, 1, 2, 4, 5]) * [1, 4, 12, 20] * >>> derivative([1, 2, 3]) * [2, 6] * */ fun der...
derivative
fun main() { var arg00: List<Int> = mutableListOf(3, 1, 2, 4, 5) var x0: List<Int> = derivative(arg00) var v0: List<Int> = mutableListOf(1, 4, 12, 20) if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutableListOf(1, 2, 3) ...
/** * You are an expert Kotlin programmer, and here is your task. * xs represent coefficients of a polynomial. * xs[0] + xs[1] * x + xs[2] * x^2 + .... * Return derivative of this polynomial in the same form. * >>> derivative([3, 1, 2, 4, 5]) * [1, 4, 12, 20] * >>> derivative([1, 2, 3]) * [2, 6] * */
kotlin
[ "fun derivative(xs: List<Int>): List<Int> {", " return xs.mapIndexed { index, value ->", " value * index", " }.drop(1)", "}", "", "" ]
HumanEval_kotlin/10
/** * You are an expert Kotlin programmer, and here is your task. * Find the shortest palindrome that begins with a supplied string. * Algorithm idea is simple: * - Find the longest postfix of supplied string that is a palindrome. * - Append to the end of the string reverse of a string prefix that comes before the...
makePalindrome
fun main() { var arg00: String = "" var x0: String = makePalindrome(arg00) var v0: String = "" if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "x" var x1: String = makePalindrome(arg10) var v1: String = "x" if (x1 !=...
/** * You are an expert Kotlin programmer, and here is your task. * Find the shortest palindrome that begins with a supplied string. * Algorithm idea is simple: * - Find the longest postfix of supplied string that is a palindrome. * - Append to the end of the string reverse of a string prefix that comes before the...
kotlin
[ "fun makePalindrome(string: String): String {", " for (startPosition in string.indices) {", " if (string.substring(startPosition) == string.substring(startPosition).reversed()) {", " return string + string.substring(0, startPosition).reversed()", " }", " }", " return st...
HumanEval_kotlin/103
/** * You are an expert Kotlin programmer, and here is your task. * Implement the function f that takes n as a parameter, * and ret urns a list of size n, such that the value of the element at index i is the factorial of i if i is even * or the sum of numbers from 1 to i otherwise. * i starts from 1. * the facto...
f
fun main() { var arg00 : Int = 5 var x0 : List<Int> = f(arg00); var v0 : List<Int> = mutableListOf(1, 2, 6, 24, 15); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = 7 var x1 : List<Int> = f(arg10); var v1 : List<Int> = mut...
/** * You are an expert Kotlin programmer, and here is your task. * Implement the function f that takes n as a parameter, * and ret urns a list of size n, such that the value of the element at index i is the factorial of i if i is even * or the sum of numbers from 1 to i otherwise. * i starts from 1. * the facto...
kotlin
[ "fun f(n : Int) : List<Int> {", " fun factorial(num: Int): Int = if (num == 0) 1 else num * factorial(num - 1)", " fun sumToNum(num: Int): Int = (1..num).sum()", " return (1..n).map { i ->", " if (i % 2 == 0) factorial(i) else sumToNum(i)", " }", "}", "", "" ]
HumanEval_kotlin/108
/** * You are an expert Kotlin programmer, and here is your task. * Given a string representing a space separated lowercase letters, return a dictionary * of the letter with the most repetition and containing the corresponding count. * If several letters have the same occurrence, return all of them. * * Example:...
histogram
fun main() { var arg00 : String = "a b b a" var x0 : Map<String, Int> = histogram(arg00); var v0 : Map<String, Int> = mutableMapOf("a" to 2, "b" to 2); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "a b c a b" var x1 : Ma...
/** * You are an expert Kotlin programmer, and here is your task. * Given a string representing a space separated lowercase letters, return a dictionary * of the letter with the most repetition and containing the corresponding count. * If several letters have the same occurrence, return all of them. * * Example:...
kotlin
[ "fun histogram(text : String) : Map<String, Int> {", " if (text.isEmpty()) return emptyMap()", "", " val counts = text.split(\" \")", " .filter { it.isNotEmpty() } // Remove any empty strings resulting from extra spaces", " .groupingBy { it }", " .eachCount()", "", " va...
HumanEval_kotlin/146
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that accepts a list of strings as a parameter, * deletes the strings that have odd lengths from it, * and returns the resulted list with a sorted order, * The list is always a list of strings and never an array of numbers, * and ...
sortedListSum
fun main() { var arg00 : List<String> = mutableListOf("aa", "a", "aaa") var x0 : List<Any> = sortedListSum(arg00); var v0 : List<Any> = mutableListOf("aa"); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<String> = mutableListOf("s...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that accepts a list of strings as a parameter, * deletes the strings that have odd lengths from it, * and returns the resulted list with a sorted order, * The list is always a list of strings and never an array of numbers, * and ...
kotlin
[ "fun sortedListSum(lst : List<String>) : List<String> {", " return lst.filter { it.length % 2 == 0 }", " .sortedWith(compareBy({ it.length }, { it }))", "}", "", "" ]
HumanEval_kotlin/38
/** * You are an expert Kotlin programmer, and here is your task. * triples_sum_to_zero takes a list of integers as an input. * it returns True if there are three distinct elements in the list that * sum to zero, and False otherwise. * >>> triples_sum_to_zero([1, 3, 5, 0]) * False * >>> triples_sum_to_zero([1, ...
triplesSumToZero
fun main() { var arg00: List<Int> = mutableListOf(1, 3, 5, 0) var x0: Boolean = triplesSumToZero(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, 5, -1) var x1: Boolean = ...
/** * You are an expert Kotlin programmer, and here is your task. * triples_sum_to_zero takes a list of integers as an input. * it returns True if there are three distinct elements in the list that * sum to zero, and False otherwise. * >>> triples_sum_to_zero([1, 3, 5, 0]) * False * >>> triples_sum_to_zero([1, ...
kotlin
[ "fun triplesSumToZero(l: List<Int>): Boolean {", " val sortedList = l.sorted()", " for (i in 0 until sortedList.size - 2) {", " // Avoid duplicate elements", " if (i > 0 && sortedList[i] == sortedList[i - 1]) continue", "", " var left = i + 1", " var right = sortedLis...
HumanEval_kotlin/143
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that takes an array of numbers as input and returns * the number of elements in the array that are greater than 10 and both * first and last digits of a number are odd (1, 3, 5, 7, 9). * For example: * specialFilter([15, -73, 1...
specialfilter
fun main() { var arg00 : List<Int> = mutableListOf(5, -2, 1, -5) var x0 : Int = specialfilter(arg00); var v0 : Int = 0; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(15, -73, 14, -15) var x1 : Int = speci...
/** * You are an expert Kotlin programmer, and here is your task. * Write a function that takes an array of numbers as input and returns * the number of elements in the array that are greater than 10 and both * first and last digits of a number are odd (1, 3, 5, 7, 9). * For example: * specialFilter([15, -73, 1...
kotlin
[ "fun specialfilter(nums : List<Int>) : Int {", " val oddDigits = setOf('1', '3', '5', '7', '9')", "\treturn nums.count { it > 10 && it.toString().first() in oddDigits && it.toString().last() in oddDigits }", "}", "", "" ]
HumanEval_kotlin/132
/** * You are an expert Kotlin programmer, and here is your task. * Create a function which returns the largest index of an element which * is not greater than or equal to the element immediately preceding it. If * no such element exists then return -1. The given array will not contain * duplicate values. * Exam...
canArrange
fun main() { var arg00 : List<Int> = mutableListOf(1, 2, 4, 3, 5) var x0 : Int = canArrange(arg00); var v0 : Int = 3; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(1, 2, 4, 5) var x1 : Int = canArrange(ar...
/** * You are an expert Kotlin programmer, and here is your task. * Create a function which returns the largest index of an element which * is not greater than or equal to the element immediately preceding it. If * no such element exists then return -1. The given array will not contain * duplicate values. * Exam...
kotlin
[ "fun canArrange(arr : List<Int>) : Int {", " for (i in (1 until arr.size).reversed()) {", " if (arr[i] < arr[i - 1]) {", " return i", " }", " }", " return -1", "}", "", "" ]
HumanEval_kotlin/12
/** * You are an expert Kotlin programmer, and here is your task. * Out of list of strings, return the longest one. Return the first one in case of multiple * strings of the same length. Return in case the input list is empty. * >>> longest([]) * >>> longest(['a', 'b', 'c']) * 'a' * >>> longest(['a', 'bb', 'cc...
longest
fun main() { var arg00: List<String> = mutableListOf() var x0: String? = longest(arg00) var v0: String? = null 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? = longest(arg1...
/** * You are an expert Kotlin programmer, and here is your task. * Out of list of strings, return the longest one. Return the first one in case of multiple * strings of the same length. Return in case the input list is empty. * >>> longest([]) * >>> longest(['a', 'b', 'c']) * 'a' * >>> longest(['a', 'bb', 'cc...
kotlin
[ "fun longest(strings: List<String>): String? {", " if (strings.isEmpty()) return null", "", " return strings.maxWithOrNull(compareBy { it.length })", "}", "", "" ]
HumanEval_kotlin/31
/** * You are an expert Kotlin programmer, and here is your task. * Return true if a given number is prime, and false otherwise. * >>> is_prime(6) * False * >>> is_prime(101) * True * >>> is_prime(11) * True * >>> is_prime(13441) * True * >>> is_prime(61) * True * >>> is_prime(4) * False * >>> is_prime(1...
isPrime
fun main() { var arg00: Int = 6 var x0: Boolean = isPrime(arg00) var v0: Boolean = false if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 101 var x1: Boolean = isPrime(arg10) var v1: Boolean = true if (x1 != v1) { ...
/** * You are an expert Kotlin programmer, and here is your task. * Return true if a given number is prime, and false otherwise. * >>> is_prime(6) * False * >>> is_prime(101) * True * >>> is_prime(11) * True * >>> is_prime(13441) * True * >>> is_prime(61) * True * >>> is_prime(4) * False * >>> is_prime(1...
kotlin
[ "fun isPrime(n: Int): Boolean {", " if (n == 1) {", " return false", " }", " for (i in 2..n) {", " if (i * i > n) {", " break", " }", " if (n % i == 0) {", " return false", " }", " }", " return true", "}", "", "" ]
HumanEval_kotlin/102
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array of integers, sort the integers that are between 1 and 9 inclusive, * reverse the resulting array, and then replace each digit by its corresponding name from * "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine". ...
byLength
fun main() { var arg00: List<Int> = mutableListOf(2, 1, 1, 4, 5, 8, 2, 3) var x0: List<String> = byLength(arg00) var v0: List<String> = mutableListOf("Eight", "Five", "Four", "Three", "Two", "Two", "One", "One") 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 an array of integers, sort the integers that are between 1 and 9 inclusive, * reverse the resulting array, and then replace each digit by its corresponding name from * "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine". ...
kotlin
[ "fun byLength(arr: List<Int>): List<String> {", " val numberNames = mapOf(", " 1 to \"One\", 2 to \"Two\", 3 to \"Three\", 4 to \"Four\",", " 5 to \"Five\", 6 to \"Six\", 7 to \"Seven\", 8 to \"Eight\", 9 to \"Nine\"", " )", "", " // Filter, sort, reverse, and then map integers to...
HumanEval_kotlin/64
/** * You are an expert Kotlin programmer, and here is your task. * * In this task, you will be given a string that represents a number of apples and oranges * that are distributed in a basket of fruit this basket contains * apples, oranges, and mango fruits. Given the string that represents the total number of * ...
fruitDistribution
fun main() { var arg00: String = "5 apples and 6 oranges" var arg01: Int = 19 var x0: Int = fruitDistribution(arg00, arg01) var v0: Int = 8 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "5 apples and 6 oranges" var arg...
/** * You are an expert Kotlin programmer, and here is your task. * * In this task, you will be given a string that represents a number of apples and oranges * that are distributed in a basket of fruit this basket contains * apples, oranges, and mango fruits. Given the string that represents the total number of * ...
kotlin
[ "fun fruitDistribution(s: String, totalFruits: Int): Int {", " // Extract the numbers from the string", " val numbers = s.split(\" \").filter { it.toIntOrNull() != null }.map { it.toInt() }", " // Assuming the string format is always \"<number> apples and <number> oranges\"", " val apples = numb...
HumanEval_kotlin/157
/** * You are an expert Kotlin programmer, and here is your task. * * Given two lists operator, and operand. The first list has basic algebra operations, and * the second list is a list of integers. Use the two given lists to build the algebric * expression and return the evaluation of this expression. * The basi...
doAlgebra
fun main() { var arg00: List<String> = mutableListOf("**", "*", "+") var arg01: List<Int> = mutableListOf(2, 3, 4, 5) var x0: Int = doAlgebra(arg00, arg01); var v0: Int = 37; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Strin...
/** * You are an expert Kotlin programmer, and here is your task. * * Given two lists operator, and operand. The first list has basic algebra operations, and * the second list is a list of integers. Use the two given lists to build the algebric * expression and return the evaluation of this expression. * The basi...
kotlin
[ "fun doAlgebra(operator: List<String>, operand: List<Int>): Int {", " if (operator.isEmpty()) {", " return operand[0]", " }", " operator.withIndex().reversed().forEach { (index, op) ->", " when (op) {", " \"+\" -> return doAlgebra(operator.subList(0, index), operand.sub...
HumanEval_kotlin/96
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes a value (string) representing a number * and returns the closest integer to it. If the number is equidistant * from two integers, round it away from zero. * Examples * >>> closest_integer("10") * 10 * >>> closest...
closestInteger
fun main() { var arg00: String = "10" var x0: Int = closestInteger(arg00) var v0: Int = 10 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "14.5" var x1: Int = closestInteger(arg10) var v1: Int = 15 if (x1 != v1) { ...
/** * You are an expert Kotlin programmer, and here is your task. * * Create a function that takes a value (string) representing a number * and returns the closest integer to it. If the number is equidistant * from two integers, round it away from zero. * Examples * >>> closest_integer("10") * 10 * >>> closest...
kotlin
[ "fun closestInteger(value: String): Int {", " val number = value.toDouble()", " val fractionalPart = number % 1.0", " val isHalf = fractionalPart == 0.5 || fractionalPart == -0.5", "", " return if (isHalf) {", " if (number > 0) Math.ceil(number).toInt() else Math.floor(number).toInt()...
HumanEval_kotlin/44
/** * You are an expert Kotlin programmer, and here is your task. * The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: * fib4(0) -> 0 * fib4(1) -> 0 * fib4(2) -> 2 * fib4(3) -> 0 * fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). * Please write a functi...
fib4
fun main() { var arg00: Int = 5 var x0: Int = fib4(arg00) var v0: Int = 4 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 8 var x1: Int = fib4(arg10) var v1: Int = 28 if (x1 != v1) { throw Exception("Exception -...
/** * You are an expert Kotlin programmer, and here is your task. * The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: * fib4(0) -> 0 * fib4(1) -> 0 * fib4(2) -> 2 * fib4(3) -> 0 * fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). * Please write a functi...
kotlin
[ "fun fib4(n: Int): Int {", " val fibs = mutableListOf(0, 0, 2, 0)", " var index = 0", " while (fibs.size <= n) {", " fibs.add(fibs[index] + fibs[index + 1] + fibs[index + 2] + fibs[index + 3])", " index++", " }", " return fibs[n]", "}", "", "" ]
HumanEval_kotlin/63
/** * You are an expert Kotlin programmer, and here is your task. * Task * Write a function that takes a string as input and returns the sum of the upper characters only' * ASCII codes. * Examples: * digitSum("") => 0 * digitSum("abAB") => 131 * digitSum("abcCd") => 67 * digitSum("helloE") => ...
digitsum
fun main() { var arg00: String = "" var x0: Int = digitsum(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "abAB" var x1: Int = digitsum(arg10) var v1: Int = 131 if (x1 != v1) { throw E...
/** * You are an expert Kotlin programmer, and here is your task. * Task * Write a function that takes a string as input and returns the sum of the upper characters only' * ASCII codes. * Examples: * digitSum("") => 0 * digitSum("abAB") => 131 * digitSum("abcCd") => 67 * digitSum("helloE") => ...
kotlin
[ "fun digitsum(s: String): Int {", " return s.filter { it.isUpperCase() }.map { it.code }.sum()", "}", "", "" ]
HumanEval_kotlin/14
/** * You are an expert Kotlin programmer, and here is your task. * Return list of all prefixes from shortest to longest of the input string * >>> all_prefixes('abc') * ['a', 'ab', 'abc'] * */ fun allPrefixes(string: String): List<Any> {
allPrefixes
fun main() { var arg00: String = "" var x0: List<Any> = allPrefixes(arg00) var v0: List<Any> = mutableListOf() if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "asdfgh" var x1: List<Any> = allPrefixes(arg10) var v1: List<...
/** * You are an expert Kotlin programmer, and here is your task. * Return list of all prefixes from shortest to longest of the input string * >>> all_prefixes('abc') * ['a', 'ab', 'abc'] * */
kotlin
[ "fun allPrefixes(string: String): List<Any> {", " return string.indices.map { index ->", " string.substring(0, index + 1)", " }", "}", "", "" ]
HumanEval_kotlin/95
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string s, count the number of uppercase vowels in even indices. * * For example: * count_upper('aBCdEf') returns 1 * count_upper('abcdefg') returns 0 * count_upper('dBBE') returns 0 * */ fun countUpper(s: String): Int {
countUpper
fun main() { var arg00: String = "abcdefg" var x0: Int = countUpper(arg00) var v0: Int = 0 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "dBBE" var x1: Int = countUpper(arg10) var v1: Int = 0 if (x1 != v1) { ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string s, count the number of uppercase vowels in even indices. * * For example: * count_upper('aBCdEf') returns 1 * count_upper('abcdefg') returns 0 * count_upper('dBBE') returns 0 * */
kotlin
[ "fun countUpper(s: String): Int {", " val vowels = setOf('A', 'E', 'I', 'O', 'U')", " return s.filterIndexed { index, c -> index % 2 == 0 && c in vowels }.length", "}", "", "" ]
HumanEval_kotlin/9
/** * You are an expert Kotlin programmer, and here is your task. * From a given list of integers, generate a list of rolling maximum element found until given moment * in the sequence. * >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) * [1, 2, 3, 3, 3, 4, 4] * */ fun rollingMax(numbers: List<Int>): List<Int> {
rollingMax
fun main() { var arg00: List<Int> = mutableListOf() var x0: List<Int> = rollingMax(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(1, 2, 3, 4) var x1: List<Int> = r...
/** * You are an expert Kotlin programmer, and here is your task. * From a given list of integers, generate a list of rolling maximum element found until given moment * in the sequence. * >>> rolling_max([1, 2, 3, 2, 3, 4, 2]) * [1, 2, 3, 3, 3, 4, 4] * */
kotlin
[ "fun rollingMax(numbers: List<Int>): List<Int> {", " return numbers.runningFold(0) { mx, value -> Math.max(mx, value) }.drop(1)", "}", "", "" ]
HumanEval_kotlin/152
/** * You are an expert Kotlin programmer, and here is your task. * Given an integer. return a tuple that has the number of even and odd digits respectively. * Example: * even_odd_count(-12) ==> (1, 1) * even_odd_count(123) ==> (1, 2) * */ fun evenOddCount(num : Int) : List<Int> {
evenOddCount
fun main() { var arg00 : Int = 7 var x0 : List<Int> = evenOddCount(arg00); var v0 : List<Int> = mutableListOf(0, 1); if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : Int = -78 var x1 : List<Int> = evenOddCount(arg10); var v1 : Li...
/** * You are an expert Kotlin programmer, and here is your task. * Given an integer. return a tuple that has the number of even and odd digits respectively. * Example: * even_odd_count(-12) ==> (1, 1) * even_odd_count(123) ==> (1, 2) * */
kotlin
[ "fun evenOddCount(num : Int) : List<Int> {", " val digits = num.toString().filter { it.isDigit() }", " val evenCount = digits.count { (it - '0') % 2 == 0 }", "\treturn listOf(evenCount, digits.length - evenCount)", "}", "", "" ]
HumanEval_kotlin/50
/** * You are an expert Kotlin programmer, and here is your task. * Add two numbers x and y * >>> add(2, 3) * 5 * >>> add(5, 7) * 12 * */ fun add(x: Int, y: Int): Int {
add
fun main() { var arg00: Int = 0 var arg01: Int = 1 var x0: Int = add(arg00, arg01) var v0: Int = 1 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: Int = 1 var arg11: Int = 0 var x1: Int = add(arg10, arg11) var v1: Int = 1...
/** * You are an expert Kotlin programmer, and here is your task. * Add two numbers x and y * >>> add(2, 3) * 5 * >>> add(5, 7) * 12 * */
kotlin
[ "fun add(x: Int, y: Int): Int {", " return x + y", "}", "", "" ]
HumanEval_kotlin/85
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array of non-negative integers, return a copy of the given array after sorting, * you will sort the given array in ascending order if the sum( first index value, last index value) is odd, * or sort it in descending order if the sum( firs...
sortArrayByBinary
fun main() { var arg00: List<Int> = mutableListOf() var x0: List<Int> = sortArrayByBinary(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(5) var x1: List<Int> = sor...
/** * You are an expert Kotlin programmer, and here is your task. * * Given an array of non-negative integers, return a copy of the given array after sorting, * you will sort the given array in ascending order if the sum( first index value, last index value) is odd, * or sort it in descending order if the sum( firs...
kotlin
[ "fun sortArrayByBinary(array: List<Int>): List<Int> {", " if (array.size == 0) {", " return emptyList()", " }", " if ((array.first() + array.last()) % 2 == 0) {", " return array.sortedDescending()", " }", " return array.sorted()", "}", "", "" ]
HumanEval_kotlin/91
/** * You are an expert Kotlin programmer, and here is your task. * You are given a list of integers. * You need to find the largest prime value and return the sum of its digits. * Examples: * For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10 * For lst = [1,0,1,8,2,4597,2,1,3...
skjkasdkd
fun main() { var arg00: List<Int> = mutableListOf(0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3) var x0: Int = skjkasdkd(arg00) var v0: Int = 10 if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: List<Int> = mutabl...
/** * You are an expert Kotlin programmer, and here is your task. * You are given a list of integers. * You need to find the largest prime value and return the sum of its digits. * Examples: * For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10 * For lst = [1,0,1,8,2,4597,2,1,3...
kotlin
[ "fun skjkasdkd(lst: List<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/148
/** * You are an expert Kotlin programmer, and here is your task. * * Given a list of numbers, return the sum of squares of the numbers * in the list that are odd. Ignore numbers that are negative or not integers. * * double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10 * double_the_difference([-1, -2, 0]) ...
doubleTheDifference
fun main() { var arg00 : List<Number> = mutableListOf() var x0 : Int = doubleTheDifference(arg00); var v0 : Int = 0; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : List<Number> = mutableListOf(5, 4) var x1 : Int = doubleTheDifferen...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a list of numbers, return the sum of squares of the numbers * in the list that are odd. Ignore numbers that are negative or not integers. * * double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10 * double_the_difference([-1, -2, 0]) ...
kotlin
[ "fun doubleTheDifference(lst : List<Number>) : Int {", "\treturn lst.sumOf { if (it is Int && it > 0 && it % 2 == 1) it * it else 0 }", "}", "", "" ]
HumanEval_kotlin/121
/** * You are an expert Kotlin programmer, and here is your task. * You have to write a function which validates a given date string and * returns True if the date is valid otherwise False. * The date is valid if all of the following rules are satisfied: * 1. The date string is not empty. * 2. The number of days ...
validDate
fun main() { var arg00 : String = "03-11-2000" var x0 : Boolean = validDate(arg00); var v0 : Boolean = true; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "15-01-2012" var x1 : Boolean = validDate(arg10); var v1 : Boo...
/** * You are an expert Kotlin programmer, and here is your task. * You have to write a function which validates a given date string and * returns True if the date is valid otherwise False. * The date is valid if all of the following rules are satisfied: * 1. The date string is not empty. * 2. The number of days ...
kotlin
[ "fun validDate(date : String) : Boolean {", " val regex = Regex(\"\"\"\\d{2}-\\d{2}-\\d{4}\"\"\")", " if (!regex.matches(date)) return false", "", " val (month, day, year) = date.split(\"-\").map { it.toInt() }", "", " if (month !in 1..12) return false", "", " val daysInMonth = when (...
HumanEval_kotlin/137
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string text, replace all spaces in it with underscores, * and if a string has more than 2 consecutive spaces, * then replace all consecutive spaces with - * * fix_spaces("Example") == "Example" * fix_spaces("Example 1") == "Example...
fixSpaces
fun main() { var arg00 : String = "Example" var x0 : String = fixSpaces(arg00); var v0 : String = "Example"; if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10 : String = "Mudasir Hanif " var x1 : String = fixSpaces(arg10); var v1 : ...
/** * You are an expert Kotlin programmer, and here is your task. * * Given a string text, replace all spaces in it with underscores, * and if a string has more than 2 consecutive spaces, * then replace all consecutive spaces with - * * fix_spaces("Example") == "Example" * fix_spaces("Example 1") == "Example...
kotlin
[ "fun fixSpaces(text : String) : String {", "\treturn text.replace(Regex(\" {3,}\"), \"-\").replace(' ', '_')", "}", "", "" ]
HumanEval_kotlin/77
/** * You are an expert Kotlin programmer, and here is your task. * You are given a string s. * Your task is to check if the string is happy or not. * A string is happy if its length is at least 3 and every 3 consecutive letters are distinct * For example: * is_happy(a) => False * is_happy(aa) => False * is_hap...
isHappy
fun main() { var arg00: String = "a" var x0: Boolean = isHappy(arg00) var v0: Boolean = false if (x0 != v0) { throw Exception("Exception -- test case 0 did not pass. x0 = " + x0) } var arg10: String = "aa" var x1: Boolean = isHappy(arg10) var v1: Boolean = false if (x1 != v1...
/** * You are an expert Kotlin programmer, and here is your task. * You are given a string s. * Your task is to check if the string is happy or not. * A string is happy if its length is at least 3 and every 3 consecutive letters are distinct * For example: * is_happy(a) => False * is_happy(aa) => False * is_hap...
kotlin
[ "fun isHappy(s: String): Boolean {", " if (s.length < 3) {", " return false", " }", "", " for (i in 0 until s.length - 2) {", " if (s[i] == s[i + 1] || s[i] == s[i + 2] || s[i + 1] == s[i + 2]) {", " return false", " }", " }", " return true", "}",...