task_id
stringlengths
18
20
prompt
stringlengths
177
1.43k
entry_point
stringlengths
1
24
test
stringlengths
287
23.1k
description
stringlengths
146
1.37k
language
stringclasses
1 value
canonical_solution
sequencelengths
5
37
HumanEval_kotlin/32
/** * You are an expert Kotlin programmer, and here is your task. * This function takes a list l and returns a list l' such that * l' is identical to l in the indices that are not divisible by three, while its values at the indices that are divisible by three are equal * to the values of the corresponding indices of l, but sorted. * >>> sort_third([1, 2, 3]) * [1, 2, 3] * >>> sort_third([5, 6, 3, 4, 8, 9, 2]) * [2, 6, 3, 4, 8, 9, 5] * */ fun sortThird(l: List<Int>): List<Int> {
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, 123, 1, -10) var x1: List<Int> = sortThird(arg10) var v1: List<Int> = mutableListOf(1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(5, 8, -12, 4, 23, 2, 3, 11, 12, -10) var x2: List<Int> = sortThird(arg20) var v2: List<Int> = mutableListOf(-10, 8, -12, 3, 23, 2, 4, 11, 12, 5) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(5, 6, 3, 4, 8, 9, 2) var x3: List<Int> = sortThird(arg30) var v3: List<Int> = mutableListOf(2, 6, 3, 4, 8, 9, 5) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(5, 8, 3, 4, 6, 9, 2) var x4: List<Int> = sortThird(arg40) var v4: List<Int> = mutableListOf(2, 8, 3, 4, 6, 9, 5) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(5, 6, 9, 4, 8, 3, 2) var x5: List<Int> = sortThird(arg50) var v5: List<Int> = mutableListOf(2, 6, 9, 4, 8, 3, 5) if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(5, 6, 3, 4, 8, 9, 2, 1) var x6: List<Int> = sortThird(arg60) var v6: List<Int> = mutableListOf(2, 6, 3, 4, 8, 9, 5, 1) if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 of l, but sorted. * >>> sort_third([1, 2, 3]) * [1, 2, 3] * >>> sort_third([5, 6, 3, 4, 8, 9, 2]) * [2, 6, 3, 4, 8, 9, 5] * */
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 * iscube(64) ==> True * iscube(0) ==> True * iscube(180) ==> False * */ fun iscube(a: Int): Boolean {
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) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = -1 var x2: Boolean = iscube(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 64 var x3: Boolean = iscube(arg30) var v3: Boolean = true if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 180 var x4: Boolean = iscube(arg40) var v4: Boolean = false if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 1000 var x5: Boolean = iscube(arg50) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 0 var x6: Boolean = iscube(arg60) var v6: Boolean = true if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 1729 var x7: Boolean = iscube(arg70) var v7: Boolean = false if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 * iscube(64) ==> True * iscube(0) ==> True * iscube(180) ==> False * */
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(a : Int, b : Int) : List<Int> {
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 = 2 var x1 : List<Int> = generateIntegers(arg10, arg11); var v1 : List<Int> = mutableListOf(2, 4, 6, 8); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 132 var arg21 : Int = 2 var x2 : List<Int> = generateIntegers(arg20, arg21); var v2 : List<Int> = mutableListOf(2, 4, 6, 8); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 17 var arg31 : Int = 89 var x3 : List<Int> = generateIntegers(arg30, arg31); var v3 : List<Int> = mutableListOf(); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 * >>> is_bored("The sky is blue. The sun is shining. I love this weather") * 1 * */ fun isBored(s: String): Int {
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) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "I love It !" var x2: Int = isBored(arg20) var v2: Int = 1 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "bIt" var x3: Int = isBored(arg30) var v3: Int = 0 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "I feel good today. I will be productive. will kill It" var x4: Int = isBored(arg40) var v4: Int = 2 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "You and I are going for a walk" var x5: Int = isBored(arg50) var v5: Int = 0 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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 * >>> is_bored("The sky is blue. The sun is shining. I love this weather") * 1 * */
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) ➞ False * * any_int(3, -2, 1) ➞ True * * any_int(3.6, -2.2, 2) ➞ False * * */ fun anyInt(x: Any, y: Any, z: Any): Boolean {
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 arg12: Any = 3 var x1: Boolean = anyInt(arg10, arg11, arg12) var v1: Boolean = false if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Any = 1.5 var arg21: Any = 5 var arg22: Any = 3.5 var x2: Boolean = anyInt(arg20, arg21, arg22) var v2: Boolean = false if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Any = 2 var arg31: Any = 6 var arg32: Any = 2 var x3: Boolean = anyInt(arg30, arg31, arg32) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Any = 4 var arg41: Any = 2 var arg42: Any = 2 var x4: Boolean = anyInt(arg40, arg41, arg42) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Any = 2.2 var arg51: Any = 2.2 var arg52: Any = 2.2 var x5: Boolean = anyInt(arg50, arg51, arg52) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Any = -4 var arg61: Any = 6 var arg62: Any = 2 var x6: Boolean = anyInt(arg60, arg61, arg62) var v6: Boolean = true if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Any = 2 var arg71: Any = 1 var arg72: Any = 1 var x7: Boolean = anyInt(arg70, arg71, arg72) var v7: Boolean = true if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: Any = 3 var arg81: Any = 4 var arg82: Any = 7 var x8: Boolean = anyInt(arg80, arg81, arg82) var v8: Boolean = true if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: Any = 3.0 var arg91: Any = 4 var arg92: Any = 7 var x9: Boolean = anyInt(arg90, arg91, arg92) var v9: Boolean = false if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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) ➞ False * * any_int(3, -2, 1) ➞ True * * any_int(3.6, -2.2, 2) ➞ False * * */
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 + 3 * Constraints: * 1. 1 <= len(arr) <= 100 * 2. 1 <= k <= len(arr) * */ fun addElements(arr : List<Int>, k : Int) : Int {
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> = mutableListOf(111, 121, 3, 4000, 5, 6) var arg11 : Int = 2 var x1 : Int = addElements(arg10, arg11); var v1 : Int = 0; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(11, 21, 3, 90, 5, 6, 7, 8, 9) var arg21 : Int = 4 var x2 : Int = addElements(arg20, arg21); var v2 : Int = 125; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(111, 21, 3, 4000, 5, 6, 7, 8, 9) var arg31 : Int = 4 var x3 : Int = addElements(arg30, arg31); var v3 : Int = 24; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(1) var arg41 : Int = 1 var x4 : Int = addElements(arg40, arg41); var v4 : Int = 1; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 + 3 * Constraints: * 1. 1 <= len(arr) <= 100 * 2. 1 <= k <= len(arr) * */
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 it should return False. * >>> below_zero([1, 2, 3]) * False * >>> below_zero([1, 2, -4, 5]) * True * */ fun belowZero(operations: List<Int>): Boolean {
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(arg10) var v1: Boolean = false if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 2, -4, 5, 6) var x2: Boolean = belowZero(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(1, -1, 2, -2, 5, -5, 4, -4) var x3: Boolean = belowZero(arg30) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(1, -1, 2, -2, 5, -5, 4, -5) var x4: Boolean = belowZero(arg40) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(1, -2, 2, -2, 5, -5, 4, -4) var x5: Boolean = belowZero(arg50) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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 it should return False. * >>> below_zero([1, 2, 3]) * False * >>> below_zero([1, 2, -4, 5]) * True * */
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 tuples, [(x1, y1), (x2, y2) ...] such that * each tuple is a coordinate - (row, columns), starting with 0. * Sort coordinates initially by rows in ascending order. * Also, sort coordinates of the row by columns in descending order. * * Examples: * get_row([ * [1,2,3,4,5,6], * [1,2,3,4,1,6], * [1,2,3,4,5,1] * ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)] * get_row([], 1) == [] * get_row([[], [1], [1, 2, 3]], 3) == [(2, 2)] * */ fun getRow(lst: List<List<Int>>, x: Int): List<List<Int>> {
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>> = mutableListOf(mutableListOf(1)) var arg11: Int = 2 var x1: List<List<Int>> = getRow(arg10, arg11) var v1: List<List<Int>> = mutableListOf() if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<List<Int>> = mutableListOf(mutableListOf(), mutableListOf(1), mutableListOf(1, 2, 3)) var arg21: Int = 3 var x2: List<List<Int>> = getRow(arg20, arg21) var v2: List<List<Int>> = mutableListOf(mutableListOf(2, 2)) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 tuples, [(x1, y1), (x2, y2) ...] such that * each tuple is a coordinate - (row, columns), starting with 0. * Sort coordinates initially by rows in ascending order. * Also, sort coordinates of the row by columns in descending order. * * Examples: * get_row([ * [1,2,3,4,5,6], * [1,2,3,4,1,6], * [1,2,3,4,5,1] * ], 1) == [(0, 0), (1, 4), (1, 0), (2, 5), (2, 0)] * get_row([], 1) == [] * get_row([[], [1], [1, 2, 3]], 3) == [(2, 2)] * */
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))", " }", " }", " }", " return coordinates", "}", "", "" ]
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, lasts four beats * 'o|' - half note, lasts two beats * '.|' - quater note, lasts one beat * >>> parse_music('o o| .| o| o| .| .| .| .| o o') * [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4] * */ fun parseMusic(musicString: String): List<Any> {
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<Any> = mutableListOf(4, 4, 4, 4) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = ".| .| .| .|" var x2: List<Any> = parseMusic(arg20) var v2: List<Any> = mutableListOf(1, 1, 1, 1) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "o| o| .| .| o o o o" var x3: List<Any> = parseMusic(arg30) var v3: List<Any> = mutableListOf(2, 2, 1, 1, 4, 4, 4, 4) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "o| .| o| .| o o| o o|" var x4: List<Any> = parseMusic(arg40) var v4: List<Any> = mutableListOf(2, 1, 2, 1, 4, 2, 4, 2) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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, lasts four beats * 'o|' - half note, lasts two beats * '.|' - quater note, lasts one beat * >>> parse_music('o o| .| o| o| .| .| .| .| o o') * [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4] * */
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", " else -> throw Exception(\"Invalid input\")", " }", " }", "}", "", "" ]
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("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 11 var x2: Int = sumToN(arg20) var v2: Int = 66 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 30 var x3: Int = sumToN(arg30) var v3: Int = 465 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 100 var x4: Int = sumToN(arg40) var v4: Int = 5050 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 * next_smallest([]) == None * next_smallest([1, 1]) == None * */ fun nextSmallest(lst: List<Int>): Int? {
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(arg10) var v1: Int? = 2 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf() var x2: Int? = nextSmallest(arg20) var v2: Int? = null if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(1, 1) var x3: Int? = nextSmallest(arg30) var v3: Int? = null if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(1, 1, 1, 1, 0) var x4: Int? = nextSmallest(arg40) var v4: Int? = 1 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(1, 1) var x5: Int? = nextSmallest(arg50) var v5: Int? = null if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(-35, 34, 12, -45) var x6: Int? = nextSmallest(arg60) var v6: Int? = -35 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 * next_smallest([]) == None * next_smallest([1, 1]) == None * */
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 = maxElement(arg10) var v1: Int = 124 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } }
/** * 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] * */ fun rescaleToUnit(numbers: List<Double>): List<Double> {
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, 49.9) var x1: List<Double> = rescaleToUnit(arg10) var v1: List<Double> = mutableListOf(1.0, 0.0) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Double> = mutableListOf(1.0, 2.0, 3.0, 4.0, 5.0) var x2: List<Double> = rescaleToUnit(arg20) var v2: List<Double> = mutableListOf(0.0, 0.25, 0.5, 0.75, 1.0) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Double> = mutableListOf(2.0, 1.0, 5.0, 3.0, 4.0) var x3: List<Double> = rescaleToUnit(arg30) var v3: List<Double> = mutableListOf(0.25, 0.0, 1.0, 0.5, 0.75) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Double> = mutableListOf(12.0, 11.0, 15.0, 13.0, 14.0) var x4: List<Double> = rescaleToUnit(arg40) var v4: List<Double> = mutableListOf(0.25, 0.0, 1.0, 0.5, 0.75) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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(x: Int, base: Int): String {
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, arg11) var v1: String = "100" if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 234 var arg21: Int = 2 var x2: String = changeBase(arg20, arg21) var v2: String = "11101010" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 16 var arg31: Int = 2 var x3: String = changeBase(arg30, arg31) var v3: String = "10000" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 8 var arg41: Int = 2 var x4: String = changeBase(arg40, arg41) var v4: String = "1000" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 7 var arg51: Int = 2 var x5: String = changeBase(arg50, arg51) var v5: String = "111" if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 2 var arg61: Int = 3 var x6: String = changeBase(arg60, arg61) var v6: String = "2" if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 3 var arg71: Int = 4 var x7: String = changeBase(arg70, arg71) var v7: String = "3" if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: Int = 4 var arg81: Int = 5 var x8: String = changeBase(arg80, arg81) var v8: String = "4" if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: Int = 5 var arg91: Int = 6 var x9: String = changeBase(arg90, arg91) var v9: String = "5" if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: Int = 6 var arg101: Int = 7 var x10: String = changeBase(arg100, arg101) var v10: String = "6" if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: Int = 7 var arg111: Int = 8 var x11: String = changeBase(arg110, arg111) var v11: String = "7" if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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", " result.insert(0, num % base)", " // Divide the number by the base for the next iteration", " num /= base", " }", "", " return result.toString()", "}", "", "" ]
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 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "These violent delights have violent ends" var x2: String = flipCase(arg20) var v2: String = "tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 format, * <numerator>/<denominator> where both numerator and denominator are positive whole numbers. * You can assume that x, and n are valid fractions, and do not have zero as denominator. * simplify("1/5", "5/1") = True * simplify("1/6", "2/1") = False * simplify("7/10", "10/2") = False * */ fun simplify(x : String, n : String) : Boolean {
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" var x1 : Boolean = simplify(arg10, arg11); var v1 : Boolean = false; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "5/1" var arg21 : String = "3/1" var x2 : Boolean = simplify(arg20, arg21); var v2 : Boolean = true; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "7/10" var arg31 : String = "10/2" var x3 : Boolean = simplify(arg30, arg31); var v3 : Boolean = false; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "2/10" var arg41 : String = "50/10" var x4 : Boolean = simplify(arg40, arg41); var v4 : Boolean = true; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "7/2" var arg51 : String = "4/2" var x5 : Boolean = simplify(arg50, arg51); var v5 : Boolean = true; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "11/6" var arg61 : String = "6/1" var x6 : Boolean = simplify(arg60, arg61); var v6 : Boolean = true; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "2/3" var arg71 : String = "5/2" var x7 : Boolean = simplify(arg70, arg71); var v7 : Boolean = false; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : String = "5/2" var arg81 : String = "3/5" var x8 : Boolean = simplify(arg80, arg81); var v8 : Boolean = false; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : String = "2/4" var arg91 : String = "8/4" var x9 : Boolean = simplify(arg90, arg91); var v9 : Boolean = true; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : String = "2/4" var arg101 : String = "4/2" var x10 : Boolean = simplify(arg100, arg101); var v10 : Boolean = true; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : String = "1/5" var arg111 : String = "5/1" var x11 : Boolean = simplify(arg110, arg111); var v11 : Boolean = true; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120 : String = "1/5" var arg121 : String = "1/5" var x12 : Boolean = simplify(arg120, arg121); var v12 : Boolean = false; if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } }
/** * 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 format, * <numerator>/<denominator> where both numerator and denominator are positive whole numbers. * You can assume that x, and n are valid fractions, and do not have zero as denominator. * simplify("1/5", "5/1") = True * simplify("1/6", "2/1") = False * simplify("7/10", "10/2") = False * */
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 * denominatorN", "", " return productNumerator % productDenominator == 0", "}", "", "" ]
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"] * words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] * */ fun wordsString(s: String): List<String> {
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, three, four, five, six" var x1: List<String> = wordsString(arg10) var v1: List<String> = mutableListOf("One", "two", "three", "four", "five", "six") if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "Hi, my name" var x2: List<String> = wordsString(arg20) var v2: List<String> = mutableListOf("Hi", "my", "name") if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "One,, two, three, four, five, six," var x3: List<String> = wordsString(arg30) var v3: List<String> = mutableListOf("One", "two", "three", "four", "five", "six") if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "" var x4: List<String> = wordsString(arg40) var v4: List<String> = mutableListOf() if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "ahmed , gamal" var x5: List<String> = wordsString(arg50) var v5: List<String> = mutableListOf("ahmed", "gamal") if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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"] * words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"] * */
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 smaller natural numbers). * Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. * Prime numbers are 2, 3, 5, 7, 11, 13, 17,... * So you have to determine a number of the following digits: 2, 3, 5, 7, * B (=decimal 11), D (=decimal 13). * Note: you may assume the input is always correct or empty string, * and symbols A,B,C,D,E,F are always uppercase. * Examples: * For num = "AB" the output should be 1. * For num = "1077E" the output should be 2. * For num = "ABED1A33" the output should be 4. * For num = "123456789ABCDEF0" the output should be 6. * For num = "2020" the output should be 2. * */ fun hexKey(num: String): Int {
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 Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "ABED1A33" var x2: Int = hexKey(arg20) var v2: Int = 4 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "2020" var x3: Int = hexKey(arg30) var v3: Int = 2 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "123456789ABCDEF0" var x4: Int = hexKey(arg40) var v4: Int = 6 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "112233445566778899AABBCCDDEEFF00" var x5: Int = hexKey(arg50) var v5: Int = 12 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "" var x6: Int = hexKey(arg60) var v6: Int = 0 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 smaller natural numbers). * Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. * Prime numbers are 2, 3, 5, 7, 11, 13, 17,... * So you have to determine a number of the following digits: 2, 3, 5, 7, * B (=decimal 11), D (=decimal 13). * Note: you may assume the input is always correct or empty string, * and symbols A,B,C,D,E,F are always uppercase. * Examples: * For num = "AB" the output should be 1. * For num = "1077E" the output should be 2. * For num = "ABED1A33" the output should be 4. * For num = "123456789ABCDEF0" the output should be 6. * For num = "2020" the output should be 2. * */
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", "b":"banana"}) should return True. * check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False. * check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False. * check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False. * check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True. * */ fun checkDictCase(dict: Map<Any?, Any?>): Boolean {
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" to "pineapple", "A" to "banana", "B" to "banana") var x1: Boolean = checkDictCase(arg10) var v1: Boolean = false if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Map<Any?, Any?> = mutableMapOf("p" to "pineapple", 5 to "banana", "a" to "apple") var x2: Boolean = checkDictCase(arg20) var v2: Boolean = false if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Map<Any?, Any?> = mutableMapOf("Name" to "John", "Age" to "36", "City" to "Houston") var x3: Boolean = checkDictCase(arg30) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Map<Any?, Any?> = mutableMapOf("STATE" to "NC", "ZIP" to "12345") var x4: Boolean = checkDictCase(arg40) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Map<Any?, Any?> = mutableMapOf("fruit" to "Orange", "taste" to "Sweet") var x5: Boolean = checkDictCase(arg50) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Map<Any?, Any?> = mutableMapOf() var x6: Boolean = checkDictCase(arg60) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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", "b":"banana"}) should return True. * check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False. * check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False. * check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False. * check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True. * */
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 - x_mean | * >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) * 1.0 * */ fun meanAbsoluteDeviation(numbers: List<Double>): Double {
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, 3.0, 4.0) var x1: Double = meanAbsoluteDeviation(arg10) var v1: Double = 1.0 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Double> = mutableListOf(1.0, 2.0, 3.0, 4.0, 5.0) var x2: Double = meanAbsoluteDeviation(arg20) var v2: Double = 1.2 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 - x_mean | * >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0]) * 1.0 * */
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" * */ fun circularShift(x: Int, shift: Int): String {
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 = circularShift(arg10, arg11) var v1: String = "12" if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 97 var arg21: Int = 8 var x2: String = circularShift(arg20, arg21) var v2: String = "79" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 12 var arg31: Int = 1 var x3: String = circularShift(arg30, arg31) var v3: String = "21" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 11 var arg41: Int = 101 var x4: String = circularShift(arg40, arg41) var v4: String = "11" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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", "", " return if (effectiveShift == length) {", " digits.reversed()", " } else {", " digits.substring(length - effectiveShift) + digits.substring(0, length - effectiveShift)", " }", "}", "", "" ]
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(arg10, arg11) var v1: Double = 2.0 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 10 var arg21: Int = 8 var x2: Double = triangleArea(arg20, arg21) var v2: Double = 40.0 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 120 var x2 : Int = digits(arg20); var v2 : Int = 1; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 5014 var x3 : Int = digits(arg30); var v3 : Int = 5; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 98765 var x4 : Int = digits(arg40); var v4 : Int = 315; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 5576543 var x5 : Int = digits(arg50); var v5 : Int = 2625; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 2468 var x6 : Int = digits(arg60); var v6 : Int = 0; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 oddDigitsProduct", "}", "", "" ]
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_nested('[[]]') ➞ True * is_nested('[]]]]]]][[[[[]') ➞ False * is_nested('[][]') ➞ False * is_nested('[]') ➞ False * is_nested('[[][]]') ➞ True * is_nested('[[]][[') ➞ True * */ fun isNested(string : String) : Boolean {
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 = false; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "[][]" var x2 : Boolean = isNested(arg20); var v2 : Boolean = false; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "[]" var x3 : Boolean = isNested(arg30); var v3 : Boolean = false; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "[[[[]]]]" var x4 : Boolean = isNested(arg40); var v4 : Boolean = true; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "[]]]]]]]]]]" var x5 : Boolean = isNested(arg50); var v5 : Boolean = false; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "[][][[]]" var x6 : Boolean = isNested(arg60); var v6 : Boolean = true; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "[[]" var x7 : Boolean = isNested(arg70); var v7 : Boolean = false; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : String = "[]]" var x8 : Boolean = isNested(arg80); var v8 : Boolean = false; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : String = "[[]][[" var x9 : Boolean = isNested(arg90); var v9 : Boolean = true; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : String = "[[][]]" var x10 : Boolean = isNested(arg100); var v10 : Boolean = true; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : String = "" var x11 : Boolean = isNested(arg110); var v11 : Boolean = false; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120 : String = "[[[[[[[[" var x12 : Boolean = isNested(arg120); var v12 : Boolean = false; if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } var arg130 : String = "]]]]]]]]" var x13 : Boolean = isNested(arg130); var v13 : Boolean = false; if (x13 != v13) { throw Exception("Exception -- test case 13 did not pass. x13 = " + x13) } }
/** * 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_nested('[[]]') ➞ True * is_nested('[]]]]]]][[[[[]') ➞ False * is_nested('[][]') ➞ False * is_nested('[]') ➞ False * is_nested('[[][]]') ➞ True * is_nested('[[]][[') ➞ True * */
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 && foundNest) return true", " }", " return false", "}", "", "" ]
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 (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "aaaaa" var x2: Boolean = isPalindrome(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "zbcd" var x3: Boolean = isPalindrome(arg30) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "xywyx" var x4: Boolean = isPalindrome(arg40) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "xywyz" var x5: Boolean = isPalindrome(arg50) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "xywzx" var x6: Boolean = isPalindrome(arg60) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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_up_to(20) => [2,3,5,7,11,13,17,19] * count_up_to(1) => [] * count_up_to(18) => [2,3,5,7,11,13,17] * */ fun countUpTo(n: Int): List<Any> {
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> = mutableListOf(2, 3, 5) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 7 var x2: List<Any> = countUpTo(arg20) var v2: List<Any> = mutableListOf(2, 3, 5) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 10 var x3: List<Any> = countUpTo(arg30) var v3: List<Any> = mutableListOf(2, 3, 5, 7) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 0 var x4: List<Any> = countUpTo(arg40) var v4: List<Any> = mutableListOf() if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 22 var x5: List<Any> = countUpTo(arg50) var v5: List<Any> = mutableListOf(2, 3, 5, 7, 11, 13, 17, 19) if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 1 var x6: List<Any> = countUpTo(arg60) var v6: List<Any> = mutableListOf() if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 18 var x7: List<Any> = countUpTo(arg70) var v7: List<Any> = mutableListOf(2, 3, 5, 7, 11, 13, 17) if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: Int = 47 var x8: List<Any> = countUpTo(arg80) var v8: List<Any> = mutableListOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43) if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: Int = 101 var x9: List<Any> = countUpTo(arg90) var v9: List<Any> = mutableListOf(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97) if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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_up_to(20) => [2,3,5,7,11,13,17,19] * count_up_to(1) => [] * count_up_to(18) => [2,3,5,7,11,13,17] * */
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) {", " return false", " }", " }", " return true", " }", " return (2 until n).filter { isPrime(it) }", "}", "", "" ]
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 letters. * * Examples: * >>> encode('test') * 'TGST' * >>> encode('This is a message') * 'tHKS KS C MGSSCGG' * */ fun encode(message: String): String {
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 (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "YES" var x2: String = encode(arg20) var v2: String = "ygs" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "This is a message" var x3: String = encode(arg30) var v3: String = "tHKS KS C MGSSCGG" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "I DoNt KnOw WhAt tO WrItE" var x4: String = encode(arg40) var v4: String = "k dQnT kNqW wHcT Tq wRkTg" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 letters. * * Examples: * >>> encode('test') * 'TGST' * >>> encode('This is a message') * 'tHKS KS C MGSSCGG' * */
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 ->", " val swappedCaseChar = if (char.isUpperCase()) {", " char.lowercaseChar()", " } else {", " char.uppercaseChar()", " }", " vowelMap.getOrDefault(swappedCaseChar, swappedCaseChar)", " }.joinToString(\"\")", "}", "", "" ]
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 the extension's name, and let SM be the number of lowercase letters * in the extension's name, the strength is given by the fraction CAP - SM. * You should find the strongest extension and return a string in this * format: ClassName.StrongestExtensionName. * If there are two or more extensions with the same strength, you should * choose the one that comes first in the list. * For example, if you are given "Slices" as the class and a list of the * extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should * return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension * (its strength is -1). * Example: * for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA' * */ fun strongestExtension(className : String, extensions : List<String>) : String {
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) } var arg10 : String = "Boku123" var arg11 : List<String> = mutableListOf("nani", "NazeDa", "YEs.WeCaNe", "32145tggg") var x1 : String = strongestExtension(arg10, arg11); var v1 : String = "Boku123.YEs.WeCaNe"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "__YESIMHERE" var arg21 : List<String> = mutableListOf("t", "eMptY", "nothing", "zeR00", "NuLl__", "123NoooneB321") var x2 : String = strongestExtension(arg20, arg21); var v2 : String = "__YESIMHERE.NuLl__"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "K" var arg31 : List<String> = mutableListOf("Ta", "TAR", "t234An", "cosSo") var x3 : String = strongestExtension(arg30, arg31); var v3 : String = "K.TAR"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "__HAHA" var arg41 : List<String> = mutableListOf("Tab", "123", "781345", "-_-") var x4 : String = strongestExtension(arg40, arg41); var v4 : String = "__HAHA.123"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "YameRore" var arg51 : List<String> = mutableListOf("HhAas", "okIWILL123", "WorkOut", "Fails", "-_-") var x5 : String = strongestExtension(arg50, arg51); var v5 : String = "YameRore.okIWILL123"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "finNNalLLly" var arg61 : List<String> = mutableListOf("Die", "NowW", "Wow", "WoW") var x6 : String = strongestExtension(arg60, arg61); var v6 : String = "finNNalLLly.WoW"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "_" var arg71 : List<String> = mutableListOf("Bb", "91245") var x7 : String = strongestExtension(arg70, arg71); var v7 : String = "_.Bb"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : String = "Sp" var arg81 : List<String> = mutableListOf("671235", "Bb") var x8 : String = strongestExtension(arg80, arg81); var v8 : String = "Sp.671235"; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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 the extension's name, and let SM be the number of lowercase letters * in the extension's name, the strength is given by the fraction CAP - SM. * You should find the strongest extension and return a string in this * format: ClassName.StrongestExtensionName. * If there are two or more extensions with the same strength, you should * choose the one that comes first in the list. * For example, if you are given "Slices" as the class and a list of the * extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should * return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension * (its strength is -1). * Example: * for Strongest_Extension('my_class', ['AA', 'Be', 'CC']) == 'my_class.AA' * */
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() }", " if (strength > maxStrength) {", " strongestExtension = extension", " maxStrength = strength", " }", " }", "", " return \"$className.$strongestExtension\"", "}", "", "" ]
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> = incrList(arg10) var v1: List<Int> = mutableListOf(4, 3, 2) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(5, 2, 5, 2, 3, 3, 9, 0, 123) var x2: List<Int> = incrList(arg20) var v2: List<Int> = mutableListOf(6, 3, 6, 3, 4, 4, 10, 1, 124) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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') * False * >>> same_chars('abcd', 'dddddddabce') * False * >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc') * False * */ fun sameChars(s0: String, s1: String): Boolean {
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: String = "dddddddabc" var x1: Boolean = sameChars(arg10, arg11) var v1: Boolean = true if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "dddddddabc" var arg21: String = "abcd" var x2: Boolean = sameChars(arg20, arg21) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "eabcd" var arg31: String = "dddddddabc" var x3: Boolean = sameChars(arg30, arg31) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "abcd" var arg41: String = "dddddddabcf" var x4: Boolean = sameChars(arg40, arg41) var v4: Boolean = false if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "eabcdzzzz" var arg51: String = "dddzzzzzzzddddabc" var x5: Boolean = sameChars(arg50, arg51) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "aabb" var arg61: String = "aaccc" var x6: Boolean = sameChars(arg60, arg61) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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') * False * >>> same_chars('abcd', 'dddddddabce') * False * >>> same_chars('eabcdzzzz', 'dddzzzzzzzddddabc') * False * */
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 * choose_num(13, 12) = -1 * */ fun chooseNum(x: Int, y: Int): Int {
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) var v1: Int = -1 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 33 var arg21: Int = 12354 var x2: Int = chooseNum(arg20, arg21) var v2: Int = 12354 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 5234 var arg31: Int = 5233 var x3: Int = chooseNum(arg30, arg31) var v3: Int = -1 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 6 var arg41: Int = 29 var x4: Int = chooseNum(arg40, arg41) var v4: Int = 28 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 27 var arg51: Int = 10 var x5: Int = chooseNum(arg50, arg51) var v5: Int = -1 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 7 var arg61: Int = 7 var x6: Int = chooseNum(arg60, arg61) var v6: Int = -1 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 546 var arg71: Int = 546 var x7: Int = chooseNum(arg70, arg71) var v7: Int = 546 if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 * choose_num(13, 12) = -1 * */
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 smallest even value are found return the node that has smallest index. * The plucked node should be returned in a list, [ smalest_value, its index ], * If there are no even values or the given array is empty, return []. * Example 1: * Input: [4,2,3] * Output: [2, 1] * Explanation: 2 has the smallest even value, and 2 has the smallest index. * Example 2: * Input: [1,2,3] * Output: [2, 1] * Explanation: 2 has the smallest even value, and 2 has the smallest index. * Example 3: * Input: [] * Output: [] * * Example 4: * Input: [5, 0, 3, 0, 4, 2] * Output: [0, 1] * Explanation: 0 is the smallest value, but there are two zeros, * so we will choose the first zero, which has the smallest index. * Constraints: * * 1 <= nodes.length <= 10000 * * 0 <= node.value * */ fun pluck(arr: List<Int>): List<Int> {
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> = pluck(arg10) var v1: List<Int> = mutableListOf(2, 1) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf() var x2: List<Int> = pluck(arg20) var v2: List<Int> = mutableListOf() if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(5, 0, 3, 0, 4, 2) var x3: List<Int> = pluck(arg30) var v3: List<Int> = mutableListOf(0, 1) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(1, 2, 3, 0, 5, 3) var x4: List<Int> = pluck(arg40) var v4: List<Int> = mutableListOf(0, 3) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(5, 4, 8, 4, 8) var x5: List<Int> = pluck(arg50) var v5: List<Int> = mutableListOf(4, 1) if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(7, 6, 7, 1) var x6: List<Int> = pluck(arg60) var v6: List<Int> = mutableListOf(6, 1) if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(7, 9, 7, 1) var x7: List<Int> = pluck(arg70) var v7: List<Int> = mutableListOf() if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 smallest even value are found return the node that has smallest index. * The plucked node should be returned in a list, [ smalest_value, its index ], * If there are no even values or the given array is empty, return []. * Example 1: * Input: [4,2,3] * Output: [2, 1] * Explanation: 2 has the smallest even value, and 2 has the smallest index. * Example 2: * Input: [1,2,3] * Output: [2, 1] * Explanation: 2 has the smallest even value, and 2 has the smallest index. * Example 3: * Input: [] * Output: [] * * Example 4: * Input: [5, 0, 3, 0, 4, 2] * Output: [0, 1] * Explanation: 0 is the smallest value, but there are two zeros, * so we will choose the first zero, which has the smallest index. * Constraints: * * 1 <= nodes.length <= 10000 * * 0 <= node.value * */
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)", " val smallestEven = evenNumbersWithIndices.minByOrNull { it.first }", "", " // Return the result according to the presence of an even number", " return if (smallestEven != null) listOf(smallestEven.first, smallestEven.second) else emptyList()", "}", "", "" ]
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. * Examples * solve("1234") = "4321" * solve("ab") = "AB" * solve("#a@C") = "#A@c" * */ fun solve(s : String) : String {
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 (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "ab" var x2 : String = solve(arg20); var v2 : String = "AB"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "#a@C" var x3 : String = solve(arg30); var v3 : String = "#A@c"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "#AsdfW^45" var x4 : String = solve(arg40); var v4 : String = "#aSDFw^45"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "#6@2" var x5 : String = solve(arg50); var v5 : String = "2@6#"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "#\$a^D" var x6 : String = solve(arg60); var v6 : String = "#\$A^d"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "#ccc" var x7 : String = solve(arg70); var v7 : String = "#CCC"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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. * Examples * solve("1234") = "4321" * solve("ab") = "AB" * solve("#a@C") = "#A@c" * */
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() -> char.uppercase()", " else -> char.toString()", " }", " }.joinToString(\"\")", "}", "", "" ]
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 operation on the given array: * You are allowed to perform right shift operation any number of times. * * One right shift operation means shifting all elements of the array by one * position in the right direction. The last element of the array will be moved to * the starting position in the array i.e. 0th index. * If it is possible to obtain the sorted array by performing the above operation * then return True else return False. * If the given array is empty then return True. * Note: The given list is guaranteed to have unique elements. * For Example: * * move_one_ball([3, 4, 5, 1, 2])==>True * Explanation: By performin 2 right shift operations, non-decreasing order can * be achieved for the given array. * move_one_ball([3, 5, 4, 1, 2])==>False * Explanation:It is not possible to get non-decreasing order for the given * array by performing any number of right shift operations. * * */ fun moveOneBall(arr: List<Int>): Boolean {
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 = moveOneBall(arg10); var v1: Boolean = true; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(4, 3, 1, 2) var x2: Boolean = moveOneBall(arg20); var v2: Boolean = false; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(3, 5, 4, 1, 2) var x3: Boolean = moveOneBall(arg30); var v3: Boolean = false; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf() var x4: Boolean = moveOneBall(arg40); var v4: Boolean = true; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 operation on the given array: * You are allowed to perform right shift operation any number of times. * * One right shift operation means shifting all elements of the array by one * position in the right direction. The last element of the array will be moved to * the starting position in the array i.e. 0th index. * If it is possible to obtain the sorted array by performing the above operation * then return True else return False. * If the given array is empty then return True. * Note: The given list is guaranteed to have unique elements. * For Example: * * move_one_ball([3, 4, 5, 1, 2])==>True * Explanation: By performin 2 right shift operations, non-decreasing order can * be achieved for the given array. * move_one_ball([3, 5, 4, 1, 2])==>False * Explanation:It is not possible to get non-decreasing order for the given * array by performing any number of right shift operations. * * */
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", " }", " }", "", " if (pivotCount > 1) {", " return false", " }", " if (pivotCount == 0) {", " return true", " }", "", " return arr.slice(0 until pivotIndex).sorted() ==", " arr.slice(0 until pivotIndex) &&", " arr.slice(pivotIndex until arr.size).sorted() ==", " arr.slice(pivotIndex until arr.size) &&", " arr.last() <= arr.first()", "}", "", "" ]
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 * >>> correct_bracketing(")(()") * False * */ fun correctBracketing2(brackets: String): Boolean {
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: Boolean = true if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "()()(()())()" var x2: Boolean = correctBracketing2(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "()()((()()())())(()()(()))" var x3: Boolean = correctBracketing2(arg30) var v3: Boolean = true if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "((()())))" var x4: Boolean = correctBracketing2(arg40) var v4: Boolean = false if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = ")(()" var x5: Boolean = correctBracketing2(arg50) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "(" var x6: Boolean = correctBracketing2(arg60) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: String = "((((" var x7: Boolean = correctBracketing2(arg70) var v7: Boolean = false if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: String = ")" var x8: Boolean = correctBracketing2(arg80) var v8: Boolean = false if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: String = "(()" var x9: Boolean = correctBracketing2(arg90) var v9: Boolean = false if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: String = "()()(()())())(()" var x10: Boolean = correctBracketing2(arg100) var v10: Boolean = false if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: String = "()()(()())()))()" var x11: Boolean = correctBracketing2(arg110) var v11: Boolean = false if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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 * >>> correct_bracketing(")(()") * False * */
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 balance.last() == 0 && balance.min() >= 0", "}", "", "" ]
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] * strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5] * strange_sort_list([]) == [] * */ fun strangeSortList(lst: List<Int>): List<Int> {
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, 9) var x1: List<Int> = strangeSortList(arg10) var v1: List<Int> = mutableListOf(5, 9, 6, 8, 7) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 2, 3, 4, 5) var x2: List<Int> = strangeSortList(arg20) var v2: List<Int> = mutableListOf(1, 5, 2, 4, 3) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(5, 6, 7, 8, 9, 1) var x3: List<Int> = strangeSortList(arg30) var v3: List<Int> = mutableListOf(1, 9, 5, 8, 6, 7) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(5, 5, 5, 5) var x4: List<Int> = strangeSortList(arg40) var v4: List<Int> = mutableListOf(5, 5, 5, 5) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf() var x5: List<Int> = strangeSortList(arg50) var v5: List<Int> = mutableListOf() if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8) var x6: List<Int> = strangeSortList(arg60) var v6: List<Int> = mutableListOf(1, 8, 2, 7, 3, 6, 4, 5) if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(0, 2, 2, 2, 5, 5, -5, -5) var x7: List<Int> = strangeSortList(arg70) var v7: List<Int> = mutableListOf(-5, 5, -5, 5, 0, 2, 2, 2) if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: List<Int> = mutableListOf(111111) var x8: List<Int> = strangeSortList(arg80) var v8: List<Int> = mutableListOf(111111) if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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] * strange_sort_list([5, 5, 5, 5]) == [5, 5, 5, 5] * strange_sort_list([]) == [] * */
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) {", " result.add(sortedList.removeAt(0))", " } else {", " result.add(sortedList.removeAt(sortedList.size - 1))", " }", " addingMinimum = !addingMinimum", " }", "", " return result", "}", "", "" ]
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_angle_triangle(3, 4, 5) == True * right_angle_triangle(1, 2, 3) == False * */ fun rightAngleTriangle(a : Int, b : Int, c : Int) : Boolean {
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 : Int = 2 var arg12 : Int = 3 var x1 : Boolean = rightAngleTriangle(arg10, arg11, arg12); var v1 : Boolean = false; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 10 var arg21 : Int = 6 var arg22 : Int = 8 var x2 : Boolean = rightAngleTriangle(arg20, arg21, arg22); var v2 : Boolean = true; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 2 var arg31 : Int = 2 var arg32 : Int = 2 var x3 : Boolean = rightAngleTriangle(arg30, arg31, arg32); var v3 : Boolean = false; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 7 var arg41 : Int = 24 var arg42 : Int = 25 var x4 : Boolean = rightAngleTriangle(arg40, arg41, arg42); var v4 : Boolean = true; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 10 var arg51 : Int = 5 var arg52 : Int = 7 var x5 : Boolean = rightAngleTriangle(arg50, arg51, arg52); var v5 : Boolean = false; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 5 var arg61 : Int = 12 var arg62 : Int = 13 var x6 : Boolean = rightAngleTriangle(arg60, arg61, arg62); var v6 : Boolean = true; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Int = 15 var arg71 : Int = 8 var arg72 : Int = 17 var x7 : Boolean = rightAngleTriangle(arg70, arg71, arg72); var v7 : Boolean = true; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : Int = 48 var arg81 : Int = 55 var arg82 : Int = 73 var x8 : Boolean = rightAngleTriangle(arg80, arg81, arg82); var v8 : Boolean = true; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : Int = 1 var arg91 : Int = 1 var arg92 : Int = 1 var x9 : Boolean = rightAngleTriangle(arg90, arg91, arg92); var v9 : Boolean = false; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : Int = 2 var arg101 : Int = 2 var arg102 : Int = 10 var x10 : Boolean = rightAngleTriangle(arg100, arg101, arg102); var v10 : Boolean = false; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } }
/** * 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_angle_triangle(3, 4, 5) == True * right_angle_triangle(1, 2, 3) == False * */
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: * >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5] * >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2] * >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4] * */ fun sortArrayByBinary(arr: List<Int>): List<Int> {
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, -3, -4, -5, -6) var x1: List<Int> = sortArrayByBinary(arg10); var v1: List<Int> = mutableListOf(-4, -2, -6, -5, -3); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 0, 2, 3, 4) var x2: List<Int> = sortArrayByBinary(arg20); var v2: List<Int> = mutableListOf(0, 1, 2, 4, 3); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf() var x3: List<Int> = sortArrayByBinary(arg30); var v3: List<Int> = mutableListOf(); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(2, 5, 77, 4, 5, 3, 5, 7, 2, 3, 4) var x4: List<Int> = sortArrayByBinary(arg40); var v4: List<Int> = mutableListOf(2, 2, 4, 4, 3, 3, 5, 5, 5, 7, 77); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(3, 6, 44, 12, 32, 5) var x5: List<Int> = sortArrayByBinary(arg50); var v5: List<Int> = mutableListOf(32, 3, 5, 6, 12, 44); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(2, 4, 8, 16, 32) var x6: List<Int> = sortArrayByBinary(arg60); var v6: List<Int> = mutableListOf(2, 4, 8, 16, 32); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(2, 4, 8, 16, 32) var x7: List<Int> = sortArrayByBinary(arg70); var v7: List<Int> = mutableListOf(2, 4, 8, 16, 32); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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: * >>> sort_array([1, 5, 2, 3, 4]) == [1, 2, 3, 4, 5] * >>> sort_array([-2, -3, -4, -5, -6]) == [-6, -5, -4, -3, -2] * >>> sort_array([1, 0, 2, 3, 4]) [0, 1, 2, 3, 4] * */
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 interval, it is assumed that its start is less or equal its end. * Your task is to determine whether the length of intersection of these two * intervals is a prime number. * Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3) * which its length is 1, which not a prime number. * If the length of the intersection is a prime number, return "YES", * otherwise, return "NO". * If the two intervals don't intersect, return "NO". * [input/output] samples: * intersection((1, 2), (2, 3)) ==> "NO" * intersection((-1, 1), (0, 4)) ==> "NO" * intersection((-3, -1), (-5, 5)) ==> "YES" * */ fun intersection(interval1 : List<Int>, interval2 : List<Int>) : String {
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> = mutableListOf(-1, 1) var arg11 : List<Int> = mutableListOf(0, 4) var x1 : String = intersection(arg10, arg11); var v1 : String = "NO"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(-3, -1) var arg21 : List<Int> = mutableListOf(-5, 5) var x2 : String = intersection(arg20, arg21); var v2 : String = "YES"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(-2, 2) var arg31 : List<Int> = mutableListOf(-4, 0) var x3 : String = intersection(arg30, arg31); var v3 : String = "YES"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(-11, 2) var arg41 : List<Int> = mutableListOf(-1, -1) var x4 : String = intersection(arg40, arg41); var v4 : String = "NO"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(1, 2) var arg51 : List<Int> = mutableListOf(3, 5) var x5 : String = intersection(arg50, arg51); var v5 : String = "NO"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf(1, 2) var arg61 : List<Int> = mutableListOf(1, 2) var x6 : String = intersection(arg60, arg61); var v6 : String = "NO"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(-2, -2) var arg71 : List<Int> = mutableListOf(-3, -2) var x7 : String = intersection(arg70, arg71); var v7 : String = "NO"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 interval, it is assumed that its start is less or equal its end. * Your task is to determine whether the length of intersection of these two * intervals is a prime number. * Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3) * which its length is 1, which not a prime number. * If the length of the intersection is a prime number, return "YES", * otherwise, return "NO". * If the two intervals don't intersect, return "NO". * [input/output] samples: * intersection((1, 2), (2, 3)) ==> "NO" * intersection((-1, 1), (0, 4)) ==> "NO" * intersection((-3, -1), (-5, 5)) ==> "YES" * */
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", " }", " if (num % i == 0) {", " return false", " }", " }", " return true", " }", "\treturn if (isPrime(Math.min(interval1[1], interval2[1]) - Math.max(interval1[0], interval2[0]))) {", " \"YES\"", " } else {", " \"NO\"", " }", "}", "", "" ]
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. * Examples * total_match([], []) ➞ [] * total_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi'] * total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin'] * total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi'] * total_match(['4'], ['1', '2', '3', '4', '5']) ➞ ['4'] * */ fun totalMatch(lst1: List<String>, lst2: List<String>): List<String> {
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: List<String> = mutableListOf("hi", "admin") var arg11: List<String> = mutableListOf("hi", "hi") var x1: List<String> = totalMatch(arg10, arg11) var v1: List<String> = mutableListOf("hi", "hi") if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<String> = mutableListOf("hi", "admin") var arg21: List<String> = mutableListOf("hi", "hi", "admin", "project") var x2: List<String> = totalMatch(arg20, arg21) var v2: List<String> = mutableListOf("hi", "admin") if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<String> = mutableListOf("4") var arg31: List<String> = mutableListOf("1", "2", "3", "4", "5") var x3: List<String> = totalMatch(arg30, arg31) var v3: List<String> = mutableListOf("4") if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<String> = mutableListOf("hi", "admin") var arg41: List<String> = mutableListOf("hI", "Hi") var x4: List<String> = totalMatch(arg40, arg41) var v4: List<String> = mutableListOf("hI", "Hi") if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<String> = mutableListOf("hi", "admin") var arg51: List<String> = mutableListOf("hI", "hi", "hi") var x5: List<String> = totalMatch(arg50, arg51) var v5: List<String> = mutableListOf("hI", "hi", "hi") if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<String> = mutableListOf("hi", "admin") var arg61: List<String> = mutableListOf("hI", "hi", "hii") var x6: List<String> = totalMatch(arg60, arg61) var v6: List<String> = mutableListOf("hi", "admin") if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<String> = mutableListOf() var arg71: List<String> = mutableListOf("this") var x7: List<String> = totalMatch(arg70, arg71) var v7: List<String> = mutableListOf() if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: List<String> = mutableListOf("this") var arg81: List<String> = mutableListOf() var x8: List<String> = totalMatch(arg80, arg81) var v8: List<String> = mutableListOf() if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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. * Examples * total_match([], []) ➞ [] * total_match(['hi', 'admin'], ['hI', 'Hi']) ➞ ['hI', 'Hi'] * total_match(['hi', 'admin'], ['hi', 'hi', 'admin', 'project']) ➞ ['hi', 'admin'] * total_match(['hi', 'admin'], ['hI', 'hi', 'hi']) ➞ ['hI', 'hi', 'hi'] * total_match(['4'], ['1', '2', '3', '4', '5']) ➞ ['4'] * */
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 * */ fun hasCloseElements(numbers: List<Double>, threshold: Double): Boolean {
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<Double> = mutableListOf(1.0, 2.0, 3.9, 4.0, 5.0, 2.2) var arg11: Double = 0.05 var x1: Boolean = hasCloseElements(arg10, arg11) var v1: Boolean = false if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Double> = mutableListOf(1.0, 2.0, 5.9, 4.0, 5.0) var arg21: Double = 0.95 var x2: Boolean = hasCloseElements(arg20, arg21) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Double> = mutableListOf(1.0, 2.0, 5.9, 4.0, 5.0) var arg31: Double = 0.8 var x3: Boolean = hasCloseElements(arg30, arg31) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Double> = mutableListOf(1.0, 2.0, 3.0, 4.0, 5.0, 2.0) var arg41: Double = 0.1 var x4: Boolean = hasCloseElements(arg40, arg41) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Double> = mutableListOf(1.1, 2.2, 3.1, 4.1, 5.1) var arg51: Double = 1.0 var x5: Boolean = hasCloseElements(arg50, arg51) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Double> = mutableListOf(1.1, 2.2, 3.1, 4.1, 5.1) var arg61: Double = 0.5 var x6: Boolean = hasCloseElements(arg60, arg61) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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". * Example: * rounded_avg(1, 5) => "0b11" * rounded_avg(7, 5) => -1 * rounded_avg(10, 20) => "0b1111" * rounded_avg(20, 33) => "0b11010" * */ fun roundedAvg(n: Int, m: Int): String {
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(arg10, arg11); var v1: String = "0b1010"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 964 var arg21: Int = 977 var x2: String = roundedAvg(arg20, arg21); var v2: String = "0b1111001010"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 996 var arg31: Int = 997 var x3: String = roundedAvg(arg30, arg31); var v3: String = "0b1111100100"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 560 var arg41: Int = 851 var x4: String = roundedAvg(arg40, arg41); var v4: String = "0b1011000001"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 185 var arg51: Int = 546 var x5: String = roundedAvg(arg50, arg51); var v5: String = "0b101101101"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 362 var arg61: Int = 496 var x6: String = roundedAvg(arg60, arg61); var v6: String = "0b110101101"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 350 var arg71: Int = 902 var x7: String = roundedAvg(arg70, arg71); var v7: String = "0b1001110010"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: Int = 197 var arg81: Int = 233 var x8: String = roundedAvg(arg80, arg81); var v8: String = "0b11010111"; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: Int = 7 var arg91: Int = 5 var x9: String = roundedAvg(arg90, arg91); var v9: String = "-1"; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: Int = 5 var arg101: Int = 1 var x10: String = roundedAvg(arg100, arg101); var v10: String = "-1"; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: Int = 5 var arg111: Int = 5 var x11: String = roundedAvg(arg110, arg111); var v11: String = "0b101"; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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". * Example: * rounded_avg(1, 5) => "0b11" * rounded_avg(7, 5) => -1 * rounded_avg(10, 20) => "0b1111" * rounded_avg(20, 33) => "0b11010" * */
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 to any other element. * For example: * smallest_change([1,2,3,5,4,7,9,6]) == 4 * smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1 * smallest_change([1, 2, 3, 2, 1]) == 0 * */ fun smallestChange(arr: List<Int>): Int {
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 = smallestChange(arg10) var v1: Int = 1 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 4, 2) var x2: Int = smallestChange(arg20) var v2: Int = 1 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(1, 4, 4, 2) var x3: Int = smallestChange(arg30) var v3: Int = 1 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(1, 2, 3, 2, 1) var x4: Int = smallestChange(arg40) var v4: Int = 0 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(3, 1, 1, 3) var x5: Int = smallestChange(arg50) var v5: Int = 0 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(1) var x6: Int = smallestChange(arg60) var v6: Int = 0 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(0, 1) var x7: Int = smallestChange(arg70) var v7: Int = 1 if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 to any other element. * For example: * smallest_change([1,2,3,5,4,7,9,6]) == 4 * smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1 * smallest_change([1, 2, 3, 2, 1]) == 0 * */
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 N = 147, the sum of digits will be 12 the output should be "1100". * * Variables: * @N integer * Constraints: 0 ≀ N ≀ 10000. * Output: * a string of binary number * */ fun solve(n: Int): String {
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) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 147 var x2: String = solve(arg20) var v2: String = "1100" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 333 var x3: String = solve(arg30) var v3: String = "1001" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 963 var x4: String = solve(arg40) var v4: String = "10010" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 N = 147, the sum of digits will be 12 the output should be "1100". * * Variables: * @N integer * Constraints: 0 ≀ N ≀ 10000. * Output: * a string of binary number * */
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 GPAs for some students, and you have to write * a function that can output a list of letter grades using the following table: * GPA | Letter grade * 4.0 A+ * > 3.7 A * > 3.3 A- * > 3.0 B+ * > 2.7 B * > 2.3 B- * > 2.0 C+ * > 1.7 C * > 1.3 C- * > 1.0 D+ * > 0.7 D * > 0.0 D- * 0.0 E * * Example: * grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-'] * */ fun numericalLetterGrade(grades: List<Double>): List<String> {
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 arg10: List<Double> = mutableListOf(1.2) var x1: List<String> = numericalLetterGrade(arg10) var v1: List<String> = mutableListOf("D+") if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Double> = mutableListOf(0.5) var x2: List<String> = numericalLetterGrade(arg20) var v2: List<String> = mutableListOf("D-") if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Double> = mutableListOf(0.0) var x3: List<String> = numericalLetterGrade(arg30) var v3: List<String> = mutableListOf("E") if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Double> = mutableListOf(1.0, 0.3, 1.5, 2.8, 3.3) var x4: List<String> = numericalLetterGrade(arg40) var v4: List<String> = mutableListOf("D", "D-", "C-", "B", "B+") if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Double> = mutableListOf(0.0, 0.7) var x5: List<String> = numericalLetterGrade(arg50) var v5: List<String> = mutableListOf("E", "D-") if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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 GPAs for some students, and you have to write * a function that can output a list of letter grades using the following table: * GPA | Letter grade * 4.0 A+ * > 3.7 A * > 3.3 A- * > 3.0 B+ * > 2.7 B * > 2.3 B- * > 2.0 C+ * > 1.7 C * > 1.3 C- * > 1.0 D+ * > 0.7 D * > 0.0 D- * 0.0 E * * Example: * grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-'] * */
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\"", " gpa > 2.3 -> \"B-\"", " gpa > 2.0 -> \"C+\"", " gpa > 1.7 -> \"C\"", " gpa > 1.3 -> \"C-\"", " gpa > 1.0 -> \"D+\"", " gpa > 0.7 -> \"D\"", " gpa > 0.0 -> \"D-\"", " else -> \"E\"", " }", " }", "}", "", "" ]
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 = monotonic(arg10) var v1: Boolean = true if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 20, 4, 10) var x2: Boolean = monotonic(arg20) var v2: Boolean = false if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(4, 1, 0, -10) var x3: Boolean = monotonic(arg30) var v3: Boolean = true if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(4, 1, 1, 0) var x4: Boolean = monotonic(arg40) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(1, 2, 3, 2, 5, 60) var x5: Boolean = monotonic(arg50) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(1, 2, 3, 4, 5, 60) var x6: Boolean = monotonic(arg60) var v6: Boolean = true if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(9, 9, 9, 9) var x7: Boolean = monotonic(arg70) var v7: Boolean = true if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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) should return 0. * multiply(14,-15) should return 20. * */ fun multiply(a: Int, b: Int): Int {
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) var v1: Int = 72 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 2020 var arg21: Int = 1851 var x2: Int = multiply(arg20, arg21) var v2: Int = 0 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 14 var arg31: Int = -15 var x3: Int = multiply(arg30, arg31) var v3: Int = 20 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 76 var arg41: Int = 67 var x4: Int = multiply(arg40, arg41) var v4: Int = 42 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 17 var arg51: Int = 27 var x5: Int = multiply(arg50, arg51) var v5: Int = 49 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 0 var arg61: Int = 1 var x6: Int = multiply(arg60, arg61) var v6: Int = 0 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 0 var arg71: Int = 0 var x7: Int = multiply(arg70, arg71) var v7: Int = 0 if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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) should return 0. * multiply(14,-15) should return 20. * */
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('orange') == False * */ fun primeLength(string: String): Boolean {
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 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "kittens" var x2: Boolean = primeLength(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "orange" var x3: Boolean = primeLength(arg30) var v3: Boolean = false if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "wow" var x4: Boolean = primeLength(arg40) var v4: Boolean = true if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "world" var x5: Boolean = primeLength(arg50) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "MadaM" var x6: Boolean = primeLength(arg60) var v6: Boolean = true if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: String = "Wow" var x7: Boolean = primeLength(arg70) var v7: Boolean = true if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: String = "" var x8: Boolean = primeLength(arg80) var v8: Boolean = false if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: String = "HI" var x9: Boolean = primeLength(arg90) var v9: Boolean = true if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: String = "go" var x10: Boolean = primeLength(arg100) var v10: Boolean = true if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: String = "gogo" var x11: Boolean = primeLength(arg110) var v11: Boolean = false if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120: String = "aaaaaaaaaaaaaaa" var x12: Boolean = primeLength(arg120) var v12: Boolean = false if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } var arg130: String = "Madam" var x13: Boolean = primeLength(arg130) var v13: Boolean = true if (x13 != v13) { throw Exception("Exception -- test case 13 did not pass. x13 = " + x13) } var arg140: String = "M" var x14: Boolean = primeLength(arg140) var v14: Boolean = false if (x14 != v14) { throw Exception("Exception -- test case 14 did not pass. x14 = " + x14) } var arg150: String = "0" var x15: Boolean = primeLength(arg150) var v15: Boolean = false if (x15 != v15) { throw Exception("Exception -- test case 15 did not pass. x15 = " + x15) } }
/** * 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('orange') == False * */
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 == 0) {", " return false", " }", " }", " return true", " }", " return isPrime(string.length)", "}", "", "" ]
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 words in the new string should be the same as the original one. * Example 1: * Input: sentence = "This is a test" * Output: "is" * Example 2: * Input: sentence = "lets go for swimming" * Output: "go for" * Constraints: * * 1 <= len(sentence) <= 100 * * sentence contains only letters * */ fun wordsInSentence(sentence : String) : String {
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(arg10); var v1 : String = "go for"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "there is no place available here" var x2 : String = wordsInSentence(arg20); var v2 : String = "there is no place"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "Hi I am Hussein" var x3 : String = wordsInSentence(arg30); var v3 : String = "Hi am Hussein"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "go for it" var x4 : String = wordsInSentence(arg40); var v4 : String = "go for it"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "here" var x5 : String = wordsInSentence(arg50); var v5 : String = ""; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "here is" var x6 : String = wordsInSentence(arg60); var v6 : String = "is"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 words in the new string should be the same as the original one. * Example 1: * Input: sentence = "This is a test" * Output: "is" * Example 2: * Input: sentence = "lets go for swimming" * Output: "go for" * Constraints: * * 1 <= len(sentence) <= 100 * * sentence contains only letters * */
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) {", " return false", " }", " }", " return true", " }", " val words = sentence.split(\" \")", " val primeLengthWords = words.filter { isPrime(it.length) }", " return primeLengthWords.joinToString(\" \")", "}", "", "" ]
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 / 2, if n is even. * tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. * For example: * tri(2) = 1 + (2 / 2) = 2 * tri(4) = 3 * tri(3) = tri(2) + tri(1) + tri(4) * = 2 + 3 + 3 = 8 * You are given a non-negative integer number n, you have to a return a list of the * first n + 1 numbers of the Tribonacci sequence. * Examples: * tri(3) = [1, 3, 2, 8] * */ fun tri(n : Int) : List<Int> {
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> = mutableListOf(1, 3, 2, 8, 3); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 5 var x2 : List<Int> = tri(arg20); var v2 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 6 var x3 : List<Int> = tri(arg30); var v3 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15, 4); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 7 var x4 : List<Int> = tri(arg40); var v4 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15, 4, 24); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 8 var x5 : List<Int> = tri(arg50); var v5 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15, 4, 24, 5); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 9 var x6 : List<Int> = tri(arg60); var v6 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15, 4, 24, 5, 35); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Int = 20 var x7 : List<Int> = tri(arg70); var v7 : List<Int> = mutableListOf(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : Int = 0 var x8 : List<Int> = tri(arg80); var v8 : List<Int> = mutableListOf(1); if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : Int = 1 var x9 : List<Int> = tri(arg90); var v9 : List<Int> = mutableListOf(1, 3); if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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 / 2, if n is even. * tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. * For example: * tri(2) = 1 + (2 / 2) = 2 * tri(4) = 3 * tri(3) = tri(2) + tri(1) + tri(4) * = 2 + 3 + 3 = 8 * You are given a non-negative integer number n, you have to a return a list of the * first n + 1 numbers of the Tribonacci sequence. * Examples: * tri(3) = [1, 3, 2, 8] * */
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.add(tris[tris.size - 2] + 2 + ind)", " }", " }", " return 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: * largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1) * largest_smallest_integers([]) == (None, None) * largest_smallest_integers([0]) == (None, None) * */ fun largestSmallestIntegers(lst : List<Int>) : List<Int?> {
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> = mutableListOf(2, 4, 1, 3, 5, 7, 0) var x1 : List<Int?> = largestSmallestIntegers(arg10); var v1 : List<Int?> = mutableListOf(null, 1); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(1, 3, 2, 4, 5, 6, -2) var x2 : List<Int?> = largestSmallestIntegers(arg20); var v2 : List<Int?> = mutableListOf(-2, 1); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(4, 5, 3, 6, 2, 7, -7) var x3 : List<Int?> = largestSmallestIntegers(arg30); var v3 : List<Int?> = mutableListOf(-7, 2); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(7, 3, 8, 4, 9, 2, 5, -9) var x4 : List<Int?> = largestSmallestIntegers(arg40); var v4 : List<Int?> = mutableListOf(-9, 2); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf() var x5 : List<Int?> = largestSmallestIntegers(arg50); var v5 : List<Int?> = mutableListOf(null, null); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf(0) var x6 : List<Int?> = largestSmallestIntegers(arg60); var v6 : List<Int?> = mutableListOf(null, null); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(-1, -3, -5, -6) var x7 : List<Int?> = largestSmallestIntegers(arg70); var v7 : List<Int?> = mutableListOf(-1, null); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<Int> = mutableListOf(-1, -3, -5, -6, 0) var x8 : List<Int?> = largestSmallestIntegers(arg80); var v8 : List<Int?> = mutableListOf(-1, null); if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<Int> = mutableListOf(-6, -4, -4, -3, 1) var x9 : List<Int?> = largestSmallestIntegers(arg90); var v9 : List<Int?> = mutableListOf(-3, 1); if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<Int> = mutableListOf(-6, -4, -4, -3, -100, 1) var x10 : List<Int?> = largestSmallestIntegers(arg100); var v10 : List<Int?> = mutableListOf(-3, 1); if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } }
/** * 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: * largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1) * largest_smallest_integers([]) == (None, None) * largest_smallest_integers([0]) == (None, None) * */
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, smallestPositive)", "}", "", "" ]
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: String, substring: String): Int {
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 = howManyTimes(arg10, arg11) var v1: Int = 4 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "cacacacac" var arg21: String = "cac" var x2: Int = howManyTimes(arg20, arg21) var v2: Int = 4 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "john doe" var arg31: String = "john" var x3: Int = howManyTimes(arg30, arg31) var v3: Int = 1 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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) == substring", " }", " }", "}", "", "" ]
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(arg10); var v1 : String? = null; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "A B C" var x2 : String? = stringToMd5(arg20); var v2 : String? = "0ef78513b0cb8cef12743f5aeb35f888"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "password" var x3 : String? = stringToMd5(arg30); var v3 : String? = "5f4dcc3b5aa765d61d8327deb882cf99"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 hashBytes = md.digest(text.toByteArray())", " return hashBytes.joinToString(separator = \"\") { byte -> \"%02x\".format(byte) }", "}", "", "" ]
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 : List<Int>) : Int {
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(arg10); var v1 : Int = 0; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(5, 9) var x2 : Int = solution(arg20); var v2 : Int = 5; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(2, 4, 8) var x3 : Int = solution(arg30); var v3 : Int = 0; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(30, 13, 23, 32) var x4 : Int = solution(arg40); var v4 : Int = 23; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(3, 13, 2, 9) var x5 : Int = solution(arg50); var v5 : Int = 3; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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_mini_roman(426) == 'cdxxvi' * */ fun intToMiniRoman(number : Int) : String {
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"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 251 var x2 : String = intToMiniRoman(arg20); var v2 : String = "ccli"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 426 var x3 : String = intToMiniRoman(arg30); var v3 : String = "cdxxvi"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 500 var x4 : String = intToMiniRoman(arg40); var v4 : String = "d"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 1 var x5 : String = intToMiniRoman(arg50); var v5 : String = "i"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 4 var x6 : String = intToMiniRoman(arg60); var v6 : String = "iv"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Int = 43 var x7 : String = intToMiniRoman(arg70); var v7 : String = "xliii"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : Int = 90 var x8 : String = intToMiniRoman(arg80); var v8 : String = "xc"; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : Int = 94 var x9 : String = intToMiniRoman(arg90); var v9 : String = "xciv"; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : Int = 532 var x10 : String = intToMiniRoman(arg100); var v10 : String = "dxxxii"; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : Int = 900 var x11 : String = intToMiniRoman(arg110); var v11 : String = "cm"; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120 : Int = 994 var x12 : String = intToMiniRoman(arg120); var v12 : String = "cmxciv"; if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } var arg130 : Int = 1000 var x13 : String = intToMiniRoman(arg130); var v13 : String = "m"; if (x13 != v13) { throw Exception("Exception -- test case 13 did not pass. x13 = " + x13) } }
/** * 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_mini_roman(426) == 'cdxxvi' * */
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 to \"x\",", " 9 to \"ix\",", " 5 to \"v\",", " 4 to \"iv\",", " 1 to \"i\"", " )", " var num = number", " val romanStringBuilder = StringBuilder()", "", " for ((value, numeral) in romanNumerals) {", " while (num >= value) {", " num -= value", " romanStringBuilder.append(numeral)", " }", " }", "", " return romanStringBuilder.toString()", "}", "", "" ]
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_sorted([1, 2, 3, 4, 5]) ➞ True * is_sorted([1, 3, 2, 4, 5]) ➞ False * is_sorted([1, 2, 3, 4, 5, 6]) ➞ True * is_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True * is_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False * is_sorted([1, 2, 2, 3, 3, 4]) ➞ True * is_sorted([1, 2, 2, 2, 3, 4]) ➞ False * */ fun isSorted(lst : List<Int>) : Boolean {
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(arg10); var v1 : Boolean = true; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(1, 3, 2, 4, 5) var x2 : Boolean = isSorted(arg20); var v2 : Boolean = false; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(1, 2, 3, 4, 5, 6) var x3 : Boolean = isSorted(arg30); var v3 : Boolean = true; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(1, 2, 3, 4, 5, 6, 7) var x4 : Boolean = isSorted(arg40); var v4 : Boolean = true; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(1, 3, 2, 4, 5, 6, 7) var x5 : Boolean = isSorted(arg50); var v5 : Boolean = false; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf() var x6 : Boolean = isSorted(arg60); var v6 : Boolean = true; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(1) var x7 : Boolean = isSorted(arg70); var v7 : Boolean = true; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<Int> = mutableListOf(3, 2, 1) var x8 : Boolean = isSorted(arg80); var v8 : Boolean = false; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<Int> = mutableListOf(1, 2, 2, 2, 3, 4) var x9 : Boolean = isSorted(arg90); var v9 : Boolean = false; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<Int> = mutableListOf(1, 2, 3, 3, 3, 4) var x10 : Boolean = isSorted(arg100); var v10 : Boolean = false; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : List<Int> = mutableListOf(1, 2, 2, 3, 3, 4) var x11 : Boolean = isSorted(arg110); var v11 : Boolean = true; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120 : List<Int> = mutableListOf(1, 2, 3, 4) var x12 : Boolean = isSorted(arg120); var v12 : Boolean = true; if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } }
/** * 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_sorted([1, 2, 3, 4, 5]) ➞ True * is_sorted([1, 3, 2, 4, 5]) ➞ False * is_sorted([1, 2, 3, 4, 5, 6]) ➞ True * is_sorted([1, 2, 3, 4, 5, 6, 7]) ➞ True * is_sorted([1, 3, 2, 4, 5, 6, 7]) ➞ False * is_sorted([1, 2, 2, 3, 3, 4]) ➞ True * is_sorted([1, 2, 2, 2, 3, 4]) ➞ False * */
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) * >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) * (2.0, 2.0) * */ fun findClosestElements(numbers: List<Double>): List<Double> {
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<Double> = mutableListOf(1.0, 2.0, 5.9, 4.0, 5.0) var x1: List<Double> = findClosestElements(arg10) var v1: List<Double> = mutableListOf(5.0, 5.9) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Double> = mutableListOf(1.0, 2.0, 3.0, 4.0, 5.0, 2.2) var x2: List<Double> = findClosestElements(arg20) var v2: List<Double> = mutableListOf(2.0, 2.2) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Double> = mutableListOf(1.0, 2.0, 3.0, 4.0, 5.0, 2.0) var x3: List<Double> = findClosestElements(arg30) var v3: List<Double> = mutableListOf(2.0, 2.0) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Double> = mutableListOf(1.1, 2.2, 3.1, 4.1, 5.1) var x4: List<Double> = findClosestElements(arg40) var v4: List<Double> = mutableListOf(2.2, 3.1) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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) * >>> find_closest_elements([1.0, 2.0, 3.0, 4.0, 5.0, 2.0]) * (2.0, 2.0) * */
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 * >>> correct_bracketing("><<>") * False * */ fun correctBracketing(brackets: String): Boolean {
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 = true if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "<><><<><>><>" var x2: Boolean = correctBracketing(arg20) var v2: Boolean = true if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "<><><<<><><>><>><<><><<>>>" var x3: Boolean = correctBracketing(arg30) var v3: Boolean = true if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "<<<><>>>>" var x4: Boolean = correctBracketing(arg40) var v4: Boolean = false if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "><<>" var x5: Boolean = correctBracketing(arg50) var v5: Boolean = false if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "<" var x6: Boolean = correctBracketing(arg60) var v6: Boolean = false if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: String = "<<<<" var x7: Boolean = correctBracketing(arg70) var v7: Boolean = false if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: String = ">" var x8: Boolean = correctBracketing(arg80) var v8: Boolean = false if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: String = "<<>" var x9: Boolean = correctBracketing(arg90) var v9: Boolean = false if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: String = "<><><<><>><>><<>" var x10: Boolean = correctBracketing(arg100) var v10: Boolean = false if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: String = "<><><<><>><>>><>" var x11: Boolean = correctBracketing(arg110) var v11: Boolean = false if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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 * >>> correct_bracketing("><<>") * False * */
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 balance.last() == 0 && balance.min() >= 0", "}", "", "" ]
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 output should be 98 * For lst = [1,3,5,7] the output should be 84 * For lst = [1.4,4.2,0] the output should be 29 * For lst = [-2.4,1,1] the output should be 6 * * */ fun sumSquares(lst : List<Double>) : Int {
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 = sumSquares(arg10); var v1 : Int = 14; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Double> = mutableListOf(1.0, 3.0, 5.0, 7.0) var x2 : Int = sumSquares(arg20); var v2 : Int = 84; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Double> = mutableListOf(1.4, 4.2, 0.0) var x3 : Int = sumSquares(arg30); var v3 : Int = 29; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Double> = mutableListOf(-2.4, 1.0, 1.0) var x4 : Int = sumSquares(arg40); var v4 : Int = 6; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Double> = mutableListOf(100.0, 1.0, 15.0, 2.0) var x5 : Int = sumSquares(arg50); var v5 : Int = 10230; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Double> = mutableListOf(10000.0, 10000.0) var x6 : Int = sumSquares(arg60); var v6 : Int = 200000000; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Double> = mutableListOf(-1.4, 4.6, 6.3) var x7 : Int = sumSquares(arg70); var v7 : Int = 75; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<Double> = mutableListOf(-1.4, 17.9, 18.9, 19.9) var x8 : Int = sumSquares(arg80); var v8 : Int = 1086; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<Double> = mutableListOf(0.0) var x9 : Int = sumSquares(arg90); var v9 : Int = 0; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<Double> = mutableListOf(-1.0) var x10 : Int = sumSquares(arg100); var v10 : Int = 1; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : List<Double> = mutableListOf(-1.0, 1.0, 0.0) var x11 : Int = sumSquares(arg110); var v11 : Int = 2; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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 output should be 98 * For lst = [1,3,5,7] the output should be 84 * For lst = [1.4,4.2,0] the output should be 29 * For lst = [-2.4,1,1] the output should be 6 * * */
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 cars move in the same speed. Two cars are said to collide * when a car that's moving left to right hits a car that's moving right to left. * However, the cars are infinitely sturdy and strong; as a result, they continue moving * in their trajectory as if they did not collide. * This function outputs the number of such collisions. * */ fun carRaceCollision(n: Int): Int {
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 Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 4 var x2: Int = carRaceCollision(arg20) var v2: Int = 16 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 8 var x3: Int = carRaceCollision(arg30) var v3: Int = 64 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 10 var x4: Int = carRaceCollision(arg40) var v4: Int = 100 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 cars move in the same speed. Two cars are said to collide * when a car that's moving left to right hits a car that's moving right to left. * However, the cars are infinitely sturdy and strong; as a result, they continue moving * in their trajectory as if they did not collide. * This function outputs the number of such collisions. * */
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 = greatestCommonDivisor(arg10, arg11) var v1: Int = 5 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 49 var arg21: Int = 14 var x2: Int = greatestCommonDivisor(arg20, arg21) var v2: Int = 7 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 144 var arg31: Int = 60 var x3: Int = greatestCommonDivisor(arg30, arg31) var v3: Int = 12 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 are 1, 2, 3. one of them is even, and two of them are odd. * Example 2: * Input: 12 * Output: (4, 6) * Explanation: * Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd. * Note: * 1. 1 <= n <= 10^3 * 2. returned tuple has the number of even and odd integer palindromes respectively. * */ fun evenOddPalindrome(n : Int) : List<Int> {
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); var v1 : List<Int> = mutableListOf(4, 6); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 3 var x2 : List<Int> = evenOddPalindrome(arg20); var v2 : List<Int> = mutableListOf(1, 2); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 63 var x3 : List<Int> = evenOddPalindrome(arg30); var v3 : List<Int> = mutableListOf(6, 8); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 25 var x4 : List<Int> = evenOddPalindrome(arg40); var v4 : List<Int> = mutableListOf(5, 6); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 19 var x5 : List<Int> = evenOddPalindrome(arg50); var v5 : List<Int> = mutableListOf(4, 6); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 9 var x6 : List<Int> = evenOddPalindrome(arg60); var v6 : List<Int> = mutableListOf(4, 5); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Int = 1 var x7 : List<Int> = evenOddPalindrome(arg70); var v7 : List<Int> = mutableListOf(0, 1); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 are 1, 2, 3. one of them is even, and two of them are odd. * Example 2: * Input: 12 * Output: (4, 6) * Explanation: * Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd. * Note: * 1. 1 <= n <= 10^3 * 2. returned tuple has the number of even and odd integer palindromes respectively. * */
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(it) }", " return listOf(countEven, countOdd)", "}", "", "" ]
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) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 63 var x2: Int = largestPrimeFactor(arg20) var v2: Int = 7 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 330 var x3: Int = largestPrimeFactor(arg30) var v3: Int = 11 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 13195 var x4: Int = largestPrimeFactor(arg40) var v4: Int = 29 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 (curN > maxFactor) {", " maxFactor = curN", " }", " return maxFactor", "}", "", "" ]
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 not nested within each other * Ignore any spaces in the input string. * >>> separate_paren_groups('( ) (( )) (( )( ))') * ['()', '(())', '(()())'] * */ fun separateParenGroups(parenString: String): List<String> {
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: String = "() (()) ((())) (((())))" var x1: List<String> = separateParenGroups(arg10) var v1: List<String> = mutableListOf("()", "(())", "((()))", "(((())))") if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "(()(())((())))" var x2: List<String> = separateParenGroups(arg20) var v2: List<String> = mutableListOf("(()(())((())))") if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "( ) (( )) (( )( ))" var x3: List<String> = separateParenGroups(arg30) var v3: List<String> = mutableListOf("()", "(())", "(()())") if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 not nested within each other * Ignore any spaces in the input string. * >>> separate_paren_groups('( ) (( )) (( )( ))') * ['()', '(())', '(()())'] * */
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", " balance++", " } else if (char == ')') {", " currentString += char", " balance--", " if (balance == 0) {", " answer.add(currentString)", " currentString = \"\"", " }", " }", " }", " return answer", "}", "", "" ]
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 appears in the list. * If no such a value exist, return -1. * Examples: * search([4, 1, 2, 2, 3, 1]) == 2 * search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 * search([5, 5, 4, 4, 4]) == -1 * */ fun search(lst: List<Int>): Int {
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) var v1: Int = 4 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(3, 3) var x2: Int = search(arg20) var v2: Int = -1 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(8, 8, 8, 8, 8, 8, 8, 8) var x3: Int = search(arg30) var v3: Int = 8 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(2, 3, 3, 2, 2) var x4: Int = search(arg40) var v4: Int = 2 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(2, 7, 8, 8, 4, 8, 7, 3, 9, 6, 5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1) var x5: Int = search(arg50) var v5: Int = 1 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(3, 2, 8, 2) var x6: Int = search(arg60) var v6: Int = 2 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10) var x7: Int = search(arg70) var v7: Int = 1 if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: List<Int> = mutableListOf(8, 8, 3, 6, 5, 6, 4) var x8: Int = search(arg80) var v8: Int = -1 if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: List<Int> = mutableListOf(6, 9, 6, 7, 1, 4, 7, 1, 8, 8, 9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9) var x9: Int = search(arg90) var v9: Int = 1 if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100: List<Int> = mutableListOf(1, 9, 10, 1, 3) var x10: Int = search(arg100) var v10: Int = 1 if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110: List<Int> = mutableListOf(6, 9, 7, 5, 8, 7, 5, 3, 7, 5, 10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10) var x11: Int = search(arg110) var v11: Int = 5 if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } var arg120: List<Int> = mutableListOf(1) var x12: Int = search(arg120) var v12: Int = 1 if (x12 != v12) { throw Exception("Exception -- test case 12 did not pass. x12 = " + x12) } var arg130: List<Int> = mutableListOf(8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5) var x13: Int = search(arg130) var v13: Int = 4 if (x13 != v13) { throw Exception("Exception -- test case 13 did not pass. x13 = " + x13) } var arg140: List<Int> = mutableListOf(2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10) var x14: Int = search(arg140) var v14: Int = 2 if (x14 != v14) { throw Exception("Exception -- test case 14 did not pass. x14 = " + x14) } var arg150: List<Int> = mutableListOf(1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3) var x15: Int = search(arg150) var v15: Int = 1 if (x15 != v15) { throw Exception("Exception -- test case 15 did not pass. x15 = " + x15) } var arg160: List<Int> = mutableListOf(9, 2, 4, 1, 5, 1, 5, 2, 5, 7, 7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4) var x16: Int = search(arg160) var v16: Int = 4 if (x16 != v16) { throw Exception("Exception -- test case 16 did not pass. x16 = " + x16) } var arg170: List<Int> = mutableListOf(2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7) var x17: Int = search(arg170) var v17: Int = 4 if (x17 != v17) { throw Exception("Exception -- test case 17 did not pass. x17 = " + x17) } var arg180: List<Int> = mutableListOf(9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1) var x18: Int = search(arg180) var v18: Int = 2 if (x18 != v18) { throw Exception("Exception -- test case 18 did not pass. x18 = " + x18) } var arg190: List<Int> = mutableListOf(5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8) var x19: Int = search(arg190) var v19: Int = -1 if (x19 != v19) { throw Exception("Exception -- test case 19 did not pass. x19 = " + x19) } var arg200: List<Int> = mutableListOf(10) var x20: Int = search(arg200) var v20: Int = -1 if (x20 != v20) { throw Exception("Exception -- test case 20 did not pass. x20 = " + x20) } var arg210: List<Int> = mutableListOf(9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2) var x21: Int = search(arg210) var v21: Int = 2 if (x21 != v21) { throw Exception("Exception -- test case 21 did not pass. x21 = " + x21) } var arg220: List<Int> = mutableListOf(5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8) var x22: Int = search(arg220) var v22: Int = 1 if (x22 != v22) { throw Exception("Exception -- test case 22 did not pass. x22 = " + x22) } var arg230: List<Int> = mutableListOf(7, 9, 9, 9, 3, 4, 1, 5, 9, 1, 2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6) var x23: Int = search(arg230) var v23: Int = 1 if (x23 != v23) { throw Exception("Exception -- test case 23 did not pass. x23 = " + x23) } var arg240: List<Int> = mutableListOf(3, 10, 10, 9, 2) var x24: Int = search(arg240) var v24: Int = -1 if (x24 != v24) { throw Exception("Exception -- test case 24 did not pass. x24 = " + x24) } }
/** * 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 appears in the list. * If no such a value exist, return -1. * Examples: * search([4, 1, 2, 2, 3, 1]) == 2 * search([1, 2, 2, 3, 3, 3, 4, 4, 4]) == 3 * search([5, 5, 4, 4, 4]) == -1 * */
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") => False * cycpattern_check("abab","baa") => True * cycpattern_check("efef","eeff") => False * cycpattern_check("himenss","simen") => True * */ fun cycpatternCheck(a : String, b : String) : Boolean {
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 = "ell" var x1 : Boolean = cycpatternCheck(arg10, arg11); var v1 : Boolean = true; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "whattup" var arg21 : String = "ptut" var x2 : Boolean = cycpatternCheck(arg20, arg21); var v2 : Boolean = false; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "efef" var arg31 : String = "fee" var x3 : Boolean = cycpatternCheck(arg30, arg31); var v3 : Boolean = true; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "abab" var arg41 : String = "aabb" var x4 : Boolean = cycpatternCheck(arg40, arg41); var v4 : Boolean = false; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "winemtt" var arg51 : String = "tinem" var x5 : Boolean = cycpatternCheck(arg50, arg51); var v5 : Boolean = true; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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") => False * cycpattern_check("abab","baa") => True * cycpattern_check("efef","eeff") => False * cycpattern_check("himenss","simen") => True * */
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, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 * Examples * split_words("Hello world!") ➞ ["Hello", "world!"] * split_words("Hello,world!") ➞ ["Hello", "world!"] * split_words("abcdef") == 3 * */ fun splitWords(txt : String) : Any {
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(arg10); var v1 : Any = mutableListOf("Hello", "world!"); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "Hello world,!" var x2 : Any = splitWords(arg20); var v2 : Any = mutableListOf("Hello", "world,!"); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "Hello,Hello,world !" var x3 : Any = splitWords(arg30); var v3 : Any = mutableListOf("Hello,Hello,world", "!"); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "abcdef" var x4 : Any = splitWords(arg40); var v4 : Any = 3; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "aaabb" var x5 : Any = splitWords(arg50); var v5 : Any = 2; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "aaaBb" var x6 : Any = splitWords(arg60); var v6 : Any = 1; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "" var x7 : Any = splitWords(arg70); var v7 : Any = 0; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 * Examples * split_words("Hello world!") ➞ ["Hello", "world!"] * split_words("Hello,world!") ➞ ["Hello", "world!"] * split_words("abcdef") == 3 * */
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, 3, 2) var arg11: Int = 8 var x1: List<Any> = intersperse(arg10, arg11) var v1: List<Any> = mutableListOf(5, 8, 6, 8, 3, 8, 2) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Any> = mutableListOf(2, 2, 2) var arg21: Int = 2 var x2: List<Any> = intersperse(arg20, arg21) var v2: List<Any> = mutableListOf(2, 2, 2, 2, 2) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 example: * >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11] * >>> order_by_points([]) == [] * */ fun orderByPoints(nums : List<Int>) : List<Int> {
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> = mutableListOf(1234, 423, 463, 145, 2, 423, 423, 53, 6, 37, 3457, 3, 56, 0, 46) var x1 : List<Int> = orderByPoints(arg10); var v1 : List<Int> = mutableListOf(0, 2, 3, 6, 53, 423, 423, 423, 1234, 145, 37, 46, 56, 463, 3457); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf() var x2 : List<Int> = orderByPoints(arg20); var v2 : List<Int> = mutableListOf(); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(1, -11, -32, 43, 54, -98, 2, -3) var x3 : List<Int> = orderByPoints(arg30); var v3 : List<Int> = mutableListOf(-3, -32, -98, -11, 1, 2, 43, 54); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) var x4 : List<Int> = orderByPoints(arg40); var v4 : List<Int> = mutableListOf(1, 10, 2, 11, 3, 4, 5, 6, 7, 8, 9); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(0, 6, 6, -76, -21, 23, 4) var x5 : List<Int> = orderByPoints(arg50); var v5 : List<Int> = mutableListOf(-76, -21, 0, 4, 23, 6, 6); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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 example: * >>> order_by_points([1, 11, -1, -11, -12]) == [-1, -11, 1, -12, 11] * >>> order_by_points([]) == [] * */
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", " break", " } else {", " digitSum += x % 10", " x /= 10", " }", " }", " return digitSum", " }", " val withSumAndIndex = nums.mapIndexed { index, num ->", " val sumOfDigits = countDigitSum(num)", " Triple(num, sumOfDigits, index)", " }", " val sorted = withSumAndIndex.sortedWith(compareBy({ it.second }, { it.third }))", " return sorted.map { it.first }", "}", "", "" ]
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') * '' * >>> remove_vowels('aaBAA') * 'B' * >>> remove_vowels('zbcd') * 'zbcd' * */ fun removeVowels(text: String): String {
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\nghjklm" if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "fedcba" var x2: String = removeVowels(arg20) var v2: String = "fdcb" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "eeeee" var x3: String = removeVowels(arg30) var v3: String = "" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "acBAA" var x4: String = removeVowels(arg40) var v4: String = "cB" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "EcBOO" var x5: String = removeVowels(arg50) var v5: String = "cB" if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "ybcd" var x6: String = removeVowels(arg60) var v6: String = "ybcd" if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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') * '' * >>> remove_vowels('aaBAA') * 'B' * >>> remove_vowels('zbcd') * 'zbcd' * */
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 lexicographical order. * find_max(["name", "of", "string"]) == "string" * find_max(["name", "enam", "game"]) == "enam" * find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa" * */ fun findMax(words : List<String>) : String {
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", "game") var x1 : String = findMax(arg10); var v1 : String = "enam"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<String> = mutableListOf("aaaaaaa", "bb", "cc") var x2 : String = findMax(arg20); var v2 : String = "aaaaaaa"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<String> = mutableListOf("abc", "cba") var x3 : String = findMax(arg30); var v3 : String = "abc"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<String> = mutableListOf("play", "this", "game", "of", "footbott") var x4 : String = findMax(arg40); var v4 : String = "footbott"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<String> = mutableListOf("we", "are", "gonna", "rock") var x5 : String = findMax(arg50); var v5 : String = "gonna"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<String> = mutableListOf("we", "are", "a", "mad", "nation") var x6 : String = findMax(arg60); var v6 : String = "nation"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<String> = mutableListOf("this", "is", "a", "prrk") var x7 : String = findMax(arg70); var v7 : String = "this"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<String> = mutableListOf("b") var x8 : String = findMax(arg80); var v8 : String = "b"; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<String> = mutableListOf("play", "play", "play") var x9 : String = findMax(arg90); var v9 : String = "play"; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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 lexicographical order. * find_max(["name", "of", "string"]) == "string" * find_max(["name", "enam", "game"]) == "enam" * find_max(["aaaaaaa", "bb" ,"cc"]) == ""aaaaaaa" * */
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 == maxUniqueCharsCount && word < maxUniqueCharsWord)) {", " maxUniqueCharsCount = uniqueCharsCount", " maxUniqueCharsWord = word", " }", " }", "", " return maxUniqueCharsWord", "}", "", "" ]
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_signs([1, 2, 2, -4]) == -9 * >>> prod_signs([0, 1]) == 0 * >>> prod_signs([]) == None * */ fun prodSigns(arr : List<Int>) : Int? {
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); var v1 : Int? = 0; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(1, 1, 1, 2, 3, -1, 1) var x2 : Int? = prodSigns(arg20); var v2 : Int? = -10; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf() var x3 : Int? = prodSigns(arg30); var v3 : Int? = null; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(2, 4, 1, 2, -1, -1, 9) var x4 : Int? = prodSigns(arg40); var v4 : Int? = 20; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(-1, 1, -1, 1) var x5 : Int? = prodSigns(arg50); var v5 : Int? = 4; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf(-1, 1, 1, 1) var x6 : Int? = prodSigns(arg60); var v6 : Int? = -4; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(-1, 1, 1, 0) var x7 : Int? = prodSigns(arg70); var v7 : Int? = 0; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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_signs([1, 2, 2, -4]) == -9 * >>> prod_signs([0, 1]) == 0 * >>> prod_signs([]) == None * */
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 correctly guessed the results of a number of matches. * You are given two arrays of scores and guesses of equal length, where each index shows a match. * Return an array of the same length denoting how far off each guess was. If they have guessed correctly, * the value is 0, and if not, the value is the absolute difference between the guess and the score. * * * example: * compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3] * compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6] * */ fun compare(game : List<Int>, guess : List<Int>) : List<Int> {
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 pass. x0 = " + x0) } var arg10 : List<Int> = mutableListOf(0, 0, 0, 0, 0, 0) var arg11 : List<Int> = mutableListOf(0, 0, 0, 0, 0, 0) var x1 : List<Int> = compare(arg10, arg11); var v1 : List<Int> = mutableListOf(0, 0, 0, 0, 0, 0); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(1, 2, 3) var arg21 : List<Int> = mutableListOf(-1, -2, -3) var x2 : List<Int> = compare(arg20, arg21); var v2 : List<Int> = mutableListOf(2, 4, 6); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(1, 2, 3, 5) var arg31 : List<Int> = mutableListOf(-1, 2, 3, 4) var x3 : List<Int> = compare(arg30, arg31); var v3 : List<Int> = mutableListOf(2, 0, 0, 1); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 correctly guessed the results of a number of matches. * You are given two arrays of scores and guesses of equal length, where each index shows a match. * Return an array of the same length denoting how far off each guess was. If they have guessed correctly, * the value is 0, and if not, the value is the absolute difference between the guess and the score. * * * example: * compare([1,2,3,4,5,1],[1,2,3,4,2,-2]) -> [0,0,0,0,3,3] * compare([0,5,0,0,0,4],[4,1,1,0,0,-2]) -> [4,4,1,0,0,6] * */
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 function will not * change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. * * Examples: * For lst = [1,2,3] the output should be 6 * For lst = [] the output should be 0 * For lst = [-1,-5,2,-1,-5] the output should be -126 * */ fun sumSquares(lst : List<Int>) : Int {
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); var v1 : Int = 14; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf() var x2 : Int = sumSquares(arg20); var v2 : Int = 0; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(1, 1, 1, 1, 1, 1, 1, 1, 1) var x3 : Int = sumSquares(arg30); var v3 : Int = 9; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(-1, -1, -1, -1, -1, -1, -1, -1, -1) var x4 : Int = sumSquares(arg40); var v4 : Int = -3; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(0) var x5 : Int = sumSquares(arg50); var v5 : Int = 0; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf(-1, -5, 2, -1, -5) var x6 : Int = sumSquares(arg60); var v6 : Int = -126; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(-56, -99, 1, 0, -2) var x7 : Int = sumSquares(arg70); var v7 : Int = 3030; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<Int> = mutableListOf(-1, 0, 0, 0, 0, 0, 0, 0, -1) var x8 : Int = sumSquares(arg80); var v8 : Int = 0; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<Int> = mutableListOf(-16, -9, -2, 36, 36, 26, -20, 25, -40, 20, -4, 12, -26, 35, 37) var x9 : Int = sumSquares(arg90); var v9 : Int = -14196; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<Int> = mutableListOf(-1, -3, 17, -1, -15, 13, -1, 14, -14, -12, -5, 14, -14, 6, 13, 11, 16, 16, 4, 10) var x10 : Int = sumSquares(arg100); var v10 : Int = -1448; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } }
/** * 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 function will not * change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. * * Examples: * For lst = [1,2,3] the output should be 6 * For lst = [] the output should be 0 * For lst = [-1,-5,2,-1,-5] the output should be -126 * */
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_last_char_is_a_letter("apple pie") ➞ False * check_if_last_char_is_a_letter("apple pi e") ➞ True * check_if_last_char_is_a_letter("apple pi e ") ➞ False * check_if_last_char_is_a_letter("") ➞ False * */ fun checkIfLastCharIsALetter(txt: String): Boolean {
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(arg10); var v1: Boolean = true; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "eeeee" var x2: Boolean = checkIfLastCharIsALetter(arg20); var v2: Boolean = false; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "A" var x3: Boolean = checkIfLastCharIsALetter(arg30); var v3: Boolean = true; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "Pumpkin pie " var x4: Boolean = checkIfLastCharIsALetter(arg40); var v4: Boolean = false; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: String = "Pumpkin pie 1" var x5: Boolean = checkIfLastCharIsALetter(arg50); var v5: Boolean = false; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: String = "" var x6: Boolean = checkIfLastCharIsALetter(arg60); var v6: Boolean = false; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: String = "eeeee e " var x7: Boolean = checkIfLastCharIsALetter(arg70); var v7: Boolean = false; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: String = "apple pie" var x8: Boolean = checkIfLastCharIsALetter(arg80); var v8: Boolean = false; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90: String = "apple pi e " var x9: Boolean = checkIfLastCharIsALetter(arg90); var v9: Boolean = false; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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_last_char_is_a_letter("apple pie") ➞ False * check_if_last_char_is_a_letter("apple pi e") ➞ True * check_if_last_char_is_a_letter("apple pi e ") ➞ False * check_if_last_char_is_a_letter("") ➞ False * */
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, * the number of carrots left after your meals ] * if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry. * * Example: * * eat(5, 6, 10) -> [11, 4] * * eat(4, 8, 9) -> [12, 1] * * eat(1, 10, 10) -> [11, 0] * * eat(2, 11, 5) -> [7, 0] * * Variables: * @number : integer * the number of carrots that you have eaten. * @need : integer * the number of carrots that you need to eat. * @remaining : integer * the number of remaining carrots thet exist in stock * * Constrain: * * 0 <= number <= 1000 * * 0 <= need <= 1000 * * 0 <= remaining <= 1000 * Have fun :) * */ fun eat(number : Int, need : Int, remaining : Int) : List<Int> {
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 arg11 : Int = 8 var arg12 : Int = 9 var x1 : List<Int> = eat(arg10, arg11, arg12); var v1 : List<Int> = mutableListOf(12, 1); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 1 var arg21 : Int = 10 var arg22 : Int = 10 var x2 : List<Int> = eat(arg20, arg21, arg22); var v2 : List<Int> = mutableListOf(11, 0); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 2 var arg31 : Int = 11 var arg32 : Int = 5 var x3 : List<Int> = eat(arg30, arg31, arg32); var v3 : List<Int> = mutableListOf(7, 0); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 4 var arg41 : Int = 5 var arg42 : Int = 7 var x4 : List<Int> = eat(arg40, arg41, arg42); var v4 : List<Int> = mutableListOf(9, 2); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 4 var arg51 : Int = 5 var arg52 : Int = 1 var x5 : List<Int> = eat(arg50, arg51, arg52); var v5 : List<Int> = mutableListOf(5, 0); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } }
/** * 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, * the number of carrots left after your meals ] * if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry. * * Example: * * eat(5, 6, 10) -> [11, 4] * * eat(4, 8, 9) -> [12, 1] * * eat(1, 10, 10) -> [11, 0] * * eat(2, 11, 5) -> [7, 0] * * Variables: * @number : integer * the number of carrots that you have eaten. * @need : integer * the number of carrots that you need to eat. * @remaining : integer * the number of remaining carrots thet exist in stock * * Constrain: * * 0 <= number <= 1000 * * 0 <= need <= 1000 * * 0 <= remaining <= 1000 * Have fun :) * */
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, 1]) * False * >>> pairs_sum_to_zero([1, 2, 3, 7]) * False * >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7]) * True * >>> pairs_sum_to_zero([1]) * False * */ fun pairsSumToZero(l: List<Int>): Boolean {
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 = pairsSumToZero(arg10) var v1: Boolean = false if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(1, 2, 3, 7) var x2: Boolean = pairsSumToZero(arg20) var v2: Boolean = false if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(2, 4, -5, 3, 5, 7) var x3: Boolean = pairsSumToZero(arg30) var v3: Boolean = true if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(1) var x4: Boolean = pairsSumToZero(arg40) var v4: Boolean = false if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: List<Int> = mutableListOf(-3, 9, -1, 3, 2, 30) var x5: Boolean = pairsSumToZero(arg50) var v5: Boolean = true if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: List<Int> = mutableListOf(-3, 9, -1, 3, 2, 31) var x6: Boolean = pairsSumToZero(arg60) var v6: Boolean = true if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: List<Int> = mutableListOf(-3, 9, -1, 4, 2, 30) var x7: Boolean = pairsSumToZero(arg70) var v7: Boolean = false if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: List<Int> = mutableListOf(-3, 9, -1, 4, 2, 31) var x8: Boolean = pairsSumToZero(arg80) var v8: Boolean = false if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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, 1]) * False * >>> pairs_sum_to_zero([1, 2, 3, 7]) * False * >>> pairs_sum_to_zero([2, 4, -5, 3, 5, 7]) * True * >>> pairs_sum_to_zero([1]) * False * */
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", " }", " }", " return false", "}", "", "" ]
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 digits in the i'th string of the input. * >>> odd_count(['1234567']) * ["the number of odd elements 4n the str4ng 4 of the 4nput."] * >>> odd_count(['3',"11111111"]) * ["the number of odd elements 1n the str1ng 1 of the 1nput.", * "the number of odd elements 8n the str8ng 8 of the 8nput."] * */ fun oddCount(lst : List<String>) : List<String> {
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) } var arg10 : List<String> = mutableListOf("3", "11111111") var x1 : List<String> = oddCount(arg10); var v1 : List<String> = mutableListOf("the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput."); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<String> = mutableListOf("271", "137", "314") var x2 : List<String> = oddCount(arg20); var v2 : List<String> = mutableListOf("the number of odd elements 2n the str2ng 2 of the 2nput.", "the number of odd elements 3n the str3ng 3 of the 3nput.", "the number of odd elements 2n the str2ng 2 of the 2nput."); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 digits in the i'th string of the input. * >>> odd_count(['1234567']) * ["the number of odd elements 4n the str4ng 4 of the 4nput."] * >>> odd_count(['3',"11111111"]) * ["the number of odd elements 1n the str1ng 1 of the 1nput.", * "the number of odd elements 8n the str8ng 8 of the 8nput."] * */
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(arg10) var v1: String = "xyz" if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<String> = mutableListOf("x", "y", "z", "w", "k") var x2: String = concatenate(arg20) var v2: String = "xyzwk" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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 then the function should return an empty list. * Note: you may assume the input string contains only letters and spaces. * Examples: * select_words("Mary had a little lamb", 4) ==> ["little"] * select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"] * select_words("simple white space", 2) ==> [] * select_words("Hello world", 4) ==> ["world"] * select_words("Uncle sam", 3) ==> ["Uncle"] * */ fun selectWords(s : String, n : Int) : List<Any> {
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 = "Mary had a little lamb" var arg11 : Int = 3 var x1 : List<Any> = selectWords(arg10, arg11); var v1 : List<Any> = mutableListOf("Mary", "lamb"); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "simple white space" var arg21 : Int = 2 var x2 : List<Any> = selectWords(arg20, arg21); var v2 : List<Any> = mutableListOf(); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "Hello world" var arg31 : Int = 4 var x3 : List<Any> = selectWords(arg30, arg31); var v3 : List<Any> = mutableListOf("world"); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "Uncle sam" var arg41 : Int = 3 var x4 : List<Any> = selectWords(arg40, arg41); var v4 : List<Any> = mutableListOf("Uncle"); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "" var arg51 : Int = 4 var x5 : List<Any> = selectWords(arg50, arg51); var v5 : List<Any> = mutableListOf(); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "a b c d e f" var arg61 : Int = 1 var x6 : List<Any> = selectWords(arg60, arg61); var v6 : List<Any> = mutableListOf("b", "c", "d", "f"); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 then the function should return an empty list. * Note: you may assume the input string contains only letters and spaces. * Examples: * select_words("Mary had a little lamb", 4) ==> ["little"] * select_words("Mary had a little lamb", 3) ==> ["Mary", "lamb"] * select_words("simple white space", 2) ==> [] * select_words("Hello world", 4) ==> ["world"] * select_words("Uncle sam", 3) ==> ["Uncle"] * */
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 = median(arg10) var v1: Double = 8.0 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(5) var x2: Double = median(arg20) var v2: Double = 5.0 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(6, 5) var x3: Double = median(arg30) var v3: Double = 5.5 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(8, 1, 3, 9, 9, 2, 7) var x4: Double = median(arg40) var v4: Double = 7.0 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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. * A string S is considered to be good if and only if all parentheses in S * are balanced. For example: the string '(())()' is good, while the string * '())' is not. * Return 'Yes' if there's a way to make a good string, and return 'No' otherwise. * Examples: * match_parens(['()(', ')']) == 'Yes' * match_parens([')', ')']) == 'No' * */ fun matchParens(lst : List<String>) : String {
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 = matchParens(arg10); var v1 : String = "No"; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<String> = mutableListOf("(()(())", "())())") var x2 : String = matchParens(arg20); var v2 : String = "No"; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<String> = mutableListOf(")())", "(()()(") var x3 : String = matchParens(arg30); var v3 : String = "Yes"; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<String> = mutableListOf("(())))", "(()())((") var x4 : String = matchParens(arg40); var v4 : String = "Yes"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<String> = mutableListOf("()", "())") var x5 : String = matchParens(arg50); var v5 : String = "No"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<String> = mutableListOf("(()(", "()))()") var x6 : String = matchParens(arg60); var v6 : String = "Yes"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<String> = mutableListOf("((((", "((())") var x7 : String = matchParens(arg70); var v7 : String = "No"; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<String> = mutableListOf(")(()", "(()(") var x8 : String = matchParens(arg80); var v8 : String = "No"; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<String> = mutableListOf(")(", ")(") var x9 : String = matchParens(arg90); var v9 : String = "No"; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<String> = mutableListOf("(", ")") var x10 : String = matchParens(arg100); var v10 : String = "Yes"; if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } var arg110 : List<String> = mutableListOf(")", "(") var x11 : String = matchParens(arg110); var v11 : String = "Yes"; if (x11 != v11) { throw Exception("Exception -- test case 11 did not pass. x11 = " + x11) } }
/** * 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. * A string S is considered to be good if and only if all parentheses in S * are balanced. For example: the string '(())()' is good, while the string * '())' is not. * Return 'Yes' if there's a way to make a good string, and return 'No' otherwise. * Examples: * match_parens(['()(', ')']) == 'Yes' * match_parens([')', ')']) == 'No' * */
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", " }", " }", " return balance.last() == 0 && balance.min() >= 0", " }", " return if (checkGood(lst[0] + lst[1]) || checkGood(lst[1] + lst[0])) {", " \"Yes\"", " } else {", " \"No\"", " }", "}", "", "" ]
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 arg12 : Int = 5 var x1 : Int = xOrY(arg10, arg11, arg12); var v1 : Int = 5; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Int = 3 var arg21 : Int = 33 var arg22 : Int = 5212 var x2 : Int = xOrY(arg20, arg21, arg22); var v2 : Int = 33; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Int = 1259 var arg31 : Int = 3 var arg32 : Int = 52 var x3 : Int = xOrY(arg30, arg31, arg32); var v3 : Int = 3; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Int = 7919 var arg41 : Int = -1 var arg42 : Int = 12 var x4 : Int = xOrY(arg40, arg41, arg42); var v4 : Int = -1; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Int = 3609 var arg51 : Int = 1245 var arg52 : Int = 583 var x5 : Int = xOrY(arg50, arg51, arg52); var v5 : Int = 583; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Int = 91 var arg61 : Int = 56 var arg62 : Int = 129 var x6 : Int = xOrY(arg60, arg61, arg62); var v6 : Int = 129; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Int = 6 var arg71 : Int = 34 var arg72 : Int = 1234 var x7 : Int = xOrY(arg70, arg71, arg72); var v7 : Int = 1234; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : Int = 1 var arg81 : Int = 2 var arg82 : Int = 0 var x8 : Int = xOrY(arg80, arg81, arg82); var v8 : Int = 0; if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : Int = 2 var arg91 : Int = 2 var arg92 : Int = 0 var x9 : Int = xOrY(arg90, arg91, arg92); var v9 : Int = 2; if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } }
/** * 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) {", " return false", " }", " }", " return true", " }", " return if (isPrime(n)) {", " x", " } else {", " y", " }", "}", "", "" ]
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 = [4, -4, 4], k = 2 * Output: [4, 4] * Example 3: * Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1 * Output: [2] * Note: * 1. The length of the array will be in the range of [1, 1000]. * 2. The elements in the array will be in the range of [-1000, 1000]. * 3. 0 <= k <= len(arr) * */ fun maximum(arr : List<Int>, k : Int) : List<Any> {
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> = mutableListOf(4, -4, 4) var arg11 : Int = 2 var x1 : List<Any> = maximum(arg10, arg11); var v1 : List<Any> = mutableListOf(4, 4); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<Int> = mutableListOf(-3, 2, 1, 2, -1, -2, 1) var arg21 : Int = 1 var x2 : List<Any> = maximum(arg20, arg21); var v2 : List<Any> = mutableListOf(2); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<Int> = mutableListOf(123, -123, 20, 0, 1, 2, -3) var arg31 : Int = 3 var x3 : List<Any> = maximum(arg30, arg31); var v3 : List<Any> = mutableListOf(2, 20, 123); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<Int> = mutableListOf(-123, 20, 0, 1, 2, -3) var arg41 : Int = 4 var x4 : List<Any> = maximum(arg40, arg41); var v4 : List<Any> = mutableListOf(0, 1, 2, 20); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<Int> = mutableListOf(5, 15, 0, 3, -13, -8, 0) var arg51 : Int = 7 var x5 : List<Any> = maximum(arg50, arg51); var v5 : List<Any> = mutableListOf(-13, -8, 0, 0, 3, 5, 15); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<Int> = mutableListOf(-1, 0, 2, 5, 3, -10) var arg61 : Int = 2 var x6 : List<Any> = maximum(arg60, arg61); var v6 : List<Any> = mutableListOf(3, 5); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<Int> = mutableListOf(1, 0, 5, -7) var arg71 : Int = 1 var x7 : List<Any> = maximum(arg70, arg71); var v7 : List<Any> = mutableListOf(5); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<Int> = mutableListOf(4, -4) var arg81 : Int = 2 var x8 : List<Any> = maximum(arg80, arg81); var v8 : List<Any> = mutableListOf(-4, 4); if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<Int> = mutableListOf(-10, 10) var arg91 : Int = 2 var x9 : List<Any> = maximum(arg90, arg91); var v9 : List<Any> = mutableListOf(-10, 10); if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<Int> = mutableListOf(1, 2, 3, -23, 243, -400, 0) var arg101 : Int = 0 var x10 : List<Any> = maximum(arg100, arg101); var v10 : List<Any> = mutableListOf(); if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } }
/** * 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 = [4, -4, 4], k = 2 * Output: [4, 4] * Example 3: * Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1 * Output: [2] * Note: * 1. The length of the array will be in the range of [1, 1000]. * 2. The elements in the array will be in the range of [-1000, 1000]. * 3. 0 <= k <= len(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. * You should return a tuple containing the result string and True/False for the check. * Example * For s = "abcde", c = "ae", the result should be ('bcd',False) * For s = "abcdef", c = "b" the result should be ('acdef',False) * For s = "abcdedcba", c = "ab", the result should be ('cdedc',True) * */ fun reverseDelete(s : String, c : String) : Pair<String, Boolean> {
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 : String = "abcdef" var arg11 : String = "b" var x1 : Pair<String, Boolean> = reverseDelete(arg10, arg11); var v1 : Pair<String, Boolean> = Pair("acdef", false); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : String = "abcdedcba" var arg21 : String = "ab" var x2 : Pair<String, Boolean> = reverseDelete(arg20, arg21); var v2 : Pair<String, Boolean> = Pair("cdedc", true); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : String = "dwik" var arg31 : String = "w" var x3 : Pair<String, Boolean> = reverseDelete(arg30, arg31); var v3 : Pair<String, Boolean> = Pair("dik", false); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : String = "a" var arg41 : String = "a" var x4 : Pair<String, Boolean> = reverseDelete(arg40, arg41); var v4 : Pair<String, Boolean> = Pair("", true); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : String = "abcdedcba" var arg51 : String = "" var x5 : Pair<String, Boolean> = reverseDelete(arg50, arg51); var v5 : Pair<String, Boolean> = Pair("abcdedcba", true); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : String = "abcdedcba" var arg61 : String = "v" var x6 : Pair<String, Boolean> = reverseDelete(arg60, arg61); var v6 : Pair<String, Boolean> = Pair("abcdedcba", true); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : String = "vabba" var arg71 : String = "v" var x7 : Pair<String, Boolean> = reverseDelete(arg70, arg71); var v7 : Pair<String, Boolean> = Pair("abba", true); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : String = "mamma" var arg81 : String = "mia" var x8 : Pair<String, Boolean> = reverseDelete(arg80, arg81); var v8 : Pair<String, Boolean> = Pair("", true); if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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. * You should return a tuple containing the result string and True/False for the check. * Example * For s = "abcde", c = "ae", the result should be ('bcd',False) * For s = "abcdef", c = "b" the result should be ('acdef',False) * For s = "abcdedcba", c = "ab", the result should be ('cdedc',True) * */
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 same capacity. * Your task is to use the buckets to empty the wells. * Output the number of times you need to lower the buckets. * Example 1: * Input: * grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]] * bucket_capacity : 1 * Output: 6 * Example 2: * Input: * grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] * bucket_capacity : 2 * Output: 5 * * Example 3: * Input: * grid : [[0,0,0], [0,0,0]] * bucket_capacity : 5 * Output: 0 * Constraints: * * all wells have the same length * * 1 <= grid.length <= 10^2 * * 1 <= grid[:,1].length <= 10^2 * * grid[i][j] -> 0 | 1 * * 1 <= capacity <= 10 * */ fun maxFill(grid : List<List<Int>>, capacity : Int) : Int {
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 = " + x0) } var arg10 : List<List<Int>> = mutableListOf(mutableListOf(0, 0, 1, 1), mutableListOf(0, 0, 0, 0), mutableListOf(1, 1, 1, 1), mutableListOf(0, 1, 1, 1)) var arg11 : Int = 2 var x1 : Int = maxFill(arg10, arg11); var v1 : Int = 5; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<List<Int>> = mutableListOf(mutableListOf(0, 0, 0), mutableListOf(0, 0, 0)) var arg21 : Int = 5 var x2 : Int = maxFill(arg20, arg21); var v2 : Int = 0; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<List<Int>> = mutableListOf(mutableListOf(1, 1, 1, 1), mutableListOf(1, 1, 1, 1)) var arg31 : Int = 2 var x3 : Int = maxFill(arg30, arg31); var v3 : Int = 4; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<List<Int>> = mutableListOf(mutableListOf(1, 1, 1, 1), mutableListOf(1, 1, 1, 1)) var arg41 : Int = 9 var x4 : Int = maxFill(arg40, arg41); var v4 : Int = 2; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 same capacity. * Your task is to use the buckets to empty the wells. * Output the number of times you need to lower the buckets. * Example 1: * Input: * grid : [[0,0,1,0], [0,1,0,0], [1,1,1,1]] * bucket_capacity : 1 * Output: 6 * Example 2: * Input: * grid : [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] * bucket_capacity : 2 * Output: 5 * * Example 3: * Input: * grid : [[0,0,0], [0,0,0]] * bucket_capacity : 5 * Output: 0 * Constraints: * * all wells have the same length * * 1 <= grid.length <= 10^2 * * 1 <= grid[:,1].length <= 10^2 * * grid[i][j] -> 0 | 1 * * 1 <= capacity <= 10 * */
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. x0 = " + x0) } var arg10: List<Int> = mutableListOf(5, 3, 2, 8) var arg11: List<Int> = mutableListOf(3, 2) var x1: List<Int> = common(arg10, arg11) var v1: List<Int> = mutableListOf(2, 3) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(4, 3, 2, 8) var arg21: List<Int> = mutableListOf(3, 2, 4) var x2: List<Int> = common(arg20, arg21) var v2: List<Int> = mutableListOf(2, 3, 4) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(4, 3, 2, 8) var arg31: List<Int> = mutableListOf() var x3: List<Int> = common(arg30, arg31) var v3: List<Int> = mutableListOf() if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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] * >>> sort_even([5, 6, 3, 4]) * [3, 6, 5, 4] * */ fun sortEven(l: List<Int>): List<Int> {
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, 123, 1, -10) var x1: List<Int> = sortEven(arg10) var v1: List<Int> = mutableListOf(-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(5, 8, -12, 4, 23, 2, 3, 11, 12, -10) var x2: List<Int> = sortEven(arg20) var v2: List<Int> = mutableListOf(-12, 8, 3, 4, 5, 2, 12, 11, 23, -10) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } }
/** * 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] * >>> sort_even([5, 6, 3, 4]) * [3, 6, 5, 4] * */
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 is greater * than the third side. * Example: * triangle_area(3, 4, 5) == 6.00 * triangle_area(1, 2, 10) == -1 * */ fun triangleArea(a: Int, b: Int, c: Int): Any {
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: Int = 10 var x1: Any = triangleArea(arg10, arg11, arg12) var v1: Any = -1 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 4 var arg21: Int = 8 var arg22: Int = 5 var x2: Any = triangleArea(arg20, arg21, arg22) var v2: Any = 8.18 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 2 var arg31: Int = 2 var arg32: Int = 2 var x3: Any = triangleArea(arg30, arg31, arg32) var v3: Any = 1.73 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 1 var arg41: Int = 2 var arg42: Int = 3 var x4: Any = triangleArea(arg40, arg41, arg42) var v4: Any = -1 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 10 var arg51: Int = 5 var arg52: Int = 7 var x5: Any = triangleArea(arg50, arg51, arg52) var v5: Any = 16.25 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 2 var arg61: Int = 6 var arg62: Int = 3 var x6: Any = triangleArea(arg60, arg61, arg62) var v6: Any = -1 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70: Int = 1 var arg71: Int = 1 var arg72: Int = 1 var x7: Any = triangleArea(arg70, arg71, arg72) var v7: Any = 0.43 if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80: Int = 2 var arg81: Int = 2 var arg82: Int = 10 var x8: Any = triangleArea(arg80, arg81, arg82) var v8: Any = -1 if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } }
/** * 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 is greater * than the third side. * Example: * triangle_area(3, 4, 5) == 6.00 * triangle_area(1, 2, 10) == -1 * */
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 efficiently compute the n-th element of the fibfib number sequence. * >>> fibfib(1) * 0 * >>> fibfib(5) * 4 * >>> fibfib(8) * 24 * */ fun fibfib(n: Int): Int {
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("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 5 var x2: Int = fibfib(arg20) var v2: Int = 4 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 8 var x3: Int = fibfib(arg30) var v3: Int = 24 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 10 var x4: Int = fibfib(arg40) var v4: Int = 81 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 12 var x5: Int = fibfib(arg50) var v5: Int = 274 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 14 var x6: Int = fibfib(arg60) var v6: Int = 927 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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 efficiently compute the n-th element of the fibfib number sequence. * >>> fibfib(1) * 0 * >>> fibfib(5) * 4 * >>> fibfib(8) * 24 * */
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] * >>> unique_digits([152, 323, 1422, 10]) * [] * */ fun uniqueDigits(x: List<Int>): List<Int> {
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, 1422, 10) var x1: List<Int> = uniqueDigits(arg10); var v1: List<Int> = mutableListOf(); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(12345, 2033, 111, 151) var x2: List<Int> = uniqueDigits(arg20); var v2: List<Int> = mutableListOf(111, 151); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(135, 103, 31) var x3: List<Int> = uniqueDigits(arg30); var v3: List<Int> = mutableListOf(31, 135); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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] * >>> unique_digits([152, 323, 1422, 10]) * [] * */
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 * >>> sort_numbers('three one five') * 'one three five' * */ fun sortNumbers(numbers: String): String {
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 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: String = "three five nine" var x2: String = sortNumbers(arg20) var v2: String = "three five nine" if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: String = "five zero four seven nine eight" var x3: String = sortNumbers(arg30) var v3: String = "zero four five seven eight nine" if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: String = "six five four three two one zero" var x4: String = sortNumbers(arg40) var v4: String = "zero one two three four five six" if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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 * >>> sort_numbers('three one five') * 'one three five' * */
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,", " \"eight\" to 8,", " \"nine\" to 9,", " )", " return numbers.split(\" \").sortedBy { value -> mapping[value] }.joinToString(\" \")", "}", "", "" ]
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. * Return the number of stones in each level in a list, where element at index * i represents the number of stones in the level (i+1). * Examples: * >>> make_a_pile(3) * [3, 5, 7] * */ fun makeAPile(n: Int): List<Int> {
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> = mutableListOf(4, 6, 8, 10) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 5 var x2: List<Int> = makeAPile(arg20) var v2: List<Int> = mutableListOf(5, 7, 9, 11, 13) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 6 var x3: List<Int> = makeAPile(arg30) var v3: List<Int> = mutableListOf(6, 8, 10, 12, 14, 16) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 8 var x4: List<Int> = makeAPile(arg40) var v4: List<Int> = mutableListOf(8, 10, 12, 14, 16, 18, 20, 22) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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. * Return the number of stones in each level in a list, where element at index * i represents the number of stones in the level (i+1). * Examples: * >>> make_a_pile(3) * [3, 5, 7] * */
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 path of length k in the grid. You can start * from any cell, and in each step you can move to any of the neighbor cells, * in other words, you can go to cells which share an edge with you current * cell. * Please note that a path of length k means visiting exactly k cells (not * necessarily distinct). * You CANNOT go off the grid. * A path A (of length k) is considered less than a path B (of length k) if * after making the ordered lists of the values on the cells that A and B go * through (let's call them lst_A and lst_B), lst_A is lexicographically less * than lst_B, in other words, there exist an integer index i (1 <= i <= k) * such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have * lst_A[j] = lst_B[j]. * It is guaranteed that the answer is unique. * Return an ordered list of the values on the cells that the minimum path go through. * Examples: * Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3 * Output: [1, 2, 1] * Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1 * Output: [1] * */ fun minpath(grid : List<List<Int>>, k : Int) : List<Int> {
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 case 0 did not pass. x0 = " + x0) } var arg10 : List<List<Int>> = mutableListOf(mutableListOf(5, 9, 3), mutableListOf(4, 1, 6), mutableListOf(7, 8, 2)) var arg11 : Int = 1 var x1 : List<Int> = minpath(arg10, arg11); var v1 : List<Int> = mutableListOf(1); if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : List<List<Int>> = mutableListOf(mutableListOf(1, 2, 3, 4), mutableListOf(5, 6, 7, 8), mutableListOf(9, 10, 11, 12), mutableListOf(13, 14, 15, 16)) var arg21 : Int = 4 var x2 : List<Int> = minpath(arg20, arg21); var v2 : List<Int> = mutableListOf(1, 2, 1, 2); if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : List<List<Int>> = mutableListOf(mutableListOf(6, 4, 13, 10), mutableListOf(5, 7, 12, 1), mutableListOf(3, 16, 11, 15), mutableListOf(8, 14, 9, 2)) var arg31 : Int = 7 var x3 : List<Int> = minpath(arg30, arg31); var v3 : List<Int> = mutableListOf(1, 10, 1, 10, 1, 10, 1); if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : List<List<Int>> = mutableListOf(mutableListOf(8, 14, 9, 2), mutableListOf(6, 4, 13, 15), mutableListOf(5, 7, 1, 12), mutableListOf(3, 10, 11, 16)) var arg41 : Int = 5 var x4 : List<Int> = minpath(arg40, arg41); var v4 : List<Int> = mutableListOf(1, 7, 1, 7, 1); if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : List<List<Int>> = mutableListOf(mutableListOf(11, 8, 7, 2), mutableListOf(5, 16, 14, 4), mutableListOf(9, 3, 15, 6), mutableListOf(12, 13, 10, 1)) var arg51 : Int = 9 var x5 : List<Int> = minpath(arg50, arg51); var v5 : List<Int> = mutableListOf(1, 6, 1, 6, 1, 6, 1, 6, 1); if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : List<List<Int>> = mutableListOf(mutableListOf(12, 13, 10, 1), mutableListOf(9, 3, 15, 6), mutableListOf(5, 16, 14, 4), mutableListOf(11, 8, 7, 2)) var arg61 : Int = 12 var x6 : List<Int> = minpath(arg60, arg61); var v6 : List<Int> = mutableListOf(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6); if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : List<List<Int>> = mutableListOf(mutableListOf(2, 7, 4), mutableListOf(3, 1, 5), mutableListOf(6, 8, 9)) var arg71 : Int = 8 var x7 : List<Int> = minpath(arg70, arg71); var v7 : List<Int> = mutableListOf(1, 3, 1, 3, 1, 3, 1, 3); if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } var arg80 : List<List<Int>> = mutableListOf(mutableListOf(6, 1, 5), mutableListOf(3, 8, 9), mutableListOf(2, 7, 4)) var arg81 : Int = 8 var x8 : List<Int> = minpath(arg80, arg81); var v8 : List<Int> = mutableListOf(1, 5, 1, 5, 1, 5, 1, 5); if (x8 != v8) { throw Exception("Exception -- test case 8 did not pass. x8 = " + x8) } var arg90 : List<List<Int>> = mutableListOf(mutableListOf(1, 2), mutableListOf(3, 4)) var arg91 : Int = 10 var x9 : List<Int> = minpath(arg90, arg91); var v9 : List<Int> = mutableListOf(1, 2, 1, 2, 1, 2, 1, 2, 1, 2); if (x9 != v9) { throw Exception("Exception -- test case 9 did not pass. x9 = " + x9) } var arg100 : List<List<Int>> = mutableListOf(mutableListOf(1, 3), mutableListOf(3, 2)) var arg101 : Int = 10 var x10 : List<Int> = minpath(arg100, arg101); var v10 : List<Int> = mutableListOf(1, 3, 1, 3, 1, 3, 1, 3, 1, 3); if (x10 != v10) { throw Exception("Exception -- test case 10 did not pass. x10 = " + x10) } }
/** * 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 path of length k in the grid. You can start * from any cell, and in each step you can move to any of the neighbor cells, * in other words, you can go to cells which share an edge with you current * cell. * Please note that a path of length k means visiting exactly k cells (not * necessarily distinct). * You CANNOT go off the grid. * A path A (of length k) is considered less than a path B (of length k) if * after making the ordered lists of the values on the cells that A and B go * through (let's call them lst_A and lst_B), lst_A is lexicographically less * than lst_B, in other words, there exist an integer index i (1 <= i <= k) * such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have * lst_A[j] = lst_B[j]. * It is guaranteed that the answer is unique. * Return an ordered list of the values on the cells that the minimum path go through. * Examples: * Input: grid = [ [1,2,3], [4,5,6], [7,8,9]], k = 3 * Output: [1, 2, 1] * Input: grid = [ [5,9,3], [4,1,6], [7,8,2]], k = 1 * Output: [1] * */
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] < bestPath[i]) {", " bestPath = path.toList()", " break", " } else if (path[i] > bestPath[i]) break", " }", " return", " }", "", " val directions = listOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1) // Up, down, left, right", " for ((dx, dy) in directions) {", " val newX = x + dx", " val newY = y + dy", " if (newX in 0 until n && newY in 0 until n) {", " path.add(grid[newX][newY])", " dfs(newX, newY, step + 1, path)", " path.removeAt(path.lastIndex) // Backtrack", " }", " }", " }", "", " for (i in 0 until n) {", " for (j in 0 until n) {", " dfs(i, j, 1, mutableListOf(grid[i][j]))", " }", " }", "", " return bestPath", "}", "", "" ]
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 floating point might be . or , * compare_one(1, 2.5) ➞ 2.5 * compare_one(1, "2,3") ➞ "2,3" * compare_one("5,1", "6") ➞ "6" * compare_one("1", 1) ➞ None * */ fun compareOne(a : Any, b : Any) : Any? {
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, arg11); var v1 : Any? = 2.5; if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Any = 2 var arg21 : Any = 3 var x2 : Any? = compareOne(arg20, arg21); var v2 : Any? = 3; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Any = 5 var arg31 : Any = 6 var x3 : Any? = compareOne(arg30, arg31); var v3 : Any? = 6; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40 : Any = 1 var arg41 : Any = "2,3" var x4 : Any? = compareOne(arg40, arg41); var v4 : Any? = "2,3"; if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50 : Any = "5,1" var arg51 : Any = "6" var x5 : Any? = compareOne(arg50, arg51); var v5 : Any? = "6"; if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60 : Any = "1" var arg61 : Any = "2" var x6 : Any? = compareOne(arg60, arg61); var v6 : Any? = "2"; if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } var arg70 : Any = "1" var arg71 : Any = 1 var x7 : Any? = compareOne(arg70, arg71); var v7 : Any? = null; if (x7 != v7) { throw Exception("Exception -- test case 7 did not pass. x7 = " + x7) } }
/** * 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 floating point might be . or , * compare_one(1, 2.5) ➞ 2.5 * compare_one(1, "2,3") ➞ "2,3" * compare_one("5,1", "6") ➞ "6" * compare_one("1", 1) ➞ None * */
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.toDouble()", " }", " throw Exception(\"Invalid number\")", " }", "", " val aval = toNumber(a)", " val bval = toNumber(b)", " return if (aval > bval) {", " return a", " } else if (aval < bval) {", " return b", " } else {", " return null", " }", "}", "", "" ]
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 * factorial of this integer. * */ fun specialFactorial(n : Long) : Long {
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 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20 : Long = 7 var x2 : Long = specialFactorial(arg20); var v2 : Long = 125411328000; if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30 : Long = 1 var x3 : Long = specialFactorial(arg30); var v3 : Long = 1; if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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 * factorial of this integer. * */
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: List<String>, substring: String): List<String> {
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<String> = mutableListOf("xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx") var arg11: String = "xxx" var x1: List<String> = filterBySubstring(arg10, arg11) var v1: List<String> = mutableListOf("xxx", "xxxAAA", "xxx") if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<String> = mutableListOf("xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx") var arg21: String = "xx" var x2: List<String> = filterBySubstring(arg20, arg21) var v2: List<String> = mutableListOf("xxx", "aaaxxy", "xxxAAA", "xxx") if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<String> = mutableListOf("grunt", "trumpet", "prune", "gruesome") var arg31: String = "run" var x3: List<String> = filterBySubstring(arg30, arg31) var v3: List<String> = mutableListOf("grunt", "prune") if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } }
/** * 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: Int = 2 if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: Int = 0 var arg21: Int = 101 var x2: Int = modp(arg20, arg21) var v2: Int = 1 if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: Int = 3 var arg31: Int = 11 var x3: Int = modp(arg30, arg31) var v3: Int = 8 if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: Int = 100 var arg41: Int = 101 var x4: Int = modp(arg40, arg41) var v4: Int = 1 if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } var arg50: Int = 30 var arg51: Int = 5 var x5: Int = modp(arg50, arg51) var v5: Int = 4 if (x5 != v5) { throw Exception("Exception -- test case 5 did not pass. x5 = " + x5) } var arg60: Int = 31 var arg61: Int = 5 var x6: Int = modp(arg60, arg61) var v6: Int = 3 if (x6 != v6) { throw Exception("Exception -- test case 6 did not pass. x6 = " + x6) } }
/** * 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]) * (10, 24) * */ fun sumProduct(numbers: List<Int>): List<Int> {
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> = sumProduct(arg10) var v1: List<Int> = mutableListOf(3, 1) if (x1 != v1) { throw Exception("Exception -- test case 1 did not pass. x1 = " + x1) } var arg20: List<Int> = mutableListOf(100, 0) var x2: List<Int> = sumProduct(arg20) var v2: List<Int> = mutableListOf(100, 0) if (x2 != v2) { throw Exception("Exception -- test case 2 did not pass. x2 = " + x2) } var arg30: List<Int> = mutableListOf(3, 5, 7) var x3: List<Int> = sumProduct(arg30) var v3: List<Int> = mutableListOf(15, 105) if (x3 != v3) { throw Exception("Exception -- test case 3 did not pass. x3 = " + x3) } var arg40: List<Int> = mutableListOf(10) var x4: List<Int> = sumProduct(arg40) var v4: List<Int> = mutableListOf(10, 10) if (x4 != v4) { throw Exception("Exception -- test case 4 did not pass. x4 = " + x4) } }
/** * 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]) * (10, 24) * */
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)", "}", "", "" ]