Datasets:

Modalities:
Text
Formats:
parquet
Size:
< 1K
Libraries:
Datasets
pandas
License:
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", "}", "", "" ]

Benchmark summary

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

How to use

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

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

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

import json
import re

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


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

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

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


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


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


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

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

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

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

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

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

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

Results

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

Downloads last month
377

Collection including JetBrains/Kotlin_HumanEval