NazmusAshrafi/apps_probs huggingface dataset:
def max_of_min_2d_array(n: int, m: int, array: List[List[int]]) -> int:
    """
    =====Function Descriptions=====
    min
    
    The tool min returns the minimum value along a given axis.
    
    import numpy
    
    my_array = numpy.array([[2, 5],
    [3, 7],
    [1, 3],
    [4, 0]])
    
    print numpy.min(my_array, axis = 0)         #Output : [1 0]
    print numpy.min(my_array, axis = 1)         #Output : [2 3 1 0]
    print numpy.min(my_array, axis = None)      #Output : 0
    print numpy.min(my_array)                   #Output : 0
    
    By default, the axis value is None. Therefore, it finds the minimum over all the dimensions of the input array.
    
    max
    
    The tool max returns the maximum value along a given axis.
    
    import numpy
    
    my_array = numpy.array([[2, 5],
    [3, 7],
    [1, 3],
    [4, 0]])
    
    print numpy.max(my_array, axis = 0)         #Output : [4 7]
    print numpy.max(my_array, axis = 1)         #Output : [5 7 3 4]
    print numpy.max(my_array, axis = None)      #Output : 7
    print numpy.max(my_array)                   #Output : 7
    
    By default, the axis value is None. Therefore, it finds the maximum over all the dimensions of the input array.
    
    =====Problem Statement=====
    You are given a 2-D array with dimensions NXM.
    Your task is to perform the min function over axis 1 and then find the max of that.
    
    =====Input Format=====
    The first line of input contains the space separated values of N and M.
    The next N lines contains M space separated integers.
    
    =====Output Format=====
    Compute the min along axis 1 and then print the max of that result.
    """
    import numpy as np
    np_array = np.array(array)
    min_values = np.min(np_array, axis=1)
    return np.max(min_values)


# Tests

def check(candidate):
    assert candidate(4, 2, [[2, 5], [3, 7], [1, 3], [4, 0]]) == 3
check(max_of_min_2d_array)
def guess_hat_color(a: str, b: str, c: str, d: str) -> int:
    """
    # Task
    Four men, `a, b, c and d` are standing in a line, one behind another.
    
    There's a wall between the first three people (a, b and c) and the last one (d).
    
    a, b and c are lined up in order of height, so that person a can see the backs of b and c, person b can see the back of c, and c can see just the wall.
    
    There are 4 hats, 2 black and 2 white. Each person is given a hat. None of them can see their own hat, but person a can see the hats of b and c, while person b can see the hat of person c. Neither c nor d can see any hats.
    
    Once a person figures out their hat's color, they shouts it.
    
    ![](http://stuffbox.in/wp-content/uploads/2016/08/Guess-hat-colour-604x270.png)
    
    Your task is to return the person who will guess their hat first. You can assume that they will speak only when they reach a correct conclusion.
    
    # Input/Output
    
    
    - `[input]` string `a`
    
    a's hat color ("white" or "black").
    
    
    - `[input]` string `b`
    
    b's hat color ("white" or "black").
    
    
    - `[input]` string `c`
    
    c's hat color ("white" or "black").
    
    
    - `[input]` string `d`
    
    d's hat color ("white" or "black").
    
    
    - `[output]` an integer
    
    The person to guess his hat's color first, `1 for a, 2 for b, 3 for c and 4 for d`.
    """


# Tests

def check(candidate):
    assert candidate('white', 'black', 'white', 'black') == 2
    assert candidate('white', 'black', 'black', 'white') == 1
check(guess_hat_color)
def tictactoe(moves: List[List[int]]) -> str:
    """
    Tic-tac-toe is played by two players A and B on a 3 x 3 grid.
    Here are the rules of Tic-Tac-Toe:
    
    Players take turns placing characters into empty squares (" ").
    The first player A always places "X" characters, while the second player B always places "O" characters.
    "X" and "O" characters are always placed into empty squares, never on filled ones.
    The game ends when there are 3 of the same (non-empty) character filling any row, column, or diagonal.
    The game also ends if all squares are non-empty.
    No more moves can be played if the game is over.
    
    Given an array moves where each element is another array of size 2 corresponding to the row and column of the grid where they mark their respective character in the order in which A and B play.
    Return the winner of the game if it exists (A or B), in case the game ends in a draw return "Draw", if there are still movements to play return "Pending".
    You can assume that moves is valid (It follows the rules of Tic-Tac-Toe), the grid is initially empty and A will play first.
    
    Example 1:
    Input: moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]
    Output: "A"
    Explanation: "A" wins, he always plays first.
    "X  "    "X  "    "X  "    "X  "    "X  "
    "   " -> "   " -> " X " -> " X " -> " X "
    "   "    "O  "    "O  "    "OO "    "OOX"
    
    Example 2:
    Input: moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]
    Output: "B"
    Explanation: "B" wins.
    "X  "    "X  "    "XX "    "XXO"    "XXO"    "XXO"
    "   " -> " O " -> " O " -> " O " -> "XO " -> "XO "
    "   "    "   "    "   "    "   "    "   "    "O  "
    
    Example 3:
    Input: moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]
    Output: "Draw"
    Explanation: The game ends in a draw since there are no moves to make.
    "XXO"
    "OOX"
    "XOX"
    
    Example 4:
    Input: moves = [[0,0],[1,1]]
    Output: "Pending"
    Explanation: The game has not finished yet.
    "X  "
    " O "
    "   "
    
    
    Constraints:
    
    1 <= moves.length <= 9
    moves[i].length == 2
    0 <= moves[i][j] <= 2
    There are no repeated elements on moves.
    moves follow the rules of tic tac toe.
    """


# Tests

def check(candidate):
    assert candidate([[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]]) == 'A'
    assert candidate([[0, 0], [1, 1], [0, 1], [0, 2], [1, 0], [2, 0]]) == 'B'
    assert candidate([[0, 0], [1, 1], [2, 0], [1, 0], [1, 2], [2, 1], [0, 1], [0, 2], [2, 2]]) == 'Draw'
    assert candidate([[0, 0], [1, 1]]) == 'Pending'
check(tictactoe)
def case_unification(s: str) -> str:
    """
    # Task
    Given an initial string `s`, switch case of the minimal possible number of letters to make the whole string written in the upper case or in the lower case.
    
    # Input/Output
    
    
    `[input]` string `s`
    
    String of odd length consisting of English letters.
    
    3 ≤ inputString.length ≤ 99.
    
    `[output]` a string
    
    The resulting string.
    
    # Example
    
    For `s = "Aba"`, the output should be `"aba"`
    
    For `s = "ABa"`, the output should be `"ABA"`
    """


# Tests

def check(candidate):
    assert candidate('asdERvT') == 'asdervt'
    assert candidate('oyTYbWQ') == 'OYTYBWQ'
    assert candidate('bbiIRvbcW') == 'bbiirvbcw'
    assert candidate('rWTmvcoRWEWQQWR') == 'RWTMVCORWEWQQWR'
check(case_unification)
def complete_series(a: List[int]) -> List[int]:
    """
    You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array.
    
    If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that item must be 0. like this:
    ```
    inputs        outputs
    [2,1]     ->  [0,1,2]
    [1,4,4,6] ->  [0]
    ```
    Notes: all numbers are positive integers.
    
    This is set of example outputs based on the input sequence.
    ```
    inputs        outputs
    [0,1]   ->    [0,1]
    [1,4,6] ->    [0,1,2,3,4,5,6]
    [3,4,5] ->    [0,1,2,3,4,5]
    [0,1,0] ->    [0]
    ```
    """


# Tests

def check(candidate):
    assert candidate([0, 1]) == [0, 1]
    assert candidate([1, 4, 6]) == [0, 1, 2, 3, 4, 5, 6]
    assert candidate([3, 4, 5]) == [0, 1, 2, 3, 4, 5]
    assert candidate([2, 1]) == [0, 1, 2]
    assert candidate([1, 4, 4, 6]) == [0]
check(complete_series)
def does_fred_need_houseboat(x: int, y: int) -> int:
    """
    # Task
    Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 square miles each year, due to erosion caused by the Mississippi River. Since Fred is hoping to live in this house the rest of his life, he needs to know if his land is going to be lost to erosion.
    
    After doing more research, Fred has learned that the land that is being lost forms a semicircle. This semicircle is part of a circle centered at (0,0), with the line that bisects the circle being the `x` axis. Locations below the `x` axis are in the water. The semicircle has an area of 0 at the beginning of year 1. (Semicircle illustrated in the Figure.)
    
    ![](http://media.openjudge.cn/images/1005/semicircle.GIF)
    
    Given two coordinates `x` and `y`, your task is to calculate that Fred Mapper's house will begin eroding in how many years.
    
    Note:
    
    1. No property will appear exactly on the semicircle boundary: it will either be inside or outside.
    
    2. All locations are given in miles.
    
    3. (0,0) will not be given.
    
    # Example
    
    For `x = 1, y = 1`, the result should be `1`.
    
    After 1 year, Fred Mapper's house will begin eroding.
    
    For `x = 25, y = 0`, the result should be `20`.
    
    After 20 year, Fred Mapper's house will begin eroding.
    
    # Input/Output
    
    
    - `[input]` integer `x`
    
    The X coordinates of the land Fred is considering. It will be an integer  point numbers measured in miles.
    
    `-100 <= x <= 100`
    
    
    - `[input]` integer `y`
    
    The Y coordinates of the land Fred is considering. It will be an integer point numbers measured in miles.
    
    `0 <= y <= 100`
    
    
    - `[output]` an integer
    
    The first year (start from 1) this point will be within the semicircle AT THE END OF YEAR.
    """


# Tests

def check(candidate):
    assert candidate(1, 1) == 1
    assert candidate(25, 0) == 20
check(does_fred_need_houseboat)
def folding(a: int, b: int) -> int:
    """
    # Task
    John was in math class and got bored, so he decided to fold some origami from a rectangular `a × b` sheet of paper (`a > b`). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along the bisector of the right angle and cutting off the excess part.
    
    
    
    After moving the square piece of paper aside, John wanted to make even more squares! He took the remaining (`a-b`) × `b` strip of paper and went on with the process until he was left with a square piece of paper.
    
    Your task is to determine how many square pieces of paper John can make.
    
    # Example:
    
    For: `a = 2, b = 1`, the output should be `2`.
    
    Given `a = 2` and `b = 1`, John can fold a `1 × 1` then another `1 × 1`.
    
    So the answer is `2`.
    
    For: `a = 10, b = 7`, the output should be `6`.
    
    We are given `a = 10` and `b = 7`. The following is the order of squares John folds: `7 × 7, 3 × 3, 3 × 3, 1 × 1, 1 × 1, and 1 × 1`.
    
    Here are pictures for the example cases.
    
    
    
    # Input/Output
    
    
    - `[input]` integer `a`
    
    `2 ≤ a ≤ 1000`
    
    
    - `[input]` integer `b`
    
    `1 ≤ b < a ≤ 1000`
    
    
    - `[output]` an integer
    
    The maximum number of squares.
    """


# Tests

def check(candidate):
    assert candidate(2, 1) == 2
    assert candidate(10, 7) == 6
    assert candidate(3, 1) == 3
    assert candidate(4, 1) == 4
    assert candidate(3, 2) == 3
    assert candidate(4, 2) == 2
    assert candidate(1000, 700) == 6
    assert candidate(1000, 999) == 1000
check(folding)
def substring_test(first: str, second: str) -> bool:
    """
    Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.
    
    #Examples:
    
    ````
    *Example 1*
    SubstringTest("Something","Fun"); //Returns false
    
    *Example 2*
    SubstringTest("Something","Home"); //Returns true
    ````
    In the above example, example 2 returns true because both of the inputs contain the substring "me". (so**ME**thing and ho**ME**)
    In example 1, the method will return false because something and fun contain no common substrings. (We do not count the 'n' as a substring in this Kata because it is only 1 character long)
    
    #Rules:
    Lowercase and uppercase letters are the same. So 'A' == 'a'.
    We only count substrings that are > 1 in length.
    
    #Input:
    Two strings with both lower and upper cases.
    #Output:
    A boolean value determining if there is a common substring between the two inputs.
    """


# Tests

def check(candidate):
    assert candidate('Something', 'Home') == True
    assert candidate('Something', 'Fun') == False
    assert candidate('Something', '') == False
    assert candidate('', 'Something') == False
    assert candidate('BANANA', 'banana') == True
    assert candidate('test', 'lllt') == False
    assert candidate('', '') == False
    assert candidate('1234567', '541265') == True
    assert candidate('supercalifragilisticexpialidocious', 'SoundOfItIsAtrocious') == True
    assert candidate('LoremipsumdolorsitametconsecteturadipiscingelitAeneannonaliquetligulautplaceratorciSuspendissepotentiMorbivolutpatauctoripsumegetaliquamPhasellusidmagnaelitNullamerostellustemporquismolestieaornarevitaediamNullaaliquamrisusnonviverrasagittisInlaoreetultricespretiumVestibulumegetnullatinciduntsempersemacrutrumfelisPraesentpurusarcutempusnecvariusidultricesaduiPellentesqueultriciesjustolobortisrhoncusdignissimNuncviverraconsequatblanditUtbibendumatlacusactristiqueAliquamimperdietnuncsempertortorefficiturviverra', 'thisisalongstringtest') == True
    assert candidate('Codewars is sweet!', 'is') == True
check(substring_test)
def nickname_generator(name: str) -> str:
    """
    Nickname Generator
    
    Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname.
    
    If the 3rd letter is a consonant, return the first 3 letters.
    
    If the 3rd letter is a vowel, return the first 4 letters.
    
    If the string is less than 4 characters, return "Error: Name too short".
    
    **Notes:**
    
    - Vowels are "aeiou", so discount the letter "y".
    - Input will always be a string.
    - Input will always have the first letter capitalised and the rest lowercase (e.g. Sam).
    - The input can be modified
    """


# Tests

def check(candidate):
    assert candidate('Jimmy') == 'Jim'
    assert candidate('Samantha') == 'Sam'
    assert candidate('Sam') == 'Error: Name too short'
    assert candidate('Kayne') == 'Kay'
    assert candidate('Melissa') == 'Mel'
    assert candidate('James') == 'Jam'
    assert candidate('Gregory') == 'Greg'
    assert candidate('Jeannie') == 'Jean'
    assert candidate('Kimberly') == 'Kim'
    assert candidate('Timothy') == 'Tim'
    assert candidate('Dani') == 'Dan'
    assert candidate('Saamy') == 'Saam'
    assert candidate('Saemy') == 'Saem'
    assert candidate('Saimy') == 'Saim'
    assert candidate('Saomy') == 'Saom'
    assert candidate('Saumy') == 'Saum'
    assert candidate('Boyna') == 'Boy'
    assert candidate('Kiyna') == 'Kiy'
    assert candidate('Sayma') == 'Say'
    assert candidate('Ni') == 'Error: Name too short'
    assert candidate('Jam') == 'Error: Name too short'
    assert candidate('Suv') == 'Error: Name too short'
check(nickname_generator)
def candles(candlesNumber: int, makeNew: int) -> int:
    """
    # Task
    When a candle finishes burning it leaves a leftover. makeNew leftovers can be combined to make a new candle, which, when burning down, will in turn leave another leftover.
    
    You have candlesNumber candles in your possession. What's the total number of candles you can burn, assuming that you create new candles as soon as you have enough leftovers?
    
    # Example
    
    For candlesNumber = 5 and makeNew = 2, the output should be `9`.
    
    Here is what you can do to burn 9 candles:
    ```
    burn 5 candles, obtain 5 leftovers;
    create 2 more candles, using 4 leftovers (1 leftover remains);
    burn 2 candles, end up with 3 leftovers;
    create another candle using 2 leftovers (1 leftover remains);
    burn the created candle, which gives another leftover (2 leftovers in total);
    create a candle from the remaining leftovers;
    burn the last candle.
    Thus, you can burn 5 + 2 + 1 + 1 = 9 candles, which is the answer.
    ```
    
    # Input/Output
    
    
    - `[input]` integer `candlesNumber`
    
    The number of candles you have in your possession.
    
    Constraints: 1 ≤ candlesNumber ≤ 50.
    
    
    - `[input]` integer `makeNew`
    
    The number of leftovers that you can use up to create a new candle.
    
    Constraints: 2 ≤ makeNew ≤ 5.
    
    
    - `[output]` an integer
    """


# Tests

def check(candidate):
    assert candidate(5, 2) == 9
check(candles)
def segment_cover(A: List[int], L: int) -> int:
    """
    # Task
    Given some points(array `A`) on the same line, determine the minimum number of line segments with length `L` needed to cover all of the given points. A point is covered if it is located inside some segment or on its bounds.
    
    # Example
    
    For `A = [1, 3, 4, 5, 8]` and `L = 3`, the output should be `2`.
    
    Check out the image below for better understanding:
    
    ![](https://codefightsuserpics.s3.amazonaws.com/tasks/segmentCover/img/example.png?_tm=1474900035857)
    
    
    For `A = [1, 5, 2, 4, 3]` and `L = 1`, the output should be `3`.
    
    segment1: `1-2`(covered points 1,2),
    
    segment2: `3-4`(covered points 3,4),
    
    segment3: `5-6`(covered point 5)
    
    For `A = [1, 10, 100, 1000]` and `L = 1`, the output should be `4`.
    
    segment1: `1-2`(covered point 1),
    
    segment2: `10-11`(covered point 10),
    
    segment3: `100-101`(covered point 100),
    
    segment4: `1000-1001`(covered point 1000)
    
    
    # Input/Output
    
    
    - `[input]` integer array A
    
    Array of point coordinates on the line (all points are different).
    
    Constraints:
    
    `1 ≤ A.length ≤ 50,`
    
    `-5000 ≤ A[i] ≤ 5000.`
    
    
    - `[input]` integer `L`
    
    Segment length, a positive integer.
    
    Constraints: `1 ≤ L ≤ 100.`
    
    
    - `[output]` an integer
    
    The minimum number of line segments that can cover all of the given points.
    """


# Tests

def check(candidate):
    assert candidate([1, 3, 4, 5, 8], 3) == 2
    assert candidate([-7, -2, 0, -1, -6, 7, 3, 4], 4) == 3
    assert candidate([1, 5, 2, 4, 3], 1) == 3
    assert candidate([1, 10, 100, 1000], 1) == 4
check(segment_cover)
def timed_reading(max_length: int, text: str) -> int:
    """
    # Task
    Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he encountered a word longer than maxLength, he simply skipped it and read on.
    
    Help the teacher figure out how many words the boy has read by calculating the number of words in the text he has read, no longer than maxLength.
    
    Formally, a word is a substring consisting of English letters, such that characters to the left of the leftmost letter and to the right of the rightmost letter are not letters.
    
    # Example
    
    For `maxLength = 4` and `text = "The Fox asked the stork, 'How is the soup?'"`, the output should be `7`
    
    The boy has read the following words: `"The", "Fox", "the", "How", "is", "the", "soup".`
    
    # Input/Output
    
    
    - `[input]` integer `maxLength`
    
    A positive integer, the maximum length of the word the boy can read.
    
    Constraints: `1 ≤ maxLength ≤ 10.`
    
    
    - `[input]` string `text`
    
    A non-empty string of English letters and punctuation marks.
    
    
    - `[output]` an integer
    
    The number of words the boy has read.
    """


# Tests

def check(candidate):
    assert candidate(4, 'The Fox asked the stork, How is the soup?') == 7
    assert candidate(1, '...') == 0
    assert candidate(3, 'This play was good for us.') == 3
    assert candidate(3, 'Suddenly he stopped, and glanced up at the houses') == 5
    assert candidate(6, 'Zebras evolved among the Old World horses within the last four million years.') == 11
    assert candidate(5, 'Although zebra species may have overlapping ranges, they do not interbreed.') == 6
    assert candidate(1, 'Oh!') == 0
    assert candidate(5, 'Now and then, however, he is horribly thoughtless, and seems to take a real delight in giving me pain.') == 14
check(timed_reading)
def evil_code_medal(user_time: str, gold: str, silver: str, bronze: str) -> str:
    """
    # Task
    `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task.
    
    To get a medal, your time must be (strictly) inferior to the time corresponding to the medal. You can be awarded `"Gold", "Silver" or "Bronze"` medal, or `"None"` medal at all. Only one medal (the best achieved) is awarded.
    
    You are given the time achieved for the task and the time corresponding to each medal. Your task is to return the awarded medal.
    
    Each time is given in the format `HH:MM:SS`.
    
    
    # Input/Output
    
    `[input]` string `userTime`
    
    The time the user achieved.
    
    `[input]` string `gold`
    
    The time corresponding to the gold medal.
    
    `[input]` string `silver`
    
    The time corresponding to the silver medal.
    
    `[input]` string `bronze`
    
    The time corresponding to the bronze medal.
    
    It is guaranteed that `gold < silver < bronze`.
    
    `[output]` a string
    
    The medal awarded, one of for options: `"Gold", "Silver", "Bronze" or "None"`.
    
    # Example
    
    For
    ```
    userTime = "00:30:00", gold = "00:15:00",
    silver = "00:45:00" and bronze = "01:15:00"```
    
    the output should be `"Silver"`
    
    For
    ```
    userTime = "01:15:00", gold = "00:15:00",
    silver = "00:45:00" and bronze = "01:15:00"```
    
    the output should be `"None"`
    
    # For Haskell version
    ```
    In Haskell, the result is a Maybe, returning Just String indicating
    the medal if they won or Nothing if they don't.
    ```
    """


# Tests

def check(candidate):
    assert candidate("00:30:00", "00:15:00", "00:45:00", "01:15:00") == "Silver"
    assert candidate("01:15:00", "00:15:00", "00:45:00", "01:15:00") == "None"
    assert candidate("00:00:01", "00:00:10", "00:01:40", "01:00:00") == "Gold"
    assert candidate("00:10:01", "00:00:10", "00:01:40", "01:00:00") == "Bronze"
    assert candidate("00:00:01", "00:00:02", "00:00:03", "00:00:04") == "Gold"
    assert candidate("90:00:01", "60:00:02", "70:00:03", "80:00:04") == "None"
    assert candidate("03:15:00", "03:15:00", "03:15:01", "03:15:02") == "Silver"
    assert candidate("99:59:58", "99:59:57", "99:59:58", "99:59:59") == "Bronze"
    assert candidate("14:49:03", "77:39:08", "92:11:36", "94:07:41") == "Gold"
    assert candidate("61:01:40", "64:19:53", "79:30:02", "95:24:48") == "Gold"
check(evil_code_medal)