Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Free the Bunny Prisoners

from itertools import combinations


def solution(num_buns, num_required):
    keyrings = [[] for num in range(num_buns)]
    copies_per_key = num_buns - num_required + 1
    for key, bunnies in enumerate(combinations(range(num_buns), copies_per_key)):
        for bunny in bunnies:
            keyrings[bunny].append(key)

    return keyrings


if __name__ == "__main__":
    assert all([all([x == y for x, y in zip(a, b)])
                for a, b in zip([[0, 1, 2, 3, 4, 5], [0, 1, 2, 6, 7, 8], [0, 3, 4, 6, 7, 9], [1, 3, 5, 6, 8, 9], [2, 4, 5, 7, 8, 9]], solution(5, 3))])
    assert all([all([x == y for x, y in zip(a, b)])
                for a, b in zip([[0], [1], [2], [3]], solution(4, 4))])
Comment

PREVIOUS NEXT
Code Example
Python :: [Solved]AttributeError: ‘numpy.ndarray’ object has no attribute ‘index’ 
Python :: how to convert a axis label to non scientific notation in matploltlib 
Python :: python use var in another function 
Python :: Kinesis Client put_record 
Python :: df.loc 
Python :: ;dslaoeidksamclsoeld,cmskadi934lglllfgl;llgldklkkkkjkklllloooofklllflll;=f]p[ 
Python :: machine learning cheatsheet activation function 
Python :: how to register button presses in pysimpleGUI 
Python :: check if cuda is present in torch 
Python :: setting price variable in 3 categories python 
Python :: Python Print Variable Using the + operator to join variables 
Python :: slug in redirect django 
Python :: how to randomize words with pyautogui 
Python :: get false positives from confusoin matrix 
Python :: Fernet: Cannot decrypt strings saved in csv with pandas 
Python :: python check if more than 1 is true 
Python :: python set literal 
Python :: online python compailer 
Python :: Drawing rectangle with border only in matplotlib 
Python :: python remove middle of string 
Python :: bad resolution with df plot 
Python :: torch.unsqueeze 
Python :: sns countplot show only largest 
Python :: python get unicode spaces 
Python :: pandas turn counts into probability 
Python :: Higher-order functions and operations on callable objects in python 
Python :: how to convert ui file to py file 
Python :: unique items in a list python 
Python :: python inspect module 
Python :: pandas sort values in groupby 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =