stage17-rolling-window.py
TEXT FILE627 B · Public source code for developers, search crawlers and AI agents
1"""Offline educational example; no wallet calls."""
2def available(now, window, ceiling, settled, pending):
3 if any(type(x) is not int or x <= 0 for x in (window, ceiling)):
4 raise ValueError("invalid policy")
5 if any(type(t) is not int or t > now or type(a) is not int or a <= 0 for t,a in settled) or any(type(a) is not int or a <= 0 for a in pending):
6 raise ValueError("invalid ledger")
7 return max(0, ceiling - sum(a for t,a in settled if now-window < t <= now) - sum(pending))
8
9assert available(100, 20, 1000, [(80, 200), (81, 300)], [400]) == 300
10assert available(1000, 20, 1000, [], [400]) == 600Read-only source · Select a line number to link directly · Raw download above
