Article de recherche · Avent 2026
wieniec.py
Code source permettant de reproduire les résultats. Il passe en revue tous les schémas d'allumage admissibles et détermine celui qui consume la couronne le plus uniformément. Lancé avec l'option --all, il retrouve tous les nombres de l'article (env. 15 s, surtout à cause du découpage en trois parts).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #!/usr/bin/env python3 """ wieniec.py -- replication code for "On the Uniform Burning of Advent Wreath Candles" (czteryswiece.ponadmurami.pl) Exhaustively enumerates every way of lighting the candles of an Advent wreath and reports how evenly they burn down. Model * n candles (default 4), n Sundays of Advent. * Every Sunday is one session of equal length, optionally split into m equal parts. * In every part of Sunday k exactly k candles burn (k = 1..n). * All candles burn at the same, constant rate. * --pink: candle no. 3 (the pink one, Gaudete) may not burn before Sunday 3 and must burn at least once on Sunday 3. Usage python wieniec.py # whole Sundays, no pink rule python wieniec.py -m 2 # Sundays split into halves python wieniec.py -m 2 --pink # halves + pink candle waits for Gaudete python wieniec.py --all # the table from the paper Ponad Murami, Advent 2026. Public domain (CC0). No candles were harmed. """ import argparse from collections import Counter from fractions import Fraction from itertools import combinations, product PINK = 2 # zero-based index of the pink candle (the third one) def slots(n, m): """All (sunday, part) pairs in chronological order.""" return [(k, p) for k in range(1, n + 1) for p in range(m)] def schedules(n, m, pink): """Yield every admissible schedule: a tuple of sets of burning candles, one per slot.""" sl = slots(n, m) options = [] for k, _ in sl: opts = list(combinations(range(n), k)) if pink and k < 3: opts = [c for c in opts if PINK not in c] options.append(opts) for sch in product(*options): if pink and not any(PINK in s for s, (k, _) in zip(sch, sl) if k == 3): continue yield sch def usage(sch, n): """How many parts each candle has burned.""" u = [0] * n for s in sch: for c in s: u[c] += 1 return u def unevenness(u, n, m): """(max - min, total deviation from the fair share), both in Sundays.""" fair = Fraction(m * (n + 1), 2) # parts per candle if perfectly fair spread = Fraction(max(u) - min(u), m) dev = sum(abs(x - fair) for x in u) / m return spread, dev def analyse(n, m, pink, show=3): total, best, hits, examples = 0, None, Counter(), [] for sch in schedules(n, m, pink): total += 1 key = unevenness(usage(sch, n), n, m) hits[key] += 1 if best is None or key < best: best, examples = key, [] if key == best and len(examples) < show: examples.append(sch) return total, best, hits[best], examples def fmt(sch, n, m): names = "ABCD" if n == 4 else [str(i + 1) for i in range(n)] out, sl = [], slots(n, m) for k in range(1, n + 1): parts = [s for s, (kk, _) in zip(sch, sl) if kk == k] out.append(f"Sunday {k}: " + " | ".join("".join(names[c] for c in p) for p in parts)) return "\n ".join(out) def report(n, m, pink): total, (spread, dev), count, ex = analyse(n, m, pink) label = f"n={n}, parts={m}, pink rule={'on' if pink else 'off'}" print(f"== {label}") print(f" admissible schedules : {total}") print(f" best spread (Sundays): {spread} total deviation: {dev}") print(f" schedules achieving it: {count}") print(" " + ("PERFECT: all candles burn equally." if spread == 0 else "Perfect equality is IMPOSSIBLE.")) for sch in ex: print(" " + fmt(sch, n, m)) print(" usage in parts:", usage(sch, n)) print() def greedy(n, m): """Constructive proof of Theorem 3: always light the k least-burned candles.""" u = [0] * n for k in range(1, n + 1): for _ in range(m): for c in sorted(range(n), key=lambda i: (u[i], i))[:k]: u[c] += 1 return u if __name__ == "__main__": ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) ap.add_argument("-n", type=int, default=4, help="number of candles / Sundays (default 4)") ap.add_argument("-m", type=int, default=1, help="parts per Sunday (default 1)") ap.add_argument("--pink", action="store_true", help="pink candle waits for Gaudete") ap.add_argument("--all", action="store_true", help="print the full table from the paper") a = ap.parse_args() if a.all: for m in (1, 2, 3): for pink in (False, True): report(4, m, pink) print("== Theorem 3 (greedy), n candles x m parts: '=' perfect, '~' not") for n in range(2, 9): print(f" n={n}: " + " ".join("=" if len(set(greedy(n, m))) == 1 else "~" for m in range(1, 7))) else: report(a.n, a.m, a.pink) |