hidden-capability-math / code /generators /combinatorics.py
ahmed-wez's picture
Candidate development release: 5000 verified tasks; evaluation withheld
6a48c9d verified
Raw History Blame Contribute Delete
4.01 kB
from common import register
D = 'combinatorics'
def add(n, c, t, s, e, **kw):
register(D, n, c, t, s, e, **kw)
add('committee_groups', [['There are {a} people in group A and {b} in group B, all distinct.', 'Two disjoint groups contain {a} and {b} distinct people.', 'Group A has {a} members, and group B has {b} different members.'], ['Form a committee with {r} people from A and {s} from B.', 'Choose exactly {r} A-members and {s} B-members for an unordered committee.', 'An unordered committee must include {r} people from the first group and {s} from the second.']], ['How many committees are possible?', 'Count the valid committees.', 'Determine the number of selections.'], lambda r: dict(a=r.randint(7, 30), b=r.randint(7, 30), r=r.randint(2, 5), s=r.randint(2, 5)), [('choices_A', 'C(a,r)'), ('answer', 'choices_A*C(b,s)')], level='easy')
add('nonadjacent_selection', [['Choose {k} positions from a row of {n} numbered positions, with no two chosen positions consecutive.', 'A row has {n} distinct positions; select {k} such that no adjacent pair is selected.', 'Among positions 1 through {n}, select {k} positions and forbid consecutive selections.']], ['How many selections are possible?', 'Count the valid position sets.', 'Determine the number of allowed subsets.'], lambda r: dict(n=r.randint(18, 45), k=r.randint(3, 8)), [('compressed_length', 'n-k+1'), ('answer', 'C(compressed_length,k)')], level='medium', depth=3)
add('surjections_three', [['Assign {n} distinct objects to {m} labeled boxes, with every box nonempty.', 'Distribute {n} distinguishable objects among {m} distinct boxes, using every box.', 'Each of {n} distinct objects goes to one of {m} labeled boxes; no box may be empty.']], ['How many assignments are there?', 'Count the onto assignments.', 'Determine the number of permitted distributions.'], lambda r: (lambda m: dict(m=m, n=r.randint(m + 1, 35)))(r.randint(3, 7)), [('answer', 'Sum((-1)**j*C(m,j)*(m-j)**n,(j,0,m))')], level='hard', depth=3, concepts=3)
add('bounded_compositions', [['Integers x_1 through x_{k} satisfy 0 <= x_i <= {u} and their sum is {n}.', 'Choose {k} ordered integers from 0 through {u}, requiring their total to be {n}.', 'An ordered tuple has {k} entries, each an integer between 0 and {u} inclusive, with sum {n}.']], ['How many tuples satisfy these constraints?', 'Count the bounded ordered compositions.', 'Determine the number of allowed integer tuples.'], lambda r: (lambda k, u: dict(k=k, u=u, n=r.randint(u + 1, (k - 1) * u)))(r.randint(3, 7), r.randint(4, 12)), [('answer', 'Sum((-1)**j*C(k,j)*Piecewise((C(n-j*(u+1)+k-1,k-1),n-j*(u+1)>=0),(0,True)),(j,0,k))')], level='hard', depth=4, concepts=3)
add('binary_no_adjacent', [['Consider strings of length {n} over {m} distinct symbols; a designated symbol cannot occur twice consecutively.', 'A string has {n} entries from an alphabet of {m} symbols; no two adjacent entries may both be the designated symbol.', 'Form length-{n} strings over {m} distinct symbols, forbidding consecutive occurrences of one designated symbol.']], ['How many strings satisfy the condition?', 'Count the permitted binary strings.', 'Determine the number of valid strings.'], lambda r: dict(n=r.randint(5, 25), m=r.randint(2, 12)), [('answer', 'Sum(C(n-j+1,j)*(m-1)**(n-j),(j,0,floor((n+1)/2)))')], level='medium', depth=3)
add('positive_compositions', [['There are {n} identical counters and {k} labeled boxes; every box must receive at least {m} counters.', 'Distribute {n} indistinguishable counters among {k} distinct boxes, giving each box at least {m}.', 'The {k} boxes are labeled, the {n} counters are identical, and no box may receive fewer than {m} counters.']], ['How many distributions are possible?', 'Count the allowed allocations.', 'Determine the number of distributions satisfying the minimum.'], lambda r: (lambda k, m: dict(k=k, m=m, n=k * m + r.randint(5, 50)))(r.randint(3, 10), r.randint(2, 8)), [('unreserved', 'n-k*m'), ('answer', 'C(unreserved+k-1,k-1)')], level='easy', depth=3)