Prompt:
import std.typecons;
import std.math;
/*

    You are given an array arr of integers and you need to return
    sum of magnitudes of integers multiplied by product of all signs
    of each number in the array, represented by 1, -1 or 0.
    Note: return null for empty arr.

    Example:
    >>> prod_signs([1L, 2L, 2L, -4L])
    9L
    >>> prod_signs([0L, 1L])
    0L
    >>> prod_signs([])
    None

*/
Nullable!(long) prod_signs(long[] arr)

unittest
{
    alias candidate = prod_signs;

{
        auto result = candidate([1L, 2L, 2L, -4L]);
        assert(!result.isNull && result.get == -9L);
}

{
        auto result = candidate([0L, 1L]);
        assert(!result.isNull && result.get == 0L);
}

{
        auto result = candidate([1L, 1L, 1L, 2L, 3L, -1L, 1L]);
        assert(!result.isNull && result.get == -10L);
}

{
        auto result = candidate([]);
        assert(result.isNull);
}

{
        auto result = candidate([2L, 4L, 1L, 2L, -1L, -1L, 9L]);
        assert(!result.isNull && result.get == 20L);
}

{
        auto result = candidate([-1L, 1L, -1L, 1L]);
        assert(!result.isNull && result.get == 4L);
}

{
        auto result = candidate([-1L, 1L, 1L, 1L]);
        assert(!result.isNull && result.get == -4L);
}

{
        auto result = candidate([-1L, 1L, 1L, 0L]);
        assert(!result.isNull && result.get == 0L);
}

}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    Given an array of integers nums, find the minimum sum of any non-empty sub-array
    of nums.
    Example
    >>> minSubArraySum([2L, 3L, 4L, 1L, 2L, 4L])
    1L
    >>> minSubArraySum([-1L, -2L, -3L])
    -6L

*/
long minSubArraySum(long[] nums)


Prompt:
import std.typecons;
import std.math;
/*
 Return a string containing space-delimited numbers starting from 0 upto n inclusive.
    >>> string_sequence(0L)
    "0"
    >>> string_sequence(5L)
    "0 1 2 3 4 5"

*/
string string_sequence(long n)

unittest
{
    alias candidate = string_sequence;

    assert(candidate(0L) == "0");
    assert(candidate(3L) == "0 1 2 3");
    assert(candidate(10L) == "0 1 2 3 4 5 6 7 8 9 10");
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
You are given 2 words. You need to return true if the second word or any of its rotations is a substring in the first word
    >>> cycpattern_check("abcd", "abd")
    false
    >>> cycpattern_check("hello", "ell")
    true
    >>> cycpattern_check("whassup", "psus")
    false
    >>> cycpattern_check("abab", "baa")
    true
    >>> cycpattern_check("efef", "eeff")
    false
    >>> cycpattern_check("himenss", "simen")
    true

*/
bool cycpattern_check(string a, string b)

unittest
{
    alias candidate = cycpattern_check;

    assert(candidate("xyzw", "xyw") == false);
    assert(candidate("yello", "ell") == true);
    assert(candidate("whattup", "ptut") == false);
    assert(candidate("efef", "fee") == true);
    assert(candidate("abab", "aabb") == false);
    assert(candidate("winemtt", "tinem") == true);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Return true is array elements are monotonically increasing or decreasing.
    >>> monotonic([1L, 2L, 4L, 20L])
    true
    >>> monotonic([1L, 20L, 4L, 10L])
    false
    >>> monotonic([4L, 1L, 0L, -10L])
    true

*/
bool monotonic(long[] l)

unittest
{
    alias candidate = monotonic;

    assert(candidate([1L, 2L, 4L, 10L]) == true);
    assert(candidate([1L, 2L, 4L, 20L]) == true);
    assert(candidate([1L, 20L, 4L, 10L]) == false);
    assert(candidate([4L, 1L, 0L, -10L]) == true);
    assert(candidate([4L, 1L, 1L, 0L]) == true);
    assert(candidate([1L, 2L, 3L, 2L, 5L, 60L]) == false);
    assert(candidate([1L, 2L, 3L, 4L, 5L, 60L]) == true);
    assert(candidate([9L, 9L, 9L, 9L]) == true);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 Out of array of strings, return the longest one. Return the first one in case of multiple
    strings of the same length. Return null in case the input array is empty.
    >>> longest([])
    None
    >>> longest(["a", "b", "c"])
    "a"
    >>> longest(["a", "bb", "ccc"])
    "ccc"

*/
Nullable!(string) longest(string[] strings)

unittest
{
    alias candidate = longest;

{
        auto result = candidate([]);
        assert(result.isNull);
}

{
        auto result = candidate(["x", "y", "z"]);
        assert(!result.isNull && result.get == "x");
}

{
        auto result = candidate(["x", "yyy", "zzzz", "www", "kkkk", "abc"]);
        assert(!result.isNull && result.get == "zzzz");
}

}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Return true if all numbers in the array l are below threshold t.
    >>> below_threshold([1L, 2L, 4L, 10L], 100L)
    true
    >>> below_threshold([1L, 20L, 4L, 10L], 5L)
    false

*/
bool below_threshold(long[] l, long t)

unittest
{
    alias candidate = below_threshold;

    assert(candidate([1L, 2L, 4L, 10L], 100L) == true);
    assert(candidate([1L, 20L, 4L, 10L], 5L) == false);
    assert(candidate([1L, 20L, 4L, 10L], 21L) == true);
    assert(candidate([1L, 20L, 4L, 10L], 22L) == true);
    assert(candidate([1L, 8L, 4L, 10L], 11L) == true);
    assert(candidate([1L, 8L, 4L, 10L], 10L) == false);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Write a function that returns true if the given number is the multiplication of 3 prime numbers
    and false otherwise.
    Knowing that (a) is less then 100.
    Example:
    >>> is_multiply_prime(30L)
    true
    30 = 2 * 3 * 5

*/
bool is_multiply_prime(long a)

unittest
{
    alias candidate = is_multiply_prime;

    assert(candidate(5L) == false);
    assert(candidate(30L) == true);
    assert(candidate(8L) == true);
    assert(candidate(10L) == false);
    assert(candidate(125L) == true);
    assert(candidate(105L) == true);
    assert(candidate(126L) == false);
    assert(candidate(729L) == false);
    assert(candidate(891L) == false);
    assert(candidate(1001L) == true);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Return only positive numbers in the array.
    >>> get_positive([-1L, 2L, -4L, 5L, 6L])
    [2L, 5L, 6L]
    >>> get_positive([5L, 3L, -5L, 2L, -3L, 3L, 9L, 0L, 123L, 1L, -10L])
    [5L, 3L, 2L, 3L, 9L, 123L, 1L]

*/
long[] get_positive(long[] l)

unittest
{
    alias candidate = get_positive;

    assert(candidate([-1L, -2L, 4L, 5L, 6L]) == [4L, 5L, 6L]);
    assert(candidate([5L, 3L, -5L, 2L, 3L, 3L, 9L, 0L, 123L, 1L, -10L]) == [5L, 3L, 2L, 3L, 3L, 9L, 123L, 1L]);
    assert(candidate([-1L, -2L]) == []);
    assert(candidate([]) == []);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
This function takes an array l and returns an array l' such that
    l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
    to the values of the corresponding indicies of l, but sorted.
    >>> sort_third([1L, 2L, 3L])
    [1L, 2L, 3L]
    >>> sort_third([5L, 6L, 3L, 4L, 8L, 9L, 2L])
    [2L, 6L, 3L, 4L, 8L, 9L, 5L]

*/
long[] sort_third(long[] l)


Prompt:
import std.typecons;
import std.math;
/*
 Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens("(()()) ((())) () ((())()())")
    [2L, 3L, 1L, 3L]

*/
long[] parse_nested_parens(string paren_string)


Prompt:
import std.typecons;
import std.math;
/*
Given length of a side and high return area for a triangle.
    >>> triangle_area(5L, 3L)
    7.5

*/
float triangle_area(long a, long h)

unittest
{
    alias candidate = triangle_area;

    assert(candidate(5L, 3L) == 7.5);
    assert(candidate(2L, 2L) == 2.0);
    assert(candidate(10L, 8L) == 40.0);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Complete the function that takes two integers and returns
    the product of their unit digits.
    Assume the input is always valid.
    Examples:
    >>> multiply(148L, 412L)
    16L
    >>> multiply(19L, 28L)
    72L
    >>> multiply(2020L, 1851L)
    0L
    >>> multiply(14L, -15L)
    20L

*/
long multiply(long a, long b)

unittest
{
    alias candidate = multiply;

    assert(candidate(148L, 412L) == 16L);
    assert(candidate(19L, 28L) == 72L);
    assert(candidate(2020L, 1851L) == 0L);
    assert(candidate(14L, -15L) == 20L);
    assert(candidate(76L, 67L) == 42L);
    assert(candidate(17L, 27L) == 49L);
    assert(candidate(0L, 1L) == 0L);
    assert(candidate(0L, 0L) == 0L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 For a given array of input numbers, calculate Mean Absolute Deviation
    around the mean of this dataset.
    Mean Absolute Deviation is the average absolute difference between each
    element and a centerpoint (mean in this case):
    MAD = average | x - x_mean |
    >>> mean_absolute_deviation([1.0, 2.0, 3.0, 4.0])
    1.0

*/
float mean_absolute_deviation(float[] numbers)

unittest
{
    alias candidate = mean_absolute_deviation;

    assert(candidate([1.0, 2.0]) == 0.5);
    assert(candidate([1.0, 2.0, 3.0, 4.0]) == 1.0);
    assert(candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == 1.2);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Return sorted unique common elements for two arrays.
    >>> common([1L, 4L, 3L, 34L, 653L, 2L, 5L], [5L, 7L, 1L, 5L, 9L, 653L, 121L])
    [1L, 5L, 653L]
    >>> common([5L, 3L, 2L, 8L], [3L, 2L])
    [2L, 3L]

*/
long[] common(long[] l1, long[] l2)


Prompt:
import std.typecons;
import std.math;
/*

    Given a positive integer, obtain its roman numeral equivalent as a string,
    and return it in lowercase.
    Restrictions: 1 <= num <= 1000

    Examples:
    >>> int_to_mini_roman(19L)
    "xix"
    >>> int_to_mini_roman(152L)
    "clii"
    >>> int_to_mini_roman(426L)
    "cdxxvi"

*/
string int_to_mini_roman(long number)

unittest
{
    alias candidate = int_to_mini_roman;

    assert(candidate(19L) == "xix");
    assert(candidate(152L) == "clii");
    assert(candidate(251L) == "ccli");
    assert(candidate(426L) == "cdxxvi");
    assert(candidate(500L) == "d");
    assert(candidate(1L) == "i");
    assert(candidate(4L) == "iv");
    assert(candidate(43L) == "xliii");
    assert(candidate(90L) == "xc");
    assert(candidate(94L) == "xciv");
    assert(candidate(532L) == "dxxxii");
    assert(candidate(900L) == "cm");
    assert(candidate(994L) == "cmxciv");
    assert(candidate(1000L) == "m");
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    In this task, you will be given a string that represents a number of apples and oranges
    that are distributed in a basket of fruit this basket contains
    apples, oranges, and mango fruits. Given the string that represents the total number of
    the oranges and apples and an integer that represent the total number of the fruits
    in the basket return the number of the mango fruits in the basket.
    for examble:
    >>> fruit_distribution("5 apples and 6 oranges", 19L)
    8L
    >>> fruit_distribution("0 apples and 1 oranges", 3L)
    2L
    >>> fruit_distribution("2 apples and 3 oranges", 100L)
    95L
    >>> fruit_distribution("100 apples and 1 oranges", 120L)
    19L

*/
long fruit_distribution(string s, long n)

unittest
{
    alias candidate = fruit_distribution;

    assert(candidate("5 apples and 6 oranges", 19L) == 8L);
    assert(candidate("5 apples and 6 oranges", 21L) == 10L);
    assert(candidate("0 apples and 1 oranges", 3L) == 2L);
    assert(candidate("1 apples and 0 oranges", 3L) == 2L);
    assert(candidate("2 apples and 3 oranges", 100L) == 95L);
    assert(candidate("2 apples and 3 oranges", 5L) == 0L);
    assert(candidate("1 apples and 100 oranges", 120L) == 19L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Task
    We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c
    then check if the result string is palindrome.
    A string is called palindrome if it reads the same backward as forward.
    You should return a tuple containing the result string and true/false for the check.
    Example
    >>> reverse_delete("abcde", "ae")
    tuple("bcd", false)
    >>> reverse_delete("abcdef", "b")
    tuple("acdef", false)
    >>> reverse_delete("abcdedcba", "ab")
    tuple("cdedc", true)

*/
Tuple!(string, bool) reverse_delete(string s, string c)

unittest
{
    alias candidate = reverse_delete;

    assert(candidate("abcde", "ae") == tuple("bcd", false));
    assert(candidate("abcdef", "b") == tuple("acdef", false));
    assert(candidate("abcdedcba", "ab") == tuple("cdedc", true));
    assert(candidate("dwik", "w") == tuple("dik", false));
    assert(candidate("a", "a") == tuple("", true));
    assert(candidate("abcdedcba", "") == tuple("abcdedcba", true));
    assert(candidate("abcdedcba", "v") == tuple("abcdedcba", true));
    assert(candidate("vabba", "v") == tuple("abba", true));
    assert(candidate("mamma", "mia") == tuple("", true));
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 Return a greatest common divisor of two integers a and b
    >>> greatest_common_divisor(3L, 5L)
    1L
    >>> greatest_common_divisor(25L, 15L)
    5L

*/
long greatest_common_divisor(long a, long b)

unittest
{
    alias candidate = greatest_common_divisor;

    assert(candidate(3L, 7L) == 1L);
    assert(candidate(10L, 15L) == 5L);
    assert(candidate(49L, 14L) == 7L);
    assert(candidate(144L, 60L) == 12L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    In this Kata, you have to sort an array of non-negative integers according to
    number of ones in their binary representation in ascending order.
    For similar number of ones, sort based on decimal value.

    It must be implemented like this:
    >>> sort_array([1L, 5L, 2L, 3L, 4L])
    [1L, 2L, 3L, 4L, 5L]
    >>> sort_array([-2L, -3L, -4L, -5L, -6L])
    [-6L, -5L, -4L, -3L, -2L]
    >>> sort_array([1L, 0L, 2L, 3L, 4L])
    [0L, 1L, 2L, 3L, 4L]

*/
long[] sort_array(long[] arr)


Prompt:
import std.typecons;
import std.math;
/*
 Concatenate array of strings into a single string
    >>> concatenate([])
    ""
    >>> concatenate(["a", "b", "c"])
    "abc"

*/
string concatenate(string[] strings)

unittest
{
    alias candidate = concatenate;

    assert(candidate([]) == "");
    assert(candidate(["x", "y", "z"]) == "xyz");
    assert(candidate(["x", "y", "z", "w", "k"]) == "xyzwk");
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Write a function that accepts an array of strings as a parameter,
    deletes the strings that have odd lengths from it,
    and returns the resulted array with a sorted order,
    The array is always an array of strings and never an array of numbers,
    and it may contain duplicates.
    The order of the array should be ascending by length of each word, and you
    should return the array sorted by that rule.
    If two words have the same length, sort the array alphabetically.
    The function should return an array of strings in sorted order.
    You may assume that all words will have the same length.
    For example:
    >>> list_sort(["aa", "a", "aaa"])
    ["aa"]
    >>> list_sort(["ab", "a", "aaa", "cd"])
    ["ab", "cd"]

*/
string[] sorted_list_sum(string[] lst)

unittest
{
    alias candidate = sorted_list_sum;

    assert(candidate(["aa", "a", "aaa"]) == ["aa"]);
    assert(candidate(["school", "AI", "asdf", "b"]) == ["AI", "asdf", "school"]);
    assert(candidate(["d", "b", "c", "a"]) == []);
    assert(candidate(["d", "dcba", "abcd", "a"]) == ["abcd", "dcba"]);
    assert(candidate(["AI", "ai", "au"]) == ["AI", "ai", "au"]);
    assert(candidate(["a", "b", "b", "c", "c", "a"]) == []);
    assert(candidate(["aaaa", "bbbb", "dd", "cc"]) == ["cc", "dd", "aaaa", "bbbb"]);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 Filter an input array of strings only for ones that contain given substring
    >>> filter_by_substring([], "a")
    []
    >>> filter_by_substring(["abc", "bacd", "cde", "array"], "a")
    ["abc", "bacd", "array"]

*/
string[] filter_by_substring(string[] strings, string substring)

unittest
{
    alias candidate = filter_by_substring;

    assert(candidate([], "john") == []);
    assert(candidate(["xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"], "xxx") == ["xxx", "xxxAAA", "xxx"]);
    assert(candidate(["xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"], "xx") == ["xxx", "aaaxxy", "xxxAAA", "xxx"]);
    assert(candidate(["grunt", "trumpet", "prune", "gruesome"], "run") == ["grunt", "prune"]);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    Create a function that takes a value (string) representing a number
    and returns the closest integer to it. If the number is equidistant
    from two integers, round it away from zero.

    Examples
    >>> closest_integer("10")
    10L
    >>> closest_integer("15.3")
    15L

    Note:
    Rounding away from zero means that if the given number is equidistant
    from two integers, the one you should return is the one that is the
    farthest from zero. For example closest_integer("14.5") should
    return 15 and closest_integer("-14.5") should return -15.

*/
long closest_integer(string value)

unittest
{
    alias candidate = closest_integer;

    assert(candidate("10") == 10L);
    assert(candidate("14.5") == 15L);
    assert(candidate("-15.5") == -16L);
    assert(candidate("15.3") == 15L);
    assert(candidate("0") == 0L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Write a function vowels_count which takes a string representing
    a word as input and returns the number of vowels in the string.
    Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
    vowel, but only when it is at the end of the given word.

    Example:
    >>> vowels_count("abcde")
    2L
    >>> vowels_count("ACEDY")
    3L

*/
long vowels_count(string s)

unittest
{
    alias candidate = vowels_count;

    assert(candidate("abcde") == 2L);
    assert(candidate("Alone") == 3L);
    assert(candidate("key") == 2L);
    assert(candidate("bye") == 1L);
    assert(candidate("keY") == 2L);
    assert(candidate("bYe") == 1L);
    assert(candidate("ACEDY") == 3L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Write a function that accepts an array of strings.
    The array contains different words. Return the word with maximum number
    of unique characters. If multiple strings have maximum number of unique
    characters, return the one which comes first in lexicographical order.

    >>> find_max(["name", "of", "string"])
    "string"
    >>> find_max(["name", "enam", "game"])
    "enam"
    >>> find_max(["aaaaaaa", "bb", "cc"])
    "aaaaaaa"

*/
string find_max(string[] words)

unittest
{
    alias candidate = find_max;

    assert(candidate(["name", "of", "string"]) == "string");
    assert(candidate(["name", "enam", "game"]) == "enam");
    assert(candidate(["aaaaaaa", "bb", "cc"]) == "aaaaaaa");
    assert(candidate(["abc", "cba"]) == "abc");
    assert(candidate(["play", "this", "game", "of", "footbott"]) == "footbott");
    assert(candidate(["we", "are", "gonna", "rock"]) == "gonna");
    assert(candidate(["we", "are", "a", "mad", "nation"]) == "nation");
    assert(candidate(["this", "is", "a", "prrk"]) == "this");
    assert(candidate(["b"]) == "b");
    assert(candidate(["play", "play", "play"]) == "play");
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    Given a string 'text', return its md5 hash equivalent string.
    If 'text' is an empty string, return null.

    >>> string_to_md5("Hello world")
    "3e25960a79dbc69b674cd4ec67a72c62"

*/
Nullable!(string) string_to_md5(string text)

unittest
{
    alias candidate = string_to_md5;

{
        auto result = candidate("Hello world");
        assert(!result.isNull && result.get == "3e25960a79dbc69b674cd4ec67a72c62");
}

{
        auto result = candidate("");
        assert(result.isNull);
}

{
        auto result = candidate("A B C");
        assert(!result.isNull && result.get == "0ef78513b0cb8cef12743f5aeb35f888");
}

{
        auto result = candidate("password");
        assert(!result.isNull && result.get == "5f4dcc3b5aa765d61d8327deb882cf99");
}

}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Change numerical base of input number x to base.
    return string representation after the conversion.
    base numbers are less than 10.
    >>> change_base(8L, 3L)
    "22"
    >>> change_base(8L, 2L)
    "1000"
    >>> change_base(7L, 2L)
    "111"

*/
string change_base(long x, long base)

unittest
{
    alias candidate = change_base;

    assert(candidate(8L, 3L) == "22");
    assert(candidate(9L, 3L) == "100");
    assert(candidate(234L, 2L) == "11101010");
    assert(candidate(16L, 2L) == "10000");
    assert(candidate(8L, 2L) == "1000");
    assert(candidate(7L, 2L) == "111");
    assert(candidate(2L, 3L) == "2");
    assert(candidate(3L, 4L) == "3");
    assert(candidate(4L, 5L) == "4");
    assert(candidate(5L, 6L) == "5");
    assert(candidate(6L, 7L) == "6");
    assert(candidate(7L, 8L) == "7");
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    Given the lengths of the three sides of a triangle. Return true if the three
    sides form a right-angled triangle, false otherwise.
    A right-angled triangle is a triangle in which one angle is right angle or
    90 degree.
    Example:
    >>> right_angle_triangle(3L, 4L, 5L)
    true
    >>> right_angle_triangle(1L, 2L, 3L)
    false

*/
bool right_angle_triangle(long a, long b, long c)

unittest
{
    alias candidate = right_angle_triangle;

    assert(candidate(3L, 4L, 5L) == true);
    assert(candidate(1L, 2L, 3L) == false);
    assert(candidate(10L, 6L, 8L) == true);
    assert(candidate(2L, 2L, 2L) == false);
    assert(candidate(7L, 24L, 25L) == true);
    assert(candidate(10L, 5L, 7L) == false);
    assert(candidate(5L, 12L, 13L) == true);
    assert(candidate(15L, 8L, 17L) == true);
    assert(candidate(48L, 55L, 73L) == true);
    assert(candidate(1L, 1L, 1L) == false);
    assert(candidate(2L, 2L, 10L) == false);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
It is the last week of the semester and the teacher has to give the grades
    to students. The teacher has been making her own algorithm for grading.
    The only problem is, she has lost the code she used for grading.
    She has given you an array of GPAs for some students and you have to write
    a function that can output an array of letter grades using the following table:
             GPA       |    Letter grade
              4.0                A+
            > 3.7                A
            > 3.3                A-
            > 3.0                B+
            > 2.7                B
            > 2.3                B-
            > 2.0                C+
            > 1.7                C
            > 1.3                C-
            > 1.0                D+
            > 0.7                D
            > 0.0                D-
              0.0                E

    Example:
    >>> grade_equation([4.0, 3L, 1.7, 2L, 3.5])
    ["A+", "B", "C-", "C", "A-"]

*/
string[] numerical_letter_grade(float[] grades)


Prompt:
import std.typecons;
import std.math;
/*
 Insert a number 'delimeter' between every two consecutive elements of input array `numbers'
    >>> intersperse([], 4L)
    []
    >>> intersperse([1L, 2L, 3L], 4L)
    [1L, 4L, 2L, 4L, 3L]

*/
long[] intersperse(long[] numbers, long delimeter)

unittest
{
    alias candidate = intersperse;

    assert(candidate([], 7L) == []);
    assert(candidate([5L, 6L, 3L, 2L], 8L) == [5L, 8L, 6L, 8L, 3L, 8L, 2L]);
    assert(candidate([2L, 2L, 2L], 2L) == [2L, 2L, 2L, 2L, 2L]);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
Write a function that takes an array of numbers as input and returns
    the number of elements in the array that are greater than 10 and both
    first and last digits of a number are odd (1, 3, 5, 7, 9).
    For example:
    >>> specialFilter([15L, -73L, 14L, -15L])
    1L
    >>> specialFilter([33L, -2L, -3L, 45L, 21L, 109L])
    2L

*/
long specialFilter(long[] nums)

unittest
{
    alias candidate = specialFilter;

    assert(candidate([5L, -2L, 1L, -5L]) == 0L);
    assert(candidate([15L, -73L, 14L, -15L]) == 1L);
    assert(candidate([33L, -2L, -3L, 45L, 21L, 109L]) == 2L);
    assert(candidate([43L, -12L, 93L, 125L, 121L, 109L]) == 4L);
    assert(candidate([71L, -2L, -33L, 75L, 21L, 19L]) == 3L);
    assert(candidate([1L]) == 0L);
    assert(candidate([]) == 0L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
sum_to_n is a function that sums numbers from 1 to n.
    >>> sum_to_n(30L)
    465L
    >>> sum_to_n(100L)
    5050L
    >>> sum_to_n(5L)
    15L
    >>> sum_to_n(10L)
    55L
    >>> sum_to_n(1L)
    1L

*/
long sum_to_n(long n)

unittest
{
    alias candidate = sum_to_n;

    assert(candidate(1L) == 1L);
    assert(candidate(6L) == 21L);
    assert(candidate(11L) == 66L);
    assert(candidate(30L) == 465L);
    assert(candidate(100L) == 5050L);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 From an array of integers, remove all elements that occur more than once.
    Keep order of elements left the same as in the input.
    >>> remove_duplicates([1L, 2L, 3L, 2L, 4L])
    [1L, 3L, 4L]

*/
long[] remove_duplicates(long[] numbers)

unittest
{
    alias candidate = remove_duplicates;

    assert(candidate([]) == []);
    assert(candidate([1L, 2L, 3L, 4L]) == [1L, 2L, 3L, 4L]);
    assert(candidate([1L, 2L, 3L, 2L, 4L, 3L, 5L]) == [1L, 4L, 5L]);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    Given two positive integers a and b, return the even digits between a
    and b, in ascending order.

    For example:
    >>> generate_integers(2L, 8L)
    [2L, 4L, 6L, 8L]
    >>> generate_integers(8L, 2L)
    [2L, 4L, 6L, 8L]
    >>> generate_integers(10L, 14L)
    []

*/
long[] generate_integers(long a, long b)

unittest
{
    alias candidate = generate_integers;

    assert(candidate(2L, 10L) == [2L, 4L, 6L, 8L]);
    assert(candidate(10L, 2L) == [2L, 4L, 6L, 8L]);
    assert(candidate(132L, 2L) == [2L, 4L, 6L, 8L]);
    assert(candidate(17L, 89L) == []);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 From a given array of integers, generate an array of rolling maximum element found until given moment
    in the sequence.
    >>> rolling_max([1L, 2L, 3L, 2L, 3L, 4L, 2L])
    [1L, 2L, 3L, 3L, 3L, 4L, 4L]

*/
long[] rolling_max(long[] numbers)

unittest
{
    alias candidate = rolling_max;

    assert(candidate([]) == []);
    assert(candidate([1L, 2L, 3L, 4L]) == [1L, 2L, 3L, 4L]);
    assert(candidate([4L, 3L, 2L, 1L]) == [4L, 4L, 4L, 4L]);
    assert(candidate([3L, 2L, 3L, 100L, 3L]) == [3L, 3L, 3L, 100L, 100L]);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 You're given an array of deposit and withdrawal operations on a bank account that starts with
    zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
    at that point function should return true. Otherwise it should return false.
    >>> below_zero([1L, 2L, 3L])
    false
    >>> below_zero([1L, 2L, -4L, 5L])
    true

*/
bool below_zero(long[] operations)

unittest
{
    alias candidate = below_zero;

    assert(candidate([]) == false);
    assert(candidate([1L, 2L, -3L, 1L, 2L, -3L]) == false);
    assert(candidate([1L, 2L, -4L, 5L, 6L]) == true);
    assert(candidate([1L, -1L, 2L, -2L, 5L, -5L, 4L, -4L]) == false);
    assert(candidate([1L, -1L, 2L, -2L, 5L, -5L, 4L, -5L]) == true);
    assert(candidate([1L, -2L, 2L, -2L, 5L, -5L, 4L, -4L]) == true);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*

    You are given a non-empty array of positive integers. Return the greatest integer that is greater than
    zero, and has a frequency greater than or equal to the value of the integer itself.
    The frequency of an integer is the number of times it appears in the array.
    If no such a value exist, return -1.
    Examples:
    >>> search([4L, 1L, 2L, 2L, 3L, 1L])
    2L
    >>> search([1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L])
    3L
    >>> search([5L, 5L, 4L, 4L, 4L])
    -1L

*/
long search(long[] lst)


Prompt:
import std.typecons;
import std.math;
/*
 brackets is a string of "(" and ")".
    return true if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("(")
    false
    >>> correct_bracketing("()")
    true
    >>> correct_bracketing("(()())")
    true
    >>> correct_bracketing(")(()")
    false

*/
bool correct_bracketing(string brackets)

unittest
{
    alias candidate = correct_bracketing;

    assert(candidate("()") == true);
    assert(candidate("(()())") == true);
    assert(candidate("()()(()())()") == true);
    assert(candidate("()()((()()())())(()()(()))") == true);
    assert(candidate("((()())))") == false);
    assert(candidate(")(()") == false);
    assert(candidate("(") == false);
    assert(candidate("((((") == false);
    assert(candidate(")") == false);
    assert(candidate("(()") == false);
    assert(candidate("()()(()())())(()") == false);
    assert(candidate("()()(()())()))()") == false);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
This function takes an array l and returns an array l' such that
    l' is identical to l in the odd indicies, while its values at the even indicies are equal
    to the values of the even indicies of l, but sorted.
    >>> sort_even([1L, 2L, 3L])
    [1L, 2L, 3L]
    >>> sort_even([5L, 6L, 3L, 4L])
    [3L, 6L, 5L, 4L]

*/
long[] sort_even(long[] l)


Prompt:
import std.typecons;
import std.math;
/*

    Check if two words have the same characters.
    >>> same_chars("eabcdzzzz", "dddzzzzzzzddeddabc")
    true
    >>> same_chars("abcd", "dddddddabc")
    true
    >>> same_chars("dddddddabc", "abcd")
    true
    >>> same_chars("eabcd", "dddddddabc")
    false
    >>> same_chars("abcd", "dddddddabce")
    false
    >>> same_chars("eabcdzzzz", "dddzzzzzzzddddabc")
    false

*/
bool same_chars(string s0, string s1)

unittest
{
    alias candidate = same_chars;

    assert(candidate("eabcdzzzz", "dddzzzzzzzddeddabc") == true);
    assert(candidate("abcd", "dddddddabc") == true);
    assert(candidate("dddddddabc", "abcd") == true);
    assert(candidate("eabcd", "dddddddabc") == false);
    assert(candidate("abcd", "dddddddabcf") == false);
    assert(candidate("eabcdzzzz", "dddzzzzzzzddddabc") == false);
    assert(candidate("aabb", "aaccc") == false);
}
void main(){}


Prompt:
import std.typecons;
import std.math;
/*
 brackets is a string of "<" and ">".
    return true if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    false
    >>> correct_bracketing("<>")
    true
    >>> correct_bracketing("<<><>>")
    true
    >>> correct_bracketing("><<>")
    false

*/
bool correct_bracketing(string brackets)

unittest
{
    alias candidate = correct_bracketing;

    assert(candidate("<>") == true);
    assert(candidate("<<><>>") == true);
    assert(candidate("<><><<><>><>") == true);
    assert(candidate("<><><<<><><>><>><<><><<>>>") == true);
    assert(candidate("<<<><>>>>") == false);
    assert(candidate("><<>") == false);
    assert(candidate("<") == false);
    assert(candidate("<<<<") == false);
    assert(candidate(">") == false);
    assert(candidate("<<>") == false);
    assert(candidate("<><><<><>><>><<>") == false);
    assert(candidate("<><><<><>><>>><>") == false);
}
void main(){}