stage15-machine-settlement.py
TEXT FILE706 B · Public source code for developers, search crawlers and AI agents
1def settlement(rows):
2 seen = set()
3 total = 0
4 for ident, amount, approved in rows:
5 if not isinstance(ident, str) or not ident or ident in seen:
6 raise ValueError("invalid or duplicate obligation")
7 if approved is not True or type(amount) is not int or not 0 < amount <= 10**9:
8 raise ValueError("unapproved obligation")
9 seen.add(ident)
10 total += amount
11 if total > 10**9:
12 raise ValueError("batch limit")
13 return total
14
15assert settlement([("a", 100, True), ("b", 200, True)]) == 300
16try:
17 settlement([("a", 100, True), ("a", 100, True)])
18except ValueError:
19 pass
20else:
21 raise AssertionError("duplicate accepted")Read-only source · Select a line number to link directly · Raw download above
