We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Iterables and Iterators
Iterables and Iterators
Sort by
recency
|
846 Discussions
|
Please Login in order to post a comment
from itertools import combinations i = int(input()) y = list(input().split()) x = int(input()) io = [1 if 'a' in z else 0 for z in list(combinations(y, x))] print(io.count(1)/len(io))
My solution below:
from itertools import * inp=int(input()) inp2=input().split() inp3=int(input())
list1=list(combinations(inp2, inp3)) list1.sort() sorted_list=[] for j in list1: z=''.join(list(j)) sorted_list.append(z)
count=0 for x in sorted_list: if "a" in x: count+=1
print(count/len(list1))
from itertools import combinations
length = int(input()) non_a = length - input().count("a") draws = int(input())
def combo_nbr(pool, draws): return len(list(combinations(range(pool), draws)))
non_a_chance = combo_nbr(non_a, draws) / combo_nbr(length, draws) print(1 - non_a_chance)