Prompt:
<?php
// Return length of given string
// >>> strlen("")
// 0
// >>> strlen("abc")
// 3
function strlen($string) {

function candidate(...$args) {
    return strlen(...$args);
}

function test(): void {
    if (candidate("") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("x") !== 1) { throw new Exception("Test failed!"); }
    if (candidate("asdasnakj") !== 9) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Create a function encrypt that takes a string as an argument and
// returns a string encrypted with the alphabet being rotated.
// The alphabet should be rotated in a manner such that the letters
// shift down by two multiplied to two places.
// For example:
// >>> encrypt("hi")
// "lm"
// >>> encrypt("asdfghjkl")
// "ewhjklnop"
// >>> encrypt("gf")
// "kj"
// >>> encrypt("et")
// "ix"
function encrypt($s) {

function candidate(...$args) {
    return encrypt(...$args);
}

function test(): void {
    if (candidate("hi") !== "lm") { throw new Exception("Test failed!"); }
    if (candidate("asdfghjkl") !== "ewhjklnop") { throw new Exception("Test failed!"); }
    if (candidate("gf") !== "kj") { throw new Exception("Test failed!"); }
    if (candidate("et") !== "ix") { throw new Exception("Test failed!"); }
    if (candidate("faewfawefaewg") !== "jeiajeaijeiak") { throw new Exception("Test failed!"); }
    if (candidate("hellomyfriend") !== "lippsqcjvmirh") { throw new Exception("Test failed!"); }
    if (candidate("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh") !== "hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl") { throw new Exception("Test failed!"); }
    if (candidate("a") !== "e") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array, 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 array is empty.
// Examples:
// >>> check_dict_case(array("a" => "apple", "b" => "banana"))
// true
// >>> check_dict_case(array("a" => "apple", "A" => "banana", "B" => "banana"))
// false
// >>> check_dict_case(array("a" => "apple", 8 => "banana", "a" => "apple"))
// false
// >>> check_dict_case(array("Name" => "John", "Age" => "36", "City" => "Houston"))
// false
// >>> check_dict_case(array("STATE" => "NC", "ZIP" => "12345"))
// true
function check_dict_case($dict) {

function candidate(...$args) {
    return check_dict_case(...$args);
}

function test(): void {
    if (candidate(array("p" => "pineapple", "b" => "banana")) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array("p" => "pineapple", "A" => "banana", "B" => "banana")) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array("p" => "pineapple", "5" => "banana", "a" => "apple")) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array("Name" => "John", "Age" => "36", "City" => "Houston")) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array("STATE" => "NC", "ZIP" => "12345")) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array("fruit" => "Orange", "taste" => "Sweet")) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a non-empty array of integers lst. add the even elements that are at odd indices..
// Examples:
// >>> add(array(4, 2, 6, 7))
// 2
function add($lst) {

function candidate(...$args) {
    return add(...$args);
}

function test(): void {
    if (candidate(array(4, 88)) !== 88) { throw new Exception("Test failed!"); }
    if (candidate(array(4, 5, 6, 7, 2, 122)) !== 122) { throw new Exception("Test failed!"); }
    if (candidate(array(4, 0, 6, 7)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(4, 4, 6, 8)) !== 12) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a string text, replace all spaces in it with underscores,
// and if a string has more than 2 consecutive spaces,
// then replace all consecutive spaces with -
// >>> fix_spaces(" Example")
// "Example"
// >>> fix_spaces(" Example 1")
// "Example_1"
// >>> fix_spaces(" Example 2")
// "_Example_2"
// >>> fix_spaces(" Example 3")
// "_Example-3"
function fix_spaces($text) {

function candidate(...$args) {
    return fix_spaces(...$args);
}

function test(): void {
    if (candidate("Example") !== "Example") { throw new Exception("Test failed!"); }
    if (candidate("Mudasir Hanif ") !== "Mudasir_Hanif_") { throw new Exception("Test failed!"); }
    if (candidate("Yellow Yellow  Dirty  Fellow") !== "Yellow_Yellow__Dirty__Fellow") { throw new Exception("Test failed!"); }
    if (candidate("Exa   mple") !== "Exa-mple") { throw new Exception("Test failed!"); }
    if (candidate("   Exa 1 2 2 mple") !== "-Exa_1_2_2_mple") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fibfib(0) == 0
// fibfib(1) == 0
// fibfib(2) == 1
// fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
// Please write a function to efficiently compute the n-th element of the fibfib number sequence.
// >>> fibfib(1)
// 0
// >>> fibfib(5)
// 4
// >>> fibfib(8)
// 24
function fibfib($n) {

function candidate(...$args) {
    return fibfib(...$args);
}

function test(): void {
    if (candidate(2) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(1) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(5) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(8) !== 24) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 81) { throw new Exception("Test failed!"); }
    if (candidate(12) !== 274) { throw new Exception("Test failed!"); }
    if (candidate(14) !== 927) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of numbers, return the sum of squares of the numbers
// in the array that are odd. Ignore numbers that are negative or not integers.
// >>> double_the_difference(array(1, 3, 2, 0))
// 10
// >>> double_the_difference(array(-1, -2, 0))
// 0
// >>> double_the_difference(array(9, -2))
// 81
// >>> double_the_difference(array(0))
// 0
// If the input array is empty, return 0.
function double_the_difference($lst) {

function candidate(...$args) {
    return double_the_difference(...$args);
}

function test(): void {
    if (candidate(array()) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(5.0, 4.0)) !== 25) { throw new Exception("Test failed!"); }
    if (candidate(array(0.1, 0.2, 0.3)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(-10.0, -20.0, -30.0)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(-1.0, -2.0, 8.0)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(0.2, 3.0, 5.0)) !== 34) { throw new Exception("Test failed!"); }
    if (candidate(array(-9.0, -7.0, -5.0, -3.0, -1.0, 1.0, 3.0, 5.0, 7.0, 9.0)) !== 165) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Filter given array of any phpthon values only for integers
// >>> filter_integers(array("a", 3.14, 5))
// array(5)
// >>> filter_integers(array(1, 2, 3, "abc", array(), array()))
// array(1, 2, 3)
function filter_integers($values) {

function candidate(...$args) {
    return filter_integers(...$args);
}

function test(): void {
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(4, array(), array(), 23.2, 9, "adasd")) !== array(4, 9)) { throw new Exception("Test failed!"); }
    if (candidate(array(3, "c", 3, 3, "a", "b")) !== array(3, 3, 3)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Imagine a road that's a perfectly straight infinitely long line.
// n cars are driving left to right;  simultaneously, a different set of n cars
// are driving right to left.   The two sets of cars start out being very far from
// each other.  All cars move in the same speed.  Two cars are said to collide
// when a car that's moving left to right hits a car that's moving right to left.
// However, the cars are infinitely sturdy and strong; as a result, they continue moving
// in their trajectory as if they did not collide.
// This function outputs the number of such collisions.
function car_race_collision($n) {

function candidate(...$args) {
    return car_race_collision(...$args);
}

function test(): void {
    if (candidate(2) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(3) !== 9) { throw new Exception("Test failed!"); }
    if (candidate(4) !== 16) { throw new Exception("Test failed!"); }
    if (candidate(8) !== 64) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 100) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Input to this function is a string representing musical notes in a special ASCII format.
// Your task is to parse this string and return array 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")
// array(4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4)
function parse_music($music_string) {

function candidate(...$args) {
    return parse_music(...$args);
}

function test(): void {
    if (candidate("") !== array()) { throw new Exception("Test failed!"); }
    if (candidate("o o o o") !== array(4, 4, 4, 4)) { throw new Exception("Test failed!"); }
    if (candidate(".| .| .| .|") !== array(1, 1, 1, 1)) { throw new Exception("Test failed!"); }
    if (candidate("o| o| .| .| o o o o") !== array(2, 2, 1, 1, 4, 4, 4, 4)) { throw new Exception("Test failed!"); }
    if (candidate("o| .| o| .| o o| o o|") !== array(2, 1, 2, 1, 4, 2, 4, 2)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You will be given a number in decimal form and your task is to convert it to
// binary format. The function should return a string, with each character representing a binary
// number. Each character in the string will be '0' or '1'.
// There will be an extra couple of characters 'db' at the beginning and at the end of the string.
// The extra characters are there to help with the format.
// Examples:
// >>> decimal_to_binary(15)
// "db1111db"
// >>> decimal_to_binary(32)
// "db100000db"
function decimal_to_binary($decimal) {

function candidate(...$args) {
    return decimal_to_binary(...$args);
}

function test(): void {
    if (candidate(0) !== "db0db") { throw new Exception("Test failed!"); }
    if (candidate(32) !== "db100000db") { throw new Exception("Test failed!"); }
    if (candidate(103) !== "db1100111db") { throw new Exception("Test failed!"); }
    if (candidate(15) !== "db1111db") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return array of all prefixes from shortest to longest of the input string
// >>> all_prefixes("abc")
// array("a", "ab", "abc")
function all_prefixes($string) {

function candidate(...$args) {
    return all_prefixes(...$args);
}

function test(): void {
    if (candidate("") !== array()) { throw new Exception("Test failed!"); }
    if (candidate("asdfgh") !== array("a", "as", "asd", "asdf", "asdfg", "asdfgh")) { throw new Exception("Test failed!"); }
    if (candidate("WWW") !== array("W", "WW", "WWW")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Add two numbers x and y
// >>> add(2, 3)
// 5
// >>> add(5, 7)
// 12
function add($x, $y) {

function candidate(...$args) {
    return add(...$args);
}

function test(): void {
    if (candidate(0, 1) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(1, 0) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(2, 3) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(5, 7) !== 12) { throw new Exception("Test failed!"); }
    if (candidate(7, 5) !== 12) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You're a hungry rabbit, and you already have eaten a certain number of carrots,
// but now you need to eat more carrots to complete the day's meals.
// you should return an array of [ total number of eaten carrots after your meals,
// the number of carrots left after your meals ]
// if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry.
// Example:
// >>> eat(5, 6, 10)
// array(11, 4)
// >>> eat(4, 8, 9)
// array(12, 1)
// >>> eat(1, 10, 10)
// array(11, 0)
// >>> eat(2, 11, 5)
// array(7, 0)
// Variables:
// @number : integer
// the number of carrots that you have eaten.
// @need : integer
// the number of carrots that you need to eat.
// @remaining : integer
// the number of remaining carrots thet exist in stock
// Constrain:
// * 0 <= number <= 1000
// * 0 <= need <= 1000
// * 0 <= remaining <= 1000
// Have fun :)
function eat($number, $need, $remaining) {

function candidate(...$args) {
    return eat(...$args);
}

function test(): void {
    if (candidate(5, 6, 10) !== array(11, 4)) { throw new Exception("Test failed!"); }
    if (candidate(4, 8, 9) !== array(12, 1)) { throw new Exception("Test failed!"); }
    if (candidate(1, 10, 10) !== array(11, 0)) { throw new Exception("Test failed!"); }
    if (candidate(2, 11, 5) !== array(7, 0)) { throw new Exception("Test failed!"); }
    if (candidate(4, 5, 7) !== array(9, 2)) { throw new Exception("Test failed!"); }
    if (candidate(4, 5, 1) !== array(5, 0)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You are given a rectangular grid of wells. Each row represents a single well,
// and each 1 in a row represents a single unit of water.
// Each well has a corresponding bucket that can be used to extract water from it,
// and all buckets have the same capacity.
// Your task is to use the buckets to empty the wells.
// Output the number of times you need to lower the buckets.
// Example 1:
// >>> max_fill(array(array(0, 0, 1, 0), array(0, 1, 0, 0), array(1, 1, 1, 1)), 1)
// 6
// Example 2:
// >>> max_fill(array(array(0, 0, 1, 1), array(0, 0, 0, 0), array(1, 1, 1, 1), array(0, 1, 1, 1)), 2)
// 5
// Example 3:
// >>> max_fill(array(array(0, 0, 0), array(0, 0, 0)), 5)
// 0
// Constraints:
// * all wells have the same length
// * 1 <= grid.length <= 10^2
// * 1 <= grid[:,1].length <= 10^2
// * grid[i][j] -> 0 | 1
// * 1 <= capacity <= 10
function max_fill($grid, $capacity) {

function candidate(...$args) {
    return max_fill(...$args);
}

function test(): void {
    if (candidate(array(array(0, 0, 1, 0), array(0, 1, 0, 0), array(1, 1, 1, 1)), 1) !== 6) { throw new Exception("Test failed!"); }
    if (candidate(array(array(0, 0, 1, 1), array(0, 0, 0, 0), array(1, 1, 1, 1), array(0, 1, 1, 1)), 2) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(array(array(0, 0, 0), array(0, 0, 0)), 5) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(array(1, 1, 1, 1), array(1, 1, 1, 1)), 2) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(array(array(1, 1, 1, 1), array(1, 1, 1, 1)), 9) !== 2) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given two arrays operator, and operand. The first array has basic algebra operations, and
// the second array is an array of integers. Use the two given arrays to build the algebric
// expression and return the evaluation of this expression.
// The basic algebra operations:
// Addition ( + )
// Subtraction ( - )
// Multiplication ( * )
// Floor division ( // )
// Exponentiation ( ** )
// Example:
// operator['+', '*', '-']
// array = [2, 3, 4, 5]
// result = 2 + 3 * 4 - 5
// => result = 9
// Note:
// The length of operator array is equal to the length of operand array minus one.
// Operand is an array of of non-negative integers.
// Operator array has at least one operator, and operand array has at least two operands.
function do_algebra($operator, $operand) {

function candidate(...$args) {
    return do_algebra(...$args);
}

function test(): void {
    if (candidate(array("**", "*", "+"), array(2, 3, 4, 5)) !== 37) { throw new Exception("Test failed!"); }
    if (candidate(array("+", "*", "-"), array(2, 3, 4, 5)) !== 9) { throw new Exception("Test failed!"); }
    if (candidate(array("//", "*"), array(7, 3, 4)) !== 8) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
// >>> flip_case("Hello")
// "hELLO"
function flip_case($string) {

function candidate(...$args) {
    return flip_case(...$args);
}

function test(): void {
    if (candidate("") !== "") { throw new Exception("Test failed!"); }
    if (candidate("Hello!") !== "hELLO!") { throw new Exception("Test failed!"); }
    if (candidate("These violent delights have violent ends") !== "tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of integers, sort the integers that are between 1 and 9 inclusive,
// reverse the resulting array, and then replace each digit by its corresponding name from
// "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine".
// For example:
// >>> by_length(array(2, 1, 1, 4, 5, 8, 2, 3))
// array("Eight", "Five", "Four", "Three", "Two", "Two", "One", "One")
// If the array is empty, return an empty array:
// >>> by_length(array())
// array()
// If the array has any strange number ignore it:
// >>> by_length(array(1, -1, 55))
// array("One")
function by_length($arr) {

function candidate(...$args) {
    return by_length(...$args);
}

function test(): void {
    if (candidate(array(2, 1, 1, 4, 5, 8, 2, 3)) !== array("Eight", "Five", "Four", "Three", "Two", "Two", "One", "One")) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(1, -1, 55)) !== array("One")) { throw new Exception("Test failed!"); }
    if (candidate(array(1, -1, 3, 2)) !== array("Three", "Two", "One")) { throw new Exception("Test failed!"); }
    if (candidate(array(9, 4, 8)) !== array("Nine", "Eight", "Four")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return array of prime factors of given integer in the order from smallest to largest.
// Each of the factors should be arrayed number of times corresponding to how many times it appeares in factorization.
// Input number should be equal to the product of all factors
// >>> factorize(8)
// array(2, 2, 2)
// >>> factorize(25)
// array(5, 5)
// >>> factorize(70)
// array(2, 5, 7)
function factorize($n) {

function candidate(...$args) {
    return factorize(...$args);
}

function test(): void {
    if (candidate(2) !== array(2)) { throw new Exception("Test failed!"); }
    if (candidate(4) !== array(2, 2)) { throw new Exception("Test failed!"); }
    if (candidate(8) !== array(2, 2, 2)) { throw new Exception("Test failed!"); }
    if (candidate(57) !== array(3, 19)) { throw new Exception("Test failed!"); }
    if (candidate(3249) !== array(3, 3, 19, 19)) { throw new Exception("Test failed!"); }
    if (candidate(185193) !== array(3, 3, 3, 19, 19, 19)) { throw new Exception("Test failed!"); }
    if (candidate(20577) !== array(3, 19, 19, 19)) { throw new Exception("Test failed!"); }
    if (candidate(18) !== array(2, 3, 3)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Implement a function that takes an 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)
// array(2, 3)
// >>> count_up_to(11)
// array(2, 3, 5, 7)
// >>> count_up_to(0)
// array()
// >>> count_up_to(20)
// array(2, 3, 5, 7, 11, 13, 17, 19)
// >>> count_up_to(1)
// array()
// >>> count_up_to(18)
// array(2, 3, 5, 7, 11, 13, 17)
function count_up_to($n) {

function candidate(...$args) {
    return count_up_to(...$args);
}

function test(): void {
    if (candidate(5) !== array(2, 3)) { throw new Exception("Test failed!"); }
    if (candidate(6) !== array(2, 3, 5)) { throw new Exception("Test failed!"); }
    if (candidate(7) !== array(2, 3, 5)) { throw new Exception("Test failed!"); }
    if (candidate(10) !== array(2, 3, 5, 7)) { throw new Exception("Test failed!"); }
    if (candidate(0) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(22) !== array(2, 3, 5, 7, 11, 13, 17, 19)) { throw new Exception("Test failed!"); }
    if (candidate(1) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(18) !== array(2, 3, 5, 7, 11, 13, 17)) { throw new Exception("Test failed!"); }
    if (candidate(47) !== array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43)) { throw new Exception("Test failed!"); }
    if (candidate(101) !== array(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)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return sorted unique elements in an array
// >>> unique(array(5, 3, 5, 2, 3, 3, 9, 0, 123))
// array(0, 2, 3, 5, 9, 123)
function unique($l) {

function candidate(...$args) {
    return unique(...$args);
}

function test(): void {
    if (candidate(array(5, 3, 5, 2, 3, 3, 9, 0, 123)) !== array(0, 2, 3, 5, 9, 123)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Write a function that accepts two arrays of strings and returns the array that has
// total number of chars in the all strings of the array less than the other array.
// if the two arrays have the same number of chars, return the first array.
// Examples
// >>> total_match(array(), array())
// array()
// >>> total_match(array("hi", "admin"), array("hI", "Hi"))
// array("hI", "Hi")
// >>> total_match(array("hi", "admin"), array("hi", "hi", "admin", "project"))
// array("hi", "admin")
// >>> total_match(array("hi", "admin"), array("hI", "hi", "hi"))
// array("hI", "hi", "hi")
// >>> total_match(array("4"), array("1", "2", "3", "4", "5"))
// array("4")
function total_match($lst1, $lst2) {

function candidate(...$args) {
    return total_match(...$args);
}

function test(): void {
    if (candidate(array(), array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array("hi", "admin"), array("hi", "hi")) !== array("hi", "hi")) { throw new Exception("Test failed!"); }
    if (candidate(array("hi", "admin"), array("hi", "hi", "admin", "project")) !== array("hi", "admin")) { throw new Exception("Test failed!"); }
    if (candidate(array("4"), array("1", "2", "3", "4", "5")) !== array("4")) { throw new Exception("Test failed!"); }
    if (candidate(array("hi", "admin"), array("hI", "Hi")) !== array("hI", "Hi")) { throw new Exception("Test failed!"); }
    if (candidate(array("hi", "admin"), array("hI", "hi", "hi")) !== array("hI", "hi", "hi")) { throw new Exception("Test failed!"); }
    if (candidate(array("hi", "admin"), array("hI", "hi", "hii")) !== array("hi", "admin")) { throw new Exception("Test failed!"); }
    if (candidate(array(), array("this")) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array("this"), array()) !== array()) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return maximum element in the array.
// >>> max_element(array(1, 2, 3))
// 3
// >>> max_element(array(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))
// 123
function max_element($l) {

function candidate(...$args) {
    return max_element(...$args);
}

function test(): void {
    if (candidate(array(1, 2, 3)) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10)) !== 124) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function is_nested($string) {

function candidate(...$args) {
    return is_nested(...$args);
}

function test(): void {
    if (candidate("[[]]") !== true) { throw new Exception("Test failed!"); }
    if (candidate("[]]]]]]][[[[[]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[][]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[[[[]]]]") !== true) { throw new Exception("Test failed!"); }
    if (candidate("[]]]]]]]]]]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[][][[]]") !== true) { throw new Exception("Test failed!"); }
    if (candidate("[[]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[]]") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[[]][[") !== true) { throw new Exception("Test failed!"); }
    if (candidate("[[][]]") !== true) { throw new Exception("Test failed!"); }
    if (candidate("") !== false) { throw new Exception("Test failed!"); }
    if (candidate("[[[[[[[[") !== false) { throw new Exception("Test failed!"); }
    if (candidate("]]]]]]]]") !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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"
function rounded_avg($n, $m) {

function candidate(...$args) {
    return rounded_avg(...$args);
}

function test(): void {
    if (candidate(1, 5) !== "0b11") { throw new Exception("Test failed!"); }
    if (candidate(7, 13) !== "0b1010") { throw new Exception("Test failed!"); }
    if (candidate(964, 977) !== "0b1111001010") { throw new Exception("Test failed!"); }
    if (candidate(996, 997) !== "0b1111100100") { throw new Exception("Test failed!"); }
    if (candidate(560, 851) !== "0b1011000010") { throw new Exception("Test failed!"); }
    if (candidate(185, 546) !== "0b101101110") { throw new Exception("Test failed!"); }
    if (candidate(362, 496) !== "0b110101101") { throw new Exception("Test failed!"); }
    if (candidate(350, 902) !== "0b1001110010") { throw new Exception("Test failed!"); }
    if (candidate(197, 233) !== "0b11010111") { throw new Exception("Test failed!"); }
    if (candidate(7, 5) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(5, 1) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(5, 5) !== "0b101") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of strings, where each string consists of only digits, return an array.
// Each element i of the output should be "the number of odd elements in the
// string i of the input." where all the i's should be replaced by the number
// of odd digits in the i'th string of the input.
// >>> odd_count(array("1234567"))
// array("the number of odd elements 4n the str4ng 4 of the 4nput.")
// >>> odd_count(array("3", "11111111"))
// array("the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput.")
function odd_count($lst) {

function candidate(...$args) {
    return odd_count(...$args);
}

function test(): void {
    if (candidate(array("1234567")) !== array("the number of odd elements 4n the str4ng 4 of the 4nput.")) { throw new Exception("Test failed!"); }
    if (candidate(array("3", "11111111")) !== array("the number of odd elements 1n the str1ng 1 of the 1nput.", "the number of odd elements 8n the str8ng 8 of the 8nput.")) { throw new Exception("Test failed!"); }
    if (candidate(array("271", "137", "314")) !== array("the number of odd elements 2n the str2ng 2 of the 2nput.", "the number of odd elements 3n the str3ng 3 of the 3nput.", "the number of odd elements 2n the str2ng 2 of the 2nput.")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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 array is guaranteed to have unique elements.
// For Example:
// >>> move_one_ball(array(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(array(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.
function move_one_ball($arr) {

function candidate(...$args) {
    return move_one_ball(...$args);
}

function test(): void {
    if (candidate(array(3, 4, 5, 1, 2)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 5, 10, 1, 2)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(4, 3, 1, 2)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 5, 4, 1, 2)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== true) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a positive integer n, return an array that has the number of even and odd
// integer palindromes that fall within the range(1, n), inclusive.
// Example 1:
// >>> even_odd_palindrome(3)
// array(1, 2)
// Explanation:
// Integer palindrome are 1, 2, 3. one of them is even, and two of them are odd.
// Example 2:
// >>> even_odd_palindrome(12)
// array(4, 6)
// Explanation:
// Integer palindrome are 1, 2, 3, 4, 5, 6, 7, 8, 9, 11. four of them are even, and 6 of them are odd.
// Note:
// 1. 1 <= n <= 10^3
// 2. returned array has the number of even and odd integer palindromes respectively.
function even_odd_palindrome($n) {

function candidate(...$args) {
    return even_odd_palindrome(...$args);
}

function test(): void {
    if (candidate(123) !== array(8, 13)) { throw new Exception("Test failed!"); }
    if (candidate(12) !== array(4, 6)) { throw new Exception("Test failed!"); }
    if (candidate(3) !== array(1, 2)) { throw new Exception("Test failed!"); }
    if (candidate(63) !== array(6, 8)) { throw new Exception("Test failed!"); }
    if (candidate(25) !== array(5, 6)) { throw new Exception("Test failed!"); }
    if (candidate(19) !== array(4, 6)) { throw new Exception("Test failed!"); }
    if (candidate(9) !== array(4, 5)) { throw new Exception("Test failed!"); }
    if (candidate(1) !== array(0, 1)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers
// Example
// >>> is_equal_to_sum_even(4)
// false
// >>> is_equal_to_sum_even(6)
// false
// >>> is_equal_to_sum_even(8)
// true
function is_equal_to_sum_even($n) {

function candidate(...$args) {
    return is_equal_to_sum_even(...$args);
}

function test(): void {
    if (candidate(4) !== false) { throw new Exception("Test failed!"); }
    if (candidate(6) !== false) { throw new Exception("Test failed!"); }
    if (candidate(8) !== true) { throw new Exception("Test failed!"); }
    if (candidate(10) !== true) { throw new Exception("Test failed!"); }
    if (candidate(11) !== false) { throw new Exception("Test failed!"); }
    if (candidate(12) !== true) { throw new Exception("Test failed!"); }
    if (candidate(13) !== false) { throw new Exception("Test failed!"); }
    if (candidate(16) !== true) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// xs represent coefficients of a polynomial.
// xs[0] + xs[1] * x + xs[2] * x^2 + ....
// Return derivative of this polynomial in the same form.
// >>> derivative(array(3, 1, 2, 4, 5))
// array(1, 4, 12, 20)
// >>> derivative(array(1, 2, 3))
// array(2, 6)
function derivative($xs) {

function candidate(...$args) {
    return derivative(...$args);
}

function test(): void {
    if (candidate(array(3, 1, 2, 4, 5)) !== array(1, 4, 12, 20)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3)) !== array(2, 6)) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 1)) !== array(2, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 1, 0, 4)) !== array(2, 2, 0, 16)) { throw new Exception("Test failed!"); }
    if (candidate(array(1)) !== array()) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of numbers, return whether or not they are sorted
// in ascending order. If array has more than 1 duplicate of the same
// number, return false. Assume no negative numbers and only integers.
// Examples
// >>> is_sorted(array(5))
// true
// >>> is_sorted(array(1, 2, 3, 4, 5))
// true
// >>> is_sorted(array(1, 3, 2, 4, 5))
// false
// >>> is_sorted(array(1, 2, 3, 4, 5, 6))
// true
// >>> is_sorted(array(1, 2, 3, 4, 5, 6, 7))
// true
// >>> is_sorted(array(1, 3, 2, 4, 5, 6, 7))
// false
// >>> is_sorted(array(1, 2, 2, 3, 3, 4))
// true
// >>> is_sorted(array(1, 2, 2, 2, 3, 4))
// false
function is_sorted($lst) {

function candidate(...$args) {
    return is_sorted(...$args);
}

function test(): void {
    if (candidate(array(5)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4, 5)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 3, 2, 4, 5)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4, 5, 6)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4, 5, 6, 7)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 3, 2, 4, 5, 6, 7)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 1)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 2, 2, 3, 4)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 3, 3, 4)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 2, 3, 3, 4)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4)) !== true) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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"
function solve($s) {

function candidate(...$args) {
    return solve(...$args);
}

function test(): void {
    if (candidate("AsDf") !== "aSdF") { throw new Exception("Test failed!"); }
    if (candidate("1234") !== "4321") { throw new Exception("Test failed!"); }
    if (candidate("ab") !== "AB") { throw new Exception("Test failed!"); }
    if (candidate("#a@C") !== "#A@c") { throw new Exception("Test failed!"); }
    if (candidate("#AsdfW^45") !== "#aSDFw^45") { throw new Exception("Test failed!"); }
    if (candidate("#6@2") !== "2@6#") { throw new Exception("Test failed!"); }
    if (candidate("#$a^D") !== "#$A^d") { throw new Exception("Test failed!"); }
    if (candidate("#ccc") !== "#CCC") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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 an array of the
// first n + 1 numbers of the Tribonacci sequence.
// Examples:
// >>> tri(3)
// array(1, 3, 2, 8)
function tri($n) {

function candidate(...$args) {
    return tri(...$args);
}

function test(): void {
    if (candidate(3) !== array(1, 3, 2, 8)) { throw new Exception("Test failed!"); }
    if (candidate(4) !== array(1, 3, 2, 8, 3)) { throw new Exception("Test failed!"); }
    if (candidate(5) !== array(1, 3, 2, 8, 3, 15)) { throw new Exception("Test failed!"); }
    if (candidate(6) !== array(1, 3, 2, 8, 3, 15, 4)) { throw new Exception("Test failed!"); }
    if (candidate(7) !== array(1, 3, 2, 8, 3, 15, 4, 24)) { throw new Exception("Test failed!"); }
    if (candidate(8) !== array(1, 3, 2, 8, 3, 15, 4, 24, 5)) { throw new Exception("Test failed!"); }
    if (candidate(9) !== array(1, 3, 2, 8, 3, 15, 4, 24, 5, 35)) { throw new Exception("Test failed!"); }
    if (candidate(20) !== array(1, 3, 2, 8, 3, 15, 4, 24, 5, 35, 6, 48, 7, 63, 8, 80, 9, 99, 10, 120, 11)) { throw new Exception("Test failed!"); }
    if (candidate(0) !== array(1)) { throw new Exception("Test failed!"); }
    if (candidate(1) !== array(1, 3)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
// >>> fizz_buzz(50)
// 0
// >>> fizz_buzz(78)
// 2
// >>> fizz_buzz(79)
// 3
function fizz_buzz($n) {

function candidate(...$args) {
    return fizz_buzz(...$args);
}

function test(): void {
    if (candidate(50) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(78) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(79) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(100) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(200) !== 6) { throw new Exception("Test failed!"); }
    if (candidate(4000) !== 192) { throw new Exception("Test failed!"); }
    if (candidate(10000) !== 639) { throw new Exception("Test failed!"); }
    if (candidate(100000) !== 8026) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Filter an input array of strings only for ones that start with a given prefix.
// >>> filter_by_prefix(array(), "a")
// array()
// >>> filter_by_prefix(array("abc", "bcd", "cde", "array"), "a")
// array("abc", "array")
function filter_by_prefix($strings, $prefix) {

function candidate(...$args) {
    return filter_by_prefix(...$args);
}

function test(): void {
    if (candidate(array(), "john") !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array("xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"), "xxx") !== array("xxx", "xxxAAA", "xxx")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a positive integer N, return the total sum of its digits in binary.
// Example
// >>> solve(1000)
// "1"
// >>> solve(150)
// "110"
// >>> solve(147)
// "1100"
// Variables:
// @N integer
// Constraints: 0 ≤ N ≤ 10000.
// Output:
// a string of binary number
function solve($N) {

function candidate(...$args) {
    return solve(...$args);
}

function test(): void {
    if (candidate(1000) !== "1") { throw new Exception("Test failed!"); }
    if (candidate(150) !== "110") { throw new Exception("Test failed!"); }
    if (candidate(147) !== "1100") { throw new Exception("Test failed!"); }
    if (candidate(333) !== "1001") { throw new Exception("Test failed!"); }
    if (candidate(963) !== "10010") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a grid with N rows and N columns (N >= 2) and a positive integer k,
// each cell of the grid contains a value. Every integer in the range [1, N * N]
// inclusive appears exactly once on the cells of the grid.
// You have to find the minimum path of length k in the grid. You can start
// from any cell, and in each step you can move to any of the neighbor cells,
// in other words, you can go to cells which share an edge with you current
// cell.
// Please note that a path of length k means visiting exactly k cells (not
// necessarily distinct).
// You CANNOT go off the grid.
// A path A (of length k) is considered less than a path B (of length k) if
// after making the ordered arrays of the values on the cells that A and B go
// through (let's call them lst_A and lst_B), lst_A is lexicographically less
// than lst_B, in other words, there exist an integer index i (1 <= i <= k)
// such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have
// lst_A[j] = lst_B[j].
// It is guaranteed that the answer is unique.
// Return an ordered array of the values on the cells that the minimum path go through.
// Examples:
// >>> minPath(array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 3)
// array(1, 2, 1)
// >>> minPath(array(array(5, 9, 3), array(4, 1, 6), array(7, 8, 2)), 1)
// array(1)
function minPath($grid, $k) {

function candidate(...$args) {
    return minPath(...$args);
}

function test(): void {
    if (candidate(array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9)), 3) !== array(1, 2, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(5, 9, 3), array(4, 1, 6), array(7, 8, 2)), 1) !== array(1)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(1, 2, 3, 4), array(5, 6, 7, 8), array(9, 10, 11, 12), array(13, 14, 15, 16)), 4) !== array(1, 2, 1, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(6, 4, 13, 10), array(5, 7, 12, 1), array(3, 16, 11, 15), array(8, 14, 9, 2)), 7) !== array(1, 10, 1, 10, 1, 10, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(8, 14, 9, 2), array(6, 4, 13, 15), array(5, 7, 1, 12), array(3, 10, 11, 16)), 5) !== array(1, 7, 1, 7, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(11, 8, 7, 2), array(5, 16, 14, 4), array(9, 3, 15, 6), array(12, 13, 10, 1)), 9) !== array(1, 6, 1, 6, 1, 6, 1, 6, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(12, 13, 10, 1), array(9, 3, 15, 6), array(5, 16, 14, 4), array(11, 8, 7, 2)), 12) !== array(1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(2, 7, 4), array(3, 1, 5), array(6, 8, 9)), 8) !== array(1, 3, 1, 3, 1, 3, 1, 3)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(6, 1, 5), array(3, 8, 9), array(2, 7, 4)), 8) !== array(1, 5, 1, 5, 1, 5, 1, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(1, 2), array(3, 4)), 10) !== array(1, 2, 1, 2, 1, 2, 1, 2, 1, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(array(1, 3), array(3, 2)), 10) !== array(1, 3, 1, 3, 1, 3, 1, 3, 1, 3)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a string s, count the number of uppercase vowels in even indices.
// For example:
// >>> count_upper("aBCdEf")
// 1
// >>> count_upper("abcdefg")
// 0
// >>> count_upper("dBBE")
// 0
function count_upper($s) {

function candidate(...$args) {
    return count_upper(...$args);
}

function test(): void {
    if (candidate("aBCdEf") !== 1) { throw new Exception("Test failed!"); }
    if (candidate("abcdefg") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("dBBE") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("B") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("U") !== 1) { throw new Exception("Test failed!"); }
    if (candidate("") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("EEEE") !== 2) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array arr of integers and a positive integer k, return a sorted array
// of length k with the maximum k numbers in arr.
// Example 1:
// >>> maximum(array(-3, -4, 5), 3)
// array(-4, -3, 5)
// Example 2:
// >>> maximum(array(4, -4, 4), 2)
// array(4, 4)
// Example 3:
// >>> maximum(array(-3, 2, 1, 2, -1, -2, 1), 1)
// array(2)
// Note:
// 1. The length of the array will be in the range of [1, 1000].
// 2. The elements in the array will be in the range of [-1000, 1000].
// 3. 0 <= k <= len(arr)
function maximum($arr, $k) {

function candidate(...$args) {
    return maximum(...$args);
}

function test(): void {
    if (candidate(array(-3, -4, 5), 3) !== array(-4, -3, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array(4, -4, 4), 2) !== array(4, 4)) { throw new Exception("Test failed!"); }
    if (candidate(array(-3, 2, 1, 2, -1, -2, 1), 1) !== array(2)) { throw new Exception("Test failed!"); }
    if (candidate(array(123, -123, 20, 0, 1, 2, -3), 3) !== array(2, 20, 123)) { throw new Exception("Test failed!"); }
    if (candidate(array(-123, 20, 0, 1, 2, -3), 4) !== array(0, 1, 2, 20)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 15, 0, 3, -13, -8, 0), 7) !== array(-13, -8, 0, 0, 3, 5, 15)) { throw new Exception("Test failed!"); }
    if (candidate(array(-1, 0, 2, 5, 3, -10), 2) !== array(3, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 0, 5, -7), 1) !== array(5)) { throw new Exception("Test failed!"); }
    if (candidate(array(4, -4), 2) !== array(-4, 4)) { throw new Exception("Test failed!"); }
    if (candidate(array(-10, 10), 2) !== array(-10, 10)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, -23, 243, -400, 0), 0) !== array()) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// For a given number n, find the largest number that divides n evenly, smaller than n
// >>> largest_divisor(15)
// 5
function largest_divisor($n) {

function candidate(...$args) {
    return largest_divisor(...$args);
}

function test(): void {
    if (candidate(3) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(7) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(100) !== 50) { throw new Exception("Test failed!"); }
    if (candidate(49) !== 7) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of non-negative integers, return a cophp of the given array after sorting,
// you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
// or sort it in descending order if the sum( first index value, last index value) is even.
// Note:
// * don't change the given array.
// Examples:
// >>> sort_array(array())
// array()
// >>> sort_array(array(5))
// array(5)
// >>> sort_array(array(2, 4, 3, 0, 1, 5))
// array(0, 1, 2, 3, 4, 5)
// >>> sort_array(array(2, 4, 3, 0, 1, 5, 6))
// array(6, 5, 4, 3, 2, 1, 0)
function sort_array($array) {

function candidate(...$args) {
    return sort_array(...$args);
}

function test(): void {
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(5)) !== array(5)) { throw new Exception("Test failed!"); }
    if (candidate(array(2, 4, 3, 0, 1, 5)) !== array(0, 1, 2, 3, 4, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array(2, 4, 3, 0, 1, 5, 6)) !== array(6, 5, 4, 3, 2, 1, 0)) { throw new Exception("Test failed!"); }
    if (candidate(array(2, 1)) !== array(1, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(15, 42, 87, 32, 11, 0)) !== array(0, 11, 15, 32, 42, 87)) { throw new Exception("Test failed!"); }
    if (candidate(array(21, 14, 23, 11)) !== array(23, 21, 14, 11)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Implement the function f that takes n as a parameter,
// and returns an array of size n, such that the value of the element at index i is the factorial of i if i is even
// or the sum of numbers from 1 to i otherwise.
// i starts from 1.
// the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i).
// Example:
// >>> f(5)
// array(1, 2, 6, 24, 15)
function f($n) {

function candidate(...$args) {
    return f(...$args);
}

function test(): void {
    if (candidate(5) !== array(1, 2, 6, 24, 15)) { throw new Exception("Test failed!"); }
    if (candidate(7) !== array(1, 2, 6, 24, 15, 720, 28)) { throw new Exception("Test failed!"); }
    if (candidate(1) !== array(1)) { throw new Exception("Test failed!"); }
    if (candidate(3) !== array(1, 2, 6)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Write a function that takes an integer a and returns true
// if this ingeger 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
function iscube($a) {

function candidate(...$args) {
    return iscube(...$args);
}

function test(): void {
    if (candidate(1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(2) !== false) { throw new Exception("Test failed!"); }
    if (candidate(-1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(64) !== true) { throw new Exception("Test failed!"); }
    if (candidate(180) !== false) { throw new Exception("Test failed!"); }
    if (candidate(1000) !== true) { throw new Exception("Test failed!"); }
    if (candidate(0) !== true) { throw new Exception("Test failed!"); }
    if (candidate(1729) !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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"
function encode($message) {

function candidate(...$args) {
    return encode(...$args);
}

function test(): void {
    if (candidate("TEST") !== "tgst") { throw new Exception("Test failed!"); }
    if (candidate("Mudasir") !== "mWDCSKR") { throw new Exception("Test failed!"); }
    if (candidate("YES") !== "ygs") { throw new Exception("Test failed!"); }
    if (candidate("This is a message") !== "tHKS KS C MGSSCGG") { throw new Exception("Test failed!"); }
    if (candidate("I DoNt KnOw WhAt tO WrItE") !== "k dQnT kNqW wHcT Tq wRkTg") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function is_bored($S) {

function candidate(...$args) {
    return is_bored(...$args);
}

function test(): void {
    if (candidate("Hello world") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("Is the sky blue?") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("I love It !") !== 1) { throw new Exception("Test failed!"); }
    if (candidate("bIt") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("I feel good today. I will be productive. will kill It") !== 2) { throw new Exception("Test failed!"); }
    if (candidate("You and I are going for a walk") !== 0) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// pairs_sum_to_zero takes an array of integers as an input.
// it returns true if there are two distinct elements in the array that
// sum to zero, and false otherwise.
// >>> pairs_sum_to_zero(array(1, 3, 5, 0))
// false
// >>> pairs_sum_to_zero(array(1, 3, -2, 1))
// false
// >>> pairs_sum_to_zero(array(1, 2, 3, 7))
// false
// >>> pairs_sum_to_zero(array(2, 4, -5, 3, 5, 7))
// true
// >>> pairs_sum_to_zero(array(1))
// false
function pairs_sum_to_zero($l) {

function candidate(...$args) {
    return pairs_sum_to_zero(...$args);
}

function test(): void {
    if (candidate(array(1, 3, 5, 0)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 3, -2, 1)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 7)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(2, 4, -5, 3, 5, 7)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(-3, 9, -1, 3, 2, 30)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(-3, 9, -1, 3, 2, 31)) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(-3, 9, -1, 4, 2, 30)) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(-3, 9, -1, 4, 2, 31)) !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given the lengths of the three sides of a triangle. Return the area of
// the triangle rounded to 2 decimal points if the three sides form a valid triangle.
// Otherwise return -1
// Three sides make a valid triangle when the sum of any two sides is greater
// than the third side.
// Example:
// >>> triangle_area(3, 4, 5)
// 6.0
// >>> triangle_area(1, 2, 10)
// -1
function triangle_area($a, $b, $c) {

function candidate(...$args) {
    return triangle_area(...$args);
}

function test(): void {
    if (candidate(3, 4, 5) !== 6.0) { throw new Exception("Test failed!"); }
    if (candidate(1, 2, 10) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(4, 8, 5) !== 8.18) { throw new Exception("Test failed!"); }
    if (candidate(2, 2, 2) !== 1.73) { throw new Exception("Test failed!"); }
    if (candidate(1, 2, 3) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(10, 5, 7) !== 16.25) { throw new Exception("Test failed!"); }
    if (candidate(2, 6, 3) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(1, 1, 1) !== 0.43) { throw new Exception("Test failed!"); }
    if (candidate(2, 2, 10) !== -1) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// There are eight planets in our solar system: the closerst to the Sun
// is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn,
// Uranus, Neptune.
// Write a function that takes two planet names as strings planet1 and planet2.
// The function should return an array containing all planets whose orbits are
// located between the orbit of planet1 and the orbit of planet2, sorted by
// the proximity to the sun.
// The function should return an empty array if planet1 or planet2
// are not correct planet names.
// Examples
// >>> bf("Jupiter", "Neptune")
// array("Saturn", "Uranus")
// >>> bf("Earth", "Mercury")
// "Venus"
// >>> bf("Mercury", "Uranus")
// array("Venus", "Earth", "Mars", "Jupiter", "Saturn")
function bf($planet1, $planet2) {

function candidate(...$args) {
    return bf(...$args);
}

function test(): void {
    if (candidate("Jupiter", "Neptune") !== array("Saturn", "Uranus")) { throw new Exception("Test failed!"); }
    if (candidate("Earth", "Mercury") !== array("Venus")) { throw new Exception("Test failed!"); }
    if (candidate("Mercury", "Uranus") !== array("Venus", "Earth", "Mars", "Jupiter", "Saturn")) { throw new Exception("Test failed!"); }
    if (candidate("Neptune", "Venus") !== array("Earth", "Mars", "Jupiter", "Saturn", "Uranus")) { throw new Exception("Test failed!"); }
    if (candidate("Earth", "Earth") !== array()) { throw new Exception("Test failed!"); }
    if (candidate("Mars", "Earth") !== array()) { throw new Exception("Test failed!"); }
    if (candidate("Jupiter", "Makemake") !== array()) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function digits($n) {

function candidate(...$args) {
    return digits(...$args);
}

function test(): void {
    if (candidate(5) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(54) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(120) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(5014) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(98765) !== 315) { throw new Exception("Test failed!"); }
    if (candidate(5576543) !== 2625) { throw new Exception("Test failed!"); }
    if (candidate(2468) !== 0) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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")
// array("Hi", "my", "name", "is", "John")
// >>> words_string("One, two, three, four, five, six")
// array("One", "two", "three", "four", "five", "six")
function words_string($s) {

function candidate(...$args) {
    return words_string(...$args);
}

function test(): void {
    if (candidate("Hi, my name is John") !== array("Hi", "my", "name", "is", "John")) { throw new Exception("Test failed!"); }
    if (candidate("One, two, three, four, five, six") !== array("One", "two", "three", "four", "five", "six")) { throw new Exception("Test failed!"); }
    if (candidate("Hi, my name") !== array("Hi", "my", "name")) { throw new Exception("Test failed!"); }
    if (candidate("One,, two, three, four, five, six,") !== array("One", "two", "three", "four", "five", "six")) { throw new Exception("Test failed!"); }
    if (candidate("") !== array()) { throw new Exception("Test failed!"); }
    if (candidate("ahmed     , gamal") !== array("ahmed", "gamal")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function how_many_times($string, $substring) {

function candidate(...$args) {
    return how_many_times(...$args);
}

function test(): void {
    if (candidate("", "x") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("xyxyxyx", "x") !== 4) { throw new Exception("Test failed!"); }
    if (candidate("cacacacac", "cac") !== 4) { throw new Exception("Test failed!"); }
    if (candidate("john doe", "john") !== 1) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Create a function that takes integers, floats, or strings representing
// real numbers, and returns the larger variable in its given variable type.
// Return null if the values are equal.
// Note: If a real number is represented as a string, the floating point might be . or ,
// >>> compare_one(1, 2.5)
// 2.5
// >>> compare_one(1, "2,3")
// "2,3"
// >>> compare_one("5,1", "6")
// "6"
// >>> compare_one("1", 1)
// null
function compare_one($a, $b) {

function candidate(...$args) {
    return compare_one(...$args);
}

function test(): void {
    if (candidate(1, 2) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(1, 2.5) !== 2.5) { throw new Exception("Test failed!"); }
    if (candidate(2, 3) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(5, 6) !== 6) { throw new Exception("Test failed!"); }
    if (candidate(1, "2,3") !== "2,3") { throw new Exception("Test failed!"); }
    if (candidate("5,1", "6") !== "6") { throw new Exception("Test failed!"); }
    if (candidate("1", "2") !== "2") { throw new Exception("Test failed!"); }
    if (candidate("1", 1) !== null) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// remove_vowels is a function that takes string and returns string without vowels.
// >>> remove_vowels("")
// ""
// >>> remove_vowels("abcdef")
// "bcdf"
// >>> remove_vowels("aaaaa")
// ""
// >>> remove_vowels("aaBAA")
// "B"
// >>> remove_vowels("zbcd")
// "zbcd"
function remove_vowels($text) {

function candidate(...$args) {
    return remove_vowels(...$args);
}

function test(): void {
    if (candidate("") !== "") { throw new Exception("Test failed!"); }
    if (candidate("abcdef\nghijklm") !== "bcdf\nghjklm") { throw new Exception("Test failed!"); }
    if (candidate("fedcba") !== "fdcb") { throw new Exception("Test failed!"); }
    if (candidate("eeeee") !== "") { throw new Exception("Test failed!"); }
    if (candidate("acBAA") !== "cB") { throw new Exception("Test failed!"); }
    if (candidate("EcBOO") !== "cB") { throw new Exception("Test failed!"); }
    if (candidate("ybcd") !== "ybcd") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given array of integers, return array 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(array(1, 2, 3, 4))
// array(1, 4, 2, 3)
// >>> strange_sort_list(array(5, 5, 5, 5))
// array(5, 5, 5, 5)
// >>> strange_sort_list(array())
// array()
function strange_sort_list($lst) {

function candidate(...$args) {
    return strange_sort_list(...$args);
}

function test(): void {
    if (candidate(array(1, 2, 3, 4)) !== array(1, 4, 2, 3)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 6, 7, 8, 9)) !== array(5, 9, 6, 8, 7)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4, 5)) !== array(1, 5, 2, 4, 3)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 6, 7, 8, 9, 1)) !== array(1, 9, 5, 8, 6, 7)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 5, 5, 5)) !== array(5, 5, 5, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4, 5, 6, 7, 8)) !== array(1, 8, 2, 7, 3, 6, 4, 5)) { throw new Exception("Test failed!"); }
    if (candidate(array(0, 2, 2, 2, 5, 5, -5, -5)) !== array(-5, 5, -5, 5, 0, 2, 2, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(111111)) !== array(111111)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// From a supplied array 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(array(1.0, 2.0, 3.0, 4.0, 5.0, 2.2))
// array(2.0, 2.2)
// >>> find_closest_elements(array(1.0, 2.0, 3.0, 4.0, 5.0, 2.0))
// array(2.0, 2.0)
function find_closest_elements($numbers) {

function candidate(...$args) {
    return find_closest_elements(...$args);
}

function test(): void {
    if (candidate(array(1.0, 2.0, 3.9, 4.0, 5.0, 2.2)) !== array(3.9, 4.0)) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 5.9, 4.0, 5.0)) !== array(5.0, 5.9)) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 3.0, 4.0, 5.0, 2.2)) !== array(2.0, 2.2)) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 3.0, 4.0, 5.0, 2.0)) !== array(2.0, 2.0)) { throw new Exception("Test failed!"); }
    if (candidate(array(1.1, 2.2, 3.1, 4.1, 5.1)) !== array(2.2, 3.1)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Your task is to write a function that returns true if a number x is a simple
// power of n and false in other cases.
// x is a simple power of n if n**int=x
// For example:
// >>> is_simple_power(1, 4)
// true
// >>> is_simple_power(2, 2)
// true
// >>> is_simple_power(8, 2)
// true
// >>> is_simple_power(3, 2)
// false
// >>> is_simple_power(3, 1)
// false
// >>> is_simple_power(5, 3)
// false
function is_simple_power($x, $n) {

function candidate(...$args) {
    return is_simple_power(...$args);
}

function test(): void {
    if (candidate(16, 2) !== true) { throw new Exception("Test failed!"); }
    if (candidate(143214, 16) !== false) { throw new Exception("Test failed!"); }
    if (candidate(4, 2) !== true) { throw new Exception("Test failed!"); }
    if (candidate(9, 3) !== true) { throw new Exception("Test failed!"); }
    if (candidate(16, 4) !== true) { throw new Exception("Test failed!"); }
    if (candidate(24, 2) !== false) { throw new Exception("Test failed!"); }
    if (candidate(128, 4) !== false) { throw new Exception("Test failed!"); }
    if (candidate(12, 6) !== false) { throw new Exception("Test failed!"); }
    if (candidate(1, 1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(1, 12) !== true) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// prime_fib returns n-th number that is a Fibonacci number and it's also prime.
// >>> prime_fib(1)
// 2
// >>> prime_fib(2)
// 3
// >>> prime_fib(3)
// 5
// >>> prime_fib(4)
// 13
// >>> prime_fib(5)
// 89
function prime_fib($n) {

function candidate(...$args) {
    return prime_fib(...$args);
}

function test(): void {
    if (candidate(1) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(2) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(3) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(4) !== 13) { throw new Exception("Test failed!"); }
    if (candidate(5) !== 89) { throw new Exception("Test failed!"); }
    if (candidate(6) !== 233) { throw new Exception("Test failed!"); }
    if (candidate(7) !== 1597) { throw new Exception("Test failed!"); }
    if (candidate(8) !== 28657) { throw new Exception("Test failed!"); }
    if (candidate(9) !== 514229) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 433494437) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Write a function which sorts the given array of integers
// in ascending order according to the sum of their digits.
// Note: if there are several items with similar sum of their digits,
// order them based on their index in original array.
// For example:
// >>> order_by_points(array(1, 11, -1, -11, -12))
// array(-1, -11, 1, -12, 11)
// >>> order_by_points(array())
// array()
function order_by_points($nums) {


Prompt:
<?php
// Check if in given array of numbers, are any two numbers closer to each other than
// given threshold.
// >>> has_close_elements(array(1.0, 2.0, 3.0), 0.5)
// false
// >>> has_close_elements(array(1.0, 2.8, 3.0, 4.0, 5.0, 2.0), 0.3)
// true
function has_close_elements($numbers, $threshold) {

function candidate(...$args) {
    return has_close_elements(...$args);
}

function test(): void {
    if (candidate(array(1.0, 2.0, 3.9, 4.0, 5.0, 2.2), 0.3) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 3.9, 4.0, 5.0, 2.2), 0.05) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 5.9, 4.0, 5.0), 0.95) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 5.9, 4.0, 5.0), 0.8) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 3.0, 4.0, 5.0, 2.0), 0.1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1.1, 2.2, 3.1, 4.1, 5.1), 1.0) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1.1, 2.2, 3.1, 4.1, 5.1), 0.5) !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Find the shortest palindrome that begins with a supplied string.
// Algorithm idea is simple:
// - Find the longest postfix of supplied string that is a palindrome.
// - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
// >>> make_palindrome("")
// ""
// >>> make_palindrome("cat")
// "catac"
// >>> make_palindrome("cata")
// "catac"
function make_palindrome($string) {

function candidate(...$args) {
    return make_palindrome(...$args);
}

function test(): void {
    if (candidate("") !== "") { throw new Exception("Test failed!"); }
    if (candidate("x") !== "x") { throw new Exception("Test failed!"); }
    if (candidate("xyz") !== "xyzyx") { throw new Exception("Test failed!"); }
    if (candidate("xyx") !== "xyx") { throw new Exception("Test failed!"); }
    if (candidate("jerry") !== "jerryrrej") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Input are two strings a and b consisting only of 1s and 0s.
// Perform binary XOR on these inputs and return result also as a string.
// >>> string_xor("010", "110")
// "100"
function string_xor($a, $b) {

function candidate(...$args) {
    return string_xor(...$args);
}

function test(): void {
    if (candidate("111000", "101010") !== "010010") { throw new Exception("Test failed!"); }
    if (candidate("1", "1") !== "0") { throw new Exception("Test failed!"); }
    if (candidate("0101", "0000") !== "0101") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// The Brazilian factorial is defined as:
// brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1!
// where n > 0
// For example:
// >>> special_factorial(4)
// 288
// The function will receive an integer as input and should return the special
// factorial of this integer.
function special_factorial($n) {

function candidate(...$args) {
    return special_factorial(...$args);
}

function test(): void {
    if (candidate(4) !== 288) { throw new Exception("Test failed!"); }
    if (candidate(5) !== 34560) { throw new Exception("Test failed!"); }
    if (candidate(7) !== 125411328000) { throw new Exception("Test failed!"); }
    if (candidate(1) !== 1) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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:
// >>> add_elements(array(111, 21, 3, 4000, 5, 6, 7, 8, 9), 4)
// 24
// Constraints:
// 1. 1 <= len(arr) <= 100
// 2. 1 <= k <= len(arr)
function add_elements($arr, $k) {

function candidate(...$args) {
    return add_elements(...$args);
}

function test(): void {
    if (candidate(array(1, -2, -3, 41, 57, 76, 87, 88, 99), 3) !== -4) { throw new Exception("Test failed!"); }
    if (candidate(array(111, 121, 3, 4000, 5, 6), 2) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(11, 21, 3, 90, 5, 6, 7, 8, 9), 4) !== 125) { throw new Exception("Test failed!"); }
    if (candidate(array(111, 21, 3, 4000, 5, 6, 7, 8, 9), 4) !== 24) { throw new Exception("Test failed!"); }
    if (candidate(array(1), 1) !== 1) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
// fib4(0) -> 0
// fib4(1) -> 0
// fib4(2) -> 2
// fib4(3) -> 0
// fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
// Please write a function to efficiently compute the n-th element of the fib4 number sequence.  Do not use recursion.
// >>> fib4(5)
// 4
// >>> fib4(6)
// 8
// >>> fib4(7)
// 14
function fib4($n) {

function candidate(...$args) {
    return fib4(...$args);
}

function test(): void {
    if (candidate(5) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(8) !== 28) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 104) { throw new Exception("Test failed!"); }
    if (candidate(12) !== 386) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an array of positive integers x. return a sorted array of all
// elements that hasn't any even digit.
// Note: Returned array should be sorted in increasing order.
// For example:
// >>> unique_digits(array(15, 33, 1422, 1))
// array(1, 15, 33)
// >>> unique_digits(array(152, 323, 1422, 10))
// array()
function unique_digits($x) {

function candidate(...$args) {
    return unique_digits(...$args);
}

function test(): void {
    if (candidate(array(15, 33, 1422, 1)) !== array(1, 15, 33)) { throw new Exception("Test failed!"); }
    if (candidate(array(152, 323, 1422, 10)) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(12345, 2033, 111, 151)) !== array(111, 151)) { throw new Exception("Test failed!"); }
    if (candidate(array(135, 103, 31)) !== array(31, 135)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a string s and a natural number n, you have been tasked to implement
// a function that returns an array of all words from string s that contain exactly
// n consonants, in order these words appear in the string s.
// If the string s is empty then the function should return an empty array.
// Note: you may assume the input string contains only letters and spaces.
// Examples:
// >>> select_words("Mary had a little lamb", 4)
// array("little")
// >>> select_words("Mary had a little lamb", 3)
// array("Mary", "lamb")
// >>> select_words("simple white space", 2)
// array()
// >>> select_words("Hello world", 4)
// array("world")
// >>> select_words("Uncle sam", 3)
// array("Uncle")
function select_words($s, $n) {

function candidate(...$args) {
    return select_words(...$args);
}

function test(): void {
    if (candidate("Mary had a little lamb", 4) !== array("little")) { throw new Exception("Test failed!"); }
    if (candidate("Mary had a little lamb", 3) !== array("Mary", "lamb")) { throw new Exception("Test failed!"); }
    if (candidate("simple white space", 2) !== array()) { throw new Exception("Test failed!"); }
    if (candidate("Hello world", 4) !== array("world")) { throw new Exception("Test failed!"); }
    if (candidate("Uncle sam", 3) !== array("Uncle")) { throw new Exception("Test failed!"); }
    if (candidate("", 4) !== array()) { throw new Exception("Test failed!"); }
    if (candidate("a b c d e f", 1) !== array("b", "c", "d", "f")) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Write a function that returns true if the object q will fly, and false otherwise.
// The object q will fly if it's balanced (it is a palindromic array) and the sum of its elements is less than or equal the maximum possible weight w.
// Example:
// >>> will_it_fly(array(1, 2), 5)
// false
// # 1+2 is less than the maximum possible weight, but it's unbalanced.
// >>> will_it_fly(array(3, 2, 3), 1)
// false
// # it's balanced, but 3+2+3 is more than the maximum possible weight.
// >>> will_it_fly(array(3, 2, 3), 9)
// true
// # 3+2+3 is less than the maximum possible weight, and it's balanced.
// >>> will_it_fly(array(3), 5)
// true
// # 3 is less than the maximum possible weight, and it's balanced.
function will_it_fly($q, $w) {

function candidate(...$args) {
    return will_it_fly(...$args);
}

function test(): void {
    if (candidate(array(3, 2, 3), 9) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2), 5) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(3), 5) !== true) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 3), 1) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3), 6) !== false) { throw new Exception("Test failed!"); }
    if (candidate(array(5), 5) !== true) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return n-th Fibonacci number.
// >>> fib(10)
// 55
// >>> fib(1)
// 1
// >>> fib(8)
// 21
function fib($n) {

function candidate(...$args) {
    return fib(...$args);
}

function test(): void {
    if (candidate(10) !== 55) { throw new Exception("Test failed!"); }
    if (candidate(1) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(8) !== 21) { throw new Exception("Test failed!"); }
    if (candidate(11) !== 89) { throw new Exception("Test failed!"); }
    if (candidate(12) !== 144) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You will be given the name of a class (a string) and an array 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 array.
// For example, if you are given "Slices" as the class and an array of the
// extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should
// return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension
// (its strength is -1).
// Example:
// >>> Strongest_Extension("my_class", array("AA", "Be", "CC"))
// "my_class.AA"
function Strongest_Extension($class_name, $extensions) {

function candidate(...$args) {
    return Strongest_Extension(...$args);
}

function test(): void {
    if (candidate("Watashi", array("tEN", "niNE", "eIGHt8OKe")) !== "Watashi.eIGHt8OKe") { throw new Exception("Test failed!"); }
    if (candidate("Boku123", array("nani", "NazeDa", "YEs.WeCaNe", "32145tggg")) !== "Boku123.YEs.WeCaNe") { throw new Exception("Test failed!"); }
    if (candidate("__YESIMHERE", array("t", "eMptY", "nothing", "zeR00", "NuLl__", "123NoooneB321")) !== "__YESIMHERE.NuLl__") { throw new Exception("Test failed!"); }
    if (candidate("K", array("Ta", "TAR", "t234An", "cosSo")) !== "K.TAR") { throw new Exception("Test failed!"); }
    if (candidate("__HAHA", array("Tab", "123", "781345", "-_-")) !== "__HAHA.123") { throw new Exception("Test failed!"); }
    if (candidate("YameRore", array("HhAas", "okIWILL123", "WorkOut", "Fails", "-_-")) !== "YameRore.okIWILL123") { throw new Exception("Test failed!"); }
    if (candidate("finNNalLLly", array("Die", "NowW", "Wow", "WoW")) !== "finNNalLLly.WoW") { throw new Exception("Test failed!"); }
    if (candidate("_", array("Bb", "91245")) !== "_.Bb") { throw new Exception("Test failed!"); }
    if (candidate("Sp", array("671235", "Bb")) !== "Sp.671235") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You are given an array of two strings, both strings consist of open
// parentheses '(' or close parentheses ')' only.
// Your job is to check if it is possible to concatenate the two strings in
// some order, that the resulting string will be good.
// A string S is considered to be good if and only if all parentheses in S
// are balanced. For example: the string '(())()' is good, while the string
// '())' is not.
// Return 'Yes' if there's a way to make a good string, and return 'No' otherwise.
// Examples:
// >>> match_parens(array("()(", ")"))
// "Yes"
// >>> match_parens(array(")", ")"))
// "No"
function match_parens($lst) {

function candidate(...$args) {
    return match_parens(...$args);
}

function test(): void {
    if (candidate(array("()(", ")")) !== "Yes") { throw new Exception("Test failed!"); }
    if (candidate(array(")", ")")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array("(()(())", "())())")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array(")())", "(()()(")) !== "Yes") { throw new Exception("Test failed!"); }
    if (candidate(array("(())))", "(()())((")) !== "Yes") { throw new Exception("Test failed!"); }
    if (candidate(array("()", "())")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array("(()(", "()))()")) !== "Yes") { throw new Exception("Test failed!"); }
    if (candidate(array("((((", "((())")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array(")(()", "(()(")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array(")(", ")(")) !== "No") { throw new Exception("Test failed!"); }
    if (candidate(array("(", ")")) !== "Yes") { throw new Exception("Test failed!"); }
    if (candidate(array(")", "(")) !== "Yes") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You are given an array of integers.
// Write a function next_smallest() that returns the 2nd smallest element of the array.
// Return null if there is no such element.
// >>> next_smallest(array(1, 2, 3, 4, 5))
// 2
// >>> next_smallest(array(5, 1, 4, 3, 2))
// 2
// >>> next_smallest(array())
// null
// >>> next_smallest(array(1, 1))
// null
function next_smallest($lst) {

function candidate(...$args) {
    return next_smallest(...$args);
}

function test(): void {
    if (candidate(array(1, 2, 3, 4, 5)) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 1, 4, 3, 2)) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== null) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 1)) !== null) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 1, 1, 1, 0)) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 1)) !== null) { throw new Exception("Test failed!"); }
    if (candidate(array(-35, 34, 12, -45)) !== -35) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function any_int($x, $y, $z) {

function candidate(...$args) {
    return any_int(...$args);
}

function test(): void {
    if (candidate(2, 3, 1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(2.5, 2, 3) !== false) { throw new Exception("Test failed!"); }
    if (candidate(1.5, 5, 3.5) !== false) { throw new Exception("Test failed!"); }
    if (candidate(2, 6, 2) !== false) { throw new Exception("Test failed!"); }
    if (candidate(4, 2, 2) !== true) { throw new Exception("Test failed!"); }
    if (candidate(2.2, 2.2, 2.2) !== false) { throw new Exception("Test failed!"); }
    if (candidate(-4, 6, 2) !== true) { throw new Exception("Test failed!"); }
    if (candidate(2, 1, 1) !== true) { throw new Exception("Test failed!"); }
    if (candidate(3, 4, 7) !== true) { throw new Exception("Test failed!"); }
    if (candidate(3.0, 4, 7) !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a positive floating point number, it can be decomposed into
// and integer part (largest integer smaller than given number) and decimals
// (leftover part always smaller than 1).
// Return the decimal part of the number.
// >>> truncate_number(3.5)
// 0.5
function truncate_number($number) {

function candidate(...$args) {
    return truncate_number(...$args);
}

function test(): void {
    if (candidate(3.5) !== 0.5) { throw new Exception("Test failed!"); }
    if (candidate(1.25) !== 0.25) { throw new Exception("Test failed!"); }
    if (candidate(123.0) !== 0.0) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return array with elements incremented by 1.
// >>> incr_list(array(1, 2, 3))
// array(2, 3, 4)
// >>> incr_list(array(5, 3, 5, 2, 3, 3, 9, 0, 123))
// array(6, 4, 6, 3, 4, 4, 10, 1, 124)
function incr_list($l) {

function candidate(...$args) {
    return incr_list(...$args);
}

function test(): void {
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 1)) !== array(4, 3, 2)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 2, 5, 2, 3, 3, 9, 0, 123)) !== array(6, 3, 6, 3, 4, 4, 10, 1, 124)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// A simple program which should return the value of x if n is
// a prime number and should return the value of y otherwise.
// Examples:
// >>> x_or_y(7, 34, 12)
// 34
// >>> x_or_y(15, 8, 5)
// 5
function x_or_y($n, $x, $y) {

function candidate(...$args) {
    return x_or_y(...$args);
}

function test(): void {
    if (candidate(7, 34, 12) !== 34) { throw new Exception("Test failed!"); }
    if (candidate(15, 8, 5) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(3, 33, 5212) !== 33) { throw new Exception("Test failed!"); }
    if (candidate(1259, 3, 52) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(7919, -1, 12) !== -1) { throw new Exception("Test failed!"); }
    if (candidate(3609, 1245, 583) !== 583) { throw new Exception("Test failed!"); }
    if (candidate(91, 56, 129) !== 129) { throw new Exception("Test failed!"); }
    if (candidate(6, 34, 1234) !== 1234) { throw new Exception("Test failed!"); }
    if (candidate(1, 2, 0) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(2, 2, 0) !== 2) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return 2^n modulo p (be aware of numerics).
// >>> modp(3, 5)
// 3
// >>> modp(1101, 101)
// 2
// >>> modp(0, 101)
// 1
// >>> modp(3, 11)
// 8
// >>> modp(100, 101)
// 1
function modp($n, $p) {

function candidate(...$args) {
    return modp(...$args);
}

function test(): void {
    if (candidate(3, 5) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(1101, 101) !== 2) { throw new Exception("Test failed!"); }
    if (candidate(0, 101) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(3, 11) !== 8) { throw new Exception("Test failed!"); }
    if (candidate(100, 101) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(30, 5) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(31, 5) !== 3) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given an integer. return an array that has the number of even and odd digits respectively.
// Example:
// >>> even_odd_count(-12)
// array(1, 1)
// >>> even_odd_count(123)
// array(1, 2)
function even_odd_count($num) {

function candidate(...$args) {
    return even_odd_count(...$args);
}

function test(): void {
    if (candidate(7) !== array(0, 1)) { throw new Exception("Test failed!"); }
    if (candidate(-78) !== array(1, 1)) { throw new Exception("Test failed!"); }
    if (candidate(3452) !== array(2, 2)) { throw new Exception("Test failed!"); }
    if (candidate(346211) !== array(3, 3)) { throw new Exception("Test failed!"); }
    if (candidate(-345821) !== array(3, 3)) { throw new Exception("Test failed!"); }
    if (candidate(-2) !== array(1, 0)) { throw new Exception("Test failed!"); }
    if (candidate(-45347) !== array(2, 3)) { throw new Exception("Test failed!"); }
    if (candidate(0) !== array(1, 0)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You are given a string s.
// Your task is to check if the string is happhp or not.
// A string is happhp if its length is at least 3 and every 3 consecutive letters are distinct
// For example:
// >>> is_happy("a")
// false
// >>> is_happy("aa")
// false
// >>> is_happy("abcd")
// true
// >>> is_happy("aabb")
// false
// >>> is_happy("adb")
// true
// >>> is_happy("xyy")
// false
function is_happy($s) {

function candidate(...$args) {
    return is_happy(...$args);
}

function test(): void {
    if (candidate("a") !== false) { throw new Exception("Test failed!"); }
    if (candidate("aa") !== false) { throw new Exception("Test failed!"); }
    if (candidate("abcd") !== true) { throw new Exception("Test failed!"); }
    if (candidate("aabb") !== false) { throw new Exception("Test failed!"); }
    if (candidate("adb") !== true) { throw new Exception("Test failed!"); }
    if (candidate("xyy") !== false) { throw new Exception("Test failed!"); }
    if (candidate("iopaxpoi") !== true) { throw new Exception("Test failed!"); }
    if (candidate("iopaxioi") !== false) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return the largest prime factor of n. Assume n > 1 and is not a prime.
// >>> largest_prime_factor(13195)
// 29
// >>> largest_prime_factor(2048)
// 2
function largest_prime_factor($n) {

function candidate(...$args) {
    return largest_prime_factor(...$args);
}

function test(): void {
    if (candidate(15) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(27) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(63) !== 7) { throw new Exception("Test failed!"); }
    if (candidate(330) !== 11) { throw new Exception("Test failed!"); }
    if (candidate(13195) !== 29) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Task
// Write a function that takes a string as input and returns the sum of the upper characters only'
// ASCII codes.
// Examples:
// >>> digitSum("")
// 0
// >>> digitSum("abAB")
// 131
// >>> digitSum("abcCd")
// 67
// >>> digitSum("helloE")
// 69
// >>> digitSum("woArBld")
// 131
// >>> digitSum("aAaaaXa")
// 153
function digitSum($s) {

function candidate(...$args) {
    return digitSum(...$args);
}

function test(): void {
    if (candidate("") !== 0) { throw new Exception("Test failed!"); }
    if (candidate("abAB") !== 131) { throw new Exception("Test failed!"); }
    if (candidate("abcCd") !== 67) { throw new Exception("Test failed!"); }
    if (candidate("helloE") !== 69) { throw new Exception("Test failed!"); }
    if (candidate("woArBld") !== 131) { throw new Exception("Test failed!"); }
    if (candidate("aAaaaXa") !== 153) { throw new Exception("Test failed!"); }
    if (candidate(" How are yOu?") !== 151) { throw new Exception("Test failed!"); }
    if (candidate("You arE Very Smart") !== 327) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given array of numbers (of at least two elements), apply a linear transform to that array,
// such that the smallest number will become 0 and the largest will become 1
// >>> rescale_to_unit(array(1.0, 2.0, 3.0, 4.0, 5.0))
// array(0.0, 0.25, 0.5, 0.75, 1.0)
function rescale_to_unit($numbers) {

function candidate(...$args) {
    return rescale_to_unit(...$args);
}

function test(): void {
    if (candidate(array(2.0, 49.9)) !== array(0.0, 1.0)) { throw new Exception("Test failed!"); }
    if (candidate(array(100.0, 49.9)) !== array(1.0, 0.0)) { throw new Exception("Test failed!"); }
    if (candidate(array(1.0, 2.0, 3.0, 4.0, 5.0)) !== array(0.0, 0.25, 0.5, 0.75, 1.0)) { throw new Exception("Test failed!"); }
    if (candidate(array(2.0, 1.0, 5.0, 3.0, 4.0)) !== array(0.25, 0.0, 1.0, 0.5, 0.75)) { throw new Exception("Test failed!"); }
    if (candidate(array(12.0, 11.0, 15.0, 13.0, 14.0)) !== array(0.25, 0.0, 1.0, 0.5, 0.75)) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Given a non-empty array of integers, return the sum of all of the odd elements that are in even positions.
// Examples
// >>> solution(array(5, 8, 7, 1))
// 12
// >>> solution(array(3, 3, 3, 3, 3))
// 9
// >>> solution(array(30, 13, 24, 321))
// 0
function solution($lst) {

function candidate(...$args) {
    return solution(...$args);
}

function test(): void {
    if (candidate(array(5, 8, 7, 1)) !== 12) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 3, 3, 3, 3)) !== 9) { throw new Exception("Test failed!"); }
    if (candidate(array(30, 13, 24, 321)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 9)) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(array(2, 4, 8)) !== 0) { throw new Exception("Test failed!"); }
    if (candidate(array(30, 13, 23, 32)) !== 23) { throw new Exception("Test failed!"); }
    if (candidate(array(3, 13, 2, 9)) !== 3) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// "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 an array, [ smalest_value, its index ],
// If there are no even values or the given array is empty, return [].
// Example 1:
// >>> pluck(array(4, 2, 3))
// array(2, 1)
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 2:
// >>> pluck(array(1, 2, 3))
// array(2, 1)
// Explanation: 2 has the smallest even value, and 2 has the smallest index.
// Example 3:
// >>> pluck(array())
// array()
// Example 4:
// >>> pluck(array(5, 0, 3, 0, 4, 2))
// array(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
function pluck($arr) {

function candidate(...$args) {
    return pluck(...$args);
}

function test(): void {
    if (candidate(array(4, 2, 3)) !== array(2, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3)) !== array(2, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array()) !== array()) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 0, 3, 0, 4, 2)) !== array(0, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 0, 5, 3)) !== array(0, 3)) { throw new Exception("Test failed!"); }
    if (candidate(array(5, 4, 8, 4, 8)) !== array(4, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(7, 6, 7, 1)) !== array(6, 1)) { throw new Exception("Test failed!"); }
    if (candidate(array(7, 9, 7, 1)) !== array()) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// You are given a positive integer n. You have to create an integer array a of length n.
// For each i (1 ≤ i ≤ n), the value of a[i] = i * i - i + 1.
// Return the number of triples (a[i], a[j], a[k]) of a where i < j < k,
// and a[i] + a[j] + a[k] is a multiple of 3.
// Example :
// >>> get_max_triples(5)
// 1
// Explanation:
// a = [1, 3, 7, 13, 21]
// The only valid triple is (1, 7, 13).
function get_max_triples($n) {

function candidate(...$args) {
    return get_max_triples(...$args);
}

function test(): void {
    if (candidate(5) !== 1) { throw new Exception("Test failed!"); }
    if (candidate(6) !== 4) { throw new Exception("Test failed!"); }
    if (candidate(10) !== 36) { throw new Exception("Test failed!"); }
    if (candidate(100) !== 53361) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// In this problem, you will implement a function that takes two arrays of numbers,
// and determines whether it is possible to perform an exchange of elements
// between them to make lst1 an array of only even numbers.
// There is no limit on the number of exchanged elements between lst1 and lst2.
// If it is possible to exchange elements between the lst1 and lst2 to make
// all the elements of lst1 to be even, return "YES".
// Otherwise, return "NO".
// For example:
// >>> exchange(array(1, 2, 3, 4), array(1, 2, 3, 4))
// "YES"
// >>> exchange(array(1, 2, 3, 4), array(1, 5, 3, 4))
// "NO"
// It is assumed that the input arrays will be non-empty.
function exchange($lst1, $lst2) {

function candidate(...$args) {
    return exchange(...$args);
}

function test(): void {
    if (candidate(array(1, 2, 3, 4), array(1, 2, 3, 4)) !== "YES") { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4), array(1, 5, 3, 4)) !== "NO") { throw new Exception("Test failed!"); }
    if (candidate(array(1, 2, 3, 4), array(2, 1, 4, 3)) !== "YES") { throw new Exception("Test failed!"); }
    if (candidate(array(5, 7, 3), array(2, 6, 4)) !== "YES") { throw new Exception("Test failed!"); }
    if (candidate(array(5, 7, 3), array(2, 6, 3)) !== "NO") { throw new Exception("Test failed!"); }
    if (candidate(array(3, 2, 6, 1, 8, 9), array(3, 5, 5, 1, 1, 1)) !== "NO") { throw new Exception("Test failed!"); }
    if (candidate(array(100, 200), array(200, 200)) !== "YES") { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// Return median of elements in the array l.
// >>> median(array(3, 1, 2, 4, 5))
// 3
// >>> median(array(-10, 4, 6, 1000, 10, 20))
// 15.0
function median($l) {

function candidate(...$args) {
    return median(...$args);
}

function test(): void {
    if (candidate(array(3, 1, 2, 4, 5)) !== 3) { throw new Exception("Test failed!"); }
    if (candidate(array(-10, 4, 6, 1000, 10, 20)) !== 8.0) { throw new Exception("Test failed!"); }
    if (candidate(array(5)) !== 5) { throw new Exception("Test failed!"); }
    if (candidate(array(6, 5)) !== 5.5) { throw new Exception("Test failed!"); }
    if (candidate(array(8, 1, 3, 9, 9, 2, 7)) !== 7) { throw new Exception("Test failed!"); }
}

test();


Prompt:
<?php
// 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
function prime_length($string) {

function candidate(...$args) {
    return prime_length(...$args);
}

function test(): void {
    if (candidate("Hello") !== true) { throw new Exception("Test failed!"); }
    if (candidate("abcdcba") !== true) { throw new Exception("Test failed!"); }
    if (candidate("kittens") !== true) { throw new Exception("Test failed!"); }
    if (candidate("orange") !== false) { throw new Exception("Test failed!"); }
    if (candidate("wow") !== true) { throw new Exception("Test failed!"); }
    if (candidate("world") !== true) { throw new Exception("Test failed!"); }
    if (candidate("MadaM") !== true) { throw new Exception("Test failed!"); }
    if (candidate("Wow") !== true) { throw new Exception("Test failed!"); }
    if (candidate("") !== false) { throw new Exception("Test failed!"); }
    if (candidate("HI") !== true) { throw new Exception("Test failed!"); }
    if (candidate("go") !== true) { throw new Exception("Test failed!"); }
    if (candidate("gogo") !== false) { throw new Exception("Test failed!"); }
    if (candidate("aaaaaaaaaaaaaaa") !== false) { throw new Exception("Test failed!"); }
    if (candidate("Madam") !== true) { throw new Exception("Test failed!"); }
    if (candidate("M") !== false) { throw new Exception("Test failed!"); }
    if (candidate("0") !== false) { throw new Exception("Test failed!"); }
}

test();