omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / combinations-with-repetitions / oracle.py
| 1 | # Independent reference for "Combinations with repetitions" (Python 3, standard library only). |
| 2 | # expected.txt is this program's stdout; omc never produced it. |
| 3 | # Cross-check, WolframLanguageEvaluator: {Binomial[3 + 2 - 1, 2], Binomial[10 + 3 - 1, 3]} -> {6, 220} |
| 4 | from itertools import product |
| 5 | from math import comb |
| 6 | kinds = ["iced", "jam", "plain"] |
| 7 | # all ordered pairs, keeping those already in non-decreasing order |
| 8 | for a, b in product(range(3), repeat=2): |
| 9 | if a <= b: |
| 10 | print(kinds[a], kinds[b]) |
| 11 | n = sum(1 for t in product(range(10), repeat=3) if t[0] <= t[1] <= t[2]) |
| 12 | assert n == comb(10 + 3 - 1, 3) |
| 13 | print("choices of 3 from 10 kinds:", n) |