python_code stringlengths 0 869k |
|---|
ENTRY_POINT = 'int_to_mini_roman'
#[PROMPT]
def int_to_mini_roman(number):
"""
Given a positive integer, obtain its roman numeral equivalent as a string,
and return it in lowercase.
Restrictions: 1 <= num <= 1000
Examples:
>>> int_to_mini_roman(19) == 'xix'
>>> int_to_mini_roman(152) == 'c... |
ENTRY_POINT = 'prod_signs'
#[PROMPT]
def prod_signs(arr):
"""
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 None for empty arr.
Example:
>>>... |
ENTRY_POINT = 'make_a_pile'
#[PROMPT]
def make_a_pile(n):
"""
Given a positive integer n, you have to make a pile of n levels of stones.
The first level has n stones.
The number of stones in the next level is:
- the next odd number if n is odd.
- the next even number if n is even.
R... |
ENTRY_POINT = 'numerical_letter_grade'
FIX = """
Add test case for E grade.
"""
#[PROMPT]
def numerical_letter_grade(grades):
"""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 ... |
ENTRY_POINT = 'hex_key'
#[PROMPT]
def hex_key(num):
"""You have been tasked to write a function that receives
a hexadecimal number as a string and counts the number of hexadecimal
digits that are primes (prime number, or a prime, is a natural number
greater than 1 that is not a product of two smalle... |
ENTRY_POINT = 'add'
#[PROMPT]
def add(x: int, y: int):
"""Add two numbers x and y
>>> add(2, 3)
5
>>> add(5, 7)
12
"""
#[SOLUTION]
return x + y
#[CHECK]
METADATA = {}
def check(candidate):
import random
assert candidate(0, 1) == 1
assert candidate(1, 0) == 1
assert can... |
ENTRY_POINT = 'vowels_count'
#[PROMPT]
FIX = """
Add more test cases.
"""
def vowels_count(s):
"""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, ... |
ENTRY_POINT = 'generate_integers'
#[PROMPT]
def generate_integers(a, b):
"""
Given two positive integers a and b, return the even digits between a
and b, in ascending order.
For example:
generate_integers(2, 8) => [2, 4, 6, 8]
generate_integers(8, 2) => [2, 4, 6, 8]
generate_integers(10, 1... |
ENTRY_POINT = 'is_equal_to_sum_even'
#[PROMPT]
def is_equal_to_sum_even(n):
"""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
"""
#[SOLUTIO... |
ENTRY_POINT = 'correct_bracketing'
#[PROMPT]
def correct_bracketing(brackets: str):
""" 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... |
ENTRY_POINT = 'modp'
#[PROMPT]
def modp(n: int, p: int):
"""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
"""
#[SOLUTION]
ret = 1
for i in range(n):
ret = (2 *... |
ENTRY_POINT = 'cycpattern_check'
#[PROMPT]
def cycpattern_check(a , b):
"""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... |
ENTRY_POINT = 'rescale_to_unit'
#[PROMPT]
from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
""" Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
>>> rescale_to_... |
ENTRY_POINT = 'largest_divisor'
#[PROMPT]
def largest_divisor(n: int) -> int:
""" For a given number n, find the largest number that divides n evenly, smaller than n
>>> largest_divisor(15)
5
"""
#[SOLUTION]
for i in reversed(range(n)):
if n % i == 0:
return i
#[CHECK]
METADA... |
ENTRY_POINT = 'is_sorted'
#[PROMPT]
def is_sorted(lst):
'''
Given a list of numbers, return whether or not they are sorted
in ascending order. If list has more than 1 duplicate of the same
number, return False. Assume no negative numbers and only integers.
Examples
is_sorted([5]) âžž True
is... |
ENTRY_POINT = 'make_palindrome'
#[PROMPT]
def is_palindrome(string: str) -> bool:
""" Test if given string is a palindrome """
return string == string[::-1]
def make_palindrome(string: str) -> str:
""" Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- F... |
ENTRY_POINT = 'simplify'
#[PROMPT]
def simplify(x, n):
"""Your task is to implement a function that will simplify the expression
x * n. The function returns True if x * n evaluates to a whole number and False
otherwise. Both x and n, are string representation of a fraction, and have the following format,
... |
ENTRY_POINT = 'Strongest_Extension'
#[PROMPT]
def Strongest_Extension(class_name, extensions):
"""You will be given the name of a class (a string) and a list of extensions.
The extensions are to be used to load additional classes to the class. The
strength of the extension is as follows: Let CAP be the num... |
ENTRY_POINT = 'maximum'
#[PROMPT]
def maximum(arr, k):
"""
Given an array arr of integers and a positive integer k, return a sorted list
of length k with the maximum k numbers in arr.
Example 1:
Input: arr = [-3, -4, 5], k = 3
Output: [-4, -3, 5]
Example 2:
Input: arr =... |
ENTRY_POINT = 'by_length'
#[PROMPT]
def by_length(arr):
"""
Given an array of integers, if the number is an integer between 1 and 9 inclusive,
replace it by its corresponding name from "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
otherwise remove it, then sort the array and r... |
ENTRY_POINT = 'string_to_md5'
#[PROMPT]
def string_to_md5(text):
"""
Given a string 'text', return its md5 hash equivalent string.
If 'text' is an empty string, return None.
>>> string_to_md5('Hello world') == '3e25960a79dbc69b674cd4ec67a72c62'
"""
#[SOLUTION]
import hashlib
return hashlib... |
ENTRY_POINT = 'sort_array'
#[PROMPT]
def sort_array(array):
"""
Given an array of non-negative integers, return a copy 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( f... |
ENTRY_POINT = 'parse_music'
#[PROMPT]
from typing import List
def parse_music(music_string: str) -> List[int]:
""" Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return list of integers corresponding to how many beats does each
... |
ENTRY_POINT = 'largest_smallest_integers'
#[PROMPT]
def largest_smallest_integers(lst):
'''
Create a function that returns a tuple (a, b), where 'a' is
the largest of negative integers, and 'b' is the smallest
of positive integers in a list.
If there is no negative or positive integers, return them... |
ENTRY_POINT = 'do_algebra'
#[PROMPT]
def do_algebra(operator, operand):
"""
Given two lists operator, and operand. The first list has basic algebra operations, and
the second list is a list of integers. Use the two given lists to build the algebric
expression and return the evaluation of this express... |
ENTRY_POINT = 'intersection'
#[PROMPT]
def intersection(interval1, interval2):
"""You are given two intervals,
where each interval is a pair of integers. For example, interval = (start, end) = (1, 2).
The given intervals are closed which means that the interval (start, end)
includes both start and end.... |
ENTRY_POINT = 'string_xor'
#[PROMPT]
from typing import List
def string_xor(a: str, b: str) -> str:
""" 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'
"""
#[SOLUTION]
def xor(... |
ENTRY_POINT = 'triples_sum_to_zero'
FIX = """
Fix the bug of allowing reuse elements.
"""
#[PROMPT]
def triples_sum_to_zero(l: list):
"""
triples_sum_to_zero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
... |
ENTRY_POINT = 'fibfib'
#[PROMPT]
def fibfib(n: int):
"""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 efficient... |
ENTRY_POINT = 'is_palindrome'
#[PROMPT]
def is_palindrome(text: str):
"""
Checks if given string is a palindrome
>>> is_palindrome('')
True
>>> is_palindrome('aba')
True
>>> is_palindrome('aaaaa')
True
>>> is_palindrome('zbcd')
False
"""
#[SOLUTION]
for i in range(len(t... |
ENTRY_POINT = 'anti_shuffle'
#[PROMPT]
def anti_shuffle(s):
"""
Write a function that takes a string and returns an ordered version of it.
Ordered version of string, is a string where all words (separated by space)
are replaced by a new word where all the characters arranged in
ascending order base... |
ENTRY_POINT = 'even_odd_palindrome'
#[PROMPT]
def even_odd_palindrome(n):
"""
Given a positive integer n, return a tuple that has the number of even and odd
integer palindromes that fall within the range(1, n), inclusive.
Example 1:
Input: 3
Output: (1, 2)
Explanation:
... |
ENTRY_POINT = 'largest_prime_factor'
FIX = """
Clarifies that n > 1 and is not a prime number.
"""
#[PROMPT]
def largest_prime_factor(n: int):
"""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
"""
#[S... |
ENTRY_POINT = 'string_sequence'
#[PROMPT]
def string_sequence(n: int) -> str:
""" Return a string containing space-delimited numbers starting from 0 upto n inclusive.
>>> string_sequence(0)
'0'
>>> string_sequence(5)
'0 1 2 3 4 5'
"""
#[SOLUTION]
return ' '.join([str(x) for x in range(n + ... |
ENTRY_POINT = 'rounded_avg'
#[PROMPT]
def rounded_avg(n, m):
"""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 ... |
ENTRY_POINT = 'unique'
#[PROMPT]
def unique(l: list):
"""Return sorted unique elements in a list
>>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])
[0, 2, 3, 5, 9, 123]
"""
#[SOLUTION]
return sorted(list(set(l)))
#[CHECK]
METADATA = {}
def check(candidate):
assert candidate([5, 3, 5, 2, 3, 3, 9, 0,... |
ENTRY_POINT = 'is_multiply_prime'
FIX = """
Fix incorrect is_prime function
Add more tests
"""
#[PROMPT]
def is_multiply_prime(a):
"""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:
i... |
ENTRY_POINT = 'tri'
#[PROMPT]
def tri(n):
"""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 eve... |
ENTRY_POINT = 'has_close_elements'
#[PROMPT]
from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
""" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
False
>>> ... |
ENTRY_POINT = 'get_closest_vowel'
#[PROMPT]
def get_closest_vowel(word):
"""You are given a word. Your task is to find the closest vowel that stands between
two consonants from the right side of the word (case sensitive).
Vowels in the beginning and ending doesn't count. Return empty string if you di... |
ENTRY_POINT = 'compare_one'
#[PROMPT]
def compare_one(a, b):
"""
Create a function that takes integers, floats, or strings representing
real numbers, and returns the larger variable in its given variable type.
Return None if the values are equal.
Note: If a real number is represented as a string, t... |
ENTRY_POINT = 'find_closest_elements'
#[PROMPT]
from typing import List, Tuple
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]:
""" From a supplied list of numbers (of length at least two) select and return two that are the closest to each
other and return them in order (smaller number,... |
ENTRY_POINT = 'intersperse'
#[PROMPT]
from typing import List
def intersperse(numbers: List[int], delimeter: int) -> List[int]:
""" Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
>>> intersperse([], 4)
[]
>>> intersperse([1, 2, 3], 4)
[1, 4, 2, 4, 3]
... |
ENTRY_POINT = 'smallest_change'
#[PROMPT]
def smallest_change(arr):
"""
Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change ... |
ENTRY_POINT = 'check_dict_case'
#[PROMPT]
def check_dict_case(dict):
"""
Given a dictionary, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given dictionary is empty.
Examples:
check_dict_case(... |
ENTRY_POINT = 'count_upper'
#[PROMPT]
def count_upper(s):
"""
Given a string s, count the number of uppercase vowels in even indices.
For example:
count_upper('aBCdEf') returns 1
count_upper('abcdefg') returns 0
count_upper('dBBE') returns 0
"""
#[SOLUTION]
count = 0
for i in r... |
ENTRY_POINT = 'digits'
#[PROMPT]
def digits(n):
"""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
"""
#[SOLUTION]
product = 1
odd_count = 0
for digit in str(n):
... |
ENTRY_POINT = 'remove_duplicates'
#[PROMPT]
from typing import List
def remove_duplicates(numbers: List[int]) -> List[int]:
""" From a list of integers, remove all elements that occur more than once.
Keep order of elements left the same as in the input.
>>> remove_duplicates([1, 2, 3, 2, 4])
[1, 3, 4]... |
ENTRY_POINT = 'select_words'
FIX = """
Make vowel check case insensitive.
"""
#[PROMPT]
def select_words(s, n):
"""Given a string s and a natural number n, you have been tasked to implement
a function that returns a list of all words from string s that contain exactly
n consonants, in order these words... |
ENTRY_POINT = 'order_by_points'
#[PROMPT]
def order_by_points(nums):
"""
Write a function which sorts the given list of integers
in ascending order according to the sum of their digits.
Note: if there are several items with similar sum of their digits,
order them based on their index in original li... |
ENTRY_POINT = 'below_threshold'
#[PROMPT]
def below_threshold(l: list, t: int):
"""Return True if all numbers in the list l are below threshold t.
>>> below_threshold([1, 2, 4, 10], 100)
True
>>> below_threshold([1, 20, 4, 10], 5)
False
"""
#[SOLUTION]
for e in l:
if e >= t:
... |
ENTRY_POINT = 'truncate_number'
#[PROMPT]
def truncate_number(number: float) -> float:
""" 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 ... |
ENTRY_POINT = 'below_zero'
#[PROMPT]
from typing import List
def below_zero(operations: List[int]) -> bool:
""" You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at ... |
ENTRY_POINT = 'how_many_times'
#[PROMPT]
def how_many_times(string: str, substring: str) -> int:
""" 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'... |
ENTRY_POINT = 'fib'
#[PROMPT]
def fib(n: int):
"""Return n-th Fibonacci number.
>>> fib(10)
55
>>> fib(1)
1
>>> fib(8)
21
"""
#[SOLUTION]
if n == 0:
return 0
if n == 1:
return 1
return fib(n - 1) + fib(n - 2)
#[CHECK]
METADATA = {}
def check(candidate):
... |
ENTRY_POINT = 'find_max'
#[PROMPT]
def find_max(words):
"""Write a function that accepts a list of strings.
The list contains different words. Return the word with maximum number
of unique characters. If multiple strings have maximum number of unique
characters, return the one which comes first in lexi... |
ENTRY_POINT = 'total_match'
FIX = """
Add test case when two list have equal number of chars.
"""
#[PROMPT]
def total_match(lst1, lst2):
'''
Write a function that accepts two lists of strings and returns the list that has
total number of chars in the all strings of the list less than the other list.
... |
ENTRY_POINT = 'max_fill'
#[PROMPT]
def max_fill(grid, capacity):
import math
"""
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,
... |
ENTRY_POINT = 'encrypt'
#[PROMPT]
def encrypt(s):
"""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 exampl... |
ENTRY_POINT = 'strlen'
#[PROMPT]
def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
#[SOLUTION]
return len(string)
#[CHECK]
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('') ==... |
ENTRY_POINT = 'sort_third'
FIX = """
Remove sort helper function.
"""
#[PROMPT]
def sort_third(l: list):
"""This function takes a list l and returns a list 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 equa... |
ENTRY_POINT = 'all_prefixes'
#[PROMPT]
from typing import List
def all_prefixes(string: str) -> List[str]:
""" Return list of all prefixes from shortest to longest of the input string
>>> all_prefixes('abc')
['a', 'ab', 'abc']
"""
#[SOLUTION]
result = []
for i in range(len(string)):
r... |
ENTRY_POINT = 'change_base'
#[PROMPT]
def change_base(x: int, base: int):
"""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
... |
ENTRY_POINT = 'skjkasdkd'
#[PROMPT]
def skjkasdkd(lst):
"""You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Examples:
For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10
For lst = [1,0,1,8,2,4597,2,1,3,... |
ENTRY_POINT = 'sum_to_n'
#[PROMPT]
def sum_to_n(n: int):
"""sum_to_n is a function that sums numbers from 1 to n.
>>> sum_to_n(30)
465
>>> sum_to_n(100)
5050
>>> sum_to_n(5)
15
>>> sum_to_n(10)
55
>>> sum_to_n(1)
1
"""
#[SOLUTION]
return sum(range(n + 1))
#[CHECK]
... |
ENTRY_POINT = 'incr_list'
#[PROMPT]
def incr_list(l: list):
"""Return list with elements incremented by 1.
>>> incr_list([1, 2, 3])
[2, 3, 4]
>>> incr_list([5, 3, 5, 2, 3, 3, 9, 0, 123])
[6, 4, 6, 3, 4, 4, 10, 1, 124]
"""
#[SOLUTION]
return [(e + 1) for e in l]
#[CHECK]
METADATA = {}
d... |
ENTRY_POINT = 'sort_array'
#[PROMPT]
def sort_array(arr):
"""
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:
... |
ENTRY_POINT = 'prime_length'
#[PROMPT]
def prime_length(string):
"""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_le... |
ENTRY_POINT = 'valid_date'
FIX = """
Add more negative test cases.
"""
#[PROMPT]
def valid_date(date):
"""You have to write a function which validates a given date string and
returns True if the date is valid otherwise False.
The date is valid if all of the following rules are satisfied:
1. The date ... |
ENTRY_POINT = 'search'
#[PROMPT]
def search(lst):
'''
You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears... |
ENTRY_POINT = 'common'
#[PROMPT]
def common(l1: list, l2: list):
"""Return sorted unique common elements for two lists.
>>> common([1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121])
[1, 5, 653]
>>> common([5, 3, 2, 8], [3, 2])
[2, 3]
"""
#[SOLUTION]
ret = set()
for e1 in l1:
... |
ENTRY_POINT = 'encode'
#[PROMPT]
def encode(message):
"""
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 let... |
ENTRY_POINT = 'histogram'
#[PROMPT]
def histogram(test):
"""Given a string representing a space separated lowercase letters, return a dictionary
of the letter with the most repetition and containing the corresponding count.
If several letters have the same occurrence, return all of them.
Example:
... |
ENTRY_POINT = 'solve'
#[PROMPT]
def solve(s):
"""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
so... |
ENTRY_POINT = 'get_max_triples'
#[PROMPT]
def get_max_triples(n):
"""
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 ... |
ENTRY_POINT = 'decimal_to_binary'
#[PROMPT]
def decimal_to_binary(decimal):
"""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'.
... |
ENTRY_POINT = 'is_happy'
#[PROMPT]
def is_happy(s):
"""You are given a string s.
Your task is to check if the string is happy or not.
A string is happy 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(a... |
ENTRY_POINT = 'get_positive'
#[PROMPT]
def get_positive(l: list):
"""Return only positive numbers in the list.
>>> get_positive([-1, 2, -4, 5, 6])
[2, 5, 6]
>>> get_positive([5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10])
[5, 3, 2, 3, 9, 123, 1]
"""
#[SOLUTION]
return [e for e in l if e > 0]
#[CH... |
ENTRY_POINT = 'greatest_common_divisor'
#[PROMPT]
def greatest_common_divisor(a: int, b: int) -> int:
""" Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
#[SOLUTION]
while b:
a, b = b, a % b
... |
ENTRY_POINT = 'file_name_check'
#[PROMPT]
def file_name_check(file_name):
"""Create a function which takes a string representing a file's name, and returns
'Yes' if the the file's name is valid, and returns 'No' otherwise.
A file's name is considered to be valid if and only if all the following conditions ... |
ENTRY_POINT = 'longest'
#[PROMPT]
from typing import List, Optional
def longest(strings: List[str]) -> Optional[str]:
""" Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest([])
>... |
ENTRY_POINT = 'specialFilter'
#[PROMPT]
def specialFilter(nums):
"""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([15,... |
ENTRY_POINT = 'special_factorial'
FIX = """
Remove k from docstring.
"""
#[PROMPT]
def special_factorial(n):
"""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... |
ENTRY_POINT = 'split_words'
FIX = """
Add check for lower case and add test.
"""
#[PROMPT]
def split_words(txt):
'''
Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you
should split on commas ',' if no commas exists you should return the number of... |
ENTRY_POINT = 'is_nested'
FIX = """
Add example clarifying two cases:
1. There can be more than one brakets in side another. e.g. [[][]]
2. Whole string doesn't need to be balanced. e.g. [[]][[
Add test cases for these two cases.
"""
#[PROMPT]
def is_nested(string):
'''
Create a function that takes a string ... |
ENTRY_POINT = 'median'
FIX = """
Fix bug in solution. Add more tests.
Add a few more tests.
"""
#[PROMPT]
def median(l: list):
"""Return median of elements in the list l.
>>> median([3, 1, 2, 4, 5])
3
>>> median([-10, 4, 6, 1000, 10, 20])
15.0
"""
#[SOLUTION]
l = sorted(l)
if len(l) %... |
ENTRY_POINT = 'odd_count'
#[PROMPT]
def odd_count(lst):
"""Given a list of strings, where each string consists of only digits, return a list.
Each element i of the output should be "the number of odd elements in the
string i of the input." where all the i's should be replaced by the number
of odd digit... |
ENTRY_POINT = 'sum_squares'
#[PROMPT]
def sum_squares(lst):
"""You are given a list of numbers.
You need to return the sum of squared numbers in the given list,
round each element in the list to the upper int(Ceiling) first.
Examples:
For lst = [1,2,3] the output should be 14
For lst = [1,4,9]... |
ENTRY_POINT = 'flip_case'
#[PROMPT]
def flip_case(string: str) -> str:
""" For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
>>> flip_case('Hello')
'hELLO'
"""
#[SOLUTION]
return string.swapcase()
#[CHECK]
METADATA = {
'author': 'jt',
'dataset': 'test... |
ENTRY_POINT = 'fib4'
FIX = """
Change solution to be non-recursive.
"""
#[PROMPT]
def fib4(n: int):
"""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) + f... |
ENTRY_POINT = 'closest_integer'
#[PROMPT]
def closest_integer(value):
'''
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")
1... |
ENTRY_POINT = 'concatenate'
#[PROMPT]
from typing import List
def concatenate(strings: List[str]) -> str:
""" Concatenate list of strings into a single string
>>> concatenate([])
''
>>> concatenate(['a', 'b', 'c'])
'abc'
"""
#[SOLUTION]
return ''.join(strings)
#[CHECK]
METADATA = {
'... |
ENTRY_POINT = 'same_chars'
#[PROMPT]
def same_chars(s0: str, s1: str):
"""
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',... |
ENTRY_POINT = 'is_prime'
#[PROMPT]
def is_prime(n):
"""Return true if a given number is prime, and false otherwise.
>>> is_prime(6)
False
>>> is_prime(101)
True
>>> is_prime(11)
True
>>> is_prime(13441)
True
>>> is_prime(61)
True
>>> is_prime(4)
False
>>> is_pri... |
ENTRY_POINT = 'add_elements'
#[PROMPT]
def add_elements(arr, k):
"""
Given a non-empty array of integers arr and an integer k, return
the sum of the first k element that has at most two digits.
Example:
Input: arr = [111,21,3,4000,5,6,7,8,9], k = 4
Output: 24 # sum of 21 + 3
Cons... |
ENTRY_POINT = 'sort_numbers'
#[PROMPT]
from typing import List
def sort_numbers(numbers: str) -> str:
""" Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with number... |
ENTRY_POINT = 'words_string'
#[PROMPT]
def words_string(s):
"""
You will be given a string of words separated by commas or spaces. Your task is
to split the string into words and return an array of the words.
For example:
words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"... |
ENTRY_POINT = 'will_it_fly'
#[PROMPT]
def will_it_fly(q,w):
'''
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 list) and the sum of its elements is less than or equal the maximum possible weight w.
Example:
... |
ENTRY_POINT = 'fruit_distribution'
FIX = """
Fixed incorrect examples by changing + to -
"""
#[PROMPT]
def fruit_distribution(s,n):
"""
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, oran... |
ENTRY_POINT = 'decode_cyclic'
#[PROMPT]
def encode_cyclic(s: str):
"""
returns encoded string by cycling groups of three characters.
"""
# split string to groups. Each of length 3.
groups = [s[(3 * i):min((3 * i + 3), len(s))] for i in range((len(s) + 2) // 3)]
# cycle elements in each group. ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.