Datasets:

inputs
stringlengths
50
14k
targets
stringlengths
4
655k
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): flat = sum(grid, []) return "".join( flat[i-1] for i in indexes )
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): flat = tuple(x for e in grid for x in e) return ''.join(flat[e-1] for e in indexes)
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(ll, indexes): flatten = [item for flat_list in ll for item in flat_list] return "".join([flatten[index-1] for index in indexes])
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): grid = sum(grid, start=['']) return ''.join(grid[i] for i in indexes)
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): l = len(grid) return "".join(grid[(i-1)//l][(i-1)%l] for i in indexes)
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): new = [] for g in grid: for el in g: new.append(el) return ''.join([new[i - 1] for i in indexes])
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): unpac_lst=[value for array in grid for value in array] return ''.join(unpac_lst[i-1] for i in indexes)
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
def grid_index(grid, indexes): n = len(grid) idxs = (i - 1 for i in indexes) return "".join(grid[i // n][i % n] for i in idxs)
You are given an n by n ( square ) grid of characters, for example: ```python [['m', 'y', 'e'], ['x', 'a', 'm'], ['p', 'l', 'e']] ``` You are also given a list of integers as input, for example: ```python [1, 3, 5, 8] ``` You have to find the characters in these indexes of the grid if you think of the indexes as: ```python [[1, 2, 3], [4, 5, 6], [7, 8, 9]] ``` Remember that the indexes start from one and not zero. Then you output a string like this: ```python "meal" ``` All inputs will be valid.
from itertools import chain def grid_index(grid, indexes): linear = list(chain.from_iterable(grid)) return ''.join(linear[q - 1] for q in indexes)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from fractions import gcd import re from functools import reduce def min_special_mult(arr): l = [e for e in arr if not re.match('(None)|([+-]?\d+)', str(e))] if len(l) == 1: return 'There is 1 invalid entry: {}'.format(l[0]) if len(l) > 1: return 'There are {} invalid entries: {}'.format(len(l), l) return reduce(lambda s, e: s * int(e) / gcd(s, int(e)) if e else s, arr, 1)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from functools import reduce gcd = lambda a, b: a if not b else gcd(b, a%b) lcm = lambda a, b: a * b / gcd(a, b) def min_special_mult(arr): errors = [] xs = set() for x in [_f for _f in arr if _f]: try: xs.add(int(x)) except: errors.append(x) if not errors: return reduce(lcm, xs) if not errors[1:]: return "There is 1 invalid entry: %s" % errors[0] return "There are %d invalid entries: %s" % (len(errors), errors)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from functools import reduce from math import gcd lcm = lambda x,y: x * y // gcd(x, y) def min_special_mult(arr): try: return abs(reduce(lcm, map(int, filter(None, arr)))) except ValueError: errors = [x for x in arr if type(x) != int and not (type(x) == str and x.isdigit())] if len(errors) == 1: return f"There is 1 invalid entry: {errors[0]}" return f"There are {len(errors)} invalid entries: {errors}"
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from fractions import gcd def lcm(a, b): return a * b // gcd(a, b) def min_special_mult(arr): valid, invalid = [], [] for x in filter(None, arr): try: valid.append(abs(int(x))) except ValueError: invalid.append(x) if len(invalid) == 1: return 'There is 1 invalid entry: {}'.format(invalid[0]) elif invalid: return 'There are {} invalid entries: {}'.format(len(invalid), invalid) return reduce(lcm, valid)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
def gcd(a,b): while b > 0: a, b = b, a % b return a def lcm(a, b): return a * b / gcd(a, b) def min_special_mult(arr): try: return reduce(lcm, map(abs, map(int, filter(None, arr)))) except: invalid = [i for i in arr if type(i) == str and not i.isdigit()] if len(invalid) == 1: return "There is 1 invalid entry: %s" % invalid[0] return "There are %s invalid entries: %s" % (len(invalid), invalid)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from fractions import gcd from functools import reduce import math def min_special_mult(arr): a = filter(lambda x:type(x)!=int, [i for i in arr if not str(i).lstrip("-").isdigit() and i!=None]) arr = [int(i) for i in arr if str(i).lstrip("-").isdigit()] if a: return "There {} {} invalid entr{}: {}".format("are" if len(a)>1 else "is",len(a),"ies" if len(a)>1 else "y",a if len(a)>1 else a[0]) return abs(reduce((lambda x,y : x*y/gcd(x,y)),arr))
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from fractions import gcd def min_special_mult(arr): def is_int(n): try: int(n) return True except: return False orig_arr = [x for x in arr if x] arr = [int(x) for x in orig_arr if is_int(x)] if len(orig_arr) - len(arr) > 0: freaks = [x for x in orig_arr if not is_int(x)] if len(freaks) > 1: return "There are {} invalid entries: {}".format(len(freaks), freaks) return "There is 1 invalid entry: {}".format(freaks[0]) arr = [abs(x) for x in arr] return reduce(lambda x, y: x * y // gcd(x, y), arr)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
def gcd(a,b): while b: a,b = b,a%b return a def lcd(a,b): return a*b/gcd(a,b) def checkstring(arr): strlist = [] for elem in arr: if type(elem) == str: strlist.append(elem) return strlist def converttoint(arr): intarray = [] for elem in arr: if elem is None: pass else: try: intarray.append(int(elem)) except: intarray.append(elem) return intarray def min_special_mult(arr): arr = converttoint(arr) if len(checkstring(arr)) == 1: return 'There is 1 invalid entry: ' + str(checkstring(arr)[0]) elif len(checkstring(arr)) > 1: return 'There are ' + str(len(checkstring(arr))) + ' invalid entries: ' + str(checkstring(arr)) current = 1 for elem in arr: current = lcd(current,elem) return current
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
from functools import reduce primes = [2, 3, 5, 7, 11, 13, 17] def gen_primes(): for p in primes: yield p next_prime = primes[-1] limit = int(next_prime ** 0.5) + 1 while True: next_prime += 2 if limit * limit < next_prime: limit += 2 for p in primes: if next_prime % p == 0: break if p > limit: primes.append(next_prime) yield next_prime break def gen_prime_factor_multiplicities(n): for p in gen_primes(): count = 0 while n % p == 0: count += 1 n /= p if count > 0: yield (p, count) if n == 1: break def min_special_mult(arr): bad = [] good = [] for a in arr: try: if a is not None: good.append(int(a)) except: bad.append(a) if bad: if len(bad) == 1: return "There is 1 invalid entry: {}".format(bad[0]) return "There are {} invalid entries: {}".format(len(bad), bad) maxes = {} for n in good: for p, m in gen_prime_factor_multiplicities(abs(n)): maxes[p] = max(maxes.get(p, m), m) factors = [p ** m for p, m in maxes.items()] return reduce(lambda a, b: a * b, factors)
Given a certain array of integers, create a function that may give the minimum number that may be divisible for all the numbers of the array. ```python min_special_mult([2, 3 ,4 ,5, 6, 7]) == 420 ``` The array may have integers that occurs more than once: ```python min_special_mult([18, 22, 4, 3, 21, 6, 3]) == 2772 ``` The array should have all its elements integer values. If the function finds an invalid entry (or invalid entries) like strings of the alphabet or symbols will not do the calculation and will compute and register them, outputting a message in singular or plural, depending on the number of invalid entries. ```python min_special_mult([16, 15, 23, 'a', '&', '12']) == "There are 2 invalid entries: ['a', '&']" min_special_mult([16, 15, 23, 'a', '&', '12', 'a']) == "There are 3 invalid entries: ['a', '&', 'a']" min_special_mult([16, 15, 23, 'a', '12']) == "There is 1 invalid entry: a" ``` If the string is a valid number, the function will convert it as an integer. ```python min_special_mult([16, 15, 23, '12']) == 5520 min_special_mult([16, 15, 23, '012']) == 5520 ``` All the `None`/`nil` elements of the array will be ignored: ```python min_special_mult([18, 22, 4, , None, 3, 21, 6, 3]) == 2772 ``` If the array has a negative number, the function will convert to a positive one. ```python min_special_mult([18, 22, 4, , None, 3, -21, 6, 3]) == 2772 min_special_mult([16, 15, 23, '-012']) == 5520 ``` Enjoy it
def min_special_mult(arr): #just simple "straight forward"... narr=[]; l=[]; c=0 for a in arr: if a==None: continue if isinstance(a,int): narr.append(a) else: try: if int(a)==a: narr.append(a); continue except: l.append(a); c+=1 if c==1: return "There is 1 invalid entry: "+l[0] if c>0: return "There are "+str(c)+" invalid entries: "+str(l) narr.sort(); n=narr[-1]; n1=n while True: f=0 for a in reversed(narr): if n%a!=0: f=1; break if f==0: return n n+=n1
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return ' '.join(letters[c] for c in word.upper())
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
def nato2(word): return ' '.join(letters[c.upper()] for c in word)
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return " ".join(letters[c.upper()] for c in word)
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
def nato(word): return ' '.join(map(letters.get, word.upper()))
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return " ".join([letters[l.upper()] for l in word])
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): stringlist = [] for ch in word.upper(): stringlist.append(letters[ch]) string = " ".join(stringlist) return string
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return ' '.join(letters.get(i.upper()) for i in word)
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return " ".join(map((lambda x: letters[x.upper()]), word))
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return " ".join([letters[c] for c in word.upper()])
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return ' '.join(letters[x.upper()] for x in word)
In this kata, we're going to create the function `nato` that takes a `word` and returns a string that spells the word using the [NATO phonetic alphabet](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet). There should be a space between each word in the returned string, and the first letter of each word should be capitalized. For those of you that don't want your fingers to bleed, this kata already has a dictionary typed out for you. ``` python nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ``` ``` ruby nato("Banana") # == "Bravo Alpha November Alpha November Alpha" ```
letters = { "A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "Echo", "F": "Foxtrot", "G": "Golf", "H": "Hotel", "I": "India", "J": "Juliett","K": "Kilo", "L": "Lima", "M": "Mike", "N": "November","O": "Oscar", "P": "Papa", "Q": "Quebec", "R": "Romeo", "S": "Sierra", "T": "Tango", "U": "Uniform", "V": "Victor", "W": "Whiskey", "X": "X-ray", "Y": "Yankee", "Z": "Zulu" } def nato(word): return ' '.join([letters[letter.upper()] for letter in word])
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): arr = [] while lst != None: arr.append(lst.value) lst = lst.next return arr
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): return ([lst.value] + list_to_array(lst.next)) if lst else []
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(ll): output = [] while ll: output.append(ll.value) ll = ll.__next__ return output
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): res = [] while lst: res.append(lst.value) lst = lst.__next__ return res
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): list = [] while lst is not None: list.append(lst.value) lst = lst.__next__ return list
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
list_to_array = lambda l: list() if l == None else [l.value] + list_to_array(l.next)
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): list=[] while lst: list.append(lst.value) lst=lst.next return list
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(lst): array = [] while lst: array.append(lst.value) lst = lst.next return array
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(node): return [] if node is None else [node.value] + list_to_array(node.next)
Linked lists are data structures composed of nested or chained objects, each containing a single value and a reference to the next object. Here's an example of a list: ```python class LinkedList: def __init__(self, value=0, next=None): self.value = value self.next = next LinkedList(1, LinkedList(2, LinkedList(3))) ``` Write a function listToArray (or list\_to\_array in Python) that converts a list to an array, like this: ``` [1, 2, 3] ``` Assume all inputs are valid lists with at least one value. For the purpose of simplicity, all values will be either numbers, strings, or Booleans.
def list_to_array(node): arr = [] while node: arr.append(node.value) node = node.next return arr
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
from collections import Counter def count_feelings(s, arr): total = sum(Counter(s) & Counter(w) == Counter(w) for w in arr) return '%s feeling%s.' % (total, '' if total == 1 else 's')
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
from collections import Counter def count_feelings(stg, lst): letters = Counter(stg) count = sum(1 for feeling in lst if not Counter(feeling) - letters) return f"{count} feeling{'s' if count != 1 else ''}."
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
def count_feelings(s, arr): return next(f'{x} feeling{["s", ""][x == 1]}.' for x in [sum(all(s.count(c) >= x.count(c) for c in x) for x in arr)])
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
from collections import Counter def count_feelings(s, arr): sc = Counter(s) n = sum(all(sc[c] >= x for c, x in Counter(feeling).items()) for feeling in arr) return f'{n} feeling{"" if n == 1 else "s"}.'
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
from collections import Counter def count_feelings(s, arr): count = sum(1 for f in arr if not Counter(f) - Counter(s)) return '{} feeling{}.'.format(count, '' if count == 1 else 's')
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
def count_feelings(s, arr): count = sum([all([char in s and s.count(char) >= f.count(char) for char in f]) for f in arr]) return '{count} {tense}.'.format(count=count, tense='feeling' if count == 1 else 'feelings')
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
def count_feelings(s, arr): c = 0 for i in arr: r = True for j in i: if (j not in s) or (i.count(j) > s.count(j)): r = False if r: c+=1 return str(c) + ' feelings.' if c != 1 else str(c) + ' feeling.'
You have two arguments: ```string``` - a string of random letters(only lowercase) and ```array``` - an array of strings(feelings). Your task is to return how many specific feelings are in the ```array```. For example: ``` string -> 'yliausoenvjw' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '3 feelings.' // 'awe', 'joy', 'love' string -> 'griefgriefgrief' array -> ['anger', 'awe', 'joy', 'love', 'grief'] output -> '1 feeling.' // 'grief' string -> 'abcdkasdfvkadf' array -> ['desire', 'joy', 'shame', 'longing', 'fear'] output -> '0 feelings.' ``` If the feeling can be formed once - plus one to the answer. If the feeling can be formed several times from different letters - plus one to the answer. Eeach letter in ```string``` participates in the formation of all feelings. 'angerw' -> 2 feelings: 'anger' and 'awe'.
from collections import Counter def count_feelings(s, arr): count = sum([1 for word in arr if len(Counter(word) - Counter(s))==0]) return "{} feeling{}.".format(count,"" if count==1 else "s")
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pkmntype): self.name = name self.level = level self.pkmntype = pkmntype def info(self): level_info = "weak" if self.level <= 20 else "fair" if self.level <= 50 else "strong" pkmntypes_info = {"water": "wet", "fire": "fiery", "grass": "grassy",} return "{}, a {} and {} Pokemon.".format(self.name, pkmntypes_info[self.pkmntype], level_info)
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pkmntype): self.name = name self.level = level self.pkmntype = pkmntype @property def element(self): return {'water': 'wet', 'fire': 'fiery', 'grass': 'grassy'}.get(self.pkmntype, '?') @property def strength(self): return 'strong' if self.level > 50 else 'fair' if self.level > 20 else 'weak' def info(self): return '{}, a {} and {} Pokemon.'.format(self.name, self.element, self.strength)
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pkmntype): self.name = name self.level = level self.pkmntype = pkmntype def level_description(self): if 20 < self.level <= 50: return 'fair' elif self.level > 50: return 'strong' return 'weak' def info(self): return { 'water': '{}, a wet and {} Pokemon.', 'fire' : '{}, a fiery and {} Pokemon.', 'grass': '{}, a grassy and {} Pokemon.' }[self.pkmntype].format(self.name, self.level_description())
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: LVL_CONVERT = [(20, 'weak'), (50, 'fair'), (float('inf'), 'strong')] TYPE_CONVERT = {'fire': 'fiery', 'water':'wet', 'grass':'grassy'} def __init__(self, name, level, typ): self.name, self.lvl, self.typ = name, level, typ def info(self): return f'{ self.name }, a { self.TYPE_CONVERT[self.typ] } and { self.getLvlKind() } Pokemon.' def getLvlKind(self): return next( v for th,v in self.LVL_CONVERT if self.lvl<=th )
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, ptype): self.name = name self.level = level self.ptype = ptype def strength(self): return 'strong' if self.level > 50 else 'fair' if self.level > 20 else 'weak' def obs_type(self): return {'water': 'wet', 'fire': 'fiery', 'grass': 'grassy'}.get(self.ptype, 'unknown') def info(self): return "%s, a %s and %s Pokemon." % (self.name, self.obs_type(), self.strength())
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
import enum class PokemonType(enum.Enum): Water = 1, Fire = 2, Grass = 3 @classmethod def from_string(cls, type_str): return {"water": cls.Water, "fire": cls.Fire, "grass": cls.Grass}[type_str] def __str__(poketype): return {PokemonType.Water: "wet", PokemonType.Fire: "fiery", PokemonType.Grass: "grassy"}[poketype] class PokeScan(object): def __init__(self, name, level, pokemon_type): self.name, self.level = name, level self.pkmntype = PokemonType.from_string(pokemon_type) @property def strength(self): if self.level <= 20: return "weak" return "fair" if self.level <= 50 else "strong" def info(self): infos = {"name": self.name, "type": str(self.pkmntype), "strength": self.strength} return "{name}, a {type} and {strength} Pokemon.".format(**infos)
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pkmntype): self.name = name self.level = level self.pkmntype = pkmntype def info(self): type_words = {'water': 'wet', 'fire':'fiery', 'grass':'grassy'} outstring = self.name + ', a ' outstring += type_words.get(self.pkmntype) + ' and ' if self.level<=20: outstring += 'weak' elif self.level<=50: outstring += 'fair' else: outstring += 'strong' outstring += ' Pokemon.' return outstring
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan(object): def __init__(self, name, level, pkmntype): self.name = name if level <= 20: self.level = 'weak' elif level <= 50: self.level = 'fair' else: self.level = 'strong' self.type = { 'water': 'wet', 'fire': 'fiery', 'grass': 'grassy' }[pkmntype] def info(self): return '{}, a {} and {} Pokemon.'.format( self.name, self.type, self.level )
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pkmntype): self.info = lambda: "{}, a {} and {} Pokemon.".format(name, {'water': 'wet', 'fire': 'fiery', 'grass': 'grassy'}[pkmntype], ['weak', 'fair', 'strong'][(level > 20) + (level > 50)])
Professor Oak has just begun learning Python and he wants to program his new Pokedex prototype with it. For a starting point, he wants to instantiate each scanned Pokemon as an object that is stored at Pokedex's memory. He needs your help! Your task is to: 1) Create a ```PokeScan``` class that takes in 3 arguments: ```name```, ```level``` and ```pkmntype```. 2) Create a ```info``` method for this class that returns some comments about the Pokemon, specifying it's name, an observation about the ```pkmntype``` and other about the ```level```. 3) Keep in mind that he has in his possession just three Pokemons for you to test the scanning function: ```Squirtle```, ```Charmander``` and ```Bulbasaur```, of ```pkmntypes``` ```water```, ```fire``` and ```grass```, respectively. 4) The ```info``` method shall return a string like this: ```Charmander, a fiery and strong Pokemon.``` 5) If the Pokemon level is less than or equal to 20, it's a ```weak``` Pokemon. If greater than 20 and less than or equal to 50, it's a ```fair``` one. If greater than 50, it's a ```strong``` Pokemon. 6) For the ```pkmntypes```, the observations are ```wet```, ```fiery``` and ```grassy``` Pokemon, according to each Pokemon type. IMPORTANT: The correct spelling of "Pokémon" is "Pokémon", with the ```"é"```, but to maximize the compatibility of the code I've had to write it as ```"Pokemon"```, without the ```"é"```. So, in your code, don't use the ```"é"```.
class PokeScan: def __init__(self, name, level, pokemon_type): adjective = {"water": "wet", "fire": "fiery", "grass": "grassy"}[pokemon_type] rank = "weak" if level <= 20 else "fair" if level <= 50 else "strong" self.info = lambda: f"{name}, a {adjective} and {rank} Pokemon."
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): l = [str(n)] while n > 1: n = 3 * n + 1 if n % 2 else n / 2 l.append(str(n)) return '->'.join(l)
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz_step(n): if n % 2 == 0: return n//2 else: return n*3 + 1 def collatz_seq(n): while n != 1: yield n n = collatz_step(n) yield 1 def collatz(n): return '->'.join(str(x) for x in collatz_seq(n))
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): return str(n) + '->' + collatz(3*n+1 if n%2 else n/2) if n != 1 else '1'
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def _collatz(n): yield n while n != 1: n = (n // 2, 3 * n + 1)[n % 2] yield n def collatz(n): return '->'.join(map(str, _collatz(n)))
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): ret = [] while n!= 1: ret.append(n) n = [n//2, (n*3)+1][n%2] return '->'.join( map( str, ret+[1] ) )
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): l = [str(n)] while n != 1: if n%2: n = 3*n+1 else: n = n//2 l.append(str(n)) return '->'.join(l)
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): numbers = sequence(n) result = '->'.join(map(str, numbers)) return result def sequence(n): if n == 1: return [1] elif n % 2 == 0: return [n] + sequence(n // 2) else: return [n] + sequence(3 * n + 1)
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): def f(n): while True: yield str(n) if n == 1: break elif n % 2: n = 3*n + 1 else: n //= 2 return '->'.join(f(n))
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): collatz = str(n) + '->' while n != 1: n = n / 2 if n % 2 == 0 else n * 3 + 1 collatz += str(n) + '->' return collatz.rstrip('->')
## Preface A collatz sequence, starting with a positive integern, is found by repeatedly applying the following function to n until n == 1 : `$f(n) = \begin{cases} n/2, \text{ if $n$ is even} \\ 3n+1, \text{ if $n$ is odd} \end{cases}$` ---- A more detailed description of the collatz conjecture may be found [on Wikipedia](http://en.wikipedia.org/wiki/Collatz_conjecture). ## The Problem Create a function `collatz` that returns a collatz sequence string starting with the positive integer argument passed into the function, in the following form: "X0->X1->...->XN" Where Xi is each iteration of the sequence and N is the length of the sequence. ## Sample Input ```python collatz(4) # should return "4->2->1" collatz(3) # should return "3->10->5->16->8->4->2->1" ``` Don't worry about invalid input. Arguments passed into the function are guaranteed to be valid integers >= 1.
def collatz(n): seq = [str(n)] while n > 1: n = (3 * n + 1) if (n % 2) else (n // 2) seq.append(str(n)) return "->".join(seq)
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*args): return sum(args) == 1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*args): return args.count(True)==1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*args): count = 0 for item in args: if item: count += 1 if count == 2: return False return True if count == 1 else False
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*x): return x.count(True) == 1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*flags): return sum(flags) == 1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
from collections import Counter def only_one(*booleans): return Counter(booleans)[True] == 1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
only_one = lambda *a: sum(a) == 1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*flags): return len([a for a in flags if a])==1
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*bool): sum = 0 for value in bool: if value: sum += 1 if sum == 1: return True else: return False
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False, False, False, False) == False ```
def only_one(*bools): return sum(x for x in bools) == 1
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from functools import reduce from gmpy2 import comb from operator import xor def transform(a, x): return reduce(xor, (comb(n + 1, x + 1) for n in a))
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
def transform(A, x): c, i, f, r = 1, x, 0, None for n in sorted(A): while i <= n: c *= i c //= i-x or x i += 1 f += c if r is None: r = f else: r ^= f return r
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from functools import reduce def transform(lst, r): return reduce(int.__xor__, (F(n, r) for n in lst)) def F(n, r): t = 1 for i in range(1, r + 2): t = t * (n - i + 2) // i return t
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from gmpy2 import comb from operator import xor from functools import reduce transform = lambda A,x: reduce(xor, (comb(n+1, x+1) for n in A))
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from functools import reduce from operator import xor F = [[0] * 11 for i in range(10001)] for x in range(1, 11): F[x][x] = y = 1 for i in range(x+1, 10001): y = y * i // (i-x) F[i][x] = F[i-1][x] + y def transform(A, x): return reduce(xor, (F[a][x] for a in A))
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from functools import reduce from operator import xor from scipy.misc import comb def transform(A, x): return reduce(xor, map(lambda n: comb(n+1,x+1,exact=True),A))
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from scipy.special import binom from operator import xor from functools import reduce def transform(A, x): return reduce(xor, [int(round(binom(n + 1, x + 1))) for n in A])
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from gmpy2 import comb from operator import xor from functools import reduce def transform(A, x): return reduce( xor ,(comb(n+1,x+1) for n in A))
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from functools import reduce from itertools import accumulate def transform(a,x): b=sorted(set([x]+a)) C=[[1]] def g(m,n): w=[C[-1][-1]] for i,j in enumerate(m,start=1): w.append(w[i-1]*j/(j-n)) return C.append(w[1:]) for j in (range(b[i-1]+1,b[i]+1) for i in range(1,len(b))): g(j,x) v={x:y for x,y in zip(b,accumulate(int(sum(i)) for i in C))} return reduce(lambda x,y:x^y,[v[i] for i in a])
Given an array `A` and an integer `x`, map each element in the array to `F(A[i],x)` then return the xor sum of the resulting array. where F(n,x) is defined as follows: F(n, x) = ^(x)Cx **+** ^(x+1)Cx **+** ^(x+2)Cx **+** ... **+** ^(n)Cx and ^(n)Cx represents [Combination](https://en.m.wikipedia.org/wiki/Combination) in mathematics ### Example ```python a = [7, 4, 11, 6, 5] x = 3 # after mapping, `a` becomes [F(7,3), F(4,3), F(11,3), F(6,3), F(5,3)] return F(7,3) ^ F(4,3) ^ F(11,3) ^ F(6,3) ^ F(5,3) #=> 384 ``` ##### e.g F(7, 3) = ^(3)C3 + ^(4)C3 + ^(5)C3 + ^(6)C3 + ^(7)C3 ## Constraints **1 <= x <= 10** **x <= A[i] <= 10^(4)** **5 <= |A| <= 10^(3)**
from scipy.special import comb as f from functools import reduce def transform(arr, n): arr = (f(x+1, n+1, exact=True) for x in arr) return reduce(lambda x,y: x^y, arr)
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): return [name for i, row in enumerate(arr) for name in row[::-1 if i % 2 else 1]]
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): rota = [] for i, row in enumerate(arr): if i % 2: row = reversed(row) rota.extend(row) return rota
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): res = [] for i in range(len(arr)): res.extend(arr[i][::(-1)**i]) return res
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): return [y for x in arr for y in (x, x[::-1])[arr.index(x) % 2]]
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): return [seat for row, seats in enumerate(arr) for seat in seats[::(-1)**row]]
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): res = [] for i in range(len(arr)): if i%2 == 1: res.extend(arr[i][::-1]) else: res.extend(arr[i]) return res
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): return list(office(arr)) def office(arr): w = 0 for e in arr: yield from e[::[1,-1][w]] w = not w
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
binRota=lambda a:[p for i,l in enumerate(a)for p in l[::1-i%2*2]]
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): res = [] for k, l in enumerate(arr): print k, l if k % 2 == 0: for w in l: res.append(w) else: for w in l[::-1]: res.append(w) return res
A startup office has an ongoing problem with its bin. Due to low budgets, they don't hire cleaners. As a result, the staff are left to voluntarily empty the bin. It has emerged that a voluntary system is not working and the bin is often overflowing. One staff member has suggested creating a rota system based upon the staff seating plan. Create a function `binRota` that accepts a 2D array of names. The function will return a single array containing staff names in the order that they should empty the bin. Adding to the problem, the office has some temporary staff. This means that the seating plan changes every month. Both staff members' names and the number of rows of seats may change. Ensure that the function `binRota` works when tested with these changes. **Notes:** - All the rows will always be the same length as each other. - There will be no empty spaces in the seating plan. - There will be no empty arrays. - Each row will be at least one seat long. An example seating plan is as follows: ![](http://i.imgur.com/aka6lh0l.png) Or as an array: ``` [ ["Stefan", "Raj", "Marie"], ["Alexa", "Amy", "Edward"], ["Liz", "Claire", "Juan"], ["Dee", "Luke", "Katie"] ] ``` The rota should start with Stefan and end with Dee, taking the left-right zigzag path as illustrated by the red line: As an output you would expect in this case: ``` ["Stefan", "Raj", "Marie", "Edward", "Amy", "Alexa", "Liz", "Claire", "Juan", "Katie", "Luke", "Dee"]) ```
def binRota(arr): arr[1::2] = map(lambda x: x[::-1], arr[1::2]) return sum(arr,[])
## Decode the diagonal. Given a grid of characters. Output a decoded message as a string. Input ``` H Z R R Q D I F C A E A ! G H T E L A E L M N H P R F X Z R P E ``` Output `HITHERE!` (diagonally down right `↘` and diagonally up right `↗` if you can't go further). The message ends when there is no space at the right up or down diagonal. To make things even clearer: the same example, but in a simplified view ``` H _ _ _ _ _ I _ _ _ _ _ ! _ _ T _ _ _ E _ _ _ H _ R _ _ _ _ _ E ```
def get_diagonale_code(grid): grid = [line.split() for line in grid.split("\n")] i, j, d, word = 0, 0, 1, "" while 0 <= i < len(grid) and j < len(grid[i]): if 0 <= j < len(grid[i]): word += grid[i][j] i, j = i + d, j + 1 else: i += d if i == 0 or i == len(grid) - 1: d = -d return word
## Decode the diagonal. Given a grid of characters. Output a decoded message as a string. Input ``` H Z R R Q D I F C A E A ! G H T E L A E L M N H P R F X Z R P E ``` Output `HITHERE!` (diagonally down right `↘` and diagonally up right `↗` if you can't go further). The message ends when there is no space at the right up or down diagonal. To make things even clearer: the same example, but in a simplified view ``` H _ _ _ _ _ I _ _ _ _ _ ! _ _ T _ _ _ E _ _ _ H _ R _ _ _ _ _ E ```
def get_diagonale_code(grid: str) -> str: if not grid: return '' s=[] for line in grid.split('\n'): s.append(line.split(' ')) if len(s)==1: return s[0][0] x,y=0,0 m=-1 r='' while(y<len(s[x])): r+=s[x][y] if x==0 or x==len(s)-1: m*=-1 x+=m y+=1 return r